@ckb-ccc/spore 0.1.0-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/CHANGELOG.md +12 -0
- package/README.md +61 -0
- package/dist/advanced.d.ts +5 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +4 -0
- package/dist/cluster/index.d.ts +56 -0
- package/dist/cluster/index.d.ts.map +1 -0
- package/dist/cluster/index.js +96 -0
- package/dist/cobuild/index.d.ts +13 -0
- package/dist/cobuild/index.d.ts.map +1 -0
- package/dist/cobuild/index.js +168 -0
- package/dist/codec/base.d.ts +6 -0
- package/dist/codec/base.d.ts.map +1 -0
- package/dist/codec/base.js +10 -0
- package/dist/codec/cluster.d.ts +41 -0
- package/dist/codec/cluster.d.ts.map +1 -0
- package/dist/codec/cluster.js +73 -0
- package/dist/codec/cobuild/buildingPacket.d.ts +465 -0
- package/dist/codec/cobuild/buildingPacket.d.ts.map +1 -0
- package/dist/codec/cobuild/buildingPacket.js +44 -0
- package/dist/codec/cobuild/index.d.ts +4 -0
- package/dist/codec/cobuild/index.d.ts.map +1 -0
- package/dist/codec/cobuild/index.js +3 -0
- package/dist/codec/cobuild/sporeAction.d.ts +314 -0
- package/dist/codec/cobuild/sporeAction.d.ts.map +1 -0
- package/dist/codec/cobuild/sporeAction.js +104 -0
- package/dist/codec/cobuild/witnessLayout.d.ts +43 -0
- package/dist/codec/cobuild/witnessLayout.d.ts.map +1 -0
- package/dist/codec/cobuild/witnessLayout.js +27 -0
- package/dist/codec/index.d.ts +4 -0
- package/dist/codec/index.d.ts.map +1 -0
- package/dist/codec/index.js +3 -0
- package/dist/codec/spore.d.ts +15 -0
- package/dist/codec/spore.d.ts.map +1 -0
- package/dist/codec/spore.js +24 -0
- package/dist/dob/api/decode.d.ts +6 -0
- package/dist/dob/api/decode.d.ts.map +1 -0
- package/dist/dob/api/decode.js +44 -0
- package/dist/dob/api/encode.d.ts +5 -0
- package/dist/dob/api/encode.d.ts.map +1 -0
- package/dist/dob/api/encode.js +77 -0
- package/dist/dob/api/index.d.ts +3 -0
- package/dist/dob/api/index.d.ts.map +1 -0
- package/dist/dob/api/index.js +2 -0
- package/dist/dob/config/index.d.ts +2 -0
- package/dist/dob/config/index.d.ts.map +1 -0
- package/dist/dob/config/index.js +1 -0
- package/dist/dob/config/predefined.d.ts +8 -0
- package/dist/dob/config/predefined.d.ts.map +1 -0
- package/dist/dob/config/predefined.js +59 -0
- package/dist/dob/helper/check.d.ts +5 -0
- package/dist/dob/helper/check.d.ts.map +1 -0
- package/dist/dob/helper/check.js +75 -0
- package/dist/dob/helper/error.d.ts +2 -0
- package/dist/dob/helper/error.d.ts.map +1 -0
- package/dist/dob/helper/error.js +40 -0
- package/dist/dob/helper/index.d.ts +3 -0
- package/dist/dob/helper/index.d.ts.map +1 -0
- package/dist/dob/helper/index.js +2 -0
- package/dist/dob/helper/object.d.ts +59 -0
- package/dist/dob/helper/object.d.ts.map +1 -0
- package/dist/dob/helper/object.js +1 -0
- package/dist/dob/index.d.ts +4 -0
- package/dist/dob/index.d.ts.map +1 -0
- package/dist/dob/index.js +3 -0
- package/dist/helper/index.d.ts +9 -0
- package/dist/helper/index.d.ts.map +1 -0
- package/dist/helper/index.js +37 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/package.json +3 -0
- package/dist/predefined/advanced.d.ts +3 -0
- package/dist/predefined/advanced.d.ts.map +1 -0
- package/dist/predefined/advanced.js +2 -0
- package/dist/predefined/index.d.ts +3 -0
- package/dist/predefined/index.d.ts.map +1 -0
- package/dist/predefined/index.js +2 -0
- package/dist/predefined/mainnet.advanced.d.ts +4 -0
- package/dist/predefined/mainnet.advanced.d.ts.map +1 -0
- package/dist/predefined/mainnet.advanced.js +61 -0
- package/dist/predefined/testnet.advanced.d.ts +4 -0
- package/dist/predefined/testnet.advanced.d.ts.map +1 -0
- package/dist/predefined/testnet.advanced.js +88 -0
- package/dist/predefined/types.d.ts +17 -0
- package/dist/predefined/types.d.ts.map +1 -0
- package/dist/predefined/types.js +18 -0
- package/dist/predefined/utils.d.ts +7 -0
- package/dist/predefined/utils.d.ts.map +1 -0
- package/dist/predefined/utils.js +26 -0
- package/dist/spore/advanced.d.ts +5 -0
- package/dist/spore/advanced.d.ts.map +1 -0
- package/dist/spore/advanced.js +62 -0
- package/dist/spore/index.d.ts +80 -0
- package/dist/spore/index.d.ts.map +1 -0
- package/dist/spore/index.js +135 -0
- package/dist.commonjs/advanced.d.ts +5 -0
- package/dist.commonjs/advanced.d.ts.map +1 -0
- package/dist.commonjs/advanced.js +20 -0
- package/dist.commonjs/cluster/index.d.ts +56 -0
- package/dist.commonjs/cluster/index.d.ts.map +1 -0
- package/dist.commonjs/cluster/index.js +102 -0
- package/dist.commonjs/cobuild/index.d.ts +13 -0
- package/dist.commonjs/cobuild/index.d.ts.map +1 -0
- package/dist.commonjs/cobuild/index.js +179 -0
- package/dist.commonjs/codec/base.d.ts +6 -0
- package/dist.commonjs/codec/base.d.ts.map +1 -0
- package/dist.commonjs/codec/base.js +13 -0
- package/dist.commonjs/codec/cluster.d.ts +41 -0
- package/dist.commonjs/codec/cluster.d.ts.map +1 -0
- package/dist.commonjs/codec/cluster.js +82 -0
- package/dist.commonjs/codec/cobuild/buildingPacket.d.ts +465 -0
- package/dist.commonjs/codec/cobuild/buildingPacket.d.ts.map +1 -0
- package/dist.commonjs/codec/cobuild/buildingPacket.js +47 -0
- package/dist.commonjs/codec/cobuild/index.d.ts +4 -0
- package/dist.commonjs/codec/cobuild/index.d.ts.map +1 -0
- package/dist.commonjs/codec/cobuild/index.js +19 -0
- package/dist.commonjs/codec/cobuild/sporeAction.d.ts +314 -0
- package/dist.commonjs/codec/cobuild/sporeAction.d.ts.map +1 -0
- package/dist.commonjs/codec/cobuild/sporeAction.js +107 -0
- package/dist.commonjs/codec/cobuild/witnessLayout.d.ts +43 -0
- package/dist.commonjs/codec/cobuild/witnessLayout.d.ts.map +1 -0
- package/dist.commonjs/codec/cobuild/witnessLayout.js +30 -0
- package/dist.commonjs/codec/index.d.ts +4 -0
- package/dist.commonjs/codec/index.d.ts.map +1 -0
- package/dist.commonjs/codec/index.js +19 -0
- package/dist.commonjs/codec/spore.d.ts +15 -0
- package/dist.commonjs/codec/spore.d.ts.map +1 -0
- package/dist.commonjs/codec/spore.js +29 -0
- package/dist.commonjs/dob/api/decode.d.ts +6 -0
- package/dist.commonjs/dob/api/decode.d.ts.map +1 -0
- package/dist.commonjs/dob/api/decode.js +49 -0
- package/dist.commonjs/dob/api/encode.d.ts +5 -0
- package/dist.commonjs/dob/api/encode.d.ts.map +1 -0
- package/dist.commonjs/dob/api/encode.js +82 -0
- package/dist.commonjs/dob/api/index.d.ts +3 -0
- package/dist.commonjs/dob/api/index.d.ts.map +1 -0
- package/dist.commonjs/dob/api/index.js +18 -0
- package/dist.commonjs/dob/config/index.d.ts +2 -0
- package/dist.commonjs/dob/config/index.d.ts.map +1 -0
- package/dist.commonjs/dob/config/index.js +17 -0
- package/dist.commonjs/dob/config/predefined.d.ts +8 -0
- package/dist.commonjs/dob/config/predefined.d.ts.map +1 -0
- package/dist.commonjs/dob/config/predefined.js +63 -0
- package/dist.commonjs/dob/helper/check.d.ts +5 -0
- package/dist.commonjs/dob/helper/check.d.ts.map +1 -0
- package/dist.commonjs/dob/helper/check.js +80 -0
- package/dist.commonjs/dob/helper/error.d.ts +2 -0
- package/dist.commonjs/dob/helper/error.d.ts.map +1 -0
- package/dist.commonjs/dob/helper/error.js +43 -0
- package/dist.commonjs/dob/helper/index.d.ts +3 -0
- package/dist.commonjs/dob/helper/index.d.ts.map +1 -0
- package/dist.commonjs/dob/helper/index.js +18 -0
- package/dist.commonjs/dob/helper/object.d.ts +59 -0
- package/dist.commonjs/dob/helper/object.d.ts.map +1 -0
- package/dist.commonjs/dob/helper/object.js +2 -0
- package/dist.commonjs/dob/index.d.ts +4 -0
- package/dist.commonjs/dob/index.d.ts.map +1 -0
- package/dist.commonjs/dob/index.js +19 -0
- package/dist.commonjs/helper/index.d.ts +9 -0
- package/dist.commonjs/helper/index.d.ts.map +1 -0
- package/dist.commonjs/helper/index.js +42 -0
- package/dist.commonjs/index.d.ts +5 -0
- package/dist.commonjs/index.d.ts.map +1 -0
- package/dist.commonjs/index.js +33 -0
- package/dist.commonjs/package.json +3 -0
- package/dist.commonjs/predefined/advanced.d.ts +3 -0
- package/dist.commonjs/predefined/advanced.d.ts.map +1 -0
- package/dist.commonjs/predefined/advanced.js +18 -0
- package/dist.commonjs/predefined/index.d.ts +3 -0
- package/dist.commonjs/predefined/index.d.ts.map +1 -0
- package/dist.commonjs/predefined/index.js +18 -0
- package/dist.commonjs/predefined/mainnet.advanced.d.ts +4 -0
- package/dist.commonjs/predefined/mainnet.advanced.d.ts.map +1 -0
- package/dist.commonjs/predefined/mainnet.advanced.js +64 -0
- package/dist.commonjs/predefined/testnet.advanced.d.ts +4 -0
- package/dist.commonjs/predefined/testnet.advanced.d.ts.map +1 -0
- package/dist.commonjs/predefined/testnet.advanced.js +91 -0
- package/dist.commonjs/predefined/types.d.ts +17 -0
- package/dist.commonjs/predefined/types.d.ts.map +1 -0
- package/dist.commonjs/predefined/types.js +22 -0
- package/dist.commonjs/predefined/utils.d.ts +7 -0
- package/dist.commonjs/predefined/utils.d.ts.map +1 -0
- package/dist.commonjs/predefined/utils.js +32 -0
- package/dist.commonjs/spore/advanced.d.ts +5 -0
- package/dist.commonjs/spore/advanced.d.ts.map +1 -0
- package/dist.commonjs/spore/advanced.js +65 -0
- package/dist.commonjs/spore/index.d.ts +80 -0
- package/dist.commonjs/spore/index.d.ts.map +1 -0
- package/dist.commonjs/spore/index.js +142 -0
- package/package.json +52 -0
- package/src/advanced.ts +4 -0
- package/src/cluster/index.ts +180 -0
- package/src/cobuild/index.ts +220 -0
- package/src/codec/base.ts +11 -0
- package/src/codec/cluster.ts +133 -0
- package/src/codec/cobuild/buildingPacket.ts +72 -0
- package/src/codec/cobuild/index.ts +3 -0
- package/src/codec/cobuild/sporeAction.ts +153 -0
- package/src/codec/cobuild/witnessLayout.ts +40 -0
- package/src/codec/index.ts +3 -0
- package/src/codec/spore.ts +36 -0
- package/src/dob/api/decode.ts +61 -0
- package/src/dob/api/encode.ts +84 -0
- package/src/dob/api/index.ts +2 -0
- package/src/dob/config/index.ts +1 -0
- package/src/dob/config/predefined.ts +71 -0
- package/src/dob/helper/check.ts +107 -0
- package/src/dob/helper/error.ts +41 -0
- package/src/dob/helper/index.ts +2 -0
- package/src/dob/helper/object.ts +66 -0
- package/src/dob/index.ts +3 -0
- package/src/helper/index.ts +68 -0
- package/src/index.ts +4 -0
- package/src/predefined/advanced.ts +2 -0
- package/src/predefined/index.ts +2 -0
- package/src/predefined/mainnet.advanced.ts +76 -0
- package/src/predefined/testnet.advanced.ts +107 -0
- package/src/predefined/types.ts +37 -0
- package/src/predefined/utils.ts +56 -0
- package/src/spore/advanced.ts +88 -0
- package/src/spore/index.ts +236 -0
- package/typedoc.json +6 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { SporeScriptInfo, SporeScriptInfoLike } from "../predefined/index.js";
|
|
3
|
+
|
|
4
|
+
export async function findSingletonCellByArgs(
|
|
5
|
+
client: ccc.Client,
|
|
6
|
+
args: ccc.HexLike,
|
|
7
|
+
scripts: (SporeScriptInfoLike | undefined)[],
|
|
8
|
+
): Promise<
|
|
9
|
+
| {
|
|
10
|
+
cell: ccc.Cell;
|
|
11
|
+
scriptInfo: SporeScriptInfo;
|
|
12
|
+
}
|
|
13
|
+
| undefined
|
|
14
|
+
> {
|
|
15
|
+
for (const scriptInfo of scripts) {
|
|
16
|
+
if (!scriptInfo) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const cell = await client.findSingletonCellByType(
|
|
21
|
+
{
|
|
22
|
+
...scriptInfo,
|
|
23
|
+
args,
|
|
24
|
+
},
|
|
25
|
+
true,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
if (cell) {
|
|
29
|
+
return {
|
|
30
|
+
cell,
|
|
31
|
+
scriptInfo: SporeScriptInfo.from(scriptInfo),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function searchOneCellBySigner(
|
|
38
|
+
signer: ccc.Signer,
|
|
39
|
+
): Promise<ccc.Cell | undefined> {
|
|
40
|
+
for await (const cell of signer.findCells(
|
|
41
|
+
{
|
|
42
|
+
scriptLenRange: [0, 1],
|
|
43
|
+
outputDataLenRange: [0, 1],
|
|
44
|
+
},
|
|
45
|
+
true,
|
|
46
|
+
undefined,
|
|
47
|
+
1,
|
|
48
|
+
)) {
|
|
49
|
+
return cell;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function injectOneCapacityCell(
|
|
54
|
+
signer: ccc.Signer,
|
|
55
|
+
tx: ccc.Transaction,
|
|
56
|
+
): Promise<void> {
|
|
57
|
+
const liveCell = await searchOneCellBySigner(signer);
|
|
58
|
+
if (!liveCell) {
|
|
59
|
+
throw new Error("No live cell found");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
tx.inputs.push(
|
|
63
|
+
ccc.CellInput.from({
|
|
64
|
+
previousOutput: liveCell.outPoint,
|
|
65
|
+
...liveCell,
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SporeScriptInfoLike, SporeVersion } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export const SCRIPTS_SPORE_MAINNET: Record<
|
|
4
|
+
SporeVersion,
|
|
5
|
+
SporeScriptInfoLike | undefined
|
|
6
|
+
> = Object.freeze({
|
|
7
|
+
[SporeVersion.DID]: {
|
|
8
|
+
codeHash:
|
|
9
|
+
"0xcfba73b58b6f30e70caed8a999748781b164ef9a1e218424a6fb55ebf641cb33",
|
|
10
|
+
hashType: "type",
|
|
11
|
+
cellDeps: [
|
|
12
|
+
{
|
|
13
|
+
cellDep: {
|
|
14
|
+
outPoint: {
|
|
15
|
+
txHash:
|
|
16
|
+
"0x37c80ba8124780920bc8fe06b49e3535b43ca339bb9a97fb462b16d575bfa9a6",
|
|
17
|
+
index: 0,
|
|
18
|
+
},
|
|
19
|
+
depType: "code",
|
|
20
|
+
},
|
|
21
|
+
type: {
|
|
22
|
+
codeHash:
|
|
23
|
+
"0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
24
|
+
hashType: "type",
|
|
25
|
+
args: "0x62312cd846659e188b05da11dc3f080b083c27371ea701d6026e11e713e0e3de",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
cobuild: true,
|
|
30
|
+
},
|
|
31
|
+
[SporeVersion.V2]: {
|
|
32
|
+
codeHash:
|
|
33
|
+
"0x4a4dce1df3dffff7f8b2cd7dff7303df3b6150c9788cb75dcf6747247132b9f5",
|
|
34
|
+
hashType: "data1",
|
|
35
|
+
cellDeps: [
|
|
36
|
+
{
|
|
37
|
+
cellDep: {
|
|
38
|
+
outPoint: {
|
|
39
|
+
txHash:
|
|
40
|
+
"0x96b198fb5ddbd1eed57ed667068f1f1e55d07907b4c0dbd38675a69ea1b69824",
|
|
41
|
+
index: 0,
|
|
42
|
+
},
|
|
43
|
+
depType: "code",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
cobuild: true,
|
|
48
|
+
},
|
|
49
|
+
[SporeVersion.V1]: undefined,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const SCRIPTS_CLUSTER_MAINNET: Record<
|
|
53
|
+
SporeVersion,
|
|
54
|
+
SporeScriptInfoLike | undefined
|
|
55
|
+
> = Object.freeze({
|
|
56
|
+
[SporeVersion.V2]: {
|
|
57
|
+
codeHash:
|
|
58
|
+
"0x7366a61534fa7c7e6225ecc0d828ea3b5366adec2b58206f2ee84995fe030075",
|
|
59
|
+
hashType: "data1",
|
|
60
|
+
cellDeps: [
|
|
61
|
+
{
|
|
62
|
+
cellDep: {
|
|
63
|
+
outPoint: {
|
|
64
|
+
txHash:
|
|
65
|
+
"0xe464b7fb9311c5e2820e61c99afc615d6b98bdefbe318c34868c010cbd0dc938",
|
|
66
|
+
index: 0,
|
|
67
|
+
},
|
|
68
|
+
depType: "code",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
cobuild: true,
|
|
73
|
+
},
|
|
74
|
+
[SporeVersion.V1]: undefined,
|
|
75
|
+
[SporeVersion.DID]: undefined,
|
|
76
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { SporeScriptInfoLike, SporeVersion } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export const SCRIPTS_SPORE_TESTNET: Record<
|
|
4
|
+
SporeVersion,
|
|
5
|
+
SporeScriptInfoLike | undefined
|
|
6
|
+
> = Object.freeze({
|
|
7
|
+
[SporeVersion.DID]: {
|
|
8
|
+
codeHash:
|
|
9
|
+
"0x0b1f412fbae26853ff7d082d422c2bdd9e2ff94ee8aaec11240a5b34cc6e890f",
|
|
10
|
+
hashType: "type",
|
|
11
|
+
cellDeps: [
|
|
12
|
+
{
|
|
13
|
+
cellDep: {
|
|
14
|
+
outPoint: {
|
|
15
|
+
txHash:
|
|
16
|
+
"0x306961e0eb04ed972c60cb89a0aed1b0ef065d96d2fc0000c62db5275e32dc6f",
|
|
17
|
+
index: 0,
|
|
18
|
+
},
|
|
19
|
+
depType: "code",
|
|
20
|
+
},
|
|
21
|
+
type: {
|
|
22
|
+
codeHash:
|
|
23
|
+
"0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
24
|
+
hashType: "type",
|
|
25
|
+
args: "0x80f0d4bf6b3951911aa6b98cc609d477a8a10b903b35cfd528d098e95c36f680",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
[SporeVersion.V2]: {
|
|
31
|
+
codeHash:
|
|
32
|
+
"0x685a60219309029d01310311dba953d67029170ca4848a4ff638e57002130a0d",
|
|
33
|
+
hashType: "data1",
|
|
34
|
+
cellDeps: [
|
|
35
|
+
{
|
|
36
|
+
cellDep: {
|
|
37
|
+
outPoint: {
|
|
38
|
+
txHash:
|
|
39
|
+
"0x5e8d2a517d50fd4bb4d01737a7952a1f1d35c8afc77240695bb569cd7d9d5a1f",
|
|
40
|
+
index: 0,
|
|
41
|
+
},
|
|
42
|
+
depType: "code",
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
cobuild: true,
|
|
47
|
+
},
|
|
48
|
+
[SporeVersion.V1]: {
|
|
49
|
+
codeHash:
|
|
50
|
+
"0xbbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494",
|
|
51
|
+
hashType: "data1",
|
|
52
|
+
cellDeps: [
|
|
53
|
+
{
|
|
54
|
+
cellDep: {
|
|
55
|
+
outPoint: {
|
|
56
|
+
txHash:
|
|
57
|
+
"0xfd694382e621f175ddf81ce91ce2ecf8bfc027d53d7d31b8438f7d26fc37fd19",
|
|
58
|
+
index: 0,
|
|
59
|
+
},
|
|
60
|
+
depType: "code",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const SCRIPTS_CLUSTER_TESTNET: Record<
|
|
68
|
+
SporeVersion,
|
|
69
|
+
SporeScriptInfoLike | undefined
|
|
70
|
+
> = Object.freeze({
|
|
71
|
+
[SporeVersion.V2]: {
|
|
72
|
+
codeHash:
|
|
73
|
+
"0x0bbe768b519d8ea7b96d58f1182eb7e6ef96c541fbd9526975077ee09f049058",
|
|
74
|
+
hashType: "data1",
|
|
75
|
+
cellDeps: [
|
|
76
|
+
{
|
|
77
|
+
cellDep: {
|
|
78
|
+
outPoint: {
|
|
79
|
+
txHash:
|
|
80
|
+
"0xcebb174d6e300e26074aea2f5dbd7f694bb4fe3de52b6dfe205e54f90164510a",
|
|
81
|
+
index: 0,
|
|
82
|
+
},
|
|
83
|
+
depType: "code",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
cobuild: true,
|
|
88
|
+
},
|
|
89
|
+
[SporeVersion.V1]: {
|
|
90
|
+
codeHash:
|
|
91
|
+
"0x598d793defef36e2eeba54a9b45130e4ca92822e1d193671f490950c3b856080",
|
|
92
|
+
hashType: "data1",
|
|
93
|
+
cellDeps: [
|
|
94
|
+
{
|
|
95
|
+
cellDep: {
|
|
96
|
+
outPoint: {
|
|
97
|
+
txHash:
|
|
98
|
+
"0x49551a20dfe39231e7db49431d26c9c08ceec96a29024eef3acc936deeb2ca76",
|
|
99
|
+
index: 0,
|
|
100
|
+
},
|
|
101
|
+
depType: "code",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
[SporeVersion.DID]: undefined,
|
|
107
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_COBUILD_INFO_HASH = ccc.hashCkb(
|
|
4
|
+
ccc.bytesFrom("CCC_DEFAULT_COBUILD_INFO", "utf8"),
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
export enum SporeVersion {
|
|
8
|
+
V1 = "V1",
|
|
9
|
+
V2 = "V2",
|
|
10
|
+
DID = "DID",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const SPORE_VERSION_DEFAULT = SporeVersion.V2;
|
|
14
|
+
|
|
15
|
+
export type SporeScriptInfoLike = ccc.ScriptInfoLike & {
|
|
16
|
+
cobuild?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export class SporeScriptInfo extends ccc.ScriptInfo {
|
|
20
|
+
constructor(
|
|
21
|
+
codeHash: ccc.Hex,
|
|
22
|
+
hashType: ccc.HashType,
|
|
23
|
+
cellDeps: ccc.CellDepInfo[],
|
|
24
|
+
public cobuild?: boolean,
|
|
25
|
+
) {
|
|
26
|
+
super(codeHash, hashType, cellDeps);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static from(scriptInfoLike: SporeScriptInfoLike): SporeScriptInfo {
|
|
30
|
+
return new SporeScriptInfo(
|
|
31
|
+
ccc.hexFrom(scriptInfoLike.codeHash),
|
|
32
|
+
ccc.hashTypeFrom(scriptInfoLike.hashType),
|
|
33
|
+
scriptInfoLike.cellDeps.map((c) => ccc.CellDepInfo.from(c)),
|
|
34
|
+
scriptInfoLike.cobuild,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import {
|
|
3
|
+
SCRIPTS_CLUSTER_MAINNET,
|
|
4
|
+
SCRIPTS_CLUSTER_TESTNET,
|
|
5
|
+
SCRIPTS_SPORE_MAINNET,
|
|
6
|
+
SCRIPTS_SPORE_TESTNET,
|
|
7
|
+
} from "./advanced.js";
|
|
8
|
+
import {
|
|
9
|
+
SPORE_VERSION_DEFAULT,
|
|
10
|
+
SporeScriptInfo,
|
|
11
|
+
SporeVersion,
|
|
12
|
+
} from "./types.js";
|
|
13
|
+
|
|
14
|
+
export function getSporeScriptInfos(client: ccc.Client) {
|
|
15
|
+
return client.addressPrefix === "ckb"
|
|
16
|
+
? SCRIPTS_SPORE_MAINNET
|
|
17
|
+
: SCRIPTS_SPORE_TESTNET;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getClusterScriptInfos(client: ccc.Client) {
|
|
21
|
+
return client.addressPrefix === "ckb"
|
|
22
|
+
? SCRIPTS_CLUSTER_MAINNET
|
|
23
|
+
: SCRIPTS_CLUSTER_TESTNET;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getSporeScriptInfo(
|
|
27
|
+
client: ccc.Client,
|
|
28
|
+
version?: SporeVersion,
|
|
29
|
+
): SporeScriptInfo {
|
|
30
|
+
const scriptInfo =
|
|
31
|
+
getSporeScriptInfos(client)[version ?? SPORE_VERSION_DEFAULT];
|
|
32
|
+
|
|
33
|
+
if (!scriptInfo) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`Spore script info not found of for version ${version} on ${client.addressPrefix}`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return SporeScriptInfo.from(scriptInfo);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getClusterScriptInfo(
|
|
43
|
+
client: ccc.Client,
|
|
44
|
+
version?: SporeVersion,
|
|
45
|
+
): SporeScriptInfo {
|
|
46
|
+
const scriptInfo =
|
|
47
|
+
getClusterScriptInfos(client)[version ?? SPORE_VERSION_DEFAULT];
|
|
48
|
+
|
|
49
|
+
if (!scriptInfo) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Cluster script info not found of for version ${version} on ${client.addressPrefix}`,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return SporeScriptInfo.from(scriptInfo);
|
|
56
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { UnpackResult } from "@ckb-lumos/codec";
|
|
3
|
+
import { assembleTransferClusterAction } from "../advanced.js";
|
|
4
|
+
import { assertCluster } from "../cluster/index.js";
|
|
5
|
+
import { Action, SporeData } from "../codec/index.js";
|
|
6
|
+
import { searchOneCellBySigner } from "../helper/index.js";
|
|
7
|
+
|
|
8
|
+
export async function prepareCluster(
|
|
9
|
+
signer: ccc.Signer,
|
|
10
|
+
tx: ccc.Transaction,
|
|
11
|
+
data: SporeData,
|
|
12
|
+
clusterMode?: "lockProxy" | "clusterCell" | "skip",
|
|
13
|
+
scriptInfoHash?: ccc.HexLike,
|
|
14
|
+
): Promise<UnpackResult<typeof Action> | undefined> {
|
|
15
|
+
// skip if the spore is not belong to a cluster
|
|
16
|
+
if (!data.clusterId || clusterMode === "skip") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!clusterMode) {
|
|
21
|
+
throw Error("clusterMode is undefined but the spore has a cluster");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { cell: cluster, scriptInfo } = await assertCluster(
|
|
25
|
+
signer.client,
|
|
26
|
+
data.clusterId,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// If this cluster has been processed, nothing will happen to the tx
|
|
30
|
+
switch (clusterMode) {
|
|
31
|
+
case "lockProxy": {
|
|
32
|
+
const lock = cluster.cellOutput.lock;
|
|
33
|
+
|
|
34
|
+
if (!(await tx.findInputIndexByLock(lock, signer.client))) {
|
|
35
|
+
// note: We can only search proxy of signer, if any custom logic is in need, developer should get
|
|
36
|
+
// the proxy filled in transaction before invoking `createSpore`
|
|
37
|
+
const proxy = await searchOneCellBySigner(signer);
|
|
38
|
+
if (!proxy) {
|
|
39
|
+
throw new Error("Cluster lock proxy cell not found");
|
|
40
|
+
}
|
|
41
|
+
tx.inputs.push(
|
|
42
|
+
ccc.CellInput.from({
|
|
43
|
+
previousOutput: proxy.outPoint,
|
|
44
|
+
...proxy,
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (tx.outputs.every((output) => output.lock !== lock)) {
|
|
49
|
+
tx.addOutput({
|
|
50
|
+
lock,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
tx.addCellDeps({
|
|
54
|
+
outPoint: cluster.outPoint,
|
|
55
|
+
depType: "code",
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
case "clusterCell": {
|
|
60
|
+
if (tx.inputs.some((i) => i.previousOutput.eq(cluster.outPoint))) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
tx.inputs.push(
|
|
65
|
+
ccc.CellInput.from({
|
|
66
|
+
previousOutput: cluster.outPoint,
|
|
67
|
+
...cluster,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
tx.addOutput(cluster.cellOutput, cluster.outputData);
|
|
71
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
72
|
+
// note: add cluster as cellDep, which will be used in Spore contract
|
|
73
|
+
tx.addCellDeps({
|
|
74
|
+
outPoint: cluster.outPoint,
|
|
75
|
+
depType: "code",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (scriptInfo.cobuild) {
|
|
79
|
+
return assembleTransferClusterAction(
|
|
80
|
+
cluster.cellOutput,
|
|
81
|
+
cluster.cellOutput,
|
|
82
|
+
scriptInfoHash,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import {
|
|
3
|
+
assembleCreateSporeAction,
|
|
4
|
+
assembleMeltSporeAction,
|
|
5
|
+
assembleTransferSporeAction,
|
|
6
|
+
prepareSporeTransaction,
|
|
7
|
+
} from "../advanced.js";
|
|
8
|
+
import { SporeData, packRawSporeData } from "../codec/index.js";
|
|
9
|
+
import {
|
|
10
|
+
findSingletonCellByArgs,
|
|
11
|
+
injectOneCapacityCell,
|
|
12
|
+
} from "../helper/index.js";
|
|
13
|
+
import {
|
|
14
|
+
SporeScriptInfo,
|
|
15
|
+
SporeScriptInfoLike,
|
|
16
|
+
getSporeScriptInfo,
|
|
17
|
+
getSporeScriptInfos,
|
|
18
|
+
} from "../predefined/index.js";
|
|
19
|
+
import { prepareCluster } from "./advanced.js";
|
|
20
|
+
|
|
21
|
+
export async function findSpore(
|
|
22
|
+
client: ccc.Client,
|
|
23
|
+
args: ccc.HexLike,
|
|
24
|
+
scripts?: SporeScriptInfoLike[],
|
|
25
|
+
): Promise<
|
|
26
|
+
| {
|
|
27
|
+
cell: ccc.Cell;
|
|
28
|
+
scriptInfo: SporeScriptInfo;
|
|
29
|
+
}
|
|
30
|
+
| undefined
|
|
31
|
+
> {
|
|
32
|
+
return findSingletonCellByArgs(
|
|
33
|
+
client,
|
|
34
|
+
args,
|
|
35
|
+
scripts ?? Object.values(getSporeScriptInfos(client)),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function assertSpore(
|
|
40
|
+
client: ccc.Client,
|
|
41
|
+
args: ccc.HexLike,
|
|
42
|
+
scripts?: SporeScriptInfoLike[],
|
|
43
|
+
): Promise<{
|
|
44
|
+
cell: ccc.Cell;
|
|
45
|
+
scriptInfo: SporeScriptInfo;
|
|
46
|
+
}> {
|
|
47
|
+
const res = await findSpore(client, args, scripts);
|
|
48
|
+
|
|
49
|
+
if (!res) {
|
|
50
|
+
throw new Error(`Spore ${ccc.hexFrom(args)} not found`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create one Spore cell with the specified Spore data.
|
|
58
|
+
*
|
|
59
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
60
|
+
* @param data specific format of data required by Spore protocol
|
|
61
|
+
* @param to owner of new spore cell, signer if no provided
|
|
62
|
+
* @param clusterMode how to process cluster cell **(if clusterId is not provided in SporeData, this parameter will be ignored)**
|
|
63
|
+
* - undefined: error if the spore has a cluster but the clusterMode is not set
|
|
64
|
+
* - lockProxy: put a cell that uses the same lock from Cluster cell in both Inputs and Outputs
|
|
65
|
+
* - clusterCell: directly put Cluster cell in Inputs and Outputs
|
|
66
|
+
* - skip: don't handle the cluster logic
|
|
67
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
68
|
+
* @param scriptInfo the script info of Spore cell, if not provided, the default script info will be used
|
|
69
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
70
|
+
* @returns
|
|
71
|
+
* - **tx**: a new transaction that contains created Spore cells
|
|
72
|
+
* - **id**: the sporeId of created Spore cell
|
|
73
|
+
*/
|
|
74
|
+
export async function createSpore(params: {
|
|
75
|
+
signer: ccc.Signer;
|
|
76
|
+
data: SporeData;
|
|
77
|
+
to?: ccc.ScriptLike;
|
|
78
|
+
clusterMode?: "lockProxy" | "clusterCell" | "skip";
|
|
79
|
+
tx?: ccc.TransactionLike;
|
|
80
|
+
scriptInfo?: SporeScriptInfoLike;
|
|
81
|
+
scriptInfoHash?: ccc.HexLike;
|
|
82
|
+
}): Promise<{
|
|
83
|
+
tx: ccc.Transaction;
|
|
84
|
+
id: ccc.Hex;
|
|
85
|
+
}> {
|
|
86
|
+
const { signer, data, to, clusterMode, scriptInfoHash } = params;
|
|
87
|
+
const scriptInfo = params.scriptInfo ?? getSporeScriptInfo(signer.client);
|
|
88
|
+
|
|
89
|
+
// prepare transaction
|
|
90
|
+
const actions = [];
|
|
91
|
+
const ids: ccc.Hex[] = [];
|
|
92
|
+
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
93
|
+
if (tx.inputs.length === 0) {
|
|
94
|
+
await injectOneCapacityCell(signer, tx);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const { script: lock } = await signer.getRecommendedAddressObj();
|
|
98
|
+
|
|
99
|
+
// build spore cell
|
|
100
|
+
const id = ccc.hashTypeId(tx.inputs[0], tx.outputs.length);
|
|
101
|
+
ids.push(id);
|
|
102
|
+
|
|
103
|
+
const packedData = packRawSporeData(data);
|
|
104
|
+
tx.addOutput(
|
|
105
|
+
{
|
|
106
|
+
lock: to ?? lock,
|
|
107
|
+
type: {
|
|
108
|
+
...scriptInfo,
|
|
109
|
+
args: id,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
packedData,
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// create spore action
|
|
116
|
+
if (scriptInfo.cobuild) {
|
|
117
|
+
const output = tx.outputs[tx.outputs.length - 1];
|
|
118
|
+
const createAction = assembleCreateSporeAction(
|
|
119
|
+
output,
|
|
120
|
+
packedData,
|
|
121
|
+
scriptInfoHash,
|
|
122
|
+
);
|
|
123
|
+
actions.push(createAction);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// complete cellDeps
|
|
127
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
128
|
+
|
|
129
|
+
const action = await prepareCluster(signer, tx, data, clusterMode);
|
|
130
|
+
if (action) {
|
|
131
|
+
actions.push(action);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
tx: await prepareSporeTransaction(signer, tx, actions),
|
|
136
|
+
id,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Transfer one Spore cell
|
|
142
|
+
*
|
|
143
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
144
|
+
* @param id sporeId
|
|
145
|
+
* @param to Spore's new owner
|
|
146
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
147
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
148
|
+
* @returns
|
|
149
|
+
* - **tx**: a new transaction that contains transferred Spore cells
|
|
150
|
+
*/
|
|
151
|
+
export async function transferSpore(params: {
|
|
152
|
+
signer: ccc.Signer;
|
|
153
|
+
id: ccc.HexLike;
|
|
154
|
+
to: ccc.ScriptLike;
|
|
155
|
+
tx?: ccc.TransactionLike;
|
|
156
|
+
scriptInfoHash?: ccc.HexLike;
|
|
157
|
+
}): Promise<{
|
|
158
|
+
tx: ccc.Transaction;
|
|
159
|
+
}> {
|
|
160
|
+
const { signer, id, to, scriptInfoHash } = params;
|
|
161
|
+
|
|
162
|
+
// prepare transaction
|
|
163
|
+
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
164
|
+
|
|
165
|
+
const { cell: sporeCell, scriptInfo } = await assertSpore(signer.client, id);
|
|
166
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
167
|
+
tx.inputs.push(
|
|
168
|
+
ccc.CellInput.from({
|
|
169
|
+
previousOutput: sporeCell.outPoint,
|
|
170
|
+
...sporeCell,
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
tx.addOutput(
|
|
174
|
+
{
|
|
175
|
+
lock: to,
|
|
176
|
+
type: sporeCell.cellOutput.type,
|
|
177
|
+
},
|
|
178
|
+
sporeCell.outputData,
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const actions = scriptInfo.cobuild
|
|
182
|
+
? [
|
|
183
|
+
assembleTransferSporeAction(
|
|
184
|
+
sporeCell.cellOutput,
|
|
185
|
+
tx.outputs[tx.outputs.length - 1],
|
|
186
|
+
scriptInfoHash,
|
|
187
|
+
),
|
|
188
|
+
]
|
|
189
|
+
: [];
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
tx: await prepareSporeTransaction(signer, tx, actions),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Melt one Spore cell
|
|
198
|
+
*
|
|
199
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
200
|
+
* @param id sporeId to be melted
|
|
201
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
202
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
203
|
+
* @returns
|
|
204
|
+
* - **tx**: a new transaction that contains melted Spore cell
|
|
205
|
+
*/
|
|
206
|
+
export async function meltSpore(params: {
|
|
207
|
+
signer: ccc.Signer;
|
|
208
|
+
id: ccc.HexLike;
|
|
209
|
+
tx?: ccc.TransactionLike;
|
|
210
|
+
scriptInfoHash?: ccc.HexLike;
|
|
211
|
+
}): Promise<{
|
|
212
|
+
tx: ccc.Transaction;
|
|
213
|
+
}> {
|
|
214
|
+
const { signer, id, scriptInfoHash } = params;
|
|
215
|
+
|
|
216
|
+
// prepare transaction
|
|
217
|
+
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
218
|
+
|
|
219
|
+
// build spore cell
|
|
220
|
+
const { cell: sporeCell, scriptInfo } = await assertSpore(signer.client, id);
|
|
221
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
222
|
+
tx.inputs.push(
|
|
223
|
+
ccc.CellInput.from({
|
|
224
|
+
previousOutput: sporeCell.outPoint,
|
|
225
|
+
...sporeCell,
|
|
226
|
+
}),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const actions = scriptInfo.cobuild
|
|
230
|
+
? [assembleMeltSporeAction(sporeCell.cellOutput, scriptInfoHash)]
|
|
231
|
+
: [];
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
tx: await prepareSporeTransaction(signer, tx, actions),
|
|
235
|
+
};
|
|
236
|
+
}
|