@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,88 @@
|
|
|
1
|
+
import { SporeVersion } from "./types.js";
|
|
2
|
+
export const SCRIPTS_SPORE_TESTNET = Object.freeze({
|
|
3
|
+
[SporeVersion.DID]: {
|
|
4
|
+
codeHash: "0x0b1f412fbae26853ff7d082d422c2bdd9e2ff94ee8aaec11240a5b34cc6e890f",
|
|
5
|
+
hashType: "type",
|
|
6
|
+
cellDeps: [
|
|
7
|
+
{
|
|
8
|
+
cellDep: {
|
|
9
|
+
outPoint: {
|
|
10
|
+
txHash: "0x306961e0eb04ed972c60cb89a0aed1b0ef065d96d2fc0000c62db5275e32dc6f",
|
|
11
|
+
index: 0,
|
|
12
|
+
},
|
|
13
|
+
depType: "code",
|
|
14
|
+
},
|
|
15
|
+
type: {
|
|
16
|
+
codeHash: "0x00000000000000000000000000000000000000000000000000545950455f4944",
|
|
17
|
+
hashType: "type",
|
|
18
|
+
args: "0x80f0d4bf6b3951911aa6b98cc609d477a8a10b903b35cfd528d098e95c36f680",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
[SporeVersion.V2]: {
|
|
24
|
+
codeHash: "0x685a60219309029d01310311dba953d67029170ca4848a4ff638e57002130a0d",
|
|
25
|
+
hashType: "data1",
|
|
26
|
+
cellDeps: [
|
|
27
|
+
{
|
|
28
|
+
cellDep: {
|
|
29
|
+
outPoint: {
|
|
30
|
+
txHash: "0x5e8d2a517d50fd4bb4d01737a7952a1f1d35c8afc77240695bb569cd7d9d5a1f",
|
|
31
|
+
index: 0,
|
|
32
|
+
},
|
|
33
|
+
depType: "code",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
cobuild: true,
|
|
38
|
+
},
|
|
39
|
+
[SporeVersion.V1]: {
|
|
40
|
+
codeHash: "0xbbad126377d45f90a8ee120da988a2d7332c78ba8fd679aab478a19d6c133494",
|
|
41
|
+
hashType: "data1",
|
|
42
|
+
cellDeps: [
|
|
43
|
+
{
|
|
44
|
+
cellDep: {
|
|
45
|
+
outPoint: {
|
|
46
|
+
txHash: "0xfd694382e621f175ddf81ce91ce2ecf8bfc027d53d7d31b8438f7d26fc37fd19",
|
|
47
|
+
index: 0,
|
|
48
|
+
},
|
|
49
|
+
depType: "code",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
export const SCRIPTS_CLUSTER_TESTNET = Object.freeze({
|
|
56
|
+
[SporeVersion.V2]: {
|
|
57
|
+
codeHash: "0x0bbe768b519d8ea7b96d58f1182eb7e6ef96c541fbd9526975077ee09f049058",
|
|
58
|
+
hashType: "data1",
|
|
59
|
+
cellDeps: [
|
|
60
|
+
{
|
|
61
|
+
cellDep: {
|
|
62
|
+
outPoint: {
|
|
63
|
+
txHash: "0xcebb174d6e300e26074aea2f5dbd7f694bb4fe3de52b6dfe205e54f90164510a",
|
|
64
|
+
index: 0,
|
|
65
|
+
},
|
|
66
|
+
depType: "code",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
cobuild: true,
|
|
71
|
+
},
|
|
72
|
+
[SporeVersion.V1]: {
|
|
73
|
+
codeHash: "0x598d793defef36e2eeba54a9b45130e4ca92822e1d193671f490950c3b856080",
|
|
74
|
+
hashType: "data1",
|
|
75
|
+
cellDeps: [
|
|
76
|
+
{
|
|
77
|
+
cellDep: {
|
|
78
|
+
outPoint: {
|
|
79
|
+
txHash: "0x49551a20dfe39231e7db49431d26c9c08ceec96a29024eef3acc936deeb2ca76",
|
|
80
|
+
index: 0,
|
|
81
|
+
},
|
|
82
|
+
depType: "code",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
[SporeVersion.DID]: undefined,
|
|
88
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
export declare const DEFAULT_COBUILD_INFO_HASH: `0x${string}`;
|
|
3
|
+
export declare enum SporeVersion {
|
|
4
|
+
V1 = "V1",
|
|
5
|
+
V2 = "V2",
|
|
6
|
+
DID = "DID"
|
|
7
|
+
}
|
|
8
|
+
export declare const SPORE_VERSION_DEFAULT = SporeVersion.V2;
|
|
9
|
+
export type SporeScriptInfoLike = ccc.ScriptInfoLike & {
|
|
10
|
+
cobuild?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare class SporeScriptInfo extends ccc.ScriptInfo {
|
|
13
|
+
cobuild?: boolean | undefined;
|
|
14
|
+
constructor(codeHash: ccc.Hex, hashType: ccc.HashType, cellDeps: ccc.CellDepInfo[], cobuild?: boolean | undefined);
|
|
15
|
+
static from(scriptInfoLike: SporeScriptInfoLike): SporeScriptInfo;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/predefined/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,eAAO,MAAM,yBAAyB,eAErC,CAAC;AAEF,oBAAY,YAAY;IACtB,EAAE,OAAO;IACT,EAAE,OAAO;IACT,GAAG,QAAQ;CACZ;AAED,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAErD,MAAM,MAAM,mBAAmB,GAAG,GAAG,CAAC,cAAc,GAAG;IACrD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,qBAAa,eAAgB,SAAQ,GAAG,CAAC,UAAU;IAKxC,OAAO,CAAC,EAAE,OAAO;gBAHxB,QAAQ,EAAE,GAAG,CAAC,GAAG,EACjB,QAAQ,EAAE,GAAG,CAAC,QAAQ,EACtB,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,EACpB,OAAO,CAAC,EAAE,OAAO,YAAA;IAK1B,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,mBAAmB,GAAG,eAAe;CAQlE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
export const DEFAULT_COBUILD_INFO_HASH = ccc.hashCkb(ccc.bytesFrom("CCC_DEFAULT_COBUILD_INFO", "utf8"));
|
|
3
|
+
export var SporeVersion;
|
|
4
|
+
(function (SporeVersion) {
|
|
5
|
+
SporeVersion["V1"] = "V1";
|
|
6
|
+
SporeVersion["V2"] = "V2";
|
|
7
|
+
SporeVersion["DID"] = "DID";
|
|
8
|
+
})(SporeVersion || (SporeVersion = {}));
|
|
9
|
+
export const SPORE_VERSION_DEFAULT = SporeVersion.V2;
|
|
10
|
+
export class SporeScriptInfo extends ccc.ScriptInfo {
|
|
11
|
+
constructor(codeHash, hashType, cellDeps, cobuild) {
|
|
12
|
+
super(codeHash, hashType, cellDeps);
|
|
13
|
+
this.cobuild = cobuild;
|
|
14
|
+
}
|
|
15
|
+
static from(scriptInfoLike) {
|
|
16
|
+
return new SporeScriptInfo(ccc.hexFrom(scriptInfoLike.codeHash), ccc.hashTypeFrom(scriptInfoLike.hashType), scriptInfoLike.cellDeps.map((c) => ccc.CellDepInfo.from(c)), scriptInfoLike.cobuild);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { SporeScriptInfo, SporeVersion } from "./types.js";
|
|
3
|
+
export declare function getSporeScriptInfos(client: ccc.Client): Record<SporeVersion, import("./types.js").SporeScriptInfoLike | undefined>;
|
|
4
|
+
export declare function getClusterScriptInfos(client: ccc.Client): Record<SporeVersion, import("./types.js").SporeScriptInfoLike | undefined>;
|
|
5
|
+
export declare function getSporeScriptInfo(client: ccc.Client, version?: SporeVersion): SporeScriptInfo;
|
|
6
|
+
export declare function getClusterScriptInfo(client: ccc.Client, version?: SporeVersion): SporeScriptInfo;
|
|
7
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/predefined/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC,OAAO,EAEL,eAAe,EACf,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,8EAIrD;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,8EAIvD;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,OAAO,CAAC,EAAE,YAAY,GACrB,eAAe,CAWjB;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,OAAO,CAAC,EAAE,YAAY,GACrB,eAAe,CAWjB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SCRIPTS_CLUSTER_MAINNET, SCRIPTS_CLUSTER_TESTNET, SCRIPTS_SPORE_MAINNET, SCRIPTS_SPORE_TESTNET, } from "./advanced.js";
|
|
2
|
+
import { SPORE_VERSION_DEFAULT, SporeScriptInfo, } from "./types.js";
|
|
3
|
+
export function getSporeScriptInfos(client) {
|
|
4
|
+
return client.addressPrefix === "ckb"
|
|
5
|
+
? SCRIPTS_SPORE_MAINNET
|
|
6
|
+
: SCRIPTS_SPORE_TESTNET;
|
|
7
|
+
}
|
|
8
|
+
export function getClusterScriptInfos(client) {
|
|
9
|
+
return client.addressPrefix === "ckb"
|
|
10
|
+
? SCRIPTS_CLUSTER_MAINNET
|
|
11
|
+
: SCRIPTS_CLUSTER_TESTNET;
|
|
12
|
+
}
|
|
13
|
+
export function getSporeScriptInfo(client, version) {
|
|
14
|
+
const scriptInfo = getSporeScriptInfos(client)[version ?? SPORE_VERSION_DEFAULT];
|
|
15
|
+
if (!scriptInfo) {
|
|
16
|
+
throw new Error(`Spore script info not found of for version ${version} on ${client.addressPrefix}`);
|
|
17
|
+
}
|
|
18
|
+
return SporeScriptInfo.from(scriptInfo);
|
|
19
|
+
}
|
|
20
|
+
export function getClusterScriptInfo(client, version) {
|
|
21
|
+
const scriptInfo = getClusterScriptInfos(client)[version ?? SPORE_VERSION_DEFAULT];
|
|
22
|
+
if (!scriptInfo) {
|
|
23
|
+
throw new Error(`Cluster script info not found of for version ${version} on ${client.addressPrefix}`);
|
|
24
|
+
}
|
|
25
|
+
return SporeScriptInfo.from(scriptInfo);
|
|
26
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { UnpackResult } from "@ckb-lumos/codec";
|
|
3
|
+
import { Action, SporeData } from "../codec/index.js";
|
|
4
|
+
export declare function prepareCluster(signer: ccc.Signer, tx: ccc.Transaction, data: SporeData, clusterMode?: "lockProxy" | "clusterCell" | "skip", scriptInfoHash?: ccc.HexLike): Promise<UnpackResult<typeof Action> | undefined>;
|
|
5
|
+
//# sourceMappingURL=advanced.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../../src/spore/advanced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGtD,wBAAsB,cAAc,CAClC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,EAAE,EAAE,GAAG,CAAC,WAAW,EACnB,IAAI,EAAE,SAAS,EACf,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,MAAM,EAClD,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,GAC3B,OAAO,CAAC,YAAY,CAAC,OAAO,MAAM,CAAC,GAAG,SAAS,CAAC,CA0ElD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { assembleTransferClusterAction } from "../advanced.js";
|
|
3
|
+
import { assertCluster } from "../cluster/index.js";
|
|
4
|
+
import { searchOneCellBySigner } from "../helper/index.js";
|
|
5
|
+
export async function prepareCluster(signer, tx, data, clusterMode, scriptInfoHash) {
|
|
6
|
+
// skip if the spore is not belong to a cluster
|
|
7
|
+
if (!data.clusterId || clusterMode === "skip") {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (!clusterMode) {
|
|
11
|
+
throw Error("clusterMode is undefined but the spore has a cluster");
|
|
12
|
+
}
|
|
13
|
+
const { cell: cluster, scriptInfo } = await assertCluster(signer.client, data.clusterId);
|
|
14
|
+
// If this cluster has been processed, nothing will happen to the tx
|
|
15
|
+
switch (clusterMode) {
|
|
16
|
+
case "lockProxy": {
|
|
17
|
+
const lock = cluster.cellOutput.lock;
|
|
18
|
+
if (!(await tx.findInputIndexByLock(lock, signer.client))) {
|
|
19
|
+
// note: We can only search proxy of signer, if any custom logic is in need, developer should get
|
|
20
|
+
// the proxy filled in transaction before invoking `createSpore`
|
|
21
|
+
const proxy = await searchOneCellBySigner(signer);
|
|
22
|
+
if (!proxy) {
|
|
23
|
+
throw new Error("Cluster lock proxy cell not found");
|
|
24
|
+
}
|
|
25
|
+
tx.inputs.push(ccc.CellInput.from({
|
|
26
|
+
previousOutput: proxy.outPoint,
|
|
27
|
+
...proxy,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
if (tx.outputs.every((output) => output.lock !== lock)) {
|
|
31
|
+
tx.addOutput({
|
|
32
|
+
lock,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
tx.addCellDeps({
|
|
36
|
+
outPoint: cluster.outPoint,
|
|
37
|
+
depType: "code",
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
case "clusterCell": {
|
|
42
|
+
if (tx.inputs.some((i) => i.previousOutput.eq(cluster.outPoint))) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
tx.inputs.push(ccc.CellInput.from({
|
|
46
|
+
previousOutput: cluster.outPoint,
|
|
47
|
+
...cluster,
|
|
48
|
+
}));
|
|
49
|
+
tx.addOutput(cluster.cellOutput, cluster.outputData);
|
|
50
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
51
|
+
// note: add cluster as cellDep, which will be used in Spore contract
|
|
52
|
+
tx.addCellDeps({
|
|
53
|
+
outPoint: cluster.outPoint,
|
|
54
|
+
depType: "code",
|
|
55
|
+
});
|
|
56
|
+
if (scriptInfo.cobuild) {
|
|
57
|
+
return assembleTransferClusterAction(cluster.cellOutput, cluster.cellOutput, scriptInfoHash);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { SporeData } from "../codec/index.js";
|
|
3
|
+
import { SporeScriptInfo, SporeScriptInfoLike } from "../predefined/index.js";
|
|
4
|
+
export declare function findSpore(client: ccc.Client, args: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
5
|
+
cell: ccc.Cell;
|
|
6
|
+
scriptInfo: SporeScriptInfo;
|
|
7
|
+
} | undefined>;
|
|
8
|
+
export declare function assertSpore(client: ccc.Client, args: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
9
|
+
cell: ccc.Cell;
|
|
10
|
+
scriptInfo: SporeScriptInfo;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Create one Spore cell with the specified Spore data.
|
|
14
|
+
*
|
|
15
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
16
|
+
* @param data specific format of data required by Spore protocol
|
|
17
|
+
* @param to owner of new spore cell, signer if no provided
|
|
18
|
+
* @param clusterMode how to process cluster cell **(if clusterId is not provided in SporeData, this parameter will be ignored)**
|
|
19
|
+
* - undefined: error if the spore has a cluster but the clusterMode is not set
|
|
20
|
+
* - lockProxy: put a cell that uses the same lock from Cluster cell in both Inputs and Outputs
|
|
21
|
+
* - clusterCell: directly put Cluster cell in Inputs and Outputs
|
|
22
|
+
* - skip: don't handle the cluster logic
|
|
23
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
24
|
+
* @param scriptInfo the script info of Spore cell, if not provided, the default script info will be used
|
|
25
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
26
|
+
* @returns
|
|
27
|
+
* - **tx**: a new transaction that contains created Spore cells
|
|
28
|
+
* - **id**: the sporeId of created Spore cell
|
|
29
|
+
*/
|
|
30
|
+
export declare function createSpore(params: {
|
|
31
|
+
signer: ccc.Signer;
|
|
32
|
+
data: SporeData;
|
|
33
|
+
to?: ccc.ScriptLike;
|
|
34
|
+
clusterMode?: "lockProxy" | "clusterCell" | "skip";
|
|
35
|
+
tx?: ccc.TransactionLike;
|
|
36
|
+
scriptInfo?: SporeScriptInfoLike;
|
|
37
|
+
scriptInfoHash?: ccc.HexLike;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
tx: ccc.Transaction;
|
|
40
|
+
id: ccc.Hex;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Transfer one Spore cell
|
|
44
|
+
*
|
|
45
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
46
|
+
* @param id sporeId
|
|
47
|
+
* @param to Spore's new owner
|
|
48
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
49
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
50
|
+
* @returns
|
|
51
|
+
* - **tx**: a new transaction that contains transferred Spore cells
|
|
52
|
+
*/
|
|
53
|
+
export declare function transferSpore(params: {
|
|
54
|
+
signer: ccc.Signer;
|
|
55
|
+
id: ccc.HexLike;
|
|
56
|
+
to: ccc.ScriptLike;
|
|
57
|
+
tx?: ccc.TransactionLike;
|
|
58
|
+
scriptInfoHash?: ccc.HexLike;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
tx: ccc.Transaction;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Melt one Spore cell
|
|
64
|
+
*
|
|
65
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
66
|
+
* @param id sporeId to be melted
|
|
67
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
68
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
69
|
+
* @returns
|
|
70
|
+
* - **tx**: a new transaction that contains melted Spore cell
|
|
71
|
+
*/
|
|
72
|
+
export declare function meltSpore(params: {
|
|
73
|
+
signer: ccc.Signer;
|
|
74
|
+
id: ccc.HexLike;
|
|
75
|
+
tx?: ccc.TransactionLike;
|
|
76
|
+
scriptInfoHash?: ccc.HexLike;
|
|
77
|
+
}): Promise<{
|
|
78
|
+
tx: ccc.Transaction;
|
|
79
|
+
}>;
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spore/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAOpC,OAAO,EAAE,SAAS,EAAoB,MAAM,mBAAmB,CAAC;AAKhE,OAAO,EACL,eAAe,EACf,mBAAmB,EAGpB,MAAM,wBAAwB,CAAC;AAGhC,wBAAsB,SAAS,CAC7B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,GAAG,CAAC,OAAO,EACjB,OAAO,CAAC,EAAE,mBAAmB,EAAE,GAC9B,OAAO,CACN;IACE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,eAAe,CAAC;CAC7B,GACD,SAAS,CACZ,CAMA;AAED,wBAAsB,WAAW,CAC/B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,GAAG,CAAC,OAAO,EACjB,OAAO,CAAC,EAAE,mBAAmB,EAAE,GAC9B,OAAO,CAAC;IACT,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CAQD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE;IACxC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;IACpB,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,MAAM,CAAC;IACnD,EAAE,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC;IACzB,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CAC9B,GAAG,OAAO,CAAC;IACV,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;IACpB,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC;CACb,CAAC,CAqDD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC;IAChB,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC;IACnB,EAAE,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC;IACzB,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CAC9B,GAAG,OAAO,CAAC;IACV,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;CACrB,CAAC,CAmCD;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,MAAM,EAAE;IACtC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC;IAChB,EAAE,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC;IACzB,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CAC9B,GAAG,OAAO,CAAC;IACV,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;CACrB,CAAC,CAuBD"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { assembleCreateSporeAction, assembleMeltSporeAction, assembleTransferSporeAction, prepareSporeTransaction, } from "../advanced.js";
|
|
3
|
+
import { packRawSporeData } from "../codec/index.js";
|
|
4
|
+
import { findSingletonCellByArgs, injectOneCapacityCell, } from "../helper/index.js";
|
|
5
|
+
import { getSporeScriptInfo, getSporeScriptInfos, } from "../predefined/index.js";
|
|
6
|
+
import { prepareCluster } from "./advanced.js";
|
|
7
|
+
export async function findSpore(client, args, scripts) {
|
|
8
|
+
return findSingletonCellByArgs(client, args, scripts ?? Object.values(getSporeScriptInfos(client)));
|
|
9
|
+
}
|
|
10
|
+
export async function assertSpore(client, args, scripts) {
|
|
11
|
+
const res = await findSpore(client, args, scripts);
|
|
12
|
+
if (!res) {
|
|
13
|
+
throw new Error(`Spore ${ccc.hexFrom(args)} not found`);
|
|
14
|
+
}
|
|
15
|
+
return res;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create one Spore cell with the specified Spore data.
|
|
19
|
+
*
|
|
20
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
21
|
+
* @param data specific format of data required by Spore protocol
|
|
22
|
+
* @param to owner of new spore cell, signer if no provided
|
|
23
|
+
* @param clusterMode how to process cluster cell **(if clusterId is not provided in SporeData, this parameter will be ignored)**
|
|
24
|
+
* - undefined: error if the spore has a cluster but the clusterMode is not set
|
|
25
|
+
* - lockProxy: put a cell that uses the same lock from Cluster cell in both Inputs and Outputs
|
|
26
|
+
* - clusterCell: directly put Cluster cell in Inputs and Outputs
|
|
27
|
+
* - skip: don't handle the cluster logic
|
|
28
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
29
|
+
* @param scriptInfo the script info of Spore cell, if not provided, the default script info will be used
|
|
30
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
31
|
+
* @returns
|
|
32
|
+
* - **tx**: a new transaction that contains created Spore cells
|
|
33
|
+
* - **id**: the sporeId of created Spore cell
|
|
34
|
+
*/
|
|
35
|
+
export async function createSpore(params) {
|
|
36
|
+
const { signer, data, to, clusterMode, scriptInfoHash } = params;
|
|
37
|
+
const scriptInfo = params.scriptInfo ?? getSporeScriptInfo(signer.client);
|
|
38
|
+
// prepare transaction
|
|
39
|
+
const actions = [];
|
|
40
|
+
const ids = [];
|
|
41
|
+
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
42
|
+
if (tx.inputs.length === 0) {
|
|
43
|
+
await injectOneCapacityCell(signer, tx);
|
|
44
|
+
}
|
|
45
|
+
const { script: lock } = await signer.getRecommendedAddressObj();
|
|
46
|
+
// build spore cell
|
|
47
|
+
const id = ccc.hashTypeId(tx.inputs[0], tx.outputs.length);
|
|
48
|
+
ids.push(id);
|
|
49
|
+
const packedData = packRawSporeData(data);
|
|
50
|
+
tx.addOutput({
|
|
51
|
+
lock: to ?? lock,
|
|
52
|
+
type: {
|
|
53
|
+
...scriptInfo,
|
|
54
|
+
args: id,
|
|
55
|
+
},
|
|
56
|
+
}, packedData);
|
|
57
|
+
// create spore action
|
|
58
|
+
if (scriptInfo.cobuild) {
|
|
59
|
+
const output = tx.outputs[tx.outputs.length - 1];
|
|
60
|
+
const createAction = assembleCreateSporeAction(output, packedData, scriptInfoHash);
|
|
61
|
+
actions.push(createAction);
|
|
62
|
+
}
|
|
63
|
+
// complete cellDeps
|
|
64
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
65
|
+
const action = await prepareCluster(signer, tx, data, clusterMode);
|
|
66
|
+
if (action) {
|
|
67
|
+
actions.push(action);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
tx: await prepareSporeTransaction(signer, tx, actions),
|
|
71
|
+
id,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Transfer one Spore cell
|
|
76
|
+
*
|
|
77
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
78
|
+
* @param id sporeId
|
|
79
|
+
* @param to Spore's new owner
|
|
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
|
|
82
|
+
* @returns
|
|
83
|
+
* - **tx**: a new transaction that contains transferred Spore cells
|
|
84
|
+
*/
|
|
85
|
+
export async function transferSpore(params) {
|
|
86
|
+
const { signer, id, to, scriptInfoHash } = params;
|
|
87
|
+
// prepare transaction
|
|
88
|
+
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
89
|
+
const { cell: sporeCell, scriptInfo } = await assertSpore(signer.client, id);
|
|
90
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
91
|
+
tx.inputs.push(ccc.CellInput.from({
|
|
92
|
+
previousOutput: sporeCell.outPoint,
|
|
93
|
+
...sporeCell,
|
|
94
|
+
}));
|
|
95
|
+
tx.addOutput({
|
|
96
|
+
lock: to,
|
|
97
|
+
type: sporeCell.cellOutput.type,
|
|
98
|
+
}, sporeCell.outputData);
|
|
99
|
+
const actions = scriptInfo.cobuild
|
|
100
|
+
? [
|
|
101
|
+
assembleTransferSporeAction(sporeCell.cellOutput, tx.outputs[tx.outputs.length - 1], scriptInfoHash),
|
|
102
|
+
]
|
|
103
|
+
: [];
|
|
104
|
+
return {
|
|
105
|
+
tx: await prepareSporeTransaction(signer, tx, actions),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Melt one Spore cell
|
|
110
|
+
*
|
|
111
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
112
|
+
* @param id sporeId to be melted
|
|
113
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
114
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
115
|
+
* @returns
|
|
116
|
+
* - **tx**: a new transaction that contains melted Spore cell
|
|
117
|
+
*/
|
|
118
|
+
export async function meltSpore(params) {
|
|
119
|
+
const { signer, id, scriptInfoHash } = params;
|
|
120
|
+
// prepare transaction
|
|
121
|
+
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
122
|
+
// build spore cell
|
|
123
|
+
const { cell: sporeCell, scriptInfo } = await assertSpore(signer.client, id);
|
|
124
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
125
|
+
tx.inputs.push(ccc.CellInput.from({
|
|
126
|
+
previousOutput: sporeCell.outPoint,
|
|
127
|
+
...sporeCell,
|
|
128
|
+
}));
|
|
129
|
+
const actions = scriptInfo.cobuild
|
|
130
|
+
? [assembleMeltSporeAction(sporeCell.cellOutput, scriptInfoHash)]
|
|
131
|
+
: [];
|
|
132
|
+
return {
|
|
133
|
+
tx: await prepareSporeTransaction(signer, tx, actions),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advanced.d.ts","sourceRoot":"","sources":["../src/advanced.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cobuild/index.js"), exports);
|
|
18
|
+
__exportStar(require("./codec/index.js"), exports);
|
|
19
|
+
__exportStar(require("./predefined/advanced.js"), exports);
|
|
20
|
+
__exportStar(require("./spore/advanced.js"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { ClusterData } from "../codec/index.js";
|
|
3
|
+
import { SporeScriptInfo, SporeScriptInfoLike } from "../predefined/index.js";
|
|
4
|
+
export declare function findCluster(client: ccc.Client, args: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
5
|
+
cell: ccc.Cell;
|
|
6
|
+
scriptInfo: SporeScriptInfo;
|
|
7
|
+
} | undefined>;
|
|
8
|
+
export declare function assertCluster(client: ccc.Client, args: ccc.HexLike, scripts?: SporeScriptInfoLike[]): Promise<{
|
|
9
|
+
cell: ccc.Cell;
|
|
10
|
+
scriptInfo: SporeScriptInfo;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new Cluster cell
|
|
14
|
+
*
|
|
15
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
16
|
+
* @param data specific format of data required by Cluster protocol
|
|
17
|
+
* @param to the owner of the Cluster cell, which will be replaced with signer if not provided
|
|
18
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
19
|
+
* @param scriptInfo the script info of new cluster, default spore version if undefined
|
|
20
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
21
|
+
* @returns
|
|
22
|
+
* - **tx**: a new transaction that contains created Cluster cell
|
|
23
|
+
* - **id**: the id of the created Cluster cell
|
|
24
|
+
*/
|
|
25
|
+
export declare function createSporeCluster(params: {
|
|
26
|
+
signer: ccc.Signer;
|
|
27
|
+
data: ClusterData;
|
|
28
|
+
to?: ccc.ScriptLike;
|
|
29
|
+
tx?: ccc.TransactionLike;
|
|
30
|
+
scriptInfo?: SporeScriptInfoLike;
|
|
31
|
+
scriptInfoHash?: ccc.HexLike;
|
|
32
|
+
}): Promise<{
|
|
33
|
+
tx: ccc.Transaction;
|
|
34
|
+
id: ccc.Hex;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Transfer a Cluster cell
|
|
38
|
+
*
|
|
39
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
40
|
+
* @param id the id of the Cluster cell to be transferred
|
|
41
|
+
* @param to the new owner of the Cluster cell
|
|
42
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
43
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
44
|
+
* @returns
|
|
45
|
+
* - **tx**: a new transaction that contains transferred Cluster cell
|
|
46
|
+
*/
|
|
47
|
+
export declare function transferSporeCluster(params: {
|
|
48
|
+
signer: ccc.Signer;
|
|
49
|
+
id: ccc.HexLike;
|
|
50
|
+
to: ccc.ScriptLike;
|
|
51
|
+
tx?: ccc.TransactionLike;
|
|
52
|
+
scriptInfoHash?: ccc.HexLike;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
tx: ccc.Transaction;
|
|
55
|
+
}>;
|
|
56
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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,EAAE,WAAW,EAAsB,MAAM,mBAAmB,CAAC;AAKpE,OAAO,EACL,eAAe,EACf,mBAAmB,EAGpB,MAAM,wBAAwB,CAAC;AAEhC,wBAAsB,WAAW,CAC/B,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,GAAG,CAAC,OAAO,EACjB,OAAO,CAAC,EAAE,mBAAmB,EAAE,GAC9B,OAAO,CACN;IACE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,eAAe,CAAC;CAC7B,GACD,SAAS,CACZ,CAMA;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,IAAI,EAAE,GAAG,CAAC,OAAO,EACjB,OAAO,CAAC,EAAE,mBAAmB,EAAE,GAC9B,OAAO,CAAC;IACT,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC,CAQD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE;IAC/C,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,CAAC,EAAE,GAAG,CAAC,UAAU,CAAC;IACpB,EAAE,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC;IACzB,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CAC9B,GAAG,OAAO,CAAC;IACV,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;IACpB,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC;CACb,CAAC,CA0CD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE;IACjD,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC;IACnB,EAAE,EAAE,GAAG,CAAC,OAAO,CAAC;IAChB,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC;IACnB,EAAE,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC;IACzB,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CAC9B,GAAG,OAAO,CAAC;IACV,EAAE,EAAE,GAAG,CAAC,WAAW,CAAC;CACrB,CAAC,CAwCD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findCluster = findCluster;
|
|
4
|
+
exports.assertCluster = assertCluster;
|
|
5
|
+
exports.createSporeCluster = createSporeCluster;
|
|
6
|
+
exports.transferSporeCluster = transferSporeCluster;
|
|
7
|
+
const core_1 = require("@ckb-ccc/core");
|
|
8
|
+
const advanced_js_1 = require("../advanced.js");
|
|
9
|
+
const index_js_1 = require("../codec/index.js");
|
|
10
|
+
const index_js_2 = require("../helper/index.js");
|
|
11
|
+
const index_js_3 = require("../predefined/index.js");
|
|
12
|
+
async function findCluster(client, args, scripts) {
|
|
13
|
+
return (0, index_js_2.findSingletonCellByArgs)(client, args, scripts ?? Object.values((0, index_js_3.getClusterScriptInfos)(client)));
|
|
14
|
+
}
|
|
15
|
+
async function assertCluster(client, args, scripts) {
|
|
16
|
+
const res = await findCluster(client, args, scripts);
|
|
17
|
+
if (!res) {
|
|
18
|
+
throw new Error(`Cluster ${core_1.ccc.hexFrom(args)} not found`);
|
|
19
|
+
}
|
|
20
|
+
return res;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a new Cluster cell
|
|
24
|
+
*
|
|
25
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
26
|
+
* @param data specific format of data required by Cluster protocol
|
|
27
|
+
* @param to the owner of the Cluster cell, which will be replaced with signer if not provided
|
|
28
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
29
|
+
* @param scriptInfo the script info of new cluster, default spore version if undefined
|
|
30
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
31
|
+
* @returns
|
|
32
|
+
* - **tx**: a new transaction that contains created Cluster cell
|
|
33
|
+
* - **id**: the id of the created Cluster cell
|
|
34
|
+
*/
|
|
35
|
+
async function createSporeCluster(params) {
|
|
36
|
+
const { signer, data, to, scriptInfoHash } = params;
|
|
37
|
+
const scriptInfo = params.scriptInfo ?? (0, index_js_3.getClusterScriptInfo)(signer.client);
|
|
38
|
+
// prepare transaction
|
|
39
|
+
const tx = core_1.ccc.Transaction.from(params.tx ?? {});
|
|
40
|
+
if (tx.inputs.length === 0) {
|
|
41
|
+
await (0, index_js_2.injectOneCapacityCell)(signer, tx);
|
|
42
|
+
}
|
|
43
|
+
// build cluster cell
|
|
44
|
+
const id = core_1.ccc.hashTypeId(tx.inputs[0], tx.outputs.length);
|
|
45
|
+
const packedClusterData = (0, index_js_1.packRawClusterData)(data);
|
|
46
|
+
tx.addOutput({
|
|
47
|
+
lock: to ?? (await signer.getRecommendedAddressObj()).script,
|
|
48
|
+
type: {
|
|
49
|
+
...scriptInfo,
|
|
50
|
+
args: id,
|
|
51
|
+
},
|
|
52
|
+
}, packedClusterData);
|
|
53
|
+
// complete cellDeps
|
|
54
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
55
|
+
// generate cobuild action
|
|
56
|
+
const actions = scriptInfo.cobuild
|
|
57
|
+
? [
|
|
58
|
+
(0, advanced_js_1.assembleCreateClusterAction)(tx.outputs[tx.outputs.length - 1], packedClusterData, scriptInfoHash),
|
|
59
|
+
]
|
|
60
|
+
: [];
|
|
61
|
+
return {
|
|
62
|
+
tx: await (0, advanced_js_1.prepareSporeTransaction)(signer, tx, actions),
|
|
63
|
+
id,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Transfer a Cluster cell
|
|
68
|
+
*
|
|
69
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
70
|
+
* @param id the id of the Cluster cell to be transferred
|
|
71
|
+
* @param to the new owner of the Cluster cell
|
|
72
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
73
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
74
|
+
* @returns
|
|
75
|
+
* - **tx**: a new transaction that contains transferred Cluster cell
|
|
76
|
+
*/
|
|
77
|
+
async function transferSporeCluster(params) {
|
|
78
|
+
const { signer, id, to, scriptInfoHash } = params;
|
|
79
|
+
// prepare transaction
|
|
80
|
+
const tx = core_1.ccc.Transaction.from(params.tx ?? {});
|
|
81
|
+
// build cluster cell
|
|
82
|
+
const { cell: cluster, scriptInfo } = await assertCluster(signer.client, id);
|
|
83
|
+
tx.inputs.push(core_1.ccc.CellInput.from({
|
|
84
|
+
previousOutput: cluster.outPoint,
|
|
85
|
+
...cluster,
|
|
86
|
+
}));
|
|
87
|
+
tx.addOutput({
|
|
88
|
+
lock: to,
|
|
89
|
+
type: cluster.cellOutput.type,
|
|
90
|
+
}, cluster.outputData);
|
|
91
|
+
// complete cellDeps
|
|
92
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
93
|
+
// generate cobuild action
|
|
94
|
+
const actions = scriptInfo.cobuild
|
|
95
|
+
? [
|
|
96
|
+
(0, advanced_js_1.assembleTransferClusterAction)(cluster.cellOutput, tx.outputs[tx.outputs.length - 1], scriptInfoHash),
|
|
97
|
+
]
|
|
98
|
+
: [];
|
|
99
|
+
return {
|
|
100
|
+
tx: await (0, advanced_js_1.prepareSporeTransaction)(signer, tx, actions),
|
|
101
|
+
};
|
|
102
|
+
}
|