@ckb-ccc/lumos-patches 0.0.10-alpha.7 → 0.0.12-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/default.d.ts +2 -2
- package/dist/default.d.ts.map +1 -1
- package/dist/default.js +45 -20
- package/dist.commonjs/default.d.ts +2 -2
- package/dist.commonjs/default.d.ts.map +1 -1
- package/dist.commonjs/default.js +45 -20
- package/package.json +4 -2
- package/src/default.ts +62 -26
package/dist/default.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
1
2
|
import { LockScriptInfo } from "@ckb-lumos/common-scripts";
|
|
2
|
-
import { CellDep, Script } from "@ckb-lumos/base";
|
|
3
3
|
/**
|
|
4
4
|
* Generates custom lock script information.
|
|
5
5
|
* @param {string} codeHash - The code hash of the custom script.
|
|
6
6
|
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
7
7
|
* @returns {LockScriptInfo} The lock script information.
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateScriptInfo(codeHash: string, cellDeps:
|
|
9
|
+
export declare function generateScriptInfo(codeHash: string, cellDeps: ccc.CellDepInfoLike[]): LockScriptInfo;
|
|
10
10
|
/**
|
|
11
11
|
* Generates default script information for CCC.
|
|
12
12
|
* @returns {LockScriptInfo[]} An array of lock script information.
|
package/dist/default.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAWpC,OAAO,EAEL,cAAc,EAEf,MAAM,2BAA2B,CAAC;AAqGnC;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,GAAG,CAAC,eAAe,EAAE,GAC9B,cAAc,CAwEhB;AAWD;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,cAAc,EAAE,CAc7D"}
|
package/dist/default.js
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { cccA } from "@ckb-ccc/core/advanced";
|
|
2
3
|
import { bytes } from "@ckb-lumos/codec";
|
|
3
|
-
import { parseFromInfo } from "@ckb-lumos/common-scripts";
|
|
4
|
-
import { addCellDep } from "@ckb-lumos/common-scripts/lib/helper";
|
|
4
|
+
import { parseFromInfo, } from "@ckb-lumos/common-scripts";
|
|
5
5
|
import { getConfig } from "@ckb-lumos/config-manager";
|
|
6
6
|
import { asserts } from "./utils.js";
|
|
7
|
+
function addCellDep(txSkeleton, newCellDep) {
|
|
8
|
+
const cellDep = txSkeleton.get("cellDeps").find((cellDep) => {
|
|
9
|
+
return (cellDep.depType === newCellDep.depType &&
|
|
10
|
+
ccc.OutPoint.from(cellDep.outPoint).eq(ccc.OutPoint.from(newCellDep.outPoint)));
|
|
11
|
+
});
|
|
12
|
+
if (!cellDep) {
|
|
13
|
+
txSkeleton = txSkeleton.update("cellDeps", (cellDeps) => {
|
|
14
|
+
return cellDeps.push({
|
|
15
|
+
outPoint: newCellDep.outPoint,
|
|
16
|
+
depType: newCellDep.depType,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return txSkeleton;
|
|
21
|
+
}
|
|
7
22
|
/**
|
|
8
23
|
* Generates a class for collecting custom script cells.
|
|
9
24
|
* @param {string} codeHash - The code hash of the custom script.
|
|
@@ -64,7 +79,7 @@ function generateCollectorClass(codeHash) {
|
|
|
64
79
|
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
65
80
|
* @returns {LockScriptInfo} The lock script information.
|
|
66
81
|
*/
|
|
67
|
-
export function generateScriptInfo(codeHash, cellDeps
|
|
82
|
+
export function generateScriptInfo(codeHash, cellDeps) {
|
|
68
83
|
return {
|
|
69
84
|
codeHash: codeHash,
|
|
70
85
|
hashType: "type",
|
|
@@ -93,14 +108,12 @@ export function generateScriptInfo(codeHash, cellDeps, cellDepTypes = []) {
|
|
|
93
108
|
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
94
109
|
});
|
|
95
110
|
}
|
|
96
|
-
cellDeps.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (txSkeleton.cellProvider != null) {
|
|
100
|
-
await Promise.all(cellDepTypes.map(async (type) => {
|
|
111
|
+
await Promise.all(cellDeps.map(async (itemLike) => {
|
|
112
|
+
const item = ccc.CellDepInfo.from(itemLike);
|
|
113
|
+
if (item.type && txSkeleton.cellProvider != null) {
|
|
101
114
|
for await (const cell of txSkeleton
|
|
102
115
|
.cellProvider.collector({
|
|
103
|
-
type,
|
|
116
|
+
type: item.type,
|
|
104
117
|
})
|
|
105
118
|
.collect()) {
|
|
106
119
|
txSkeleton = addCellDep(txSkeleton, {
|
|
@@ -108,8 +121,17 @@ export function generateScriptInfo(codeHash, cellDeps, cellDepTypes = []) {
|
|
|
108
121
|
outPoint: cell.outPoint,
|
|
109
122
|
});
|
|
110
123
|
}
|
|
111
|
-
}
|
|
112
|
-
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
txSkeleton = addCellDep(txSkeleton, {
|
|
127
|
+
...item.cellDep,
|
|
128
|
+
outPoint: {
|
|
129
|
+
txHash: item.cellDep.outPoint.txHash,
|
|
130
|
+
index: ccc.numToHex(item.cellDep.outPoint.index),
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
113
135
|
return txSkeleton;
|
|
114
136
|
},
|
|
115
137
|
},
|
|
@@ -126,13 +148,16 @@ const NOSTR_TESTNET_TYPE = {
|
|
|
126
148
|
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
127
149
|
*/
|
|
128
150
|
export function generateDefaultScriptInfos() {
|
|
151
|
+
const mainnet = cccA.MAINNET_SCRIPTS;
|
|
152
|
+
const testnet = cccA.TESTNET_SCRIPTS;
|
|
129
153
|
return [
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
]),
|
|
136
|
-
generateScriptInfo(
|
|
137
|
-
]
|
|
154
|
+
ccc.KnownScript.JoyId,
|
|
155
|
+
ccc.KnownScript.NostrLock,
|
|
156
|
+
ccc.KnownScript.PWLock,
|
|
157
|
+
]
|
|
158
|
+
.map((script) => [
|
|
159
|
+
generateScriptInfo(testnet[script].codeHash, testnet[script].cellDeps),
|
|
160
|
+
generateScriptInfo(mainnet[script].codeHash, mainnet[script].cellDeps),
|
|
161
|
+
])
|
|
162
|
+
.flat();
|
|
138
163
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
1
2
|
import { LockScriptInfo } from "@ckb-lumos/common-scripts";
|
|
2
|
-
import { CellDep, Script } from "@ckb-lumos/base";
|
|
3
3
|
/**
|
|
4
4
|
* Generates custom lock script information.
|
|
5
5
|
* @param {string} codeHash - The code hash of the custom script.
|
|
6
6
|
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
7
7
|
* @returns {LockScriptInfo} The lock script information.
|
|
8
8
|
*/
|
|
9
|
-
export declare function generateScriptInfo(codeHash: string, cellDeps:
|
|
9
|
+
export declare function generateScriptInfo(codeHash: string, cellDeps: ccc.CellDepInfoLike[]): LockScriptInfo;
|
|
10
10
|
/**
|
|
11
11
|
* Generates default script information for CCC.
|
|
12
12
|
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../src/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAWpC,OAAO,EAEL,cAAc,EAEf,MAAM,2BAA2B,CAAC;AAqGnC;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,GAAG,CAAC,eAAe,EAAE,GAC9B,cAAc,CAwEhB;AAWD;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,cAAc,EAAE,CAc7D"}
|
package/dist.commonjs/default.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateDefaultScriptInfos = exports.generateScriptInfo = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@ckb-ccc/core");
|
|
5
|
+
const advanced_1 = require("@ckb-ccc/core/advanced");
|
|
5
6
|
const codec_1 = require("@ckb-lumos/codec");
|
|
6
7
|
const common_scripts_1 = require("@ckb-lumos/common-scripts");
|
|
7
|
-
const helper_1 = require("@ckb-lumos/common-scripts/lib/helper");
|
|
8
8
|
const config_manager_1 = require("@ckb-lumos/config-manager");
|
|
9
9
|
const utils_js_1 = require("./utils.js");
|
|
10
|
+
function addCellDep(txSkeleton, newCellDep) {
|
|
11
|
+
const cellDep = txSkeleton.get("cellDeps").find((cellDep) => {
|
|
12
|
+
return (cellDep.depType === newCellDep.depType &&
|
|
13
|
+
core_1.ccc.OutPoint.from(cellDep.outPoint).eq(core_1.ccc.OutPoint.from(newCellDep.outPoint)));
|
|
14
|
+
});
|
|
15
|
+
if (!cellDep) {
|
|
16
|
+
txSkeleton = txSkeleton.update("cellDeps", (cellDeps) => {
|
|
17
|
+
return cellDeps.push({
|
|
18
|
+
outPoint: newCellDep.outPoint,
|
|
19
|
+
depType: newCellDep.depType,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return txSkeleton;
|
|
24
|
+
}
|
|
10
25
|
/**
|
|
11
26
|
* Generates a class for collecting custom script cells.
|
|
12
27
|
* @param {string} codeHash - The code hash of the custom script.
|
|
@@ -67,7 +82,7 @@ function generateCollectorClass(codeHash) {
|
|
|
67
82
|
* @param {CellDep[]} cellDeps - The cell dependencies for the custom script.
|
|
68
83
|
* @returns {LockScriptInfo} The lock script information.
|
|
69
84
|
*/
|
|
70
|
-
function generateScriptInfo(codeHash, cellDeps
|
|
85
|
+
function generateScriptInfo(codeHash, cellDeps) {
|
|
71
86
|
return {
|
|
72
87
|
codeHash: codeHash,
|
|
73
88
|
hashType: "type",
|
|
@@ -96,23 +111,30 @@ function generateScriptInfo(codeHash, cellDeps, cellDepTypes = []) {
|
|
|
96
111
|
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
97
112
|
});
|
|
98
113
|
}
|
|
99
|
-
cellDeps.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (txSkeleton.cellProvider != null) {
|
|
103
|
-
await Promise.all(cellDepTypes.map(async (type) => {
|
|
114
|
+
await Promise.all(cellDeps.map(async (itemLike) => {
|
|
115
|
+
const item = core_1.ccc.CellDepInfo.from(itemLike);
|
|
116
|
+
if (item.type && txSkeleton.cellProvider != null) {
|
|
104
117
|
for await (const cell of txSkeleton
|
|
105
118
|
.cellProvider.collector({
|
|
106
|
-
type,
|
|
119
|
+
type: item.type,
|
|
107
120
|
})
|
|
108
121
|
.collect()) {
|
|
109
|
-
txSkeleton =
|
|
122
|
+
txSkeleton = addCellDep(txSkeleton, {
|
|
110
123
|
depType: "code",
|
|
111
124
|
outPoint: cell.outPoint,
|
|
112
125
|
});
|
|
113
126
|
}
|
|
114
|
-
}
|
|
115
|
-
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
txSkeleton = addCellDep(txSkeleton, {
|
|
130
|
+
...item.cellDep,
|
|
131
|
+
outPoint: {
|
|
132
|
+
txHash: item.cellDep.outPoint.txHash,
|
|
133
|
+
index: core_1.ccc.numToHex(item.cellDep.outPoint.index),
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
116
138
|
return txSkeleton;
|
|
117
139
|
},
|
|
118
140
|
},
|
|
@@ -130,14 +152,17 @@ const NOSTR_TESTNET_TYPE = {
|
|
|
130
152
|
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
131
153
|
*/
|
|
132
154
|
function generateDefaultScriptInfos() {
|
|
155
|
+
const mainnet = advanced_1.cccA.MAINNET_SCRIPTS;
|
|
156
|
+
const testnet = advanced_1.cccA.TESTNET_SCRIPTS;
|
|
133
157
|
return [
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
]),
|
|
140
|
-
generateScriptInfo(
|
|
141
|
-
]
|
|
158
|
+
core_1.ccc.KnownScript.JoyId,
|
|
159
|
+
core_1.ccc.KnownScript.NostrLock,
|
|
160
|
+
core_1.ccc.KnownScript.PWLock,
|
|
161
|
+
]
|
|
162
|
+
.map((script) => [
|
|
163
|
+
generateScriptInfo(testnet[script].codeHash, testnet[script].cellDeps),
|
|
164
|
+
generateScriptInfo(mainnet[script].codeHash, mainnet[script].cellDeps),
|
|
165
|
+
])
|
|
166
|
+
.flat();
|
|
142
167
|
}
|
|
143
168
|
exports.generateDefaultScriptInfos = generateDefaultScriptInfos;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ckb-ccc/lumos-patches",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12-alpha.2",
|
|
4
4
|
"description": "Patches for using Lumos with CCC",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,11 +39,13 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
+
"@ckb-ccc/core": "0.0.12-alpha.1",
|
|
42
43
|
"@ckb-lumos/base": "^0.24.0-next.1",
|
|
43
44
|
"@ckb-lumos/codec": "^0.24.0-next.1",
|
|
44
45
|
"@ckb-lumos/common-scripts": "^0.24.0-next.1",
|
|
45
46
|
"@ckb-lumos/config-manager": "^0.24.0-next.1",
|
|
47
|
+
"@ckb-lumos/helpers": "^0.24.0-next.1",
|
|
46
48
|
"@joyid/ckb": "^1.0.1"
|
|
47
49
|
},
|
|
48
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "376a1a965e35c550a425ade00926e5fd6a9127cb"
|
|
49
51
|
}
|
package/src/default.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { cccA } from "@ckb-ccc/core/advanced";
|
|
4
3
|
import {
|
|
5
4
|
Cell,
|
|
6
5
|
CellCollector,
|
|
@@ -10,11 +9,40 @@ import {
|
|
|
10
9
|
Script,
|
|
11
10
|
} from "@ckb-lumos/base";
|
|
12
11
|
import { bytes } from "@ckb-lumos/codec";
|
|
13
|
-
import {
|
|
14
|
-
|
|
12
|
+
import {
|
|
13
|
+
FromInfo,
|
|
14
|
+
LockScriptInfo,
|
|
15
|
+
parseFromInfo,
|
|
16
|
+
} from "@ckb-lumos/common-scripts";
|
|
15
17
|
import { Config, getConfig } from "@ckb-lumos/config-manager";
|
|
18
|
+
import { TransactionSkeletonType } from "@ckb-lumos/helpers";
|
|
16
19
|
import { asserts } from "./utils.js";
|
|
17
20
|
|
|
21
|
+
function addCellDep(
|
|
22
|
+
txSkeleton: TransactionSkeletonType,
|
|
23
|
+
newCellDep: CellDep,
|
|
24
|
+
): TransactionSkeletonType {
|
|
25
|
+
const cellDep = txSkeleton.get("cellDeps").find((cellDep) => {
|
|
26
|
+
return (
|
|
27
|
+
cellDep.depType === newCellDep.depType &&
|
|
28
|
+
ccc.OutPoint.from(cellDep.outPoint).eq(
|
|
29
|
+
ccc.OutPoint.from(newCellDep.outPoint),
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!cellDep) {
|
|
35
|
+
txSkeleton = txSkeleton.update("cellDeps", (cellDeps) => {
|
|
36
|
+
return cellDeps.push({
|
|
37
|
+
outPoint: newCellDep.outPoint,
|
|
38
|
+
depType: newCellDep.depType,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return txSkeleton;
|
|
44
|
+
}
|
|
45
|
+
|
|
18
46
|
/**
|
|
19
47
|
* Generates a class for collecting custom script cells.
|
|
20
48
|
* @param {string} codeHash - The code hash of the custom script.
|
|
@@ -94,8 +122,7 @@ function generateCollectorClass(codeHash: string) {
|
|
|
94
122
|
*/
|
|
95
123
|
export function generateScriptInfo(
|
|
96
124
|
codeHash: string,
|
|
97
|
-
cellDeps:
|
|
98
|
-
cellDepTypes: Script[] = [],
|
|
125
|
+
cellDeps: ccc.CellDepInfoLike[],
|
|
99
126
|
): LockScriptInfo {
|
|
100
127
|
return {
|
|
101
128
|
codeHash: codeHash,
|
|
@@ -138,16 +165,13 @@ export function generateScriptInfo(
|
|
|
138
165
|
});
|
|
139
166
|
}
|
|
140
167
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (txSkeleton.cellProvider != null) {
|
|
146
|
-
await Promise.all(
|
|
147
|
-
cellDepTypes.map(async (type) => {
|
|
168
|
+
await Promise.all(
|
|
169
|
+
cellDeps.map(async (itemLike) => {
|
|
170
|
+
const item = ccc.CellDepInfo.from(itemLike);
|
|
171
|
+
if (item.type && txSkeleton.cellProvider != null) {
|
|
148
172
|
for await (const cell of txSkeleton
|
|
149
173
|
.cellProvider!.collector({
|
|
150
|
-
type,
|
|
174
|
+
type: item.type,
|
|
151
175
|
})
|
|
152
176
|
.collect()) {
|
|
153
177
|
txSkeleton = addCellDep(txSkeleton, {
|
|
@@ -155,9 +179,17 @@ export function generateScriptInfo(
|
|
|
155
179
|
outPoint: cell.outPoint!,
|
|
156
180
|
});
|
|
157
181
|
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
182
|
+
} else {
|
|
183
|
+
txSkeleton = addCellDep(txSkeleton, {
|
|
184
|
+
...item.cellDep,
|
|
185
|
+
outPoint: {
|
|
186
|
+
txHash: item.cellDep.outPoint.txHash,
|
|
187
|
+
index: ccc.numToHex(item.cellDep.outPoint.index),
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
161
193
|
|
|
162
194
|
return txSkeleton;
|
|
163
195
|
},
|
|
@@ -179,13 +211,17 @@ const NOSTR_TESTNET_TYPE: Script = {
|
|
|
179
211
|
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
180
212
|
*/
|
|
181
213
|
export function generateDefaultScriptInfos(): LockScriptInfo[] {
|
|
214
|
+
const mainnet = cccA.MAINNET_SCRIPTS;
|
|
215
|
+
const testnet = cccA.TESTNET_SCRIPTS;
|
|
216
|
+
|
|
182
217
|
return [
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
218
|
+
ccc.KnownScript.JoyId,
|
|
219
|
+
ccc.KnownScript.NostrLock,
|
|
220
|
+
ccc.KnownScript.PWLock,
|
|
221
|
+
]
|
|
222
|
+
.map((script) => [
|
|
223
|
+
generateScriptInfo(testnet[script]!.codeHash, testnet[script]!.cellDeps),
|
|
224
|
+
generateScriptInfo(mainnet[script]!.codeHash, mainnet[script]!.cellDeps),
|
|
225
|
+
])
|
|
226
|
+
.flat();
|
|
191
227
|
}
|