@offckb/cli 0.2.7 → 0.3.0-canary-a9175e7.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 +46 -19
- package/ckb/devnet/specs/dev.toml +7 -7
- package/dist/cfg/setting.d.ts +38 -0
- package/dist/cfg/setting.js +67 -7
- package/dist/cli.js +51 -32
- package/dist/cmd/clean.js +7 -5
- package/dist/cmd/config.d.ts +5 -3
- package/dist/cmd/config.js +39 -12
- package/dist/cmd/create.d.ts +1 -1
- package/dist/cmd/create.js +19 -8
- package/dist/cmd/debug.d.ts +13 -0
- package/dist/cmd/debug.js +100 -0
- package/dist/cmd/deploy.js +45 -25
- package/dist/cmd/deposit.js +9 -2
- package/dist/cmd/inject-config.d.ts +0 -3
- package/dist/cmd/inject-config.js +20 -80
- package/dist/cmd/list-hashes.d.ts +25 -1
- package/dist/cmd/list-hashes.js +24 -16
- package/dist/cmd/{deployed-scripts.d.ts → my-scripts.d.ts} +1 -1
- package/dist/cmd/my-scripts.js +25 -0
- package/dist/cmd/node.d.ts +5 -1
- package/dist/cmd/node.js +22 -8
- package/dist/cmd/proxy-rpc.d.ts +7 -0
- package/dist/cmd/proxy-rpc.js +23 -0
- package/dist/cmd/sync-config.js +16 -11
- package/dist/cmd/system-scripts.d.ts +42 -0
- package/dist/cmd/system-scripts.js +265 -0
- package/dist/deploy/migration.d.ts +45 -0
- package/dist/deploy/migration.js +131 -0
- package/dist/deploy/toml.d.ts +38 -0
- package/dist/deploy/toml.js +60 -0
- package/dist/deploy/util.d.ts +2 -0
- package/dist/deploy/util.js +19 -0
- package/dist/node/init-chain.js +41 -0
- package/dist/{cmd/develop → node}/install.d.ts +4 -5
- package/dist/{cmd/develop → node}/install.js +31 -31
- package/dist/scripts/gen.d.ts +5 -0
- package/dist/scripts/gen.js +69 -0
- package/dist/scripts/public.d.ts +8 -0
- package/dist/scripts/public.js +396 -0
- package/dist/scripts/type.d.ts +46 -0
- package/dist/scripts/type.js +19 -0
- package/dist/scripts/util.d.ts +3 -0
- package/dist/scripts/util.js +84 -0
- package/dist/template/config.d.ts +4 -0
- package/dist/template/config.js +60 -0
- package/dist/template/offckb.config.d.ts +69 -0
- package/dist/template/offckb.config.js +79 -0
- package/dist/{util/template.js → template/option.js} +2 -2
- package/dist/template/option.json +16 -0
- package/dist/tools/ckb-debugger.d.ts +12 -0
- package/dist/tools/ckb-debugger.js +31 -0
- package/dist/tools/ckb-tx-dumper.d.ts +6 -0
- package/dist/tools/ckb-tx-dumper.js +21 -0
- package/dist/tools/rpc-proxy.d.ts +9 -0
- package/dist/tools/rpc-proxy.js +84 -0
- package/dist/util/ckb.d.ts +3 -2
- package/dist/util/ckb.js +16 -3
- package/dist/util/encoding.d.ts +1 -0
- package/dist/util/encoding.js +7 -1
- package/dist/util/fs.d.ts +1 -2
- package/dist/util/fs.js +8 -32
- package/dist/util/git.js +19 -7
- package/dist/util/request.js +0 -1
- package/dist/util/type.d.ts +1 -0
- package/dist/util/validator.d.ts +1 -0
- package/dist/util/validator.js +13 -4
- package/package.json +6 -2
- package/dist/cfg/const.d.ts +0 -20
- package/dist/cfg/const.js +0 -51
- package/dist/cmd/deployed-scripts.js +0 -14
- package/dist/cmd/develop/build-account.d.ts +0 -1
- package/dist/cmd/develop/build-account.js +0 -9
- package/dist/cmd/develop/genkey.d.ts +0 -14
- package/dist/cmd/develop/genkey.js +0 -143
- package/dist/cmd/develop/init-chain.js +0 -76
- package/dist/cmd/develop/lumos-config.d.ts +0 -4
- package/dist/cmd/develop/lumos-config.js +0 -153
- package/dist/util/config.d.ts +0 -9
- package/dist/util/config.js +0 -136
- package/templates/config.json +0 -98
- /package/ckb/devnet/specs/{omni_lock → omnilock} +0 -0
- /package/ckb/devnet/specs/{spore-scripts → spore}/spore +0 -0
- /package/ckb/devnet/specs/{spore-scripts/cluster → spore/spore_cluster} +0 -0
- /package/ckb/devnet/specs/{spore-scripts/cluster_agent → spore/spore_cluster_agent} +0 -0
- /package/ckb/devnet/specs/{spore-scripts/cluster_proxy → spore/spore_cluster_proxy} +0 -0
- /package/ckb/devnet/specs/{spore-scripts → spore}/spore_extension_lua +0 -0
- /package/ckb/devnet/specs/{xudt_rce → xudt} +0 -0
- /package/dist/{cmd/develop → node}/init-chain.d.ts +0 -0
- /package/dist/{util/template.d.ts → template/option.d.ts} +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.debugRaw = exports.buildTxFileOptionBy = exports.parseSingleScriptOption = exports.debugSingleScript = exports.buildTransactionDebugOptions = exports.debugTransaction = void 0;
|
|
7
|
+
const setting_1 = require("../cfg/setting");
|
|
8
|
+
const ckb_debugger_1 = require("../tools/ckb-debugger");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const ckb_tx_dumper_1 = require("../tools/ckb-tx-dumper");
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
// todo: if we use import this throws error in tsc building
|
|
13
|
+
//import { cccA } from '@ckb-ccc/core/dist.commonjs/advanced';
|
|
14
|
+
const { cccA } = require('@ckb-ccc/core/advanced');
|
|
15
|
+
function debugTransaction(txHash) {
|
|
16
|
+
const txFile = buildTxFileOptionBy(txHash);
|
|
17
|
+
const opts = buildTransactionDebugOptions(txHash);
|
|
18
|
+
for (const opt of opts) {
|
|
19
|
+
console.log(`\n******************************`);
|
|
20
|
+
console.log(`****** ${opt.name} ******\n`);
|
|
21
|
+
debugRaw(`${txFile} ${opt.cmdOption}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.debugTransaction = debugTransaction;
|
|
25
|
+
function buildTransactionDebugOptions(txHash) {
|
|
26
|
+
var _a;
|
|
27
|
+
const settings = (0, setting_1.readSettings)();
|
|
28
|
+
const txJsonFilePath = `${settings.devnet.transactionsPath}/${txHash}.json`;
|
|
29
|
+
const txJson = JSON.parse(fs_1.default.readFileSync(txJsonFilePath, 'utf-8'));
|
|
30
|
+
const cccTx = cccA.JsonRpcTransformers.transactionTo(txJson);
|
|
31
|
+
const result = [];
|
|
32
|
+
for (const [index, input] of cccTx.inputs.entries()) {
|
|
33
|
+
result.push({
|
|
34
|
+
name: `Input[${index}].Lock`,
|
|
35
|
+
cmdOption: `--cell-index ${index} --cell-type input --script-group-type lock`,
|
|
36
|
+
});
|
|
37
|
+
if ((_a = input.cellOutput) === null || _a === void 0 ? void 0 : _a.type) {
|
|
38
|
+
result.push({
|
|
39
|
+
name: `Input[${index}].Type`,
|
|
40
|
+
cmdOption: `--cell-index ${index} --cell-type input --script-group-type type`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
for (const [index, output] of cccTx.outputs.entries()) {
|
|
45
|
+
if (output.type) {
|
|
46
|
+
result.push({
|
|
47
|
+
name: `Output[${index}].Type`,
|
|
48
|
+
cmdOption: `--cell-index ${index} --cell-type output --script-group-type type`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
exports.buildTransactionDebugOptions = buildTransactionDebugOptions;
|
|
55
|
+
function debugSingleScript(txHash, cellIndex, cellType, scriptType, bin) {
|
|
56
|
+
const txFile = buildTxFileOptionBy(txHash);
|
|
57
|
+
let opt = `--cell-index ${cellIndex} --cell-type ${cellType} --script-group-type ${scriptType}`;
|
|
58
|
+
if (bin) {
|
|
59
|
+
opt = opt + ` --bin ${bin}`;
|
|
60
|
+
}
|
|
61
|
+
debugRaw(`${txFile} ${opt}`);
|
|
62
|
+
}
|
|
63
|
+
exports.debugSingleScript = debugSingleScript;
|
|
64
|
+
// Helper function to validate and parse the --script value
|
|
65
|
+
function parseSingleScriptOption(value) {
|
|
66
|
+
const regex = /^(input|output)\[(\d+)\]\.(lock|type)$/i;
|
|
67
|
+
const match = value.match(regex);
|
|
68
|
+
if (!match) {
|
|
69
|
+
throw new Error(`Invalid --script value: ${value}, example format: "input[0].lock"`);
|
|
70
|
+
}
|
|
71
|
+
const [_, cellType, cellIndex, scriptType] = match;
|
|
72
|
+
return {
|
|
73
|
+
cellType: cellType.toLowerCase(), // input or output
|
|
74
|
+
cellIndex: parseInt(cellIndex, 10), // number in []
|
|
75
|
+
scriptType: scriptType.toLowerCase(), // lock or type
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
exports.parseSingleScriptOption = parseSingleScriptOption;
|
|
79
|
+
function buildTxFileOptionBy(txHash) {
|
|
80
|
+
const settings = (0, setting_1.readSettings)();
|
|
81
|
+
const outputFilePath = `${settings.devnet.debugFullTransactionsPath}/${txHash}.json`;
|
|
82
|
+
if (!fs_1.default.existsSync(outputFilePath)) {
|
|
83
|
+
const rpc = settings.devnet.rpcUrl;
|
|
84
|
+
const txJsonFilePath = `${settings.devnet.transactionsPath}/${txHash}.json`;
|
|
85
|
+
if (!fs_1.default.existsSync(outputFilePath)) {
|
|
86
|
+
fs_1.default.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
(0, ckb_tx_dumper_1.dumpTransaction)({ rpc, txJsonFilePath, outputFilePath });
|
|
89
|
+
}
|
|
90
|
+
const opt = `--tx-file ${outputFilePath}`;
|
|
91
|
+
return opt;
|
|
92
|
+
}
|
|
93
|
+
exports.buildTxFileOptionBy = buildTxFileOptionBy;
|
|
94
|
+
function debugRaw(options) {
|
|
95
|
+
if (!ckb_debugger_1.CKBDebugger.isBinaryInstalled()) {
|
|
96
|
+
ckb_debugger_1.CKBDebugger.installCKBDebugger();
|
|
97
|
+
}
|
|
98
|
+
return ckb_debugger_1.CKBDebugger.runRaw(options);
|
|
99
|
+
}
|
|
100
|
+
exports.debugRaw = debugRaw;
|
package/dist/cmd/deploy.js
CHANGED
|
@@ -15,14 +15,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.deploy = void 0;
|
|
16
16
|
const lumos_1 = require("@ckb-lumos/lumos");
|
|
17
17
|
const fs_1 = __importDefault(require("fs"));
|
|
18
|
-
const const_1 = require("../cfg/const");
|
|
19
18
|
const type_1 = require("../util/type");
|
|
20
19
|
const path_1 = __importDefault(require("path"));
|
|
21
20
|
const ckb_1 = require("../util/ckb");
|
|
22
21
|
const account_1 = require("../cfg/account");
|
|
23
|
-
const config_1 = require("../util/config");
|
|
24
22
|
const fs_2 = require("../util/fs");
|
|
25
23
|
const validator_1 = require("../util/validator");
|
|
24
|
+
const toml_1 = require("../deploy/toml");
|
|
25
|
+
const migration_1 = require("../deploy/migration");
|
|
26
|
+
const utils_1 = require("@ckb-lumos/lumos/utils");
|
|
27
|
+
const gen_1 = require("../scripts/gen");
|
|
28
|
+
const config_1 = require("../template/config");
|
|
26
29
|
function deploy(opt = { network: type_1.Network.devnet, target: null }) {
|
|
27
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
31
|
const network = opt.network;
|
|
@@ -34,12 +37,12 @@ function deploy(opt = { network: type_1.Network.devnet, target: null }) {
|
|
|
34
37
|
const from = ckb_1.CKB.generateAccountFromPrivateKey(privateKey, lumosConfig);
|
|
35
38
|
const targetFolder = opt.target;
|
|
36
39
|
if (targetFolder) {
|
|
37
|
-
const binFolder = (0, fs_2.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(
|
|
40
|
+
const binFolder = (0, fs_2.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(process.cwd(), targetFolder);
|
|
38
41
|
const bins = (0, fs_2.listBinaryFilesInFolder)(binFolder);
|
|
39
42
|
const binPaths = bins.map((bin) => path_1.default.resolve(binFolder, bin));
|
|
40
43
|
const results = yield deployBinaries(binPaths, from, ckb);
|
|
41
44
|
// record the deployed contract infos
|
|
42
|
-
recordDeployResult(results, network, false); // we don't update
|
|
45
|
+
recordDeployResult(results, network, false); // we don't update my-scripts.json since we don't know where the file is
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
45
48
|
// check if target workspace is valid
|
|
@@ -58,13 +61,14 @@ function deploy(opt = { network: type_1.Network.devnet, target: null }) {
|
|
|
58
61
|
}
|
|
59
62
|
exports.deploy = deploy;
|
|
60
63
|
function getToDeployBinsPath() {
|
|
61
|
-
const
|
|
64
|
+
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
65
|
+
const fileContent = fs_1.default.readFileSync(userOffCKBConfigPath, 'utf-8');
|
|
62
66
|
const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/);
|
|
63
67
|
if (match && match[1]) {
|
|
64
68
|
const contractBinFolderValue = match[1];
|
|
65
69
|
const binFolderPath = (0, fs_2.isAbsolutePath)(contractBinFolderValue)
|
|
66
70
|
? contractBinFolderValue
|
|
67
|
-
: path_1.default.resolve(
|
|
71
|
+
: path_1.default.resolve(process.cwd(), contractBinFolderValue);
|
|
68
72
|
const bins = (0, fs_2.listBinaryFilesInFolder)(binFolderPath);
|
|
69
73
|
return bins.map((bin) => path_1.default.resolve(binFolderPath, bin));
|
|
70
74
|
}
|
|
@@ -73,25 +77,23 @@ function getToDeployBinsPath() {
|
|
|
73
77
|
return [];
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
|
-
function recordDeployResult(results, network,
|
|
80
|
+
function recordDeployResult(results, network, updateMyScriptsJsonFile = true) {
|
|
77
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
82
|
if (results.length === 0) {
|
|
79
83
|
return;
|
|
80
84
|
}
|
|
81
85
|
for (const result of results) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const filename = `${contractName}.json`;
|
|
85
|
-
const filePath = path_1.default.resolve(const_1.deployedContractInfoFolderPath, network, filename);
|
|
86
|
-
if (!(0, fs_2.isFolderExists)(path_1.default.resolve(const_1.deployedContractInfoFolderPath, network))) {
|
|
87
|
-
fs_1.default.mkdirSync(path_1.default.resolve(const_1.deployedContractInfoFolderPath, network), { recursive: true });
|
|
88
|
-
}
|
|
89
|
-
fs_1.default.writeFileSync(filePath, jsonContent);
|
|
86
|
+
(0, toml_1.generateDeploymentToml)(result.deploymentOptions, network);
|
|
87
|
+
(0, migration_1.generateDeploymentRecipeJsonFile)(result.deploymentOptions.name, result.deploymentRecipe, network);
|
|
90
88
|
}
|
|
91
|
-
// update
|
|
92
|
-
if (
|
|
93
|
-
const
|
|
94
|
-
|
|
89
|
+
// update my-scripts.json
|
|
90
|
+
if (updateMyScriptsJsonFile) {
|
|
91
|
+
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
92
|
+
const folder = config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
93
|
+
if (folder) {
|
|
94
|
+
const myScriptsFilePath = path_1.default.resolve(folder, 'my-scripts.json');
|
|
95
|
+
(0, gen_1.genMyScriptsJsonFile)(myScriptsFilePath);
|
|
96
|
+
}
|
|
95
97
|
}
|
|
96
98
|
console.log('done.');
|
|
97
99
|
});
|
|
@@ -112,7 +114,7 @@ function deployBinaries(binPaths, from, ckb) {
|
|
|
112
114
|
function deployBinary(binPath, from, ckb) {
|
|
113
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
116
|
const bin = yield (0, fs_2.readFileToUint8Array)(binPath);
|
|
115
|
-
const contractName =
|
|
117
|
+
const contractName = path_1.default.basename(binPath);
|
|
116
118
|
const result = yield lumos_1.commons.deploy.generateDeployWithTypeIdTx({
|
|
117
119
|
cellProvider: ckb.indexer,
|
|
118
120
|
fromInfo: from.address,
|
|
@@ -127,11 +129,29 @@ function deployBinary(binPath, from, ckb) {
|
|
|
127
129
|
const tx = lumos_1.helpers.sealTransaction(txSkeleton, [Sig]);
|
|
128
130
|
const res = yield ckb.rpc.sendTransaction(tx, 'passthrough');
|
|
129
131
|
console.log(`contract ${contractName} deployed, tx hash:`, res);
|
|
130
|
-
//todo: upgrade lumos
|
|
131
|
-
// indexer.waitForSync has a bug, we use negative number to workaround.
|
|
132
|
-
// the negative number presents the block difference from current tip to wait
|
|
133
132
|
console.log('wait 4 blocks..');
|
|
134
|
-
yield ckb.indexer.waitForSync(-4);
|
|
135
|
-
|
|
133
|
+
yield ckb.indexer.waitForSync(-4); // why negative 4? a bug in ckb-lumos
|
|
134
|
+
// todo: handle multiple cell recipes?
|
|
135
|
+
return {
|
|
136
|
+
deploymentOptions: {
|
|
137
|
+
name: contractName,
|
|
138
|
+
binFilePath: binPath,
|
|
139
|
+
enableTypeId: true,
|
|
140
|
+
lockScript: tx.outputs[+result.scriptConfig.INDEX].lock,
|
|
141
|
+
},
|
|
142
|
+
deploymentRecipe: {
|
|
143
|
+
cellRecipes: [
|
|
144
|
+
{
|
|
145
|
+
name: contractName,
|
|
146
|
+
txHash: result.scriptConfig.TX_HASH,
|
|
147
|
+
index: result.scriptConfig.INDEX,
|
|
148
|
+
occupiedCapacity: '0x' + BigInt(tx.outputsData[+result.scriptConfig.INDEX].slice(2).length / 2).toString(16),
|
|
149
|
+
dataHash: (0, utils_1.ckbHash)(tx.outputsData[+result.scriptConfig.INDEX]),
|
|
150
|
+
typeId: (0, utils_1.computeScriptHash)(result.typeId),
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
depGroupRecipes: [],
|
|
154
|
+
},
|
|
155
|
+
};
|
|
136
156
|
});
|
|
137
157
|
}
|
package/dist/cmd/deposit.js
CHANGED
|
@@ -11,7 +11,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.deposit = void 0;
|
|
13
13
|
const ckb_1 = require("../util/ckb");
|
|
14
|
-
const genkey_1 = require("./develop/genkey");
|
|
15
14
|
const account_1 = require("../cfg/account");
|
|
16
15
|
const type_1 = require("../util/type");
|
|
17
16
|
const link_1 = require("../util/link");
|
|
@@ -42,7 +41,7 @@ function depositFromTestnetFaucet(ckbAddress, ckb) {
|
|
|
42
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
42
|
console.log('testnet faucet only supports fixed-amount claim: 10,000 CKB');
|
|
44
43
|
const lumosConfig = ckb.getLumosConfig();
|
|
45
|
-
const randomAccountPrivateKey = '0x' +
|
|
44
|
+
const randomAccountPrivateKey = '0x' + generateHex(64);
|
|
46
45
|
const randomAccount = ckb_1.CKB.generateAccountFromPrivateKey(randomAccountPrivateKey, lumosConfig);
|
|
47
46
|
console.log(`use random account to claim from faucet: \n\nprivate key: ${randomAccountPrivateKey}\n\n address: ${randomAccount.address}`);
|
|
48
47
|
try {
|
|
@@ -90,3 +89,11 @@ function sendClaimRequest(toAddress) {
|
|
|
90
89
|
}
|
|
91
90
|
});
|
|
92
91
|
}
|
|
92
|
+
function generateHex(length) {
|
|
93
|
+
const characters = 'abcdef0123456789';
|
|
94
|
+
let result = '';
|
|
95
|
+
for (let i = 0; i < length; i++) {
|
|
96
|
+
result += characters[Math.floor(Math.random() * characters.length)];
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
@@ -1,100 +1,40 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
28
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
const
|
|
31
|
-
const const_1 = require("../cfg/const");
|
|
32
|
-
const child_process_1 = require("child_process");
|
|
33
|
-
const fs_1 = __importStar(require("fs"));
|
|
34
|
-
const config_1 = require("../util/config");
|
|
6
|
+
exports.injectConfig = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
35
8
|
const validator_1 = require("../util/validator");
|
|
36
|
-
const
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const gen_1 = require("../scripts/gen");
|
|
11
|
+
const config_1 = require("../template/config");
|
|
12
|
+
const version = require('../../package.json').version;
|
|
37
13
|
function injectConfig() {
|
|
38
14
|
(0, validator_1.validateTypescriptWorkspace)();
|
|
39
15
|
// inject the offckb.config.ts file into users workspace
|
|
40
16
|
// copy config template
|
|
41
|
-
|
|
17
|
+
const predefinedOffCKBConfigTsPath = path_1.default.resolve('../template', 'offckb.config.ts');
|
|
18
|
+
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
19
|
+
(0, fs_1.copyFileSync)(predefinedOffCKBConfigTsPath, userOffCKBConfigPath);
|
|
42
20
|
// update the version in the offckb.config.ts
|
|
43
|
-
(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
(0,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// todo: select yarn/npm/pnpm to install the lumos version from user
|
|
53
|
-
const version = readLumosVersionFromOffCKBConfig();
|
|
54
|
-
installLumosPackage(version);
|
|
21
|
+
config_1.OffCKBConfigFile.updateVersion(version, userOffCKBConfigPath);
|
|
22
|
+
const contractInfoFolder = config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
23
|
+
if (!contractInfoFolder) {
|
|
24
|
+
throw new Error('No contract info folder found in offckb.config.ts!');
|
|
25
|
+
}
|
|
26
|
+
const systemJsonFilePath = path_1.default.resolve(contractInfoFolder, 'system-scripts.json');
|
|
27
|
+
(0, gen_1.genSystemScriptsJsonFile)(systemJsonFilePath);
|
|
28
|
+
const myScriptsJsonFilePath = path_1.default.resolve(contractInfoFolder, 'my-scripts.json');
|
|
29
|
+
(0, gen_1.genMyScriptsJsonFile)(myScriptsJsonFilePath);
|
|
55
30
|
console.log(`\n\nAll good. You can now use it in your project like:
|
|
56
31
|
|
|
57
32
|
import offCKB from "offckb.config";
|
|
58
33
|
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const rpc = offCKB.rpc;
|
|
34
|
+
const myScriptCodeHash = offCKB.myScripts['script-name'].codeHash;
|
|
35
|
+
const omnilockScriptCodeHash = offCKB.systemScripts['omnilock'].codeHash;
|
|
62
36
|
|
|
63
37
|
Check example at https://github.com/nervosnetwork/docs.nervos.org/tree/develop/examples/simple-transfer
|
|
64
38
|
`);
|
|
65
39
|
}
|
|
66
40
|
exports.injectConfig = injectConfig;
|
|
67
|
-
function readLumosVersionFromOffCKBConfig() {
|
|
68
|
-
const fileContent = fs_1.default.readFileSync(const_1.userOffCKBConfigPath, 'utf-8');
|
|
69
|
-
const match = fileContent.match(/lumosVersion:\s*['"]([^'"]+)['"]/);
|
|
70
|
-
if (match && match[1]) {
|
|
71
|
-
return match[1];
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
console.log('lumosVersion value not found in offckb.config.ts', match);
|
|
75
|
-
return const_1.defaultLumosVersion;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.readLumosVersionFromOffCKBConfig = readLumosVersionFromOffCKBConfig;
|
|
79
|
-
function installLumosPackage(version) {
|
|
80
|
-
// Check if package.json exists
|
|
81
|
-
const packageJsonPath = path_1.default.join(const_1.currentExecPath, 'package.json');
|
|
82
|
-
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
83
|
-
throw new Error('package.json not found in the current directory');
|
|
84
|
-
}
|
|
85
|
-
const packageLock = path_1.default.join(const_1.currentExecPath, 'package-lock.json');
|
|
86
|
-
if (fs_1.default.existsSync(packageLock)) {
|
|
87
|
-
return (0, child_process_1.execSync)(`npm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
|
|
88
|
-
}
|
|
89
|
-
const yarnLock = path_1.default.join(const_1.currentExecPath, 'yarn.lock');
|
|
90
|
-
if (fs_1.default.existsSync(yarnLock)) {
|
|
91
|
-
console.log(`yarn add @ckb-lumos/lumos@${version}`);
|
|
92
|
-
return (0, child_process_1.execSync)(`yarn add @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
|
|
93
|
-
}
|
|
94
|
-
const pnpmLock = path_1.default.join(const_1.currentExecPath, 'pnpm-lock.json');
|
|
95
|
-
if (fs_1.default.existsSync(pnpmLock)) {
|
|
96
|
-
return (0, child_process_1.execSync)(`pnpm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
|
|
97
|
-
}
|
|
98
|
-
return (0, child_process_1.execSync)(`pnpm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
|
|
99
|
-
}
|
|
100
|
-
exports.installLumosPackage = installLumosPackage;
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
import { H256 } from '../util/type';
|
|
2
|
+
export interface SystemCell {
|
|
3
|
+
path: string;
|
|
4
|
+
tx_hash: H256;
|
|
5
|
+
index: number;
|
|
6
|
+
data_hash: H256;
|
|
7
|
+
type_hash?: H256;
|
|
8
|
+
}
|
|
9
|
+
export interface DepGroupCell {
|
|
10
|
+
included_cells: string[];
|
|
11
|
+
tx_hash: H256;
|
|
12
|
+
index: number;
|
|
13
|
+
}
|
|
14
|
+
export interface SpecHashes {
|
|
15
|
+
spec_hash: H256;
|
|
16
|
+
genesis: H256;
|
|
17
|
+
cellbase: H256;
|
|
18
|
+
system_cells: SystemCell[];
|
|
19
|
+
dep_groups: DepGroupCell[];
|
|
20
|
+
}
|
|
21
|
+
export interface ListHashes {
|
|
22
|
+
offckb: SpecHashes;
|
|
23
|
+
}
|
|
24
|
+
export declare function listHashes(version?: string): Promise<void>;
|
|
25
|
+
export declare function getListHashes(version?: string): string | null;
|
package/dist/cmd/list-hashes.js
CHANGED
|
@@ -9,24 +9,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.listHashes = void 0;
|
|
12
|
+
exports.getListHashes = exports.listHashes = void 0;
|
|
13
13
|
const child_process_1 = require("child_process");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
function listHashes() {
|
|
14
|
+
const setting_1 = require("../cfg/setting");
|
|
15
|
+
const encoding_1 = require("../util/encoding");
|
|
16
|
+
function listHashes(version) {
|
|
18
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const cmd = `${const_1.ckbBinPath} list-hashes -C ${const_1.devnetPath}`;
|
|
22
|
-
try {
|
|
23
|
-
(0, child_process_1.execSync)(cmd, {
|
|
24
|
-
stdio: 'inherit',
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error('Error running dependency binary:', error);
|
|
29
|
-
}
|
|
18
|
+
const output = getListHashes(version);
|
|
19
|
+
console.log(output);
|
|
30
20
|
});
|
|
31
21
|
}
|
|
32
22
|
exports.listHashes = listHashes;
|
|
23
|
+
function getListHashes(version) {
|
|
24
|
+
const settings = (0, setting_1.readSettings)();
|
|
25
|
+
const ckbVersion = version || settings.bins.defaultCKBVersion;
|
|
26
|
+
const ckbBinPath = (0, encoding_1.encodeBinPathForTerminal)((0, setting_1.getCKBBinaryPath)(ckbVersion));
|
|
27
|
+
const devnetPath = (0, encoding_1.encodeBinPathForTerminal)(settings.devnet.configPath);
|
|
28
|
+
const cmd = `${ckbBinPath} list-hashes -C ${devnetPath}`;
|
|
29
|
+
try {
|
|
30
|
+
const output = (0, child_process_1.execSync)(cmd, {
|
|
31
|
+
encoding: 'utf-8',
|
|
32
|
+
});
|
|
33
|
+
return output;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('Error running dependency binary:', error);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.getListHashes = getListHashes;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { NetworkOption } from '../util/type';
|
|
2
2
|
export interface DeployedScriptOption extends NetworkOption {
|
|
3
3
|
}
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function printMyScripts(option?: DeployedScriptOption): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printMyScripts = void 0;
|
|
4
|
+
const toml_1 = require("../deploy/toml");
|
|
5
|
+
const util_1 = require("../deploy/util");
|
|
6
|
+
const util_2 = require("../scripts/util");
|
|
7
|
+
const type_1 = require("../util/type");
|
|
8
|
+
const validator_1 = require("../util/validator");
|
|
9
|
+
function printMyScripts(option = { network: type_1.Network.devnet }) {
|
|
10
|
+
const network = option.network;
|
|
11
|
+
(0, validator_1.validateNetworkOpt)(network);
|
|
12
|
+
const scriptsInfo = (0, util_2.readUserDeployedScriptsInfo)(network);
|
|
13
|
+
console.log(`*** User-deployed Scripts on ${network.toUpperCase()} ***`);
|
|
14
|
+
const scriptNames = Object.keys(scriptsInfo);
|
|
15
|
+
scriptNames.forEach((scriptName) => {
|
|
16
|
+
const deployToml = (0, toml_1.readDeploymentToml)(scriptName, network);
|
|
17
|
+
console.log(`- ${scriptName}`);
|
|
18
|
+
console.log(`Path: ${(0, util_1.getContractsPath)(network)}/${scriptName}`);
|
|
19
|
+
console.log(`Binary File: ${deployToml.cells[0].location.file}`);
|
|
20
|
+
console.log(`Enable Type Id: ${deployToml.cells[0].enableTypeId}`);
|
|
21
|
+
console.log(`Script Info: ${JSON.stringify(scriptsInfo[scriptName], null, 2)}`);
|
|
22
|
+
console.log(`\n`);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.printMyScripts = printMyScripts;
|
package/dist/cmd/node.d.ts
CHANGED
package/dist/cmd/node.js
CHANGED
|
@@ -11,22 +11,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.node = void 0;
|
|
13
13
|
const child_process_1 = require("child_process");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
14
|
+
const init_chain_1 = require("../node/init-chain");
|
|
15
|
+
const install_1 = require("../node/install");
|
|
16
|
+
const setting_1 = require("../cfg/setting");
|
|
17
|
+
const encoding_1 = require("../util/encoding");
|
|
18
|
+
const rpc_proxy_1 = require("../tools/rpc-proxy");
|
|
19
|
+
const type_1 = require("../util/type");
|
|
20
|
+
function node({ version, noProxyServer }) {
|
|
18
21
|
var _a, _b;
|
|
19
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
|
|
23
|
+
const settings = (0, setting_1.readSettings)();
|
|
24
|
+
const ckbVersion = version || settings.bins.defaultCKBVersion;
|
|
25
|
+
yield (0, install_1.installCKBBinary)(ckbVersion);
|
|
21
26
|
yield (0, init_chain_1.initChainIfNeeded)();
|
|
22
|
-
const
|
|
23
|
-
const
|
|
27
|
+
const ckbBinPath = (0, encoding_1.encodeBinPathForTerminal)((0, setting_1.getCKBBinaryPath)(ckbVersion));
|
|
28
|
+
const devnetConfigPath = (0, encoding_1.encodeBinPathForTerminal)(settings.devnet.configPath);
|
|
29
|
+
const ckbCmd = `${ckbBinPath} run -C ${devnetConfigPath}`;
|
|
30
|
+
const minerCmd = `${ckbBinPath} miner -C ${devnetConfigPath}`;
|
|
24
31
|
try {
|
|
25
32
|
// Run first command
|
|
26
33
|
const ckbProcess = (0, child_process_1.exec)(ckbCmd);
|
|
27
34
|
// Log first command's output
|
|
28
35
|
(_a = ckbProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
29
|
-
console.log('CKB
|
|
36
|
+
console.log('CKB:', data.toString());
|
|
30
37
|
});
|
|
31
38
|
(_b = ckbProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
32
39
|
console.error('CKB error:', data.toString());
|
|
@@ -43,6 +50,13 @@ function node() {
|
|
|
43
50
|
(_d = minerProcess.stderr) === null || _d === void 0 ? void 0 : _d.on('data', (data) => {
|
|
44
51
|
console.error('CKB-Miner error:', data.toString());
|
|
45
52
|
});
|
|
53
|
+
console.log('noProxyServer: ', noProxyServer);
|
|
54
|
+
if (!noProxyServer) {
|
|
55
|
+
const ckbRpc = settings.devnet.rpcUrl;
|
|
56
|
+
const port = settings.rpc.proxyPort;
|
|
57
|
+
const proxy = (0, rpc_proxy_1.createRPCProxy)(type_1.Network.devnet, ckbRpc, port);
|
|
58
|
+
proxy.start();
|
|
59
|
+
}
|
|
46
60
|
}
|
|
47
61
|
catch (error) {
|
|
48
62
|
console.error('Error running CKB-Miner:', error);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.proxyRpc = void 0;
|
|
4
|
+
const setting_1 = require("../cfg/setting");
|
|
5
|
+
const rpc_proxy_1 = require("../tools/rpc-proxy");
|
|
6
|
+
const type_1 = require("../util/type");
|
|
7
|
+
function proxyRpc(options) {
|
|
8
|
+
const settings = (0, setting_1.readSettings)();
|
|
9
|
+
const network = options.network || type_1.Network.devnet;
|
|
10
|
+
let ckbRpc = options.ckbRpc;
|
|
11
|
+
if (!ckbRpc) {
|
|
12
|
+
ckbRpc =
|
|
13
|
+
network === type_1.Network.devnet
|
|
14
|
+
? settings.devnet.rpcUrl
|
|
15
|
+
: network === type_1.Network.testnet
|
|
16
|
+
? settings.testnet.rpcUrl
|
|
17
|
+
: settings.mainnet.rpcUrl;
|
|
18
|
+
}
|
|
19
|
+
const port = options.port || settings.rpc.proxyPort;
|
|
20
|
+
const proxy = (0, rpc_proxy_1.createRPCProxy)(network, ckbRpc, port);
|
|
21
|
+
proxy.start();
|
|
22
|
+
}
|
|
23
|
+
exports.proxyRpc = proxyRpc;
|
package/dist/cmd/sync-config.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.syncConfig = void 0;
|
|
4
|
-
const
|
|
5
|
-
const config_1 = require("../util/config");
|
|
6
|
-
const type_1 = require("../util/type");
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const validator_1 = require("../util/validator");
|
|
9
|
+
const gen_1 = require("../scripts/gen");
|
|
10
|
+
const config_1 = require("../template/config");
|
|
8
11
|
function syncConfig() {
|
|
9
12
|
(0, validator_1.validateExecDappEnvironment)();
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(0,
|
|
17
|
-
|
|
13
|
+
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
14
|
+
const contractInfoFolder = config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
15
|
+
if (!contractInfoFolder) {
|
|
16
|
+
throw new Error('No contract info folder found in offckb.config.ts!');
|
|
17
|
+
}
|
|
18
|
+
const systemJsonFilePath = path_1.default.resolve(contractInfoFolder, 'system-scripts.json');
|
|
19
|
+
(0, gen_1.genSystemScriptsJsonFile)(systemJsonFilePath);
|
|
20
|
+
const myScriptsJsonFilePath = path_1.default.resolve(contractInfoFolder, 'my-scripts.json');
|
|
21
|
+
(0, gen_1.genMyScriptsJsonFile)(myScriptsJsonFilePath);
|
|
22
|
+
console.log('scripts json config updated.');
|
|
18
23
|
}
|
|
19
24
|
exports.syncConfig = syncConfig;
|