@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @ckb-ccc/spore
|
|
2
|
+
|
|
3
|
+
## 0.1.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#74](https://github.com/ckb-ecofund/ccc/pull/74) [`f21d7e4`](https://github.com/ckb-ecofund/ccc/commit/f21d7e4cf422edab4a836ef6d678b620594fef8d) Thanks [@Hanssen0](https://github.com/Hanssen0)! - add spore package and some known scripts
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`f21d7e4`](https://github.com/ckb-ecofund/ccc/commit/f21d7e4cf422edab4a836ef6d678b620594fef8d)]:
|
|
12
|
+
- @ckb-ccc/core@0.1.0-alpha.4
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://app.ckbccc.com/">
|
|
3
|
+
<img alt="Logo" src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/logo.svg" width="20%" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center" style="font-size: 48px;">
|
|
8
|
+
CCC's support for Spore protocol
|
|
9
|
+
</h1>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@ckb-ccc/spore"><img
|
|
13
|
+
alt="NPM Version" src="https://img.shields.io/npm/v/%40ckb-ccc%2Fspore"
|
|
14
|
+
/></a>
|
|
15
|
+
<img alt="GitHub commit activity" src="https://img.shields.io/github/commit-activity/m/ckb-ecofund/ccc" />
|
|
16
|
+
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/ckb-ecofund/ccc/master" />
|
|
17
|
+
<img alt="GitHub branch check runs" src="https://img.shields.io/github/check-runs/ckb-ecofund/ccc/master" />
|
|
18
|
+
<a href="https://live.ckbccc.com/"><img
|
|
19
|
+
alt="Playground" src="https://img.shields.io/website?url=https%3A%2F%2Flive.ckbccc.com%2F&label=Playground"
|
|
20
|
+
/></a>
|
|
21
|
+
<a href="https://app.ckbccc.com/"><img
|
|
22
|
+
alt="App" src="https://img.shields.io/website?url=https%3A%2F%2Fapp.ckbccc.com%2F&label=App"
|
|
23
|
+
/></a>
|
|
24
|
+
<a href="https://docs.ckbccc.com/"><img
|
|
25
|
+
alt="Docs" src="https://img.shields.io/website?url=https%3A%2F%2Fdocs.ckbccc.com%2F&label=Docs"
|
|
26
|
+
/></a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
"CCC - CKBers' Codebase" is the next step of "Common Chains Connector".
|
|
31
|
+
<br />
|
|
32
|
+
Empower yourself with CCC to discover the unlimited potential of CKB.
|
|
33
|
+
<br />
|
|
34
|
+
Interoperate with wallets from different chain ecosystems.
|
|
35
|
+
<br />
|
|
36
|
+
Fully enabling CKB's Turing completeness and cryptographic freedom power.
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
## Playground
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
<a href="https://live.ckbccc.com/">
|
|
43
|
+
<img src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/preview.png" width="90%" />
|
|
44
|
+
</a>
|
|
45
|
+
</p>
|
|
46
|
+
|
|
47
|
+
This project is still under active development, and we are looking forward to your feedback. You can [experiment instantly in the playground](https://live.ckbccc.com/). If you are new to the CKB, we recommend checking [Nervos CKB Docs](https://docs.nervos.org/) for basic knowledge.
|
|
48
|
+
|
|
49
|
+
## App
|
|
50
|
+
|
|
51
|
+
<p align="center">
|
|
52
|
+
<a href="https://app.ckbccc.com/">
|
|
53
|
+
<img src="https://raw.githubusercontent.com/ckb-ecofund/ccc/master/assets/appPreview.png" width="50%" />
|
|
54
|
+
</a>
|
|
55
|
+
</p>
|
|
56
|
+
|
|
57
|
+
For non-developers, you can also [try CCC's app now here](https://app.ckbccc.com/). It showcases how to use CCC for some basic scenarios in CKB.
|
|
58
|
+
|
|
59
|
+
<h3 align="center">
|
|
60
|
+
Read more about CCC on <a href="https://docs.ckbccc.com">our website</a> or <a href="https://github.com/ckb-ecofund/ccc">GitHub Repo</a>.
|
|
61
|
+
</h3>
|
|
@@ -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"}
|
package/dist/advanced.js
ADDED
|
@@ -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,96 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { assembleCreateClusterAction, assembleTransferClusterAction, prepareSporeTransaction, } from "../advanced.js";
|
|
3
|
+
import { packRawClusterData } from "../codec/index.js";
|
|
4
|
+
import { findSingletonCellByArgs, injectOneCapacityCell, } from "../helper/index.js";
|
|
5
|
+
import { getClusterScriptInfo, getClusterScriptInfos, } from "../predefined/index.js";
|
|
6
|
+
export async function findCluster(client, args, scripts) {
|
|
7
|
+
return findSingletonCellByArgs(client, args, scripts ?? Object.values(getClusterScriptInfos(client)));
|
|
8
|
+
}
|
|
9
|
+
export async function assertCluster(client, args, scripts) {
|
|
10
|
+
const res = await findCluster(client, args, scripts);
|
|
11
|
+
if (!res) {
|
|
12
|
+
throw new Error(`Cluster ${ccc.hexFrom(args)} not found`);
|
|
13
|
+
}
|
|
14
|
+
return res;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a new Cluster cell
|
|
18
|
+
*
|
|
19
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
20
|
+
* @param data specific format of data required by Cluster protocol
|
|
21
|
+
* @param to the owner of the Cluster cell, which will be replaced with signer if not provided
|
|
22
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
23
|
+
* @param scriptInfo the script info of new cluster, default spore version if undefined
|
|
24
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
25
|
+
* @returns
|
|
26
|
+
* - **tx**: a new transaction that contains created Cluster cell
|
|
27
|
+
* - **id**: the id of the created Cluster cell
|
|
28
|
+
*/
|
|
29
|
+
export async function createSporeCluster(params) {
|
|
30
|
+
const { signer, data, to, scriptInfoHash } = params;
|
|
31
|
+
const scriptInfo = params.scriptInfo ?? getClusterScriptInfo(signer.client);
|
|
32
|
+
// prepare transaction
|
|
33
|
+
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
34
|
+
if (tx.inputs.length === 0) {
|
|
35
|
+
await injectOneCapacityCell(signer, tx);
|
|
36
|
+
}
|
|
37
|
+
// build cluster cell
|
|
38
|
+
const id = ccc.hashTypeId(tx.inputs[0], tx.outputs.length);
|
|
39
|
+
const packedClusterData = packRawClusterData(data);
|
|
40
|
+
tx.addOutput({
|
|
41
|
+
lock: to ?? (await signer.getRecommendedAddressObj()).script,
|
|
42
|
+
type: {
|
|
43
|
+
...scriptInfo,
|
|
44
|
+
args: id,
|
|
45
|
+
},
|
|
46
|
+
}, packedClusterData);
|
|
47
|
+
// complete cellDeps
|
|
48
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
49
|
+
// generate cobuild action
|
|
50
|
+
const actions = scriptInfo.cobuild
|
|
51
|
+
? [
|
|
52
|
+
assembleCreateClusterAction(tx.outputs[tx.outputs.length - 1], packedClusterData, scriptInfoHash),
|
|
53
|
+
]
|
|
54
|
+
: [];
|
|
55
|
+
return {
|
|
56
|
+
tx: await prepareSporeTransaction(signer, tx, actions),
|
|
57
|
+
id,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Transfer a Cluster cell
|
|
62
|
+
*
|
|
63
|
+
* @param signer who takes the responsibility to balance and sign the transaction
|
|
64
|
+
* @param id the id of the Cluster cell to be transferred
|
|
65
|
+
* @param to the new owner of the Cluster cell
|
|
66
|
+
* @param tx the transaction skeleton, if not provided, a new one will be created
|
|
67
|
+
* @param scriptInfoHash the script info hash used in cobuild
|
|
68
|
+
* @returns
|
|
69
|
+
* - **tx**: a new transaction that contains transferred Cluster cell
|
|
70
|
+
*/
|
|
71
|
+
export async function transferSporeCluster(params) {
|
|
72
|
+
const { signer, id, to, scriptInfoHash } = params;
|
|
73
|
+
// prepare transaction
|
|
74
|
+
const tx = ccc.Transaction.from(params.tx ?? {});
|
|
75
|
+
// build cluster cell
|
|
76
|
+
const { cell: cluster, scriptInfo } = await assertCluster(signer.client, id);
|
|
77
|
+
tx.inputs.push(ccc.CellInput.from({
|
|
78
|
+
previousOutput: cluster.outPoint,
|
|
79
|
+
...cluster,
|
|
80
|
+
}));
|
|
81
|
+
tx.addOutput({
|
|
82
|
+
lock: to,
|
|
83
|
+
type: cluster.cellOutput.type,
|
|
84
|
+
}, cluster.outputData);
|
|
85
|
+
// complete cellDeps
|
|
86
|
+
await tx.addCellDepInfos(signer.client, scriptInfo.cellDeps);
|
|
87
|
+
// generate cobuild action
|
|
88
|
+
const actions = scriptInfo.cobuild
|
|
89
|
+
? [
|
|
90
|
+
assembleTransferClusterAction(cluster.cellOutput, tx.outputs[tx.outputs.length - 1], scriptInfoHash),
|
|
91
|
+
]
|
|
92
|
+
: [];
|
|
93
|
+
return {
|
|
94
|
+
tx: await prepareSporeTransaction(signer, tx, actions),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { UnpackResult } from "@ckb-lumos/codec";
|
|
3
|
+
import { Action, ActionVec, WitnessLayout } from "../codec/index.js";
|
|
4
|
+
export declare function assembleCreateSporeAction(sporeOutput: ccc.CellOutputLike, sporeData: ccc.BytesLike, scriptInfoHash?: ccc.HexLike): UnpackResult<typeof Action>;
|
|
5
|
+
export declare function assembleTransferSporeAction(sporeInput: ccc.CellOutputLike, sporeOutput: ccc.CellOutputLike, scriptInfoHash?: ccc.HexLike): UnpackResult<typeof Action>;
|
|
6
|
+
export declare function assembleMeltSporeAction(sporeInput: ccc.CellOutputLike, scriptInfoHash?: ccc.HexLike): UnpackResult<typeof Action>;
|
|
7
|
+
export declare function assembleCreateClusterAction(clusterOutput: ccc.CellOutputLike, clusterData: ccc.BytesLike, scriptInfoHash?: ccc.HexLike): UnpackResult<typeof Action>;
|
|
8
|
+
export declare function assembleTransferClusterAction(clusterInput: ccc.CellOutputLike, clusterOutput: ccc.CellOutputLike, scriptInfoHash?: ccc.HexLike): UnpackResult<typeof Action>;
|
|
9
|
+
export declare function prepareSporeTransaction(signer: ccc.Signer, txLike: ccc.TransactionLike, actions: UnpackResult<typeof ActionVec>): Promise<ccc.Transaction>;
|
|
10
|
+
export declare function unpackCommonCobuildProof(data: ccc.HexLike): UnpackResult<typeof WitnessLayout> | undefined;
|
|
11
|
+
export declare function extractCobuildActionsFromTx(tx: ccc.Transaction): UnpackResult<typeof ActionVec>;
|
|
12
|
+
export declare function injectCobuild(tx: ccc.Transaction, actions: UnpackResult<typeof ActionVec>): void;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cobuild/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EACL,MAAM,EACN,SAAS,EAET,aAAa,EACd,MAAM,mBAAmB,CAAC;AAG3B,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,GAAG,CAAC,cAAc,EAC/B,SAAS,EAAE,GAAG,CAAC,SAAS,EACxB,cAAc,GAAE,GAAG,CAAC,OAAmC,GACtD,YAAY,CAAC,OAAO,MAAM,CAAC,CAsB7B;AAED,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,GAAG,CAAC,cAAc,EAC9B,WAAW,EAAE,GAAG,CAAC,cAAc,EAC/B,cAAc,GAAE,GAAG,CAAC,OAAmC,GACtD,YAAY,CAAC,OAAO,MAAM,CAAC,CA0B7B;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,GAAG,CAAC,cAAc,EAC9B,cAAc,GAAE,GAAG,CAAC,OAAmC,GACtD,YAAY,CAAC,OAAO,MAAM,CAAC,CAqB7B;AAED,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,GAAG,CAAC,cAAc,EACjC,WAAW,EAAE,GAAG,CAAC,SAAS,EAC1B,cAAc,GAAE,GAAG,CAAC,OAAmC,GACtD,YAAY,CAAC,OAAO,MAAM,CAAC,CAsB7B;AAED,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,GAAG,CAAC,cAAc,EAChC,aAAa,EAAE,GAAG,CAAC,cAAc,EACjC,cAAc,GAAE,GAAG,CAAC,OAAmC,GACtD,YAAY,CAAC,OAAO,MAAM,CAAC,CAyB7B;AAED,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,GAAG,CAAC,MAAM,EAClB,MAAM,EAAE,GAAG,CAAC,eAAe,EAC3B,OAAO,EAAE,YAAY,CAAC,OAAO,SAAS,CAAC,GACtC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAW1B;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,GAAG,CAAC,OAAO,GAChB,YAAY,CAAC,OAAO,aAAa,CAAC,GAAG,SAAS,CAMhD;AAED,wBAAgB,2BAA2B,CACzC,EAAE,EAAE,GAAG,CAAC,WAAW,GAClB,YAAY,CAAC,OAAO,SAAS,CAAC,CAiBhC;AAED,wBAAgB,aAAa,CAC3B,EAAE,EAAE,GAAG,CAAC,WAAW,EACnB,OAAO,EAAE,YAAY,CAAC,OAAO,SAAS,CAAC,GACtC,IAAI,CAaN"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { SporeAction, WitnessLayout, } from "../codec/index.js";
|
|
3
|
+
import { DEFAULT_COBUILD_INFO_HASH } from "../predefined/index.js";
|
|
4
|
+
export function assembleCreateSporeAction(sporeOutput, sporeData, scriptInfoHash = DEFAULT_COBUILD_INFO_HASH) {
|
|
5
|
+
if (!sporeOutput.type) {
|
|
6
|
+
throw new Error("Spore cell must have a type script");
|
|
7
|
+
}
|
|
8
|
+
const sporeType = ccc.Script.from(sporeOutput.type);
|
|
9
|
+
const sporeTypeHash = sporeType.hash();
|
|
10
|
+
const actionData = SporeAction.pack({
|
|
11
|
+
type: "CreateSpore",
|
|
12
|
+
value: {
|
|
13
|
+
sporeId: sporeType.args,
|
|
14
|
+
dataHash: ccc.hashCkb(sporeData),
|
|
15
|
+
to: {
|
|
16
|
+
type: "Script",
|
|
17
|
+
value: ccc.Script.from(sporeOutput.lock),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
scriptInfoHash: ccc.hexFrom(scriptInfoHash),
|
|
23
|
+
scriptHash: sporeTypeHash,
|
|
24
|
+
data: ccc.hexFrom(actionData),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function assembleTransferSporeAction(sporeInput, sporeOutput, scriptInfoHash = DEFAULT_COBUILD_INFO_HASH) {
|
|
28
|
+
if (!sporeInput.type || !sporeOutput.type) {
|
|
29
|
+
throw new Error("Spore cell must have a type script");
|
|
30
|
+
}
|
|
31
|
+
const sporeType = ccc.Script.from(sporeOutput.type);
|
|
32
|
+
const sporeTypeHash = sporeType.hash();
|
|
33
|
+
const actionData = SporeAction.pack({
|
|
34
|
+
type: "TransferSpore",
|
|
35
|
+
value: {
|
|
36
|
+
sporeId: sporeType.args,
|
|
37
|
+
from: {
|
|
38
|
+
type: "Script",
|
|
39
|
+
value: ccc.Script.from(sporeInput.lock),
|
|
40
|
+
},
|
|
41
|
+
to: {
|
|
42
|
+
type: "Script",
|
|
43
|
+
value: ccc.Script.from(sporeOutput.lock),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
scriptInfoHash: ccc.hexFrom(scriptInfoHash),
|
|
49
|
+
scriptHash: sporeTypeHash,
|
|
50
|
+
data: ccc.hexFrom(actionData),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function assembleMeltSporeAction(sporeInput, scriptInfoHash = DEFAULT_COBUILD_INFO_HASH) {
|
|
54
|
+
if (!sporeInput.type) {
|
|
55
|
+
throw new Error("Spore cell must have a type script");
|
|
56
|
+
}
|
|
57
|
+
const sporeType = ccc.Script.from(sporeInput.type);
|
|
58
|
+
const sporeTypeHash = sporeType.hash();
|
|
59
|
+
const actionData = SporeAction.pack({
|
|
60
|
+
type: "MeltSpore",
|
|
61
|
+
value: {
|
|
62
|
+
sporeId: sporeType.args,
|
|
63
|
+
from: {
|
|
64
|
+
type: "Script",
|
|
65
|
+
value: ccc.Script.from(sporeInput.lock),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
scriptInfoHash: ccc.hexFrom(scriptInfoHash),
|
|
71
|
+
scriptHash: sporeTypeHash,
|
|
72
|
+
data: ccc.hexFrom(actionData),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function assembleCreateClusterAction(clusterOutput, clusterData, scriptInfoHash = DEFAULT_COBUILD_INFO_HASH) {
|
|
76
|
+
if (!clusterOutput.type) {
|
|
77
|
+
throw new Error("Cluster cell must have a type script");
|
|
78
|
+
}
|
|
79
|
+
const clusterType = ccc.Script.from(clusterOutput.type);
|
|
80
|
+
const clusterTypeHash = clusterType.hash();
|
|
81
|
+
const actionData = SporeAction.pack({
|
|
82
|
+
type: "CreateCluster",
|
|
83
|
+
value: {
|
|
84
|
+
clusterId: clusterType.args,
|
|
85
|
+
dataHash: ccc.hashCkb(clusterData),
|
|
86
|
+
to: {
|
|
87
|
+
type: "Script",
|
|
88
|
+
value: ccc.Script.from(clusterOutput.lock),
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
scriptInfoHash: ccc.hexFrom(scriptInfoHash),
|
|
94
|
+
scriptHash: clusterTypeHash,
|
|
95
|
+
data: ccc.hexFrom(actionData),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function assembleTransferClusterAction(clusterInput, clusterOutput, scriptInfoHash = DEFAULT_COBUILD_INFO_HASH) {
|
|
99
|
+
if (!clusterInput.type || !clusterOutput.type) {
|
|
100
|
+
throw new Error("Cluster cell must have a type script");
|
|
101
|
+
}
|
|
102
|
+
const clusterType = ccc.Script.from(clusterOutput.type);
|
|
103
|
+
const clusterTypeHash = clusterType.hash();
|
|
104
|
+
const actionData = SporeAction.pack({
|
|
105
|
+
type: "TransferCluster",
|
|
106
|
+
value: {
|
|
107
|
+
clusterId: clusterType.args,
|
|
108
|
+
from: {
|
|
109
|
+
type: "Script",
|
|
110
|
+
value: ccc.Script.from(clusterInput.lock),
|
|
111
|
+
},
|
|
112
|
+
to: {
|
|
113
|
+
type: "Script",
|
|
114
|
+
value: ccc.Script.from(clusterOutput.lock),
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
scriptInfoHash: ccc.hexFrom(scriptInfoHash),
|
|
120
|
+
scriptHash: clusterTypeHash,
|
|
121
|
+
data: ccc.hexFrom(actionData),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export async function prepareSporeTransaction(signer, txLike, actions) {
|
|
125
|
+
let tx = ccc.Transaction.from(txLike);
|
|
126
|
+
if (actions.length === 0) {
|
|
127
|
+
return signer.prepareTransaction(tx);
|
|
128
|
+
}
|
|
129
|
+
const existedActions = extractCobuildActionsFromTx(tx);
|
|
130
|
+
tx = await signer.prepareTransaction(tx);
|
|
131
|
+
injectCobuild(tx, [...existedActions, ...actions]);
|
|
132
|
+
return tx;
|
|
133
|
+
}
|
|
134
|
+
export function unpackCommonCobuildProof(data) {
|
|
135
|
+
try {
|
|
136
|
+
return WitnessLayout.unpack(ccc.bytesFrom(data));
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export function extractCobuildActionsFromTx(tx) {
|
|
143
|
+
if (tx.witnesses.length === 0) {
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
const witnessLayout = unpackCommonCobuildProof(tx.witnesses[tx.witnesses.length - 1]);
|
|
147
|
+
if (!witnessLayout) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
if (witnessLayout.type !== "SighashAll") {
|
|
151
|
+
throw new Error("Invalid cobuild proof type: " + witnessLayout.type);
|
|
152
|
+
}
|
|
153
|
+
// Remove existed cobuild witness
|
|
154
|
+
tx.witnesses.pop();
|
|
155
|
+
return witnessLayout.value.message.actions;
|
|
156
|
+
}
|
|
157
|
+
export function injectCobuild(tx, actions) {
|
|
158
|
+
const witnessLayout = ccc.hexFrom(WitnessLayout.pack({
|
|
159
|
+
type: "SighashAll",
|
|
160
|
+
value: {
|
|
161
|
+
seal: "0x",
|
|
162
|
+
message: {
|
|
163
|
+
actions,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
}));
|
|
167
|
+
tx.witnesses.push(ccc.hexFrom(witnessLayout));
|
|
168
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/codec/base.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,SAAS,gEAGpB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { molecule } from "@ckb-lumos/codec";
|
|
3
|
+
/**
|
|
4
|
+
* The codec for packing/unpacking UTF-8 raw strings.
|
|
5
|
+
* Should be packed like so: String.pack('something')
|
|
6
|
+
*/
|
|
7
|
+
export const RawString = molecule.byteVecOf({
|
|
8
|
+
pack: (packable) => ccc.bytesFrom(packable, "utf8"),
|
|
9
|
+
unpack: (unpackable) => ccc.bytesTo(unpackable, "utf8"),
|
|
10
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { molecule } from "@ckb-lumos/codec";
|
|
3
|
+
export declare const MolClusterDataV1: molecule.ObjectLayoutCodec<{
|
|
4
|
+
name: import("@ckb-lumos/codec/lib/base.js").BytesCodec<string, string>;
|
|
5
|
+
description: import("@ckb-lumos/codec/lib/base.js").BytesCodec<string, string>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const MolClusterDataV2: molecule.ObjectLayoutCodec<{
|
|
8
|
+
name: import("@ckb-lumos/codec/lib/base.js").BytesCodec<string, string>;
|
|
9
|
+
description: import("@ckb-lumos/codec/lib/base.js").BytesCodec<string, string>;
|
|
10
|
+
mutantId: molecule.OptionLayoutCodec<import("@ckb-lumos/codec/lib/base.js").BytesCodec<string, import("@ckb-lumos/codec").BytesLike>>;
|
|
11
|
+
}>;
|
|
12
|
+
export interface ClusterDataV1 {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ClusterDataV2 {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
mutantId?: ccc.HexLike;
|
|
20
|
+
}
|
|
21
|
+
export type ClusterData = ClusterDataV2;
|
|
22
|
+
export type ClusterDataVersion = "v1" | "v2";
|
|
23
|
+
/**
|
|
24
|
+
* Pack RawClusterData to Uint8Array.
|
|
25
|
+
* Pass an optional "version" field to select a specific packing version.
|
|
26
|
+
*/
|
|
27
|
+
export declare function packRawClusterData(packable: ClusterData): Uint8Array;
|
|
28
|
+
export declare function packRawClusterData(packable: ClusterDataV1, version: "v1"): Uint8Array;
|
|
29
|
+
export declare function packRawClusterData(packable: ClusterDataV2, version: "v2"): Uint8Array;
|
|
30
|
+
export declare function packRawClusterDataV1(packable: ClusterDataV1): Uint8Array;
|
|
31
|
+
export declare function packRawClusterDataV2(packable: ClusterDataV2): Uint8Array;
|
|
32
|
+
/**
|
|
33
|
+
* Unpack Hex/Bytes to RawClusterData.
|
|
34
|
+
* Pass an optional "version" field to select a specific unpacking version.
|
|
35
|
+
*/
|
|
36
|
+
export declare function unpackToRawClusterData(unpackable: ccc.BytesLike): ClusterData;
|
|
37
|
+
export declare function unpackToRawClusterData(unpackable: ccc.BytesLike, version: "v1"): ClusterDataV1;
|
|
38
|
+
export declare function unpackToRawClusterData(unpackable: ccc.BytesLike, version: "v2"): ClusterDataV2;
|
|
39
|
+
export declare function unpackToRawClusterDataV1(unpackable: ccc.BytesLike): ClusterDataV1;
|
|
40
|
+
export declare function unpackToRawClusterDataV2(unpackable: ccc.BytesLike): ClusterDataV2;
|
|
41
|
+
//# sourceMappingURL=cluster.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cluster.d.ts","sourceRoot":"","sources":["../../src/codec/cluster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,eAAO,MAAM,gBAAgB;;;EAM5B,CAAC;AACF,eAAO,MAAM,gBAAgB;;;;EAO5B,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AACD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;CACxB;AACD,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC;AAExC,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,IAAI,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,WAAW,GAAG,UAAU,CAAC;AACtE,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,IAAI,GACZ,UAAU,CAAC;AACd,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,IAAI,GACZ,UAAU,CAAC;AAgBd,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,GAAG,UAAU,CAKxE;AACD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,GAAG,UAAU,CAMxE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,GAAG,CAAC,SAAS,GAAG,WAAW,CAAC;AAC/E,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,GAAG,CAAC,SAAS,EACzB,OAAO,EAAE,IAAI,GACZ,aAAa,CAAC;AACjB,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,GAAG,CAAC,SAAS,EACzB,OAAO,EAAE,IAAI,GACZ,aAAa,CAAC;AA0BjB,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,GAAG,CAAC,SAAS,GACxB,aAAa,CAMf;AACD,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,GAAG,CAAC,SAAS,GACxB,aAAa,CAOf"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ccc } from "@ckb-ccc/core";
|
|
2
|
+
import { blockchain } from "@ckb-lumos/base";
|
|
3
|
+
import { molecule } from "@ckb-lumos/codec";
|
|
4
|
+
import { RawString } from "./base.js";
|
|
5
|
+
export const MolClusterDataV1 = molecule.table({
|
|
6
|
+
name: RawString,
|
|
7
|
+
description: RawString,
|
|
8
|
+
}, ["name", "description"]);
|
|
9
|
+
export const MolClusterDataV2 = molecule.table({
|
|
10
|
+
name: RawString,
|
|
11
|
+
description: RawString,
|
|
12
|
+
mutantId: blockchain.BytesOpt,
|
|
13
|
+
}, ["name", "description", "mutantId"]);
|
|
14
|
+
export function packRawClusterData(packable, version) {
|
|
15
|
+
if (!version) {
|
|
16
|
+
return packRawClusterDataV2(packable);
|
|
17
|
+
}
|
|
18
|
+
switch (version) {
|
|
19
|
+
case "v1":
|
|
20
|
+
return packRawClusterDataV1(packable);
|
|
21
|
+
case "v2":
|
|
22
|
+
return packRawClusterDataV2(packable);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function packRawClusterDataV1(packable) {
|
|
26
|
+
return MolClusterDataV1.pack({
|
|
27
|
+
name: packable.name,
|
|
28
|
+
description: packable.description,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export function packRawClusterDataV2(packable) {
|
|
32
|
+
return MolClusterDataV2.pack({
|
|
33
|
+
name: packable.name,
|
|
34
|
+
description: packable.description,
|
|
35
|
+
mutantId: packable.mutantId,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function unpackToRawClusterData(unpackable, version) {
|
|
39
|
+
if (version) {
|
|
40
|
+
switch (version) {
|
|
41
|
+
case "v1":
|
|
42
|
+
return unpackToRawClusterDataV1(unpackable);
|
|
43
|
+
case "v2":
|
|
44
|
+
return unpackToRawClusterDataV2(unpackable);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
return unpackToRawClusterDataV2(unpackable);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
try {
|
|
52
|
+
return unpackToRawClusterDataV1(unpackable);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
throw new Error(`Cannot unpack ClusterData, no matching molecule: ${ccc.hexFrom(unpackable)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function unpackToRawClusterDataV1(unpackable) {
|
|
60
|
+
const decoded = MolClusterDataV1.unpack(unpackable);
|
|
61
|
+
return {
|
|
62
|
+
name: decoded.name,
|
|
63
|
+
description: decoded.description,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function unpackToRawClusterDataV2(unpackable) {
|
|
67
|
+
const decoded = MolClusterDataV2.unpack(unpackable);
|
|
68
|
+
return {
|
|
69
|
+
name: decoded.name,
|
|
70
|
+
description: decoded.description,
|
|
71
|
+
mutantId: ccc.apply(ccc.hexFrom, decoded.mutantId),
|
|
72
|
+
};
|
|
73
|
+
}
|