@offckb/cli 0.3.0-canary-3b77560.0 → 0.3.0-canary-ce4cd80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -4
- package/dist/cmd/deploy.js +9 -4
- package/dist/deploy/migration.d.ts +4 -4
- package/dist/deploy/migration.js +16 -8
- package/dist/deploy/toml.d.ts +1 -1
- package/dist/deploy/toml.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ Start building on CKB blockchain, right now, right away!
|
|
|
25
25
|
- [Get started](#get-started)
|
|
26
26
|
- [Running CKB](#running-ckb)
|
|
27
27
|
- [List scripts info](#list-scripts-info)
|
|
28
|
+
- [Tweak Devnet Config](#tweak-devnet-config)
|
|
28
29
|
- [Create a full-stack Project](#create-a-full-stack-project)
|
|
29
30
|
- [Create a script-only Project](#create-a-script-only-project)
|
|
30
31
|
- [Build and Deploy a script](#build-and-deploy-a-script)
|
|
@@ -47,7 +48,7 @@ Start building on CKB blockchain, right now, right away!
|
|
|
47
48
|
npm install -g @offckb/cli
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
_We recommand using [LTS](https://nodejs.org/en/download/package-manager) version of Node to run `offckb`_
|
|
51
52
|
|
|
52
53
|
## Usage
|
|
53
54
|
|
|
@@ -81,7 +82,7 @@ Commands:
|
|
|
81
82
|
help [command] display help for command
|
|
82
83
|
```
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
_Use `offckb [command] -h` to learn more about a specific command._
|
|
85
86
|
|
|
86
87
|
## Get started
|
|
87
88
|
|
|
@@ -96,7 +97,7 @@ offckb node
|
|
|
96
97
|
Or specify a CKB version:
|
|
97
98
|
|
|
98
99
|
```sh
|
|
99
|
-
offckb node 0.117.0
|
|
100
|
+
offckb node 0.117.0
|
|
100
101
|
```
|
|
101
102
|
|
|
102
103
|
Or set the default CKB version:
|
|
@@ -140,6 +141,39 @@ Or print the scripts info in a CCC style:
|
|
|
140
141
|
offckb system-scripts --export-style ccc
|
|
141
142
|
```
|
|
142
143
|
|
|
144
|
+
### Tweak Devnet Config
|
|
145
|
+
|
|
146
|
+
By default, offckb use a fixed devnet config for the local blockchain. You can tweak the config to customize the devnet:
|
|
147
|
+
|
|
148
|
+
First, start a default CKB devnet and locate your devnet folder
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
offckb node
|
|
152
|
+
# after starting, press ctrl-c to kill the node
|
|
153
|
+
# then get the config
|
|
154
|
+
offckb config list
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Result:
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"devnet": {
|
|
162
|
+
"rpcUrl": "http://localhost:8114",
|
|
163
|
+
"configPath": "~/Library/Application Support/offckb-nodejs/devnet",
|
|
164
|
+
"dataPath": "~/Library/Application Support/offckb-nodejs/devnet/data"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Pay attention to the `devnet.configPath` and `devnet.dataPath`. They are the ones we need.
|
|
170
|
+
|
|
171
|
+
1. `cd` into the `devnet.configPath`, this is the config folder for the local blockchain. Modify the config in the folder to better customize the devnet. For customization, see [Custom Devnet Setup](https://docs.nervos.org/docs/node/run-devnet-node#custom-devnet-setup) and [Configure CKB](https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md) for better explanation of the config files.
|
|
172
|
+
2. After modifications, remove everything in the `devnet.dataPath` folder. This will clean the chain data.
|
|
173
|
+
3. Restart local blockchain by running `offckb node`
|
|
174
|
+
|
|
175
|
+
Done.
|
|
176
|
+
|
|
143
177
|
### Create a full-stack Project
|
|
144
178
|
|
|
145
179
|
Create a new project from predefined boilerplates.
|
|
@@ -164,7 +198,7 @@ Note: you need to have rust/cargo/cargo-generate/clang 16+ installed in your env
|
|
|
164
198
|
|
|
165
199
|
The fullstack boilerplate project is a monorepo, which contains a script project and a frontend project.
|
|
166
200
|
|
|
167
|
-
To build the script, in the root of the project, run:
|
|
201
|
+
To build the script, in the root of the project, run:
|
|
168
202
|
|
|
169
203
|
```sh
|
|
170
204
|
make build
|
package/dist/cmd/deploy.js
CHANGED
|
@@ -131,21 +131,26 @@ function deployBinary(binPath, from, ckb) {
|
|
|
131
131
|
console.log(`contract ${contractName} deployed, tx hash:`, res);
|
|
132
132
|
console.log('wait 4 blocks..');
|
|
133
133
|
yield ckb.indexer.waitForSync(-4); // why negative 4? a bug in ckb-lumos
|
|
134
|
+
const txHash = result.scriptConfig.TX_HASH;
|
|
135
|
+
const index = result.scriptConfig.INDEX;
|
|
136
|
+
const dataByteLen = BigInt(tx.outputsData[+index].slice(2).length / 2);
|
|
137
|
+
const dataShannonLen = dataByteLen * BigInt('100000000');
|
|
138
|
+
const occupiedCapacity = '0x' + dataShannonLen.toString(16);
|
|
134
139
|
// todo: handle multiple cell recipes?
|
|
135
140
|
return {
|
|
136
141
|
deploymentOptions: {
|
|
137
142
|
name: contractName,
|
|
138
143
|
binFilePath: binPath,
|
|
139
144
|
enableTypeId: true,
|
|
140
|
-
lockScript: tx.outputs[+
|
|
145
|
+
lockScript: tx.outputs[+index].lock,
|
|
141
146
|
},
|
|
142
147
|
deploymentRecipe: {
|
|
143
148
|
cellRecipes: [
|
|
144
149
|
{
|
|
145
150
|
name: contractName,
|
|
146
|
-
txHash
|
|
147
|
-
index
|
|
148
|
-
occupiedCapacity
|
|
151
|
+
txHash,
|
|
152
|
+
index,
|
|
153
|
+
occupiedCapacity,
|
|
149
154
|
dataHash: (0, utils_1.ckbHash)(tx.outputsData[+result.scriptConfig.INDEX]),
|
|
150
155
|
typeId: (0, utils_1.computeScriptHash)(result.typeId),
|
|
151
156
|
},
|
|
@@ -23,17 +23,17 @@ export interface DeploymentRecipeJson {
|
|
|
23
23
|
cell_recipes: {
|
|
24
24
|
name: string;
|
|
25
25
|
tx_hash: string;
|
|
26
|
-
index:
|
|
27
|
-
occupied_capacity:
|
|
26
|
+
index: number;
|
|
27
|
+
occupied_capacity: number;
|
|
28
28
|
data_hash: string;
|
|
29
29
|
type_id?: string;
|
|
30
30
|
}[];
|
|
31
31
|
dep_group_recipes: {
|
|
32
32
|
name: string;
|
|
33
33
|
tx_hash: string;
|
|
34
|
-
index:
|
|
34
|
+
index: number;
|
|
35
35
|
data_hash: string;
|
|
36
|
-
occupied_capacity:
|
|
36
|
+
occupied_capacity: number;
|
|
37
37
|
}[];
|
|
38
38
|
}
|
|
39
39
|
export declare function generateDeploymentRecipeJsonFile(name: string, deploymentRecipe: DeploymentRecipe, network?: Network): void;
|
package/dist/deploy/migration.js
CHANGED
|
@@ -84,22 +84,30 @@ exports.getNewestMigrationFile = getNewestMigrationFile;
|
|
|
84
84
|
function deploymentRecipeToJson(recipe) {
|
|
85
85
|
return {
|
|
86
86
|
cell_recipes: recipe.cellRecipes.map((val) => {
|
|
87
|
+
if (BigInt(val.occupiedCapacity) > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
88
|
+
// CKB blocksize limit is 500k, so it should be impossible to have a cell occupied data larger than Number.MAX_SAFE_INTEGER which is 9007,1992,5474,0991
|
|
89
|
+
console.error(`invalid occupiedCapacity: ${val.occupiedCapacity}, the cell_recipes json might be incorrect for cell outpoint ${val.txHash}:${+val.index}`);
|
|
90
|
+
}
|
|
87
91
|
return {
|
|
88
92
|
name: val.name,
|
|
89
93
|
tx_hash: val.txHash,
|
|
90
|
-
index: val.index,
|
|
91
|
-
occupied_capacity: val.occupiedCapacity,
|
|
94
|
+
index: +val.index,
|
|
95
|
+
occupied_capacity: +BigInt(val.occupiedCapacity).toString(10),
|
|
92
96
|
data_hash: val.dataHash,
|
|
93
97
|
type_id: val.typeId,
|
|
94
98
|
};
|
|
95
99
|
}),
|
|
96
100
|
dep_group_recipes: recipe.depGroupRecipes.map((val) => {
|
|
101
|
+
if (BigInt(val.occupiedCapacity) > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
102
|
+
// CKB blocksize limit is 500k, so it should be impossible to have a cell occupied data larger than Number.MAX_SAFE_INTEGER which is 9007,1992,5474,0991
|
|
103
|
+
console.error(`invalid occupiedCapacity: ${val.occupiedCapacity}, the dep_group_recipes json might be incorrect for cell outpoint ${val.txHash}:${+val.index}`);
|
|
104
|
+
}
|
|
97
105
|
return {
|
|
98
106
|
name: val.name,
|
|
99
107
|
tx_hash: val.txHash,
|
|
100
|
-
index: val.index,
|
|
108
|
+
index: +val.index,
|
|
101
109
|
data_hash: val.dataHash,
|
|
102
|
-
occupied_capacity: val.occupiedCapacity,
|
|
110
|
+
occupied_capacity: +BigInt(val.occupiedCapacity).toString(10),
|
|
103
111
|
};
|
|
104
112
|
}),
|
|
105
113
|
};
|
|
@@ -111,8 +119,8 @@ function deploymentRecipeFromJson(json) {
|
|
|
111
119
|
return {
|
|
112
120
|
name: val.name,
|
|
113
121
|
txHash: val.tx_hash,
|
|
114
|
-
index: val.index,
|
|
115
|
-
occupiedCapacity: val.occupied_capacity,
|
|
122
|
+
index: '0x' + val.index.toString(16),
|
|
123
|
+
occupiedCapacity: '0x' + val.occupied_capacity.toString(16),
|
|
116
124
|
dataHash: val.data_hash,
|
|
117
125
|
typeId: val.type_id,
|
|
118
126
|
};
|
|
@@ -121,9 +129,9 @@ function deploymentRecipeFromJson(json) {
|
|
|
121
129
|
return {
|
|
122
130
|
name: val.name,
|
|
123
131
|
txHash: val.tx_hash,
|
|
124
|
-
index: val.index,
|
|
132
|
+
index: '0x' + val.index.toString(16),
|
|
125
133
|
dataHash: val.data_hash,
|
|
126
|
-
occupiedCapacity: val.occupied_capacity,
|
|
134
|
+
occupiedCapacity: '0x' + val.occupied_capacity.toString(16),
|
|
127
135
|
};
|
|
128
136
|
}),
|
|
129
137
|
};
|
package/dist/deploy/toml.d.ts
CHANGED
package/dist/deploy/toml.js
CHANGED
|
@@ -13,7 +13,7 @@ function generateDeploymentToml(options, network) {
|
|
|
13
13
|
cells: [
|
|
14
14
|
{
|
|
15
15
|
name: options.name,
|
|
16
|
-
enable_type_id: options.enableTypeId
|
|
16
|
+
enable_type_id: options.enableTypeId,
|
|
17
17
|
location: {
|
|
18
18
|
file: options.binFilePath,
|
|
19
19
|
},
|
|
@@ -44,7 +44,7 @@ function readDeploymentToml(scriptName, network) {
|
|
|
44
44
|
cells: [
|
|
45
45
|
{
|
|
46
46
|
name: data.cells[0].name,
|
|
47
|
-
enableTypeId: data.cells[0].enable_type_id
|
|
47
|
+
enableTypeId: data.cells[0].enable_type_id,
|
|
48
48
|
location: {
|
|
49
49
|
file: data.cells[0].location.file,
|
|
50
50
|
},
|