@ckb-ccc/lumos-patches 0.0.6-alpha.0 → 0.0.8-alpha.3
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/README.md +6 -4
- package/dist.commonjs/default.d.ts +7 -3
- package/dist.commonjs/default.js +125 -106
- package/dist.commonjs/index.d.ts +1 -1
- package/dist.commonjs/index.js +30 -14
- package/dist.commonjs/utils.d.ts +5 -2
- package/dist.commonjs/utils.js +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,11 +21,13 @@
|
|
|
21
21
|
</p>
|
|
22
22
|
|
|
23
23
|
<p align="center">
|
|
24
|
-
"
|
|
24
|
+
"CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
|
|
25
25
|
<br />
|
|
26
|
-
|
|
26
|
+
Empower yourself with CCC to discover the unlimited potential of CKB.
|
|
27
27
|
<br />
|
|
28
|
-
|
|
28
|
+
Interoperate with wallets from different chain ecosystems.
|
|
29
|
+
<br />
|
|
30
|
+
Fully enabling CKB's Turing completeness and cryptographic freedom power.
|
|
29
31
|
</p>
|
|
30
32
|
|
|
31
33
|
## Preview
|
|
@@ -36,7 +38,7 @@
|
|
|
36
38
|
</a>
|
|
37
39
|
</p>
|
|
38
40
|
|
|
39
|
-
This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/).
|
|
41
|
+
This project is still under active development, and we are looking forward to your feedback. [Try its demo now here](https://ckbccc-demo.vercel.app/). It showcases how to use CCC for some basic scenarios in CKB.
|
|
40
42
|
|
|
41
43
|
<h3 align="center">
|
|
42
44
|
Read more about CCC on its <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
import { LockScriptInfo } from "@ckb-lumos/common-scripts";
|
|
2
1
|
import { CellDep, Script } from "@ckb-lumos/base";
|
|
2
|
+
import { LockScriptInfo } from "@ckb-lumos/common-scripts";
|
|
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(
|
|
9
|
+
export declare function generateScriptInfo(
|
|
10
|
+
codeHash: string,
|
|
11
|
+
cellDeps: CellDep[],
|
|
12
|
+
cellDepTypes?: Script[],
|
|
13
|
+
): LockScriptInfo;
|
|
10
14
|
/**
|
|
11
15
|
* Generates default script information for CCC.
|
|
12
16
|
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
13
17
|
*/
|
|
14
18
|
export declare function generateDefaultScriptInfos(): LockScriptInfo[];
|
|
15
|
-
//# sourceMappingURL=default.d.ts.map
|
|
19
|
+
//# sourceMappingURL=default.d.ts.map
|
package/dist.commonjs/default.js
CHANGED
|
@@ -13,53 +13,59 @@ const utils_1 = require("./utils");
|
|
|
13
13
|
* @returns {typeof JoyIDCellCollector} The CustomCellCollector class.
|
|
14
14
|
*/
|
|
15
15
|
function generateCollectorClass(codeHash) {
|
|
16
|
+
/**
|
|
17
|
+
* Class representing a collector for custom script cells.
|
|
18
|
+
* @class
|
|
19
|
+
*/
|
|
20
|
+
return class CustomCellCollector {
|
|
16
21
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @
|
|
22
|
+
* Creates an instance of CustomCollector.
|
|
23
|
+
* @param {FromInfo} fromInfo - The information about the address to collect cells from.
|
|
24
|
+
* @param {CellProvider} cellProvider - The provider to collect cells from.
|
|
25
|
+
* @param {Object} options - The options for the collector.
|
|
26
|
+
* @param {QueryOptions} [options.queryOptions={}] - The query options for collecting cells.
|
|
27
|
+
* @param {Config} [options.config=getConfig()] - The Lumos configuration.
|
|
28
|
+
* @throws {Error} If cellProvider is not provided or fromInfo is not a string.
|
|
19
29
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
yield inputCell;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
};
|
|
30
|
+
constructor(
|
|
31
|
+
fromInfo,
|
|
32
|
+
cellProvider,
|
|
33
|
+
{ queryOptions = {}, config = (0, config_manager_1.getConfig)() },
|
|
34
|
+
) {
|
|
35
|
+
if (!cellProvider) {
|
|
36
|
+
throw new Error(`cellProvider is required when collecting cells`);
|
|
37
|
+
}
|
|
38
|
+
const { fromScript } = (0, common_scripts_1.parseFromInfo)(fromInfo, {
|
|
39
|
+
config,
|
|
40
|
+
});
|
|
41
|
+
this.fromScript = fromScript;
|
|
42
|
+
if (!codec_1.bytes.equal(fromScript.codeHash, codeHash)) {
|
|
43
|
+
this.cellCollector = undefined;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
queryOptions = {
|
|
47
|
+
...queryOptions,
|
|
48
|
+
lock: this.fromScript,
|
|
49
|
+
type: queryOptions.type || "empty",
|
|
50
|
+
data: queryOptions.data || "0x",
|
|
51
|
+
};
|
|
52
|
+
this.cellCollector = cellProvider.collector(queryOptions);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Collects custom cells.
|
|
56
|
+
* @async
|
|
57
|
+
* @generator
|
|
58
|
+
* @yields {Cell} The collected cell.
|
|
59
|
+
*/
|
|
60
|
+
async *collect() {
|
|
61
|
+
if (!this.cellCollector) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
for await (const inputCell of this.cellCollector.collect()) {
|
|
65
|
+
yield inputCell;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
63
69
|
}
|
|
64
70
|
/**
|
|
65
71
|
* Generates custom lock script information.
|
|
@@ -68,76 +74,89 @@ function generateCollectorClass(codeHash) {
|
|
|
68
74
|
* @returns {LockScriptInfo} The lock script information.
|
|
69
75
|
*/
|
|
70
76
|
function generateScriptInfo(codeHash, cellDeps, cellDepTypes = []) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
77
|
+
return {
|
|
78
|
+
codeHash: codeHash,
|
|
79
|
+
hashType: "type",
|
|
80
|
+
lockScriptInfo: {
|
|
81
|
+
CellCollector: generateCollectorClass(codeHash),
|
|
82
|
+
prepareSigningEntries: () => {
|
|
83
|
+
throw new Error(
|
|
84
|
+
"Custom scripts doesn't support prepareSigningEntries.",
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
async setupInputCell(txSkeleton, inputCell, _, options = {}) {
|
|
88
|
+
const fromScript = inputCell.cellOutput.lock;
|
|
89
|
+
(0, utils_1.asserts)(
|
|
90
|
+
codec_1.bytes.equal(fromScript.codeHash, codeHash),
|
|
91
|
+
`The input script is not specified script`,
|
|
92
|
+
);
|
|
93
|
+
// add inputCell to txSkeleton
|
|
94
|
+
txSkeleton = txSkeleton.update("inputs", (inputs) =>
|
|
95
|
+
inputs.push(inputCell),
|
|
96
|
+
);
|
|
97
|
+
const output = {
|
|
98
|
+
cellOutput: {
|
|
99
|
+
capacity: inputCell.cellOutput.capacity,
|
|
100
|
+
lock: inputCell.cellOutput.lock,
|
|
101
|
+
type: inputCell.cellOutput.type,
|
|
102
|
+
},
|
|
103
|
+
data: inputCell.data,
|
|
104
|
+
};
|
|
105
|
+
txSkeleton = txSkeleton.update("outputs", (outputs) =>
|
|
106
|
+
outputs.push(output),
|
|
107
|
+
);
|
|
108
|
+
const since = options.since;
|
|
109
|
+
if (since) {
|
|
110
|
+
txSkeleton = txSkeleton.update("inputSinces", (inputSinces) => {
|
|
111
|
+
return inputSinces.set(txSkeleton.get("inputs").size - 1, since);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
cellDeps.forEach((item) => {
|
|
115
|
+
txSkeleton = (0, helper_1.addCellDep)(txSkeleton, item);
|
|
116
|
+
});
|
|
117
|
+
if (txSkeleton.cellProvider != null) {
|
|
118
|
+
await Promise.all(
|
|
119
|
+
cellDepTypes.map(async (type) => {
|
|
120
|
+
for await (const cell of txSkeleton.cellProvider
|
|
121
|
+
.collector({
|
|
122
|
+
type,
|
|
123
|
+
})
|
|
124
|
+
.collect()) {
|
|
125
|
+
txSkeleton = (0, helper_1.addCellDep)(txSkeleton, {
|
|
126
|
+
depType: "code",
|
|
127
|
+
outPoint: cell.outPoint,
|
|
101
128
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
depType: "code",
|
|
111
|
-
outPoint: cell.outPoint,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
|
-
return txSkeleton;
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
};
|
|
129
|
+
}
|
|
130
|
+
}),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return txSkeleton;
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
120
137
|
}
|
|
121
138
|
exports.generateScriptInfo = generateScriptInfo;
|
|
122
|
-
const NOSTR_TESTNET_TYPE_HASH =
|
|
139
|
+
const NOSTR_TESTNET_TYPE_HASH =
|
|
140
|
+
"0x6ae5ee0cb887b2df5a9a18137315b9bdc55be8d52637b2de0624092d5f0c91d5";
|
|
123
141
|
const NOSTR_TESTNET_TYPE = {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
142
|
+
codeHash:
|
|
143
|
+
"0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
144
|
+
hashType: "type",
|
|
145
|
+
args: "0x8dc56c6f35f0c535e23ded1629b1f20535477a1b43e59f14617d11e32c50e0aa",
|
|
127
146
|
};
|
|
128
147
|
/**
|
|
129
148
|
* Generates default script information for CCC.
|
|
130
149
|
* @returns {LockScriptInfo[]} An array of lock script information.
|
|
131
150
|
*/
|
|
132
151
|
function generateDefaultScriptInfos() {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
return [
|
|
153
|
+
generateScriptInfo((0, ckb_1.getJoyIDLockScript)(false).codeHash, [
|
|
154
|
+
(0, ckb_1.getJoyIDCellDep)(false),
|
|
155
|
+
]),
|
|
156
|
+
generateScriptInfo((0, ckb_1.getJoyIDLockScript)(true).codeHash, [
|
|
157
|
+
(0, ckb_1.getJoyIDCellDep)(true),
|
|
158
|
+
]),
|
|
159
|
+
generateScriptInfo(NOSTR_TESTNET_TYPE_HASH, [], [NOSTR_TESTNET_TYPE]),
|
|
160
|
+
];
|
|
142
161
|
}
|
|
143
162
|
exports.generateDefaultScriptInfos = generateDefaultScriptInfos;
|
package/dist.commonjs/index.d.ts
CHANGED
package/dist.commonjs/index.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
11
|
+
) {
|
|
12
|
+
desc = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return m[k];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}
|
|
21
|
+
: function (o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
});
|
|
25
|
+
var __exportStar =
|
|
26
|
+
(this && this.__exportStar) ||
|
|
27
|
+
function (m, exports) {
|
|
28
|
+
for (var p in m)
|
|
29
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
|
|
30
|
+
__createBinding(exports, m, p);
|
|
31
|
+
};
|
|
16
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
33
|
__exportStar(require("./default"), exports);
|
|
18
34
|
__exportStar(require("./utils"), exports);
|
package/dist.commonjs/utils.d.ts
CHANGED
|
@@ -4,5 +4,8 @@
|
|
|
4
4
|
* @param {string} [message="Assert failed"] - The error message to throw if the condition is false.
|
|
5
5
|
* @throws {Error} If the condition is false.
|
|
6
6
|
*/
|
|
7
|
-
export declare function asserts(
|
|
8
|
-
|
|
7
|
+
export declare function asserts(
|
|
8
|
+
condition: unknown,
|
|
9
|
+
message?: string,
|
|
10
|
+
): asserts condition;
|
|
11
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/dist.commonjs/utils.js
CHANGED
|
@@ -8,8 +8,8 @@ exports.asserts = void 0;
|
|
|
8
8
|
* @throws {Error} If the condition is false.
|
|
9
9
|
*/
|
|
10
10
|
function asserts(condition, message = "Assert failed") {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (!condition) {
|
|
12
|
+
throw new Error(message);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
15
|
exports.asserts = asserts;
|
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.8-alpha.3",
|
|
4
4
|
"description": "Patches for using Lumos with CCC",
|
|
5
5
|
"author": "Hanssen0 <hanssen0@hanssen0.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"@ckb-lumos/config-manager": "^0.22.2",
|
|
45
45
|
"@joyid/ckb": "^0.0.11"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "bddfa3e5631252194dfde32b79ee589703f18afb"
|
|
48
48
|
}
|