@offckb/cli 0.3.0-rc3 → 0.3.0-rc5
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 +27 -20
- package/dist/cfg/setting.d.ts +11 -2
- package/dist/cli.js +16 -6
- package/dist/cmd/balance.d.ts +1 -1
- package/dist/cmd/balance.js +6 -8
- package/dist/cmd/debug.d.ts +1 -1
- package/dist/cmd/debug.js +5 -5
- package/dist/cmd/deploy.d.ts +2 -1
- package/dist/cmd/deploy.js +15 -116
- package/dist/cmd/deposit.d.ts +2 -2
- package/dist/cmd/deposit.js +29 -31
- package/dist/cmd/list-hashes.d.ts +1 -1
- package/dist/cmd/my-scripts.d.ts +1 -1
- package/dist/cmd/my-scripts.js +2 -2
- package/dist/cmd/node.js +2 -2
- package/dist/cmd/proxy-rpc.d.ts +1 -1
- package/dist/cmd/proxy-rpc.js +4 -4
- package/dist/cmd/system-scripts.d.ts +70 -2
- package/dist/cmd/system-scripts.js +4 -0
- package/dist/cmd/transfer-all.d.ts +5 -0
- package/dist/cmd/transfer-all.js +37 -0
- package/dist/cmd/transfer.d.ts +2 -2
- package/dist/cmd/transfer.js +8 -11
- package/dist/deploy/index.d.ts +18 -0
- package/dist/deploy/index.js +126 -0
- package/dist/deploy/migration.d.ts +17 -12
- package/dist/deploy/migration.js +52 -15
- package/dist/deploy/toml.d.ts +8 -4
- package/dist/deploy/toml.js +2 -2
- package/dist/deploy/util.d.ts +1 -1
- package/dist/deploy/util.js +4 -4
- package/dist/node/install.js +3 -4
- package/dist/scripts/gen.js +4 -4
- package/dist/scripts/private.d.ts +4 -0
- package/dist/scripts/private.js +14 -0
- package/dist/scripts/util.d.ts +1 -1
- package/dist/scripts/util.js +1 -1
- package/dist/sdk/ckb.d.ts +37 -0
- package/dist/sdk/ckb.js +254 -0
- package/dist/sdk/network.d.ts +17 -0
- package/dist/sdk/network.js +22 -0
- package/dist/tools/moleculec-es.js +3 -4
- package/dist/tools/rpc-proxy.d.ts +1 -1
- package/dist/tools/rpc-proxy.js +2 -2
- package/dist/{util/type.d.ts → type/base.d.ts} +2 -0
- package/dist/util/request.d.ts +6 -6
- package/dist/util/request.js +15 -11
- package/dist/util/validator.js +2 -2
- package/package.json +5 -4
- package/dist/util/ckb.d.ts +0 -141
- package/dist/util/ckb.js +0 -312
- /package/dist/{util/type.js → type/base.js} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { config } from '@ckb-lumos/lumos';
|
|
2
1
|
import { SystemCell } from './list-hashes';
|
|
3
2
|
import { CellDepInfoLike, Script } from '@ckb-ccc/core';
|
|
4
3
|
import { SystemScriptsRecord } from '../scripts/type';
|
|
@@ -36,7 +35,76 @@ export declare function systemCellToScriptInfo(cell: SystemCell, depType: 'code'
|
|
|
36
35
|
};
|
|
37
36
|
}[];
|
|
38
37
|
};
|
|
39
|
-
export declare function toLumosConfig(scripts: SystemScriptsRecord, addressPrefix?: 'ckb' | 'ckt'):
|
|
38
|
+
export declare function toLumosConfig(scripts: SystemScriptsRecord, addressPrefix?: 'ckb' | 'ckt'): {
|
|
39
|
+
PREFIX: "ckb" | "ckt";
|
|
40
|
+
SCRIPTS: {
|
|
41
|
+
SECP256K1_BLAKE160: {
|
|
42
|
+
CODE_HASH: `0x${string}`;
|
|
43
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
44
|
+
TX_HASH: `0x${string}`;
|
|
45
|
+
INDEX: string;
|
|
46
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
47
|
+
SHORT_ID: number;
|
|
48
|
+
};
|
|
49
|
+
SECP256K1_BLAKE160_MULTISIG: {
|
|
50
|
+
CODE_HASH: `0x${string}`;
|
|
51
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
52
|
+
TX_HASH: `0x${string}`;
|
|
53
|
+
INDEX: string;
|
|
54
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
55
|
+
};
|
|
56
|
+
DAO: {
|
|
57
|
+
CODE_HASH: `0x${string}`;
|
|
58
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
59
|
+
TX_HASH: `0x${string}`;
|
|
60
|
+
INDEX: string;
|
|
61
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
62
|
+
SHORT_ID: number;
|
|
63
|
+
};
|
|
64
|
+
SUDT: {
|
|
65
|
+
CODE_HASH: `0x${string}`;
|
|
66
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
67
|
+
TX_HASH: `0x${string}`;
|
|
68
|
+
INDEX: string;
|
|
69
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
70
|
+
};
|
|
71
|
+
XUDT: {
|
|
72
|
+
CODE_HASH: `0x${string}`;
|
|
73
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
74
|
+
TX_HASH: `0x${string}`;
|
|
75
|
+
INDEX: string;
|
|
76
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
77
|
+
};
|
|
78
|
+
OMNILOCK: {
|
|
79
|
+
CODE_HASH: `0x${string}`;
|
|
80
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
81
|
+
TX_HASH: `0x${string}`;
|
|
82
|
+
INDEX: string;
|
|
83
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
84
|
+
};
|
|
85
|
+
ANYONE_CAN_PAY: {
|
|
86
|
+
CODE_HASH: `0x${string}`;
|
|
87
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
88
|
+
TX_HASH: `0x${string}`;
|
|
89
|
+
INDEX: string;
|
|
90
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
91
|
+
};
|
|
92
|
+
SPORE: {
|
|
93
|
+
CODE_HASH: `0x${string}`;
|
|
94
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
95
|
+
TX_HASH: `0x${string}`;
|
|
96
|
+
INDEX: string;
|
|
97
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
98
|
+
};
|
|
99
|
+
SPORE_CLUSTER: {
|
|
100
|
+
CODE_HASH: `0x${string}`;
|
|
101
|
+
HASH_TYPE: import("@ckb-ccc/core").HashType;
|
|
102
|
+
TX_HASH: `0x${string}`;
|
|
103
|
+
INDEX: string;
|
|
104
|
+
DEP_TYPE: import("@ckb-ccc/core").DepType;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
};
|
|
40
108
|
export declare function toCCCKnownScripts(scripts: SystemScriptsRecord): Record<string, Pick<Script, "codeHash" | "hashType"> & {
|
|
41
109
|
cellDeps: CellDepInfoLike[];
|
|
42
110
|
}>;
|
|
@@ -213,6 +213,7 @@ function toLumosConfig(scripts, addressPrefix = 'ckt') {
|
|
|
213
213
|
},
|
|
214
214
|
};
|
|
215
215
|
if (scripts.always_success) {
|
|
216
|
+
// @ts-expect-error we remove the lumos config type deps
|
|
216
217
|
config.SCRIPTS['ALWAYS_SUCCESS'] = {
|
|
217
218
|
CODE_HASH: scripts.always_success.script.codeHash,
|
|
218
219
|
HASH_TYPE: scripts.always_success.script.hashType,
|
|
@@ -222,6 +223,7 @@ function toLumosConfig(scripts, addressPrefix = 'ckt') {
|
|
|
222
223
|
};
|
|
223
224
|
}
|
|
224
225
|
if (scripts.spore_cluster_agent) {
|
|
226
|
+
// @ts-expect-error we remove the lumos config type deps
|
|
225
227
|
config.SCRIPTS['SPORE_CLUSTER_AGENT'] = {
|
|
226
228
|
CODE_HASH: scripts.spore_cluster_agent.script.codeHash,
|
|
227
229
|
HASH_TYPE: scripts.spore_cluster_agent.script.hashType,
|
|
@@ -231,6 +233,7 @@ function toLumosConfig(scripts, addressPrefix = 'ckt') {
|
|
|
231
233
|
};
|
|
232
234
|
}
|
|
233
235
|
if (scripts.spore_cluster_proxy) {
|
|
236
|
+
// @ts-expect-error we remove the lumos config type deps
|
|
234
237
|
config.SCRIPTS['SPORE_CLUSTER_PROXY'] = {
|
|
235
238
|
CODE_HASH: scripts.spore_cluster_proxy.script.codeHash,
|
|
236
239
|
HASH_TYPE: scripts.spore_cluster_proxy.script.hashType,
|
|
@@ -240,6 +243,7 @@ function toLumosConfig(scripts, addressPrefix = 'ckt') {
|
|
|
240
243
|
};
|
|
241
244
|
}
|
|
242
245
|
if (scripts.spore_extension_lua) {
|
|
246
|
+
// @ts-expect-error we remove the lumos config type deps
|
|
243
247
|
config.SCRIPTS['SPORE_LUA'] = {
|
|
244
248
|
CODE_HASH: scripts.spore_extension_lua.script.codeHash,
|
|
245
249
|
HASH_TYPE: scripts.spore_extension_lua.script.hashType,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.transferAll = void 0;
|
|
13
|
+
const ckb_1 = require("../sdk/ckb");
|
|
14
|
+
const base_1 = require("../type/base");
|
|
15
|
+
const link_1 = require("../util/link");
|
|
16
|
+
const validator_1 = require("../util/validator");
|
|
17
|
+
function transferAll(toAddress, opt = { network: base_1.Network.devnet }) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const network = opt.network;
|
|
20
|
+
(0, validator_1.validateNetworkOpt)(network);
|
|
21
|
+
if (opt.privkey == null) {
|
|
22
|
+
throw new Error('--privkey is required!');
|
|
23
|
+
}
|
|
24
|
+
const privateKey = opt.privkey;
|
|
25
|
+
const ckb = new ckb_1.CKB({ network });
|
|
26
|
+
const txHash = yield ckb.transferAll({
|
|
27
|
+
toAddress,
|
|
28
|
+
privateKey,
|
|
29
|
+
});
|
|
30
|
+
if (network === 'testnet') {
|
|
31
|
+
console.log(`Successfully transfer, check ${(0, link_1.buildTestnetTxLink)(txHash)} for details.`);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
console.log('Successfully transfer, txHash:', txHash);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.transferAll = transferAll;
|
package/dist/cmd/transfer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NetworkOption } from '../
|
|
1
|
+
import { NetworkOption } from '../type/base';
|
|
2
2
|
export interface TransferOptions extends NetworkOption {
|
|
3
3
|
privkey?: string | null;
|
|
4
4
|
}
|
|
5
|
-
export declare function transfer(toAddress: string,
|
|
5
|
+
export declare function transfer(toAddress: string, amountInCKB: string, opt?: TransferOptions): Promise<void>;
|
package/dist/cmd/transfer.js
CHANGED
|
@@ -10,11 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.transfer = void 0;
|
|
13
|
-
const ckb_1 = require("../
|
|
14
|
-
const
|
|
13
|
+
const ckb_1 = require("../sdk/ckb");
|
|
14
|
+
const base_1 = require("../type/base");
|
|
15
15
|
const link_1 = require("../util/link");
|
|
16
16
|
const validator_1 = require("../util/validator");
|
|
17
|
-
function transfer(toAddress,
|
|
17
|
+
function transfer(toAddress, amountInCKB, opt = { network: base_1.Network.devnet }) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
const network = opt.network;
|
|
20
20
|
(0, validator_1.validateNetworkOpt)(network);
|
|
@@ -22,15 +22,12 @@ function transfer(toAddress, amount, opt = { network: type_1.Network.devnet }) {
|
|
|
22
22
|
throw new Error('--privkey is required!');
|
|
23
23
|
}
|
|
24
24
|
const privateKey = opt.privkey;
|
|
25
|
-
const ckb = new ckb_1.CKB(network);
|
|
26
|
-
const lumosConfig = ckb.getLumosConfig();
|
|
27
|
-
const from = ckb_1.CKB.generateAccountFromPrivateKey(privateKey, lumosConfig);
|
|
25
|
+
const ckb = new ckb_1.CKB({ network });
|
|
28
26
|
const txHash = yield ckb.transfer({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}, lumosConfig);
|
|
27
|
+
toAddress,
|
|
28
|
+
amountInCKB,
|
|
29
|
+
privateKey,
|
|
30
|
+
});
|
|
34
31
|
if (network === 'testnet') {
|
|
35
32
|
console.log(`Successfully transfer, check ${(0, link_1.buildTestnetTxLink)(txHash)} for details.`);
|
|
36
33
|
return;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DeploymentOptions } from '../deploy/toml';
|
|
2
|
+
import { DeploymentRecipe } from '../deploy/migration';
|
|
3
|
+
import { Network } from '../type/base';
|
|
4
|
+
import { CKB } from '../sdk/ckb';
|
|
5
|
+
import { HexString } from '../type/base';
|
|
6
|
+
export type DeployBinaryReturnType = ReturnType<typeof deployBinary>;
|
|
7
|
+
export type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
8
|
+
export type DeployedInterfaceType = UnwrapPromise<DeployBinaryReturnType>;
|
|
9
|
+
export declare function getToDeployBinsPath(): string[];
|
|
10
|
+
export declare function recordDeployResult(results: DeployedInterfaceType[], network: Network, isUpdateMyScriptsJsonFile?: boolean): Promise<void>;
|
|
11
|
+
export declare function deployBinaries(binPaths: string[], privateKey: HexString, enableTypeId: boolean, ckb: CKB): Promise<{
|
|
12
|
+
deploymentRecipe: DeploymentRecipe;
|
|
13
|
+
deploymentOptions: DeploymentOptions;
|
|
14
|
+
}[]>;
|
|
15
|
+
export declare function deployBinary(binPath: string, privateKey: HexString, enableTypeId: boolean, ckb: CKB): Promise<{
|
|
16
|
+
deploymentRecipe: DeploymentRecipe;
|
|
17
|
+
deploymentOptions: DeploymentOptions;
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.deployBinary = exports.deployBinaries = exports.recordDeployResult = exports.getToDeployBinsPath = void 0;
|
|
16
|
+
const toml_1 = require("../deploy/toml");
|
|
17
|
+
const migration_1 = require("../deploy/migration");
|
|
18
|
+
const gen_1 = require("../scripts/gen");
|
|
19
|
+
const offckb_config_1 = require("../template/offckb-config");
|
|
20
|
+
const fs_1 = require("../util/fs");
|
|
21
|
+
const path_1 = __importDefault(require("path"));
|
|
22
|
+
const fs_2 = __importDefault(require("fs"));
|
|
23
|
+
const core_1 = require("@ckb-ccc/core");
|
|
24
|
+
function getToDeployBinsPath() {
|
|
25
|
+
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
26
|
+
const fileContent = fs_2.default.readFileSync(userOffCKBConfigPath, 'utf-8');
|
|
27
|
+
const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/);
|
|
28
|
+
if (match && match[1]) {
|
|
29
|
+
const contractBinFolderValue = match[1];
|
|
30
|
+
const binFolderPath = (0, fs_1.isAbsolutePath)(contractBinFolderValue)
|
|
31
|
+
? contractBinFolderValue
|
|
32
|
+
: path_1.default.resolve(process.cwd(), contractBinFolderValue);
|
|
33
|
+
const bins = (0, fs_1.listBinaryFilesInFolder)(binFolderPath);
|
|
34
|
+
return bins.map((bin) => path_1.default.resolve(binFolderPath, bin));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
console.log('contractBinFolder value not found in offckb.config.ts');
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.getToDeployBinsPath = getToDeployBinsPath;
|
|
42
|
+
function recordDeployResult(results, network, isUpdateMyScriptsJsonFile = true) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (results.length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
for (const result of results) {
|
|
48
|
+
(0, toml_1.generateDeploymentToml)(result.deploymentOptions, network);
|
|
49
|
+
(0, migration_1.generateDeploymentMigrationFile)(result.deploymentOptions.name, result.deploymentRecipe, network);
|
|
50
|
+
}
|
|
51
|
+
// update my-scripts.json
|
|
52
|
+
if (isUpdateMyScriptsJsonFile) {
|
|
53
|
+
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
54
|
+
const folder = offckb_config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
55
|
+
if (folder) {
|
|
56
|
+
const myScriptsFilePath = path_1.default.resolve(folder, 'my-scripts.json');
|
|
57
|
+
(0, gen_1.genMyScriptsJsonFile)(myScriptsFilePath);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
console.log('done.');
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.recordDeployResult = recordDeployResult;
|
|
64
|
+
function deployBinaries(binPaths, privateKey, enableTypeId, ckb) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
if (binPaths.length === 0) {
|
|
67
|
+
console.log('No binary to deploy.');
|
|
68
|
+
}
|
|
69
|
+
const results = [];
|
|
70
|
+
for (const bin of binPaths) {
|
|
71
|
+
const result = yield deployBinary(bin, privateKey, enableTypeId, ckb);
|
|
72
|
+
results.push(result);
|
|
73
|
+
}
|
|
74
|
+
return results;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.deployBinaries = deployBinaries;
|
|
78
|
+
function deployBinary(binPath, privateKey, enableTypeId, ckb) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
const bin = yield (0, fs_1.readFileToUint8Array)(binPath);
|
|
81
|
+
const contractName = path_1.default.basename(binPath);
|
|
82
|
+
const result = !enableTypeId
|
|
83
|
+
? yield ckb.deployScript(bin, privateKey)
|
|
84
|
+
: migration_1.Migration.isDeployedWithTypeId(contractName, ckb.network)
|
|
85
|
+
? yield ckb.upgradeTypeIdScript(contractName, bin, privateKey)
|
|
86
|
+
: yield ckb.deployNewTypeIDScript(bin, privateKey);
|
|
87
|
+
console.log(`contract ${contractName} deployed, tx hash:`, result.txHash);
|
|
88
|
+
console.log('wait for tx confirmed on-chain...');
|
|
89
|
+
yield ckb.waitForTxConfirm(result.txHash);
|
|
90
|
+
console.log('tx committed.');
|
|
91
|
+
const txHash = result.txHash;
|
|
92
|
+
const typeIdScript = result.typeId;
|
|
93
|
+
const index = result.scriptOutputCellIndex;
|
|
94
|
+
const tx = result.tx;
|
|
95
|
+
const dataByteLen = BigInt(tx.outputsData[+index].slice(2).length / 2);
|
|
96
|
+
const dataShannonLen = dataByteLen * BigInt('100000000');
|
|
97
|
+
const occupiedCapacity = '0x' + dataShannonLen.toString(16);
|
|
98
|
+
if (enableTypeId && typeIdScript == null) {
|
|
99
|
+
throw new Error('type id script is null while enableTypeId is true.');
|
|
100
|
+
}
|
|
101
|
+
const typeIdScriptHash = enableTypeId ? core_1.ccc.Script.from(typeIdScript).hash() : undefined;
|
|
102
|
+
// todo: handle multiple cell recipes?
|
|
103
|
+
return {
|
|
104
|
+
deploymentOptions: {
|
|
105
|
+
name: contractName,
|
|
106
|
+
binFilePath: binPath,
|
|
107
|
+
enableTypeId: enableTypeId,
|
|
108
|
+
lockScript: tx.outputs[+index].lock,
|
|
109
|
+
},
|
|
110
|
+
deploymentRecipe: {
|
|
111
|
+
cellRecipes: [
|
|
112
|
+
{
|
|
113
|
+
name: contractName,
|
|
114
|
+
txHash,
|
|
115
|
+
index: '0x' + index.toString(16),
|
|
116
|
+
occupiedCapacity,
|
|
117
|
+
dataHash: core_1.ccc.hashCkb(tx.outputsData[+index]),
|
|
118
|
+
typeId: typeIdScriptHash,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
depGroupRecipes: [],
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
exports.deployBinary = deployBinary;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Network } from '../type/base';
|
|
2
|
+
import { HexNumber } from '../type/base';
|
|
3
3
|
export interface CellRecipe {
|
|
4
4
|
name: string;
|
|
5
5
|
txHash: string;
|
|
@@ -19,27 +19,32 @@ export interface DeploymentRecipe {
|
|
|
19
19
|
cellRecipes: CellRecipe[];
|
|
20
20
|
depGroupRecipes: DepGroupRecipe[];
|
|
21
21
|
}
|
|
22
|
-
export interface
|
|
22
|
+
export interface MigrationJson {
|
|
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
|
-
export declare
|
|
40
|
-
|
|
39
|
+
export declare class Migration {
|
|
40
|
+
static find(scriptName: string, network?: Network): DeploymentRecipe | null;
|
|
41
|
+
static isDeployed(scriptName: string, network?: Network): boolean;
|
|
42
|
+
static isDeployedWithTypeId(scriptName: string, network?: Network): boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare function generateDeploymentMigrationFile(name: string, deploymentRecipe: DeploymentRecipe, network?: Network): void;
|
|
45
|
+
export declare function readDeploymentMigrationFile(filePath: string): DeploymentRecipe;
|
|
41
46
|
export declare function getFormattedMigrationDate(): string;
|
|
42
47
|
export declare function getMigrationFolderPath(scriptName: string, network: Network): string;
|
|
43
|
-
export declare function getNewestMigrationFile(folderPath: string): string |
|
|
44
|
-
export declare function deploymentRecipeToJson(recipe: DeploymentRecipe):
|
|
45
|
-
export declare function deploymentRecipeFromJson(json:
|
|
48
|
+
export declare function getNewestMigrationFile(folderPath: string): string | null;
|
|
49
|
+
export declare function deploymentRecipeToJson(recipe: DeploymentRecipe): MigrationJson;
|
|
50
|
+
export declare function deploymentRecipeFromJson(json: MigrationJson): DeploymentRecipe;
|
package/dist/deploy/migration.js
CHANGED
|
@@ -26,12 +26,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.deploymentRecipeFromJson = exports.deploymentRecipeToJson = exports.getNewestMigrationFile = exports.getMigrationFolderPath = exports.getFormattedMigrationDate = exports.
|
|
30
|
-
const
|
|
29
|
+
exports.deploymentRecipeFromJson = exports.deploymentRecipeToJson = exports.getNewestMigrationFile = exports.getMigrationFolderPath = exports.getFormattedMigrationDate = exports.readDeploymentMigrationFile = exports.generateDeploymentMigrationFile = exports.Migration = void 0;
|
|
30
|
+
const base_1 = require("../type/base");
|
|
31
31
|
const path_1 = __importStar(require("path"));
|
|
32
32
|
const fs_1 = __importDefault(require("fs"));
|
|
33
33
|
const util_1 = require("./util");
|
|
34
|
-
|
|
34
|
+
class Migration {
|
|
35
|
+
static find(scriptName, network = base_1.Network.devnet) {
|
|
36
|
+
const filePath = getMigrationFolderPath(scriptName, network);
|
|
37
|
+
const migrationFile = getNewestMigrationFile(filePath);
|
|
38
|
+
if (migrationFile == null)
|
|
39
|
+
return null;
|
|
40
|
+
return readDeploymentMigrationFile(migrationFile);
|
|
41
|
+
}
|
|
42
|
+
static isDeployed(scriptName, network = base_1.Network.devnet) {
|
|
43
|
+
const deploymentReceipt = Migration.find(scriptName, network);
|
|
44
|
+
if (deploymentReceipt == null)
|
|
45
|
+
return false;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
static isDeployedWithTypeId(scriptName, network = base_1.Network.devnet) {
|
|
49
|
+
const isDeployed = this.isDeployed(scriptName, network);
|
|
50
|
+
if (isDeployed === false)
|
|
51
|
+
return false;
|
|
52
|
+
const deploymentReceipt = Migration.find(scriptName, network);
|
|
53
|
+
const typeId = deploymentReceipt.cellRecipes[0].typeId;
|
|
54
|
+
if (typeId == null)
|
|
55
|
+
return false;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Migration = Migration;
|
|
60
|
+
function generateDeploymentMigrationFile(name, deploymentRecipe, network = base_1.Network.devnet) {
|
|
35
61
|
const cellRecipes = deploymentRecipe.cellRecipes;
|
|
36
62
|
const depGroupRecipes = deploymentRecipe.depGroupRecipes;
|
|
37
63
|
const jsonString = JSON.stringify(deploymentRecipeToJson({ cellRecipes, depGroupRecipes }), null, 2);
|
|
@@ -44,13 +70,13 @@ function generateDeploymentRecipeJsonFile(name, deploymentRecipe, network = type
|
|
|
44
70
|
console.log(`${name} migration json file ${outputFilePath} generated successfully.`);
|
|
45
71
|
}
|
|
46
72
|
}
|
|
47
|
-
exports.
|
|
48
|
-
function
|
|
73
|
+
exports.generateDeploymentMigrationFile = generateDeploymentMigrationFile;
|
|
74
|
+
function readDeploymentMigrationFile(filePath) {
|
|
49
75
|
const jsonString = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
50
76
|
const data = JSON.parse(jsonString);
|
|
51
77
|
return deploymentRecipeFromJson(data);
|
|
52
78
|
}
|
|
53
|
-
exports.
|
|
79
|
+
exports.readDeploymentMigrationFile = readDeploymentMigrationFile;
|
|
54
80
|
function getFormattedMigrationDate() {
|
|
55
81
|
const now = new Date();
|
|
56
82
|
const year = now.getFullYear();
|
|
@@ -68,6 +94,9 @@ function getMigrationFolderPath(scriptName, network) {
|
|
|
68
94
|
}
|
|
69
95
|
exports.getMigrationFolderPath = getMigrationFolderPath;
|
|
70
96
|
function getNewestMigrationFile(folderPath) {
|
|
97
|
+
if (!fs_1.default.existsSync(folderPath) || !fs_1.default.lstatSync(folderPath).isDirectory()) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
71
100
|
const files = fs_1.default
|
|
72
101
|
.readdirSync(folderPath)
|
|
73
102
|
.filter((file) => file.endsWith('.json')) // Ensure only JSON files are considered
|
|
@@ -78,28 +107,36 @@ function getNewestMigrationFile(folderPath) {
|
|
|
78
107
|
return timestampA.localeCompare(timestampB);
|
|
79
108
|
});
|
|
80
109
|
// Return the full path of the newest file (last in sorted array) or undefined if no files
|
|
81
|
-
return files.length > 0 ? path_1.default.join(folderPath, files[files.length - 1]) :
|
|
110
|
+
return files.length > 0 ? path_1.default.join(folderPath, files[files.length - 1]) : null;
|
|
82
111
|
}
|
|
83
112
|
exports.getNewestMigrationFile = getNewestMigrationFile;
|
|
84
113
|
function deploymentRecipeToJson(recipe) {
|
|
85
114
|
return {
|
|
86
115
|
cell_recipes: recipe.cellRecipes.map((val) => {
|
|
116
|
+
if (BigInt(val.occupiedCapacity) > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
117
|
+
// 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
|
|
118
|
+
console.error(`invalid occupiedCapacity: ${val.occupiedCapacity}, the cell_recipes json might be incorrect for cell outpoint ${val.txHash}:${+val.index}`);
|
|
119
|
+
}
|
|
87
120
|
return {
|
|
88
121
|
name: val.name,
|
|
89
122
|
tx_hash: val.txHash,
|
|
90
|
-
index: val.index,
|
|
91
|
-
occupied_capacity: val.occupiedCapacity,
|
|
123
|
+
index: +val.index,
|
|
124
|
+
occupied_capacity: +BigInt(val.occupiedCapacity).toString(10),
|
|
92
125
|
data_hash: val.dataHash,
|
|
93
126
|
type_id: val.typeId,
|
|
94
127
|
};
|
|
95
128
|
}),
|
|
96
129
|
dep_group_recipes: recipe.depGroupRecipes.map((val) => {
|
|
130
|
+
if (BigInt(val.occupiedCapacity) > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
131
|
+
// 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
|
|
132
|
+
console.error(`invalid occupiedCapacity: ${val.occupiedCapacity}, the dep_group_recipes json might be incorrect for cell outpoint ${val.txHash}:${+val.index}`);
|
|
133
|
+
}
|
|
97
134
|
return {
|
|
98
135
|
name: val.name,
|
|
99
136
|
tx_hash: val.txHash,
|
|
100
|
-
index: val.index,
|
|
137
|
+
index: +val.index,
|
|
101
138
|
data_hash: val.dataHash,
|
|
102
|
-
occupied_capacity: val.occupiedCapacity,
|
|
139
|
+
occupied_capacity: +BigInt(val.occupiedCapacity).toString(10),
|
|
103
140
|
};
|
|
104
141
|
}),
|
|
105
142
|
};
|
|
@@ -111,8 +148,8 @@ function deploymentRecipeFromJson(json) {
|
|
|
111
148
|
return {
|
|
112
149
|
name: val.name,
|
|
113
150
|
txHash: val.tx_hash,
|
|
114
|
-
index: val.index,
|
|
115
|
-
occupiedCapacity: val.occupied_capacity,
|
|
151
|
+
index: '0x' + val.index.toString(16),
|
|
152
|
+
occupiedCapacity: '0x' + val.occupied_capacity.toString(16),
|
|
116
153
|
dataHash: val.data_hash,
|
|
117
154
|
typeId: val.type_id,
|
|
118
155
|
};
|
|
@@ -121,9 +158,9 @@ function deploymentRecipeFromJson(json) {
|
|
|
121
158
|
return {
|
|
122
159
|
name: val.name,
|
|
123
160
|
txHash: val.tx_hash,
|
|
124
|
-
index: val.index,
|
|
161
|
+
index: '0x' + val.index.toString(16),
|
|
125
162
|
dataHash: val.data_hash,
|
|
126
|
-
occupiedCapacity: val.occupied_capacity,
|
|
163
|
+
occupiedCapacity: '0x' + val.occupied_capacity.toString(16),
|
|
127
164
|
};
|
|
128
165
|
}),
|
|
129
166
|
};
|
package/dist/deploy/toml.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Network } from '../util/type';
|
|
1
|
+
import { Network } from '../type/base';
|
|
3
2
|
import { HashType } from '@ckb-ccc/core';
|
|
3
|
+
import { HexString } from '../type/base';
|
|
4
4
|
export interface DeploymentOptions {
|
|
5
5
|
name: string;
|
|
6
6
|
binFilePath: string;
|
|
7
7
|
enableTypeId: boolean;
|
|
8
|
-
lockScript:
|
|
8
|
+
lockScript: {
|
|
9
|
+
codeHash: HexString;
|
|
10
|
+
hashType: HashType;
|
|
11
|
+
args: HexString;
|
|
12
|
+
};
|
|
9
13
|
}
|
|
10
14
|
export interface DeploymentToml {
|
|
11
15
|
cells: {
|
|
12
16
|
name: string;
|
|
13
|
-
enable_type_id:
|
|
17
|
+
enable_type_id: boolean;
|
|
14
18
|
location: {
|
|
15
19
|
file: string;
|
|
16
20
|
};
|
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
|
},
|
package/dist/deploy/util.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Network } from '../
|
|
1
|
+
import { Network } from '../type/base';
|
|
2
2
|
export declare function getContractsPath(network: Network): string;
|
package/dist/deploy/util.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getContractsPath = void 0;
|
|
4
4
|
const setting_1 = require("../cfg/setting");
|
|
5
|
-
const
|
|
5
|
+
const base_1 = require("../type/base");
|
|
6
6
|
function getContractsPath(network) {
|
|
7
7
|
const settings = (0, setting_1.readSettings)();
|
|
8
|
-
if (network ===
|
|
8
|
+
if (network === base_1.Network.devnet) {
|
|
9
9
|
return settings.devnet.contractsPath;
|
|
10
10
|
}
|
|
11
|
-
if (network ===
|
|
11
|
+
if (network === base_1.Network.testnet) {
|
|
12
12
|
return settings.testnet.contractsPath;
|
|
13
13
|
}
|
|
14
|
-
if (network ===
|
|
14
|
+
if (network === base_1.Network.mainnet) {
|
|
15
15
|
return settings.mainnet.contractsPath;
|
|
16
16
|
}
|
|
17
17
|
throw new Error(`invalid network ${network}`);
|
package/dist/node/install.js
CHANGED
|
@@ -97,10 +97,9 @@ exports.downloadCKBBinaryAndUnzip = downloadCKBBinaryAndUnzip;
|
|
|
97
97
|
function downloadAndSaveCKBBinary(version, tempFilePath) {
|
|
98
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
99
|
const downloadURL = buildDownloadUrl(version);
|
|
100
|
-
const response = yield request_1.Request.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
fs.writeFileSync(tempFilePath, response.data);
|
|
100
|
+
const response = yield request_1.Request.send(downloadURL);
|
|
101
|
+
const arrayBuffer = yield response.arrayBuffer();
|
|
102
|
+
fs.writeFileSync(tempFilePath, Buffer.from(arrayBuffer));
|
|
104
103
|
});
|
|
105
104
|
}
|
|
106
105
|
exports.downloadAndSaveCKBBinary = downloadAndSaveCKBBinary;
|
package/dist/scripts/gen.js
CHANGED
|
@@ -31,7 +31,7 @@ const fs = __importStar(require("fs"));
|
|
|
31
31
|
const public_1 = __importDefault(require("./public"));
|
|
32
32
|
const system_scripts_1 = require("../cmd/system-scripts");
|
|
33
33
|
const path_1 = __importDefault(require("path"));
|
|
34
|
-
const
|
|
34
|
+
const base_1 = require("../type/base");
|
|
35
35
|
const util_1 = require("./util");
|
|
36
36
|
function genSystemScripts() {
|
|
37
37
|
const devnetScripts = (0, system_scripts_1.getSystemScriptsFromListHashes)();
|
|
@@ -54,9 +54,9 @@ function genSystemScriptsJsonFile(filePath) {
|
|
|
54
54
|
exports.genSystemScriptsJsonFile = genSystemScriptsJsonFile;
|
|
55
55
|
function genMyScripts() {
|
|
56
56
|
const networkMyScripts = {
|
|
57
|
-
devnet: (0, util_1.readUserDeployedScriptsInfo)(
|
|
58
|
-
testnet: (0, util_1.readUserDeployedScriptsInfo)(
|
|
59
|
-
mainnet: (0, util_1.readUserDeployedScriptsInfo)(
|
|
57
|
+
devnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.devnet),
|
|
58
|
+
testnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.testnet),
|
|
59
|
+
mainnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.mainnet),
|
|
60
60
|
};
|
|
61
61
|
return networkMyScripts;
|
|
62
62
|
}
|