@ckb-ccc/spore 1.2.3 → 1.3.0
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/CHANGELOG.md +10 -9
- package/dist/cluster/index.d.ts +34 -15
- package/dist/cluster/index.d.ts.map +1 -1
- package/dist/cluster/index.js +57 -23
- package/dist/cobuild/index.js +1 -2
- package/dist/spore/advanced.d.ts.map +1 -1
- package/dist/spore/advanced.js +1 -5
- package/dist/spore/index.d.ts +47 -21
- package/dist/spore/index.d.ts.map +1 -1
- package/dist/spore/index.js +78 -37
- package/dist.commonjs/advanced.js +17 -7
- package/dist.commonjs/barrel.js +17 -7
- package/dist.commonjs/cluster/index.d.ts +34 -15
- package/dist.commonjs/cluster/index.d.ts.map +1 -1
- package/dist.commonjs/cluster/index.js +58 -23
- package/dist.commonjs/cobuild/index.js +1 -2
- package/dist.commonjs/index.js +17 -7
- package/dist.commonjs/spore/advanced.d.ts.map +1 -1
- package/dist.commonjs/spore/advanced.js +1 -5
- package/dist.commonjs/spore/index.d.ts +47 -21
- package/dist.commonjs/spore/index.d.ts.map +1 -1
- package/dist.commonjs/spore/index.js +79 -37
- package/package.json +2 -2
- package/src/cluster/index.ts +79 -30
- package/src/cobuild/index.ts +2 -2
- package/src/spore/advanced.ts +1 -6
- package/src/spore/index.ts +105 -45
package/dist.commonjs/barrel.js
CHANGED
|
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.dob = void 0;
|
|
30
40
|
__exportStar(require("./cluster/index.js"), exports);
|
|
@@ -14,12 +14,12 @@ export declare function assertCluster(client: ccc.Client, args: ccc.HexLike, scr
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a new Cluster cell
|
|
16
16
|
*
|
|
17
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
18
|
-
* @param data specific format of data required by Cluster protocol
|
|
19
|
-
* @param to the owner of the Cluster cell, which will be replaced with signer if not provided
|
|
20
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
21
|
-
* @param scriptInfo the script info of new cluster, default spore version if undefined
|
|
22
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
17
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
18
|
+
* @param params.data specific format of data required by Cluster protocol
|
|
19
|
+
* @param params.to the owner of the Cluster cell, which will be replaced with signer if not provided
|
|
20
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
21
|
+
* @param params.scriptInfo the script info of new cluster, default spore version if undefined
|
|
22
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
23
23
|
* @returns
|
|
24
24
|
* - **tx**: a new transaction that contains created Cluster cell
|
|
25
25
|
* - **id**: the id of the created Cluster cell
|
|
@@ -38,11 +38,11 @@ export declare function createSporeCluster(params: {
|
|
|
38
38
|
/**
|
|
39
39
|
* Transfer a Cluster cell
|
|
40
40
|
*
|
|
41
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
42
|
-
* @param id the id of the Cluster cell to be transferred
|
|
43
|
-
* @param to the new owner of the Cluster cell
|
|
44
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
45
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
41
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
42
|
+
* @param params.id the id of the Cluster cell to be transferred
|
|
43
|
+
* @param params.to the new owner of the Cluster cell
|
|
44
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
45
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
46
46
|
* @returns
|
|
47
47
|
* - **tx**: a new transaction that contains transferred Cluster cell
|
|
48
48
|
*/
|
|
@@ -51,6 +51,7 @@ export declare function transferSporeCluster(params: {
|
|
|
51
51
|
id: ccc.HexLike;
|
|
52
52
|
to: ccc.ScriptLike;
|
|
53
53
|
tx?: ccc.TransactionLike;
|
|
54
|
+
scripts?: SporeScriptInfoLike[];
|
|
54
55
|
scriptInfoHash?: ccc.HexLike;
|
|
55
56
|
}): Promise<{
|
|
56
57
|
tx: ccc.Transaction;
|
|
@@ -58,11 +59,11 @@ export declare function transferSporeCluster(params: {
|
|
|
58
59
|
/**
|
|
59
60
|
* Search on-chain clusters under the signer's control
|
|
60
61
|
*
|
|
61
|
-
* @param signer the owner of clusters
|
|
62
|
-
* @param order the order in creation time of clusters
|
|
63
|
-
* @param scriptInfos the deployed script infos of clusters
|
|
62
|
+
* @param params.signer the owner of clusters
|
|
63
|
+
* @param params.order the order in creation time of clusters
|
|
64
|
+
* @param params.scriptInfos the deployed script infos of clusters
|
|
64
65
|
*/
|
|
65
|
-
export declare function findSporeClustersBySigner(
|
|
66
|
+
export declare function findSporeClustersBySigner(params: {
|
|
66
67
|
signer: ccc.Signer;
|
|
67
68
|
order?: "asc" | "desc";
|
|
68
69
|
limit?: number;
|
|
@@ -73,4 +74,22 @@ export declare function findSporeClustersBySigner({ signer, order, limit, script
|
|
|
73
74
|
clusterData: ClusterDataView;
|
|
74
75
|
scriptInfo: SporeScriptInfo;
|
|
75
76
|
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Search on-chain clusters under the specified lock or not
|
|
79
|
+
*
|
|
80
|
+
* @param params.client the client to search clusters
|
|
81
|
+
* @param params.lock the lock of clusters
|
|
82
|
+
*/
|
|
83
|
+
export declare function findSporeClusters(params: {
|
|
84
|
+
client: ccc.Client;
|
|
85
|
+
lock?: ccc.ScriptLike;
|
|
86
|
+
order?: "asc" | "desc";
|
|
87
|
+
limit?: number;
|
|
88
|
+
scriptInfos?: SporeScriptInfoLike[];
|
|
89
|
+
}): AsyncGenerator<{
|
|
90
|
+
cell: ccc.Cell;
|
|
91
|
+
cluster: ccc.Cell;
|
|
92
|
+
clusterData: ClusterDataView;
|
|
93
|
+
scriptInfo: SporeScriptInfo;
|
|
94
|
+
}>;
|
|
76
95
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cluster/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAMpC,OAAO,EACL,eAAe,EAGhB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,eAAe,EACf,mBAAmB,EAGpB,MAAM,wBAAwB,CAAC;AAEhC,wBAAsB,WAAW,CAC/B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,EAAE,EAAE,GAAG,CAAC,OAAO,EACf,OAAO,CAAC,EAAE,mBAAmB,EAAE,GAC9B,OAAO,CACN;IACE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,OAAO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CAC7B,CAAC,CAkCD"}
|
|
@@ -5,6 +5,7 @@ exports.assertCluster = assertCluster;
|
|
|
5
5
|
exports.createSporeCluster = createSporeCluster;
|
|
6
6
|
exports.transferSporeCluster = transferSporeCluster;
|
|
7
7
|
exports.findSporeClustersBySigner = findSporeClustersBySigner;
|
|
8
|
+
exports.findSporeClusters = findSporeClusters;
|
|
8
9
|
const core_1 = require("@ckb-ccc/core");
|
|
9
10
|
const advanced_js_1 = require("../advanced.js");
|
|
10
11
|
const index_js_1 = require("../codec/index.js");
|
|
@@ -32,12 +33,12 @@ async function assertCluster(client, args, scripts) {
|
|
|
32
33
|
/**
|
|
33
34
|
* Create a new Cluster cell
|
|
34
35
|
*
|
|
35
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
36
|
-
* @param data specific format of data required by Cluster protocol
|
|
37
|
-
* @param to the owner of the Cluster cell, which will be replaced with signer if not provided
|
|
38
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
39
|
-
* @param scriptInfo the script info of new cluster, default spore version if undefined
|
|
40
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
36
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
37
|
+
* @param params.data specific format of data required by Cluster protocol
|
|
38
|
+
* @param params.to the owner of the Cluster cell, which will be replaced with signer if not provided
|
|
39
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
40
|
+
* @param params.scriptInfo the script info of new cluster, default spore version if undefined
|
|
41
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
41
42
|
* @returns
|
|
42
43
|
* - **tx**: a new transaction that contains created Cluster cell
|
|
43
44
|
* - **id**: the id of the created Cluster cell
|
|
@@ -74,32 +75,29 @@ async function createSporeCluster(params) {
|
|
|
74
75
|
/**
|
|
75
76
|
* Transfer a Cluster cell
|
|
76
77
|
*
|
|
77
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
78
|
-
* @param id the id of the Cluster cell to be transferred
|
|
79
|
-
* @param to the new owner of the Cluster cell
|
|
80
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
81
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
78
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
79
|
+
* @param params.id the id of the Cluster cell to be transferred
|
|
80
|
+
* @param params.to the new owner of the Cluster cell
|
|
81
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
82
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
82
83
|
* @returns
|
|
83
84
|
* - **tx**: a new transaction that contains transferred Cluster cell
|
|
84
85
|
*/
|
|
85
86
|
async function transferSporeCluster(params) {
|
|
86
|
-
const { signer, id, to, scriptInfoHash } = params;
|
|
87
|
+
const { signer, id, to, scripts, scriptInfoHash } = params;
|
|
87
88
|
// prepare transaction
|
|
88
89
|
const tx = core_1.ccc.Transaction.from(params.tx ?? {});
|
|
89
90
|
// build cluster cell
|
|
90
|
-
const { cell: cluster, scriptInfo } = await assertCluster(signer.client, id);
|
|
91
|
-
tx.
|
|
92
|
-
previousOutput: cluster.outPoint,
|
|
93
|
-
...cluster,
|
|
94
|
-
}));
|
|
91
|
+
const { cell: cluster, scriptInfo: clusterScriptInfo } = await assertCluster(signer.client, id, scripts);
|
|
92
|
+
tx.addInput(cluster);
|
|
95
93
|
tx.addOutput({
|
|
96
94
|
lock: to,
|
|
97
95
|
type: cluster.cellOutput.type,
|
|
98
96
|
}, cluster.outputData);
|
|
99
97
|
// complete cellDeps
|
|
100
|
-
await tx.addCellDepInfos(signer.client,
|
|
98
|
+
await tx.addCellDepInfos(signer.client, clusterScriptInfo.cellDeps);
|
|
101
99
|
// generate cobuild action
|
|
102
|
-
const actions =
|
|
100
|
+
const actions = clusterScriptInfo.cobuild
|
|
103
101
|
? [
|
|
104
102
|
(0, advanced_js_1.assembleTransferClusterAction)(cluster.cellOutput, tx.outputs[tx.outputs.length - 1], scriptInfoHash),
|
|
105
103
|
]
|
|
@@ -111,11 +109,12 @@ async function transferSporeCluster(params) {
|
|
|
111
109
|
/**
|
|
112
110
|
* Search on-chain clusters under the signer's control
|
|
113
111
|
*
|
|
114
|
-
* @param signer the owner of clusters
|
|
115
|
-
* @param order the order in creation time of clusters
|
|
116
|
-
* @param scriptInfos the deployed script infos of clusters
|
|
112
|
+
* @param params.signer the owner of clusters
|
|
113
|
+
* @param params.order the order in creation time of clusters
|
|
114
|
+
* @param params.scriptInfos the deployed script infos of clusters
|
|
117
115
|
*/
|
|
118
|
-
async function* findSporeClustersBySigner(
|
|
116
|
+
async function* findSporeClustersBySigner(params) {
|
|
117
|
+
const { signer, order, limit, scriptInfos } = params;
|
|
119
118
|
for (const scriptInfo of scriptInfos ??
|
|
120
119
|
Object.values((0, index_js_3.getClusterScriptInfos)(signer.client))) {
|
|
121
120
|
if (!scriptInfo) {
|
|
@@ -136,3 +135,39 @@ async function* findSporeClustersBySigner({ signer, order, limit, scriptInfos, }
|
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Search on-chain clusters under the specified lock or not
|
|
140
|
+
*
|
|
141
|
+
* @param params.client the client to search clusters
|
|
142
|
+
* @param params.lock the lock of clusters
|
|
143
|
+
*/
|
|
144
|
+
async function* findSporeClusters(params) {
|
|
145
|
+
const { client, lock, order, limit, scriptInfos } = params;
|
|
146
|
+
for (const scriptInfo of scriptInfos ??
|
|
147
|
+
Object.values((0, index_js_3.getClusterScriptInfos)(client))) {
|
|
148
|
+
if (!scriptInfo) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
for await (const cluster of client.findCells({
|
|
152
|
+
script: {
|
|
153
|
+
...scriptInfo,
|
|
154
|
+
args: "",
|
|
155
|
+
},
|
|
156
|
+
scriptType: "type",
|
|
157
|
+
scriptSearchMode: "prefix",
|
|
158
|
+
withData: true,
|
|
159
|
+
filter: lock
|
|
160
|
+
? {
|
|
161
|
+
script: lock,
|
|
162
|
+
}
|
|
163
|
+
: undefined,
|
|
164
|
+
}, order, limit)) {
|
|
165
|
+
yield {
|
|
166
|
+
cell: cluster,
|
|
167
|
+
cluster,
|
|
168
|
+
clusterData: (0, index_js_1.unpackToRawClusterData)(cluster.outputData),
|
|
169
|
+
scriptInfo: index_js_3.SporeScriptInfo.from(scriptInfo),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -166,7 +166,7 @@ function extractCobuildActionsFromTx(tx) {
|
|
|
166
166
|
return witnessLayout.value.message.actions;
|
|
167
167
|
}
|
|
168
168
|
function injectCobuild(tx, actions) {
|
|
169
|
-
|
|
169
|
+
tx.setWitnessAt(Math.max(tx.witnesses.length, tx.inputs.length), index_js_1.WitnessLayout.encode({
|
|
170
170
|
type: "SighashAll",
|
|
171
171
|
value: {
|
|
172
172
|
seal: "0x",
|
|
@@ -175,5 +175,4 @@ function injectCobuild(tx, actions) {
|
|
|
175
175
|
},
|
|
176
176
|
},
|
|
177
177
|
}));
|
|
178
|
-
tx.witnesses.push(core_1.ccc.hexFrom(witnessLayout));
|
|
179
178
|
}
|
package/dist.commonjs/index.js
CHANGED
|
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.spore = void 0;
|
|
30
40
|
__exportStar(require("./barrel.js"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/spore/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE1D,wBAAsB,cAAc,CAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,EAAE,EAAE,GAAG,CAAC,WAAW,EACnB,IAAI,EAAE,aAAa,EACnB,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,MAAM,EAClD,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,GAC3B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,MAAM,CAAC,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/spore/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGzC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE1D,wBAAsB,cAAc,CAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,EAAE,EAAE,GAAG,CAAC,WAAW,EACnB,IAAI,EAAE,aAAa,EACnB,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,MAAM,EAClD,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,GAC3B,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,MAAM,CAAC,GAAG,SAAS,CAAC,CA4DvD"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prepareCluster = prepareCluster;
|
|
4
|
-
const core_1 = require("@ckb-ccc/core");
|
|
5
4
|
const advanced_js_1 = require("../advanced.js");
|
|
6
5
|
const index_js_1 = require("../cluster/index.js");
|
|
7
6
|
async function prepareCluster(signer, tx, data, clusterMode, scriptInfoHash) {
|
|
@@ -37,10 +36,7 @@ async function prepareCluster(signer, tx, data, clusterMode, scriptInfoHash) {
|
|
|
37
36
|
if (tx.inputs.some((i) => i.previousOutput.eq(cluster.outPoint))) {
|
|
38
37
|
return;
|
|
39
38
|
}
|
|
40
|
-
tx.
|
|
41
|
-
previousOutput: cluster.outPoint,
|
|
42
|
-
...cluster,
|
|
43
|
-
}));
|
|
39
|
+
tx.addInput(cluster);
|
|
44
40
|
tx.addOutput(cluster.cellOutput, cluster.outputData);
|
|
45
41
|
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
46
42
|
// note: add cluster as cellDep, which will be used in Spore contract
|
|
@@ -14,17 +14,17 @@ export declare function assertSpore(client: ccc.Client, args: ccc.HexLike, scrip
|
|
|
14
14
|
/**
|
|
15
15
|
* Create one Spore cell with the specified Spore data.
|
|
16
16
|
*
|
|
17
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
18
|
-
* @param data specific format of data required by Spore protocol
|
|
19
|
-
* @param to owner of new spore cell, signer if no provided
|
|
20
|
-
* @param clusterMode how to process cluster cell **(if clusterId is not provided in SporeData, this parameter will be ignored)**
|
|
17
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
18
|
+
* @param params.data specific format of data required by Spore protocol
|
|
19
|
+
* @param params.to owner of new spore cell, signer if no provided
|
|
20
|
+
* @param params.clusterMode how to process cluster cell **(if clusterId is not provided in SporeData, this parameter will be ignored)**
|
|
21
21
|
* - undefined: error if the spore has a cluster but the clusterMode is not set
|
|
22
22
|
* - lockProxy: put a cell that uses the same lock from Cluster cell in both Inputs and Outputs
|
|
23
23
|
* - clusterCell: directly put Cluster cell in Inputs and Outputs
|
|
24
24
|
* - skip: don't handle the cluster logic
|
|
25
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
26
|
-
* @param scriptInfo the script info of Spore cell, if not provided, the default script info will be used
|
|
27
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
25
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
26
|
+
* @param params.scriptInfo the script info of Spore cell, if not provided, the default script info will be used
|
|
27
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
28
28
|
* @returns
|
|
29
29
|
* - **tx**: a new transaction that contains created Spore cells
|
|
30
30
|
* - **id**: the sporeId of created Spore cell
|
|
@@ -44,11 +44,11 @@ export declare function createSpore(params: {
|
|
|
44
44
|
/**
|
|
45
45
|
* Transfer one Spore cell
|
|
46
46
|
*
|
|
47
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
48
|
-
* @param id sporeId
|
|
49
|
-
* @param to Spore's new owner
|
|
50
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
51
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
47
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
48
|
+
* @param params.id sporeId
|
|
49
|
+
* @param params.to Spore's new owner
|
|
50
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
51
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
52
52
|
* @returns
|
|
53
53
|
* - **tx**: a new transaction that contains transferred Spore cells
|
|
54
54
|
*/
|
|
@@ -57,6 +57,7 @@ export declare function transferSpore(params: {
|
|
|
57
57
|
id: ccc.HexLike;
|
|
58
58
|
to: ccc.ScriptLike;
|
|
59
59
|
tx?: ccc.TransactionLike;
|
|
60
|
+
scripts?: SporeScriptInfoLike[];
|
|
60
61
|
scriptInfoHash?: ccc.HexLike;
|
|
61
62
|
}): Promise<{
|
|
62
63
|
tx: ccc.Transaction;
|
|
@@ -64,10 +65,10 @@ export declare function transferSpore(params: {
|
|
|
64
65
|
/**
|
|
65
66
|
* Melt one Spore cell
|
|
66
67
|
*
|
|
67
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
68
|
-
* @param id sporeId to be melted
|
|
69
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
70
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
68
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
69
|
+
* @param params.id sporeId to be melted
|
|
70
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
71
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
71
72
|
* @returns
|
|
72
73
|
* - **tx**: a new transaction that contains melted Spore cell
|
|
73
74
|
*/
|
|
@@ -75,6 +76,7 @@ export declare function meltSpore(params: {
|
|
|
75
76
|
signer: ccc.Signer;
|
|
76
77
|
id: ccc.HexLike;
|
|
77
78
|
tx?: ccc.TransactionLike;
|
|
79
|
+
scripts?: SporeScriptInfoLike[];
|
|
78
80
|
scriptInfoHash?: ccc.HexLike;
|
|
79
81
|
}): Promise<{
|
|
80
82
|
tx: ccc.Transaction;
|
|
@@ -82,13 +84,13 @@ export declare function meltSpore(params: {
|
|
|
82
84
|
/**
|
|
83
85
|
* Search on-chain spores under the signer's control, if cluster provided, filter spores belonging to this cluster
|
|
84
86
|
*
|
|
85
|
-
* @param signer the owner of spores
|
|
86
|
-
* @param order the order in creation time of spores
|
|
87
|
-
* @param clusterId the cluster that spores belong to. "" to find public spores
|
|
88
|
-
* @param scriptInfos the deployed script infos of spores
|
|
87
|
+
* @param params.signer the owner of spores
|
|
88
|
+
* @param params.order the order in creation time of spores
|
|
89
|
+
* @param params.clusterId the cluster that spores belong to. "" to find public spores
|
|
90
|
+
* @param params.scriptInfos the deployed script infos of spores
|
|
89
91
|
* @returns specified spore cells
|
|
90
92
|
*/
|
|
91
|
-
export declare function findSporesBySigner(
|
|
93
|
+
export declare function findSporesBySigner(params: {
|
|
92
94
|
signer: ccc.Signer;
|
|
93
95
|
order?: "asc" | "desc";
|
|
94
96
|
limit?: number;
|
|
@@ -100,4 +102,28 @@ export declare function findSporesBySigner({ signer, clusterId, scriptInfos, lim
|
|
|
100
102
|
sporeData: SporeDataView;
|
|
101
103
|
scriptInfo: SporeScriptInfo;
|
|
102
104
|
}>;
|
|
105
|
+
/**
|
|
106
|
+
* Search on-chain spores under the specified lock or not, if cluster provided, filter spores belonging to this cluster
|
|
107
|
+
*
|
|
108
|
+
* @param params.client the client to search spores
|
|
109
|
+
* @param params.lock the lock of spores
|
|
110
|
+
* @param params.clusterId the cluster that spores belong to. "" to find public spores
|
|
111
|
+
* @param params.scriptInfos the deployed script infos of spores
|
|
112
|
+
* @param params.limit the limit of spores to search
|
|
113
|
+
* @param params.order the order in creation time of spores
|
|
114
|
+
* @returns specified spore cells
|
|
115
|
+
*/
|
|
116
|
+
export declare function findSpores(params: {
|
|
117
|
+
client: ccc.Client;
|
|
118
|
+
lock?: ccc.ScriptLike;
|
|
119
|
+
clusterId?: ccc.HexLike;
|
|
120
|
+
scriptInfos?: SporeScriptInfoLike[];
|
|
121
|
+
limit?: number;
|
|
122
|
+
order?: "asc" | "desc";
|
|
123
|
+
}): AsyncGenerator<{
|
|
124
|
+
cell: ccc.Cell;
|
|
125
|
+
spore: ccc.Cell;
|
|
126
|
+
sporeData: SporeDataView;
|
|
127
|
+
scriptInfo: SporeScriptInfo;
|
|
128
|
+
}>;
|
|
103
129
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1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,CAAC;IACV,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;CACrB,CAAC,CAsBD;AAED;;;;;;;;GAQG;AACH,wBAAuB,kBAAkB,CAAC,MAAM,EAAE;IAChD,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACrC,GAAG,cAAc,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CAiCD;AAED;;;;;;;;;;GAUG;AACH,wBAAuB,UAAU,CAAC,MAAM,EAAE;IACxC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;IACtB,SAAS,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CACxB,GAAG,cAAc,CAAC;IACjB,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC;IAChB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CAwCD"}
|
|
@@ -6,6 +6,7 @@ exports.createSpore = createSpore;
|
|
|
6
6
|
exports.transferSpore = transferSpore;
|
|
7
7
|
exports.meltSpore = meltSpore;
|
|
8
8
|
exports.findSporesBySigner = findSporesBySigner;
|
|
9
|
+
exports.findSpores = findSpores;
|
|
9
10
|
const core_1 = require("@ckb-ccc/core");
|
|
10
11
|
const advanced_js_1 = require("../advanced.js");
|
|
11
12
|
const index_js_1 = require("../codec/index.js");
|
|
@@ -34,17 +35,17 @@ async function assertSpore(client, args, scripts) {
|
|
|
34
35
|
/**
|
|
35
36
|
* Create one Spore cell with the specified Spore data.
|
|
36
37
|
*
|
|
37
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
38
|
-
* @param data specific format of data required by Spore protocol
|
|
39
|
-
* @param to owner of new spore cell, signer if no provided
|
|
40
|
-
* @param clusterMode how to process cluster cell **(if clusterId is not provided in SporeData, this parameter will be ignored)**
|
|
38
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
39
|
+
* @param params.data specific format of data required by Spore protocol
|
|
40
|
+
* @param params.to owner of new spore cell, signer if no provided
|
|
41
|
+
* @param params.clusterMode how to process cluster cell **(if clusterId is not provided in SporeData, this parameter will be ignored)**
|
|
41
42
|
* - undefined: error if the spore has a cluster but the clusterMode is not set
|
|
42
43
|
* - lockProxy: put a cell that uses the same lock from Cluster cell in both Inputs and Outputs
|
|
43
44
|
* - clusterCell: directly put Cluster cell in Inputs and Outputs
|
|
44
45
|
* - skip: don't handle the cluster logic
|
|
45
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
46
|
-
* @param scriptInfo the script info of Spore cell, if not provided, the default script info will be used
|
|
47
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
46
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
47
|
+
* @param params.scriptInfo the script info of Spore cell, if not provided, the default script info will be used
|
|
48
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
48
49
|
* @returns
|
|
49
50
|
* - **tx**: a new transaction that contains created Spore cells
|
|
50
51
|
* - **id**: the sporeId of created Spore cell
|
|
@@ -89,29 +90,26 @@ async function createSpore(params) {
|
|
|
89
90
|
/**
|
|
90
91
|
* Transfer one Spore cell
|
|
91
92
|
*
|
|
92
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
93
|
-
* @param id sporeId
|
|
94
|
-
* @param to Spore's new owner
|
|
95
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
96
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
93
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
94
|
+
* @param params.id sporeId
|
|
95
|
+
* @param params.to Spore's new owner
|
|
96
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
97
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
97
98
|
* @returns
|
|
98
99
|
* - **tx**: a new transaction that contains transferred Spore cells
|
|
99
100
|
*/
|
|
100
101
|
async function transferSpore(params) {
|
|
101
|
-
const { signer, id, to, scriptInfoHash } = params;
|
|
102
|
+
const { signer, id, to, scripts, scriptInfoHash } = params;
|
|
102
103
|
// prepare transaction
|
|
103
104
|
const tx = core_1.ccc.Transaction.from(params.tx ?? {});
|
|
104
|
-
const { cell: sporeCell, scriptInfo } = await assertSpore(signer.client, id);
|
|
105
|
-
await tx.addCellDepInfos(signer.client,
|
|
106
|
-
tx.
|
|
107
|
-
previousOutput: sporeCell.outPoint,
|
|
108
|
-
...sporeCell,
|
|
109
|
-
}));
|
|
105
|
+
const { cell: sporeCell, scriptInfo: sporeScriptInfo } = await assertSpore(signer.client, id, scripts);
|
|
106
|
+
await tx.addCellDepInfos(signer.client, sporeScriptInfo.cellDeps);
|
|
107
|
+
tx.addInput(sporeCell);
|
|
110
108
|
tx.addOutput({
|
|
111
109
|
lock: to,
|
|
112
110
|
type: sporeCell.cellOutput.type,
|
|
113
111
|
}, sporeCell.outputData);
|
|
114
|
-
const actions =
|
|
112
|
+
const actions = sporeScriptInfo.cobuild
|
|
115
113
|
? [
|
|
116
114
|
(0, advanced_js_1.assembleTransferSporeAction)(sporeCell.cellOutput, tx.outputs[tx.outputs.length - 1], scriptInfoHash),
|
|
117
115
|
]
|
|
@@ -123,25 +121,22 @@ async function transferSpore(params) {
|
|
|
123
121
|
/**
|
|
124
122
|
* Melt one Spore cell
|
|
125
123
|
*
|
|
126
|
-
* @param signer who takes the responsibility to balance and sign the transaction
|
|
127
|
-
* @param id sporeId to be melted
|
|
128
|
-
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
129
|
-
* @param scriptInfoHash the script info hash used in cobuild
|
|
124
|
+
* @param params.signer who takes the responsibility to balance and sign the transaction
|
|
125
|
+
* @param params.id sporeId to be melted
|
|
126
|
+
* @param params.tx the transaction skeleton, if not provided, a new one will be created
|
|
127
|
+
* @param params.scriptInfoHash the script info hash used in cobuild
|
|
130
128
|
* @returns
|
|
131
129
|
* - **tx**: a new transaction that contains melted Spore cell
|
|
132
130
|
*/
|
|
133
131
|
async function meltSpore(params) {
|
|
134
|
-
const { signer, id, scriptInfoHash } = params;
|
|
132
|
+
const { signer, id, scripts, scriptInfoHash } = params;
|
|
135
133
|
// prepare transaction
|
|
136
134
|
const tx = core_1.ccc.Transaction.from(params.tx ?? {});
|
|
137
135
|
// build spore cell
|
|
138
|
-
const { cell: sporeCell, scriptInfo } = await assertSpore(signer.client, id);
|
|
139
|
-
await tx.addCellDepInfos(signer.client,
|
|
140
|
-
tx.
|
|
141
|
-
|
|
142
|
-
...sporeCell,
|
|
143
|
-
}));
|
|
144
|
-
const actions = scriptInfo.cobuild
|
|
136
|
+
const { cell: sporeCell, scriptInfo: sporeScriptInfo } = await assertSpore(signer.client, id, scripts);
|
|
137
|
+
await tx.addCellDepInfos(signer.client, sporeScriptInfo.cellDeps);
|
|
138
|
+
tx.addInput(sporeCell);
|
|
139
|
+
const actions = sporeScriptInfo.cobuild
|
|
145
140
|
? [(0, advanced_js_1.assembleMeltSporeAction)(sporeCell.cellOutput, scriptInfoHash)]
|
|
146
141
|
: [];
|
|
147
142
|
return {
|
|
@@ -151,13 +146,14 @@ async function meltSpore(params) {
|
|
|
151
146
|
/**
|
|
152
147
|
* Search on-chain spores under the signer's control, if cluster provided, filter spores belonging to this cluster
|
|
153
148
|
*
|
|
154
|
-
* @param signer the owner of spores
|
|
155
|
-
* @param order the order in creation time of spores
|
|
156
|
-
* @param clusterId the cluster that spores belong to. "" to find public spores
|
|
157
|
-
* @param scriptInfos the deployed script infos of spores
|
|
149
|
+
* @param params.signer the owner of spores
|
|
150
|
+
* @param params.order the order in creation time of spores
|
|
151
|
+
* @param params.clusterId the cluster that spores belong to. "" to find public spores
|
|
152
|
+
* @param params.scriptInfos the deployed script infos of spores
|
|
158
153
|
* @returns specified spore cells
|
|
159
154
|
*/
|
|
160
|
-
async function* findSporesBySigner(
|
|
155
|
+
async function* findSporesBySigner(params) {
|
|
156
|
+
const { signer, clusterId, scriptInfos, limit, order } = params;
|
|
161
157
|
for (const scriptInfo of scriptInfos ??
|
|
162
158
|
Object.values((0, index_js_3.getSporeScriptInfos)(signer.client))) {
|
|
163
159
|
if (!scriptInfo) {
|
|
@@ -183,3 +179,49 @@ async function* findSporesBySigner({ signer, clusterId, scriptInfos, limit, orde
|
|
|
183
179
|
}
|
|
184
180
|
}
|
|
185
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Search on-chain spores under the specified lock or not, if cluster provided, filter spores belonging to this cluster
|
|
184
|
+
*
|
|
185
|
+
* @param params.client the client to search spores
|
|
186
|
+
* @param params.lock the lock of spores
|
|
187
|
+
* @param params.clusterId the cluster that spores belong to. "" to find public spores
|
|
188
|
+
* @param params.scriptInfos the deployed script infos of spores
|
|
189
|
+
* @param params.limit the limit of spores to search
|
|
190
|
+
* @param params.order the order in creation time of spores
|
|
191
|
+
* @returns specified spore cells
|
|
192
|
+
*/
|
|
193
|
+
async function* findSpores(params) {
|
|
194
|
+
const { client, lock, clusterId, scriptInfos, limit, order } = params;
|
|
195
|
+
for (const scriptInfo of scriptInfos ??
|
|
196
|
+
Object.values((0, index_js_3.getSporeScriptInfos)(client))) {
|
|
197
|
+
if (!scriptInfo) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
for await (const spore of client.findCells({
|
|
201
|
+
script: {
|
|
202
|
+
...scriptInfo,
|
|
203
|
+
args: [],
|
|
204
|
+
},
|
|
205
|
+
scriptType: "type",
|
|
206
|
+
scriptSearchMode: "prefix",
|
|
207
|
+
withData: true,
|
|
208
|
+
filter: lock
|
|
209
|
+
? {
|
|
210
|
+
script: lock,
|
|
211
|
+
}
|
|
212
|
+
: undefined,
|
|
213
|
+
}, order, limit)) {
|
|
214
|
+
const sporeData = (0, index_js_1.unpackToRawSporeData)(spore.outputData);
|
|
215
|
+
if (!clusterId ||
|
|
216
|
+
(clusterId === "" && !sporeData.clusterId) ||
|
|
217
|
+
sporeData.clusterId === core_1.ccc.hexFrom(clusterId)) {
|
|
218
|
+
yield {
|
|
219
|
+
cell: spore,
|
|
220
|
+
spore,
|
|
221
|
+
sporeData,
|
|
222
|
+
scriptInfo: index_js_3.SporeScriptInfo.from(scriptInfo),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|