@offckb/cli 0.3.4 → 0.4.0-canary-113bf31.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 +17 -138
- package/build/build/Release/cpufeatures.node +0 -0
- package/build/build/Release/secp256k1.node +0 -0
- package/build/index.js +114977 -0
- package/package.json +12 -6
- package/dist/cfg/account.d.ts +0 -55
- package/dist/cfg/account.js +0 -66
- package/dist/cfg/env-path.d.ts +0 -9
- package/dist/cfg/env-path.js +0 -63
- package/dist/cfg/setting.d.ts +0 -67
- package/dist/cfg/setting.js +0 -147
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -224
- package/dist/cmd/accounts.d.ts +0 -1
- package/dist/cmd/accounts.js +0 -40
- package/dist/cmd/balance.d.ts +0 -4
- package/dist/cmd/balance.js +0 -25
- package/dist/cmd/clean.d.ts +0 -1
- package/dist/cmd/clean.js +0 -27
- package/dist/cmd/config.d.ts +0 -11
- package/dist/cmd/config.js +0 -107
- package/dist/cmd/create.d.ts +0 -7
- package/dist/cmd/create.js +0 -77
- package/dist/cmd/debug.d.ts +0 -16
- package/dist/cmd/debug.js +0 -120
- package/dist/cmd/deploy.d.ts +0 -9
- package/dist/cmd/deploy.js +0 -76
- package/dist/cmd/deposit.d.ts +0 -5
- package/dist/cmd/deposit.js +0 -97
- package/dist/cmd/inject-config.d.ts +0 -4
- package/dist/cmd/inject-config.js +0 -72
- package/dist/cmd/list-hashes.d.ts +0 -25
- package/dist/cmd/list-hashes.js +0 -39
- package/dist/cmd/mol.d.ts +0 -2
- package/dist/cmd/mol.js +0 -38
- package/dist/cmd/my-scripts.d.ts +0 -4
- package/dist/cmd/my-scripts.js +0 -24
- package/dist/cmd/node.d.ts +0 -5
- package/dist/cmd/node.js +0 -70
- package/dist/cmd/proxy-rpc.d.ts +0 -7
- package/dist/cmd/proxy-rpc.js +0 -22
- package/dist/cmd/repl.d.ts +0 -17
- package/dist/cmd/repl.js +0 -111
- package/dist/cmd/sync-scripts.d.ts +0 -4
- package/dist/cmd/sync-scripts.js +0 -30
- package/dist/cmd/system-scripts.d.ts +0 -99
- package/dist/cmd/system-scripts.js +0 -301
- package/dist/cmd/transfer-all.d.ts +0 -6
- package/dist/cmd/transfer-all.js +0 -37
- package/dist/cmd/transfer.d.ts +0 -6
- package/dist/cmd/transfer.js +0 -38
- package/dist/deploy/index.d.ts +0 -18
- package/dist/deploy/index.js +0 -127
- package/dist/deploy/migration.d.ts +0 -50
- package/dist/deploy/migration.js +0 -178
- package/dist/deploy/toml.d.ts +0 -42
- package/dist/deploy/toml.js +0 -59
- package/dist/deploy/util.d.ts +0 -2
- package/dist/deploy/util.js +0 -18
- package/dist/molecule/mol.d.ts +0 -9
- package/dist/molecule/mol.js +0 -149
- package/dist/node/init-chain.d.ts +0 -1
- package/dist/node/init-chain.js +0 -40
- package/dist/node/install.d.ts +0 -11
- package/dist/node/install.js +0 -235
- package/dist/scripts/gen.d.ts +0 -5
- package/dist/scripts/gen.js +0 -78
- package/dist/scripts/private.d.ts +0 -4
- package/dist/scripts/private.js +0 -13
- package/dist/scripts/public.d.ts +0 -8
- package/dist/scripts/public.js +0 -229
- package/dist/scripts/type.d.ts +0 -51
- package/dist/scripts/type.js +0 -19
- package/dist/scripts/util.d.ts +0 -3
- package/dist/scripts/util.js +0 -93
- package/dist/sdk/ckb.d.ts +0 -37
- package/dist/sdk/ckb.js +0 -254
- package/dist/sdk/network.d.ts +0 -17
- package/dist/sdk/network.js +0 -22
- package/dist/template/offckb-config.d.ts +0 -4
- package/dist/template/offckb-config.js +0 -70
- package/dist/template/option.d.ts +0 -8
- package/dist/template/option.js +0 -22
- package/dist/tools/ckb-debugger.d.ts +0 -12
- package/dist/tools/ckb-debugger.js +0 -31
- package/dist/tools/ckb-tx-dumper.d.ts +0 -6
- package/dist/tools/ckb-tx-dumper.js +0 -20
- package/dist/tools/moleculec-es.d.ts +0 -8
- package/dist/tools/moleculec-es.js +0 -100
- package/dist/tools/moleculec-go.d.ts +0 -5
- package/dist/tools/moleculec-go.js +0 -35
- package/dist/tools/moleculec-rust.d.ts +0 -5
- package/dist/tools/moleculec-rust.js +0 -35
- package/dist/tools/rpc-proxy.d.ts +0 -7
- package/dist/tools/rpc-proxy.js +0 -90
- package/dist/type/base.d.ts +0 -11
- package/dist/type/base.js +0 -10
- package/dist/util/encoding.d.ts +0 -2
- package/dist/util/encoding.js +0 -24
- package/dist/util/fs.d.ts +0 -13
- package/dist/util/fs.js +0 -218
- package/dist/util/git.d.ts +0 -2
- package/dist/util/git.js +0 -106
- package/dist/util/link.d.ts +0 -1
- package/dist/util/link.js +0 -6
- package/dist/util/request.d.ts +0 -8
- package/dist/util/request.js +0 -61
- package/dist/util/validator.d.ts +0 -5
- package/dist/util/validator.js +0 -67
- package/npm-shrinkwrap.json +0 -4514
package/dist/cmd/debug.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
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.debugTransaction = debugTransaction;
|
|
7
|
-
exports.buildTransactionDebugOptions = buildTransactionDebugOptions;
|
|
8
|
-
exports.debugSingleScript = debugSingleScript;
|
|
9
|
-
exports.parseSingleScriptOption = parseSingleScriptOption;
|
|
10
|
-
exports.buildTxFileOptionBy = buildTxFileOptionBy;
|
|
11
|
-
exports.buildTransactionJsonFilePath = buildTransactionJsonFilePath;
|
|
12
|
-
exports.buildDebugFullTransactionFilePath = buildDebugFullTransactionFilePath;
|
|
13
|
-
exports.debugRaw = debugRaw;
|
|
14
|
-
const setting_1 = require("../cfg/setting");
|
|
15
|
-
const ckb_debugger_1 = require("../tools/ckb-debugger");
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const ckb_tx_dumper_1 = require("../tools/ckb-tx-dumper");
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const advanced_1 = require("@ckb-ccc/core/advanced");
|
|
20
|
-
const base_1 = require("../type/base");
|
|
21
|
-
const encoding_1 = require("../util/encoding");
|
|
22
|
-
function debugTransaction(txHash, network) {
|
|
23
|
-
const txFile = buildTxFileOptionBy(txHash, network);
|
|
24
|
-
const opts = buildTransactionDebugOptions(txHash, network);
|
|
25
|
-
for (const opt of opts) {
|
|
26
|
-
console.log(`\n******************************`);
|
|
27
|
-
console.log(`****** ${opt.name} ******\n`);
|
|
28
|
-
debugRaw(`${txFile} ${opt.cmdOption}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function buildTransactionDebugOptions(txHash, network) {
|
|
32
|
-
var _a;
|
|
33
|
-
const txJsonFilePath = buildTransactionJsonFilePath(network, txHash);
|
|
34
|
-
const txJson = JSON.parse(fs_1.default.readFileSync(txJsonFilePath, 'utf-8'));
|
|
35
|
-
const cccTx = advanced_1.cccA.JsonRpcTransformers.transactionTo(txJson);
|
|
36
|
-
const result = [];
|
|
37
|
-
for (const [index, input] of cccTx.inputs.entries()) {
|
|
38
|
-
result.push({
|
|
39
|
-
name: `Input[${index}].Lock`,
|
|
40
|
-
cmdOption: `--cell-index ${index} --cell-type input --script-group-type lock`,
|
|
41
|
-
});
|
|
42
|
-
if ((_a = input.cellOutput) === null || _a === void 0 ? void 0 : _a.type) {
|
|
43
|
-
result.push({
|
|
44
|
-
name: `Input[${index}].Type`,
|
|
45
|
-
cmdOption: `--cell-index ${index} --cell-type input --script-group-type type`,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
for (const [index, output] of cccTx.outputs.entries()) {
|
|
50
|
-
if (output.type) {
|
|
51
|
-
result.push({
|
|
52
|
-
name: `Output[${index}].Type`,
|
|
53
|
-
cmdOption: `--cell-index ${index} --cell-type output --script-group-type type`,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
function debugSingleScript(txHash, cellIndex, cellType, scriptType, network, bin) {
|
|
60
|
-
const txFile = buildTxFileOptionBy(txHash, network);
|
|
61
|
-
let opt = `--cell-index ${cellIndex} --cell-type ${cellType} --script-group-type ${scriptType}`;
|
|
62
|
-
if (bin) {
|
|
63
|
-
opt = opt + ` --bin ${bin}`;
|
|
64
|
-
}
|
|
65
|
-
debugRaw(`${txFile} ${opt}`);
|
|
66
|
-
}
|
|
67
|
-
// Helper function to validate and parse the --script value
|
|
68
|
-
function parseSingleScriptOption(value) {
|
|
69
|
-
const regex = /^(input|output)\[(\d+)\]\.(lock|type)$/i;
|
|
70
|
-
const match = value.match(regex);
|
|
71
|
-
if (!match) {
|
|
72
|
-
throw new Error(`Invalid --script value: ${value}, example format: "input[0].lock"`);
|
|
73
|
-
}
|
|
74
|
-
const [_, cellType, cellIndex, scriptType] = match;
|
|
75
|
-
return {
|
|
76
|
-
cellType: cellType.toLowerCase(), // input or output
|
|
77
|
-
cellIndex: parseInt(cellIndex, 10), // number in []
|
|
78
|
-
scriptType: scriptType.toLowerCase(), // lock or type
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function buildTxFileOptionBy(txHash, network) {
|
|
82
|
-
const settings = (0, setting_1.readSettings)();
|
|
83
|
-
const outputFilePath = buildDebugFullTransactionFilePath(network, txHash);
|
|
84
|
-
if (!fs_1.default.existsSync(outputFilePath)) {
|
|
85
|
-
const rpc = settings.devnet.rpcUrl;
|
|
86
|
-
const txJsonFilePath = buildTransactionJsonFilePath(network, txHash);
|
|
87
|
-
if (!fs_1.default.existsSync(outputFilePath)) {
|
|
88
|
-
fs_1.default.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
89
|
-
}
|
|
90
|
-
(0, ckb_tx_dumper_1.dumpTransaction)({ rpc, txJsonFilePath, outputFilePath });
|
|
91
|
-
}
|
|
92
|
-
const opt = `--tx-file ${(0, encoding_1.encodeBinPathForTerminal)(outputFilePath)}`;
|
|
93
|
-
return opt;
|
|
94
|
-
}
|
|
95
|
-
function buildTransactionJsonFilePath(network, txHash) {
|
|
96
|
-
const settings = (0, setting_1.readSettings)();
|
|
97
|
-
if (network === base_1.Network.devnet) {
|
|
98
|
-
return `${settings.devnet.transactionsPath}/${txHash}.json`;
|
|
99
|
-
}
|
|
100
|
-
if (network === base_1.Network.testnet) {
|
|
101
|
-
return `${settings.testnet.transactionsPath}/${txHash}.json`;
|
|
102
|
-
}
|
|
103
|
-
return `${settings.mainnet.transactionsPath}/${txHash}.json`;
|
|
104
|
-
}
|
|
105
|
-
function buildDebugFullTransactionFilePath(network, txHash) {
|
|
106
|
-
const settings = (0, setting_1.readSettings)();
|
|
107
|
-
if (network === base_1.Network.devnet) {
|
|
108
|
-
return `${settings.devnet.debugFullTransactionsPath}/${txHash}.json`;
|
|
109
|
-
}
|
|
110
|
-
if (network === base_1.Network.testnet) {
|
|
111
|
-
return `${settings.testnet.debugFullTransactionsPath}/${txHash}.json`;
|
|
112
|
-
}
|
|
113
|
-
return `${settings.mainnet.debugFullTransactionsPath}/${txHash}.json`;
|
|
114
|
-
}
|
|
115
|
-
function debugRaw(options) {
|
|
116
|
-
if (!ckb_debugger_1.CKBDebugger.isBinaryInstalled()) {
|
|
117
|
-
ckb_debugger_1.CKBDebugger.installCKBDebugger();
|
|
118
|
-
}
|
|
119
|
-
return ckb_debugger_1.CKBDebugger.runRaw(options);
|
|
120
|
-
}
|
package/dist/cmd/deploy.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { NetworkOption } from '../type/base';
|
|
2
|
-
export interface DeployOptions extends NetworkOption {
|
|
3
|
-
target?: string;
|
|
4
|
-
config?: string;
|
|
5
|
-
privkey?: string | null;
|
|
6
|
-
typeId?: boolean;
|
|
7
|
-
proxyRpc?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function deploy(opt?: DeployOptions): Promise<void>;
|
package/dist/cmd/deploy.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
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.deploy = deploy;
|
|
16
|
-
const base_1 = require("../type/base");
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const account_1 = require("../cfg/account");
|
|
19
|
-
const fs_1 = require("../util/fs");
|
|
20
|
-
const validator_1 = require("../util/validator");
|
|
21
|
-
const deploy_1 = require("../deploy");
|
|
22
|
-
const ckb_1 = require("../sdk/ckb");
|
|
23
|
-
const fs_2 = __importDefault(require("fs"));
|
|
24
|
-
function deploy() {
|
|
25
|
-
return __awaiter(this, arguments, void 0, function* (opt = { network: base_1.Network.devnet, typeId: false, target: undefined, proxyRpc: false }) {
|
|
26
|
-
var _a;
|
|
27
|
-
const network = opt.network;
|
|
28
|
-
(0, validator_1.validateNetworkOpt)(network);
|
|
29
|
-
const isEnableProxyRpc = opt.proxyRpc;
|
|
30
|
-
const ckb = new ckb_1.CKB({ network, isEnableProxyRpc });
|
|
31
|
-
// we use deployerAccount to deploy contract by default
|
|
32
|
-
const privateKey = opt.privkey || account_1.deployerAccount.privkey;
|
|
33
|
-
const enableTypeId = (_a = opt.typeId) !== null && _a !== void 0 ? _a : false;
|
|
34
|
-
const configPath = opt.config;
|
|
35
|
-
const targetFolder = opt.target;
|
|
36
|
-
if (targetFolder) {
|
|
37
|
-
const binFilesOrFolder = (0, fs_1.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(process.cwd(), targetFolder);
|
|
38
|
-
let binPaths = (0, fs_1.getBinaryFilesFromPath)(binFilesOrFolder);
|
|
39
|
-
// ignore the binary file which is too large(> 500kb) to upload on chain
|
|
40
|
-
binPaths = binPaths.filter((binPath) => {
|
|
41
|
-
const size = (0, fs_1.getBinaryFileSizeInBytes)(binPath);
|
|
42
|
-
if (size > 500 * 1024) {
|
|
43
|
-
console.warn(`[warning]: ignore deploying the binary file ${binPath} since its size is too large: ${size} bytes`);
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
});
|
|
48
|
-
const results = yield (0, deploy_1.deployBinaries)(binPaths, privateKey, enableTypeId, ckb);
|
|
49
|
-
// record the deployed contract infos
|
|
50
|
-
(0, deploy_1.recordDeployResult)(results, network); // we don't update my-scripts.json since we don't know where the file is
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
// read contract bin folder
|
|
54
|
-
const userOffCKBConfigPath = configPath
|
|
55
|
-
? (0, fs_1.isAbsolutePath)(configPath)
|
|
56
|
-
? configPath
|
|
57
|
-
: path_1.default.resolve(process.cwd(), configPath)
|
|
58
|
-
: path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
59
|
-
if (!fs_2.default.existsSync(userOffCKBConfigPath)) {
|
|
60
|
-
throw new Error(`config file not exits: ${userOffCKBConfigPath}, tips: use --config to specific the offckb.config.ts file`);
|
|
61
|
-
}
|
|
62
|
-
let bins = (0, deploy_1.getToDeployBinsPath)(userOffCKBConfigPath);
|
|
63
|
-
// ignore the binary file which is too large(> 500kb) to upload on chain
|
|
64
|
-
bins = bins.filter((binPath) => {
|
|
65
|
-
const size = (0, fs_1.getBinaryFileSizeInBytes)(binPath);
|
|
66
|
-
if (size > 500 * 1024) {
|
|
67
|
-
console.warn(`[warning]: ignore deploying the binary file ${binPath} since its size is too large: ${size} bytes`);
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
});
|
|
72
|
-
const results = yield (0, deploy_1.deployBinaries)(bins, privateKey, enableTypeId, ckb);
|
|
73
|
-
// record the deployed contract infos
|
|
74
|
-
(0, deploy_1.recordDeployResult)(results, network, userOffCKBConfigPath);
|
|
75
|
-
});
|
|
76
|
-
}
|
package/dist/cmd/deposit.d.ts
DELETED
package/dist/cmd/deposit.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
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.deposit = deposit;
|
|
13
|
-
const ckb_1 = require("../sdk/ckb");
|
|
14
|
-
const account_1 = require("../cfg/account");
|
|
15
|
-
const base_1 = require("../type/base");
|
|
16
|
-
const link_1 = require("../util/link");
|
|
17
|
-
const validator_1 = require("../util/validator");
|
|
18
|
-
const request_1 = require("../util/request");
|
|
19
|
-
function deposit(toAddress_1, amountInCKB_1) {
|
|
20
|
-
return __awaiter(this, arguments, void 0, function* (toAddress, amountInCKB, opt = { network: base_1.Network.devnet, proxyRpc: false }) {
|
|
21
|
-
const network = opt.network;
|
|
22
|
-
(0, validator_1.validateNetworkOpt)(network);
|
|
23
|
-
const isEnableProxyRpc = opt.proxyRpc;
|
|
24
|
-
const ckb = new ckb_1.CKB({ network, isEnableProxyRpc });
|
|
25
|
-
if (network === 'testnet') {
|
|
26
|
-
return yield depositFromTestnetFaucet(toAddress, ckb);
|
|
27
|
-
}
|
|
28
|
-
// deposit from devnet miner
|
|
29
|
-
const privateKey = account_1.ckbDevnetMinerAccount.privkey;
|
|
30
|
-
const txHash = yield ckb.transfer({
|
|
31
|
-
toAddress,
|
|
32
|
-
privateKey,
|
|
33
|
-
amountInCKB,
|
|
34
|
-
});
|
|
35
|
-
console.log('tx hash: ', txHash);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function depositFromTestnetFaucet(ckbAddress, ckb) {
|
|
39
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
-
console.log('testnet faucet only supports fixed-amount claim: 10,000 CKB');
|
|
41
|
-
const randomAccountPrivateKey = '0x' + generateHex(64);
|
|
42
|
-
const randomAccountAddress = yield ckb.buildSecp256k1Address(randomAccountPrivateKey);
|
|
43
|
-
console.log(`use random account to claim from faucet: \n\nprivate key: ${randomAccountPrivateKey}\n\n address: ${randomAccountAddress}`);
|
|
44
|
-
try {
|
|
45
|
-
const claimResponse = yield sendClaimRequest(randomAccountAddress);
|
|
46
|
-
console.log('Wait for claim transaction confirmed to transfer all from random account to your account..');
|
|
47
|
-
console.log('You can transfer by yourself if it ends up fails..');
|
|
48
|
-
if (claimResponse.txHash != null) {
|
|
49
|
-
yield ckb.waitForTxConfirm(claimResponse.txHash);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
yield ckb.waitForBlocksBy(4); // wait 4 blocks
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.log(error);
|
|
57
|
-
throw new Error('claim request failed.');
|
|
58
|
-
}
|
|
59
|
-
const txHash = yield ckb.transferAll({ privateKey: randomAccountPrivateKey, toAddress: ckbAddress });
|
|
60
|
-
console.log(`Done, check ${(0, link_1.buildTestnetTxLink)(txHash)} for details.`);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function sendClaimRequest(toAddress) {
|
|
64
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const url = 'https://faucet-api.nervos.org/claim_events'; // Replace 'YOUR_API_ENDPOINT' with the actual API endpoint
|
|
66
|
-
const headers = {
|
|
67
|
-
'User-Agent': 'node-fetch-requests/v2',
|
|
68
|
-
'Accept-Encoding': 'gzip, deflate',
|
|
69
|
-
Accept: '*/*',
|
|
70
|
-
Connection: 'keep-alive',
|
|
71
|
-
'Content-Type': 'application/json',
|
|
72
|
-
};
|
|
73
|
-
const body = JSON.stringify({
|
|
74
|
-
claim_event: {
|
|
75
|
-
address_hash: toAddress,
|
|
76
|
-
amount: '10000', // unit: CKB
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
const config = {
|
|
80
|
-
method: 'post',
|
|
81
|
-
headers: headers,
|
|
82
|
-
body,
|
|
83
|
-
};
|
|
84
|
-
const response = yield request_1.Request.send(url, config);
|
|
85
|
-
console.log('send claim request, status: ', response.status); // Handle the response data here
|
|
86
|
-
const jsonResponse = yield response.json();
|
|
87
|
-
return jsonResponse.data.attributes;
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function generateHex(length) {
|
|
91
|
-
const characters = 'abcdef0123456789';
|
|
92
|
-
let result = '';
|
|
93
|
-
for (let i = 0; i < length; i++) {
|
|
94
|
-
result += characters[Math.floor(Math.random() * characters.length)];
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.injectConfig = injectConfig;
|
|
37
|
-
const fs_1 = require("fs");
|
|
38
|
-
const path_1 = __importStar(require("path"));
|
|
39
|
-
const gen_1 = require("../scripts/gen");
|
|
40
|
-
const offckb_config_1 = require("../template/offckb-config");
|
|
41
|
-
const setting_1 = require("../cfg/setting");
|
|
42
|
-
const version = require('../../package.json').version;
|
|
43
|
-
function injectConfig({ target }) {
|
|
44
|
-
// inject the offckb.config.ts file into users workspace
|
|
45
|
-
// copy config template
|
|
46
|
-
const userOffCKBConfigPath = target
|
|
47
|
-
? (0, path_1.isAbsolute)(target)
|
|
48
|
-
? target
|
|
49
|
-
: path_1.default.resolve(process.cwd(), target)
|
|
50
|
-
: path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
51
|
-
const predefinedOffCKBConfigTsPath = path_1.default.resolve(setting_1.packageRootPath, 'templates/v3/offckb.config.example.ts');
|
|
52
|
-
(0, fs_1.copyFileSync)(predefinedOffCKBConfigTsPath, userOffCKBConfigPath);
|
|
53
|
-
// update the version in the offckb.config.ts
|
|
54
|
-
offckb_config_1.OffCKBConfigFile.updateVersion(version, userOffCKBConfigPath);
|
|
55
|
-
const contractInfoFolder = offckb_config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
56
|
-
if (!contractInfoFolder) {
|
|
57
|
-
throw new Error('No contract info folder found in offckb.config.ts!');
|
|
58
|
-
}
|
|
59
|
-
const systemJsonFilePath = path_1.default.resolve(contractInfoFolder, 'system-scripts.json');
|
|
60
|
-
(0, gen_1.genSystemScriptsJsonFile)(systemJsonFilePath);
|
|
61
|
-
const myScriptsJsonFilePath = path_1.default.resolve(contractInfoFolder, 'my-scripts.json');
|
|
62
|
-
(0, gen_1.genMyScriptsJsonFile)(myScriptsJsonFilePath);
|
|
63
|
-
console.log(`\n\nAll good. You can now use it in your project like:
|
|
64
|
-
|
|
65
|
-
import offCKB from "offckb.config";
|
|
66
|
-
|
|
67
|
-
const myScriptCodeHash = offCKB.myScripts['script-name'].codeHash;
|
|
68
|
-
const omnilockScriptCodeHash = offCKB.systemScripts['omnilock'].codeHash;
|
|
69
|
-
|
|
70
|
-
Check example at https://github.com/nervosnetwork/docs.nervos.org/tree/develop/examples/simple-transfer
|
|
71
|
-
`);
|
|
72
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { H256 } from '../type/base';
|
|
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 printDevnetListHashes(version?: string): Promise<void>;
|
|
25
|
-
export declare function getDevnetListHashes(version?: string): string | null;
|
package/dist/cmd/list-hashes.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
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.printDevnetListHashes = printDevnetListHashes;
|
|
13
|
-
exports.getDevnetListHashes = getDevnetListHashes;
|
|
14
|
-
const child_process_1 = require("child_process");
|
|
15
|
-
const setting_1 = require("../cfg/setting");
|
|
16
|
-
const encoding_1 = require("../util/encoding");
|
|
17
|
-
function printDevnetListHashes(version) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const output = getDevnetListHashes(version);
|
|
20
|
-
console.log(output);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
function getDevnetListHashes(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
|
-
}
|
package/dist/cmd/mol.d.ts
DELETED
package/dist/cmd/mol.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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.molSingleFile = molSingleFile;
|
|
16
|
-
exports.molFiles = molFiles;
|
|
17
|
-
const mol_1 = require("../molecule/mol");
|
|
18
|
-
const fs_1 = __importDefault(require("fs"));
|
|
19
|
-
const path_1 = __importDefault(require("path"));
|
|
20
|
-
function molSingleFile(schemeFilePath, outputFilePath, bindingLang) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
yield (0, mol_1.generateMolBindings)(schemeFilePath, outputFilePath, bindingLang);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function molFiles(schemaFolderPath, outputFolderPath, bindingLang) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const files = fs_1.default.readdirSync(schemaFolderPath).filter((file) => file.endsWith('.mol'));
|
|
28
|
-
if (files.length === 0) {
|
|
29
|
-
throw new Error(`No .mol files found in the specified folder: ${schemaFolderPath}`);
|
|
30
|
-
}
|
|
31
|
-
for (const file of files) {
|
|
32
|
-
const filePath = path_1.default.join(schemaFolderPath, file);
|
|
33
|
-
const outputFileName = path_1.default.basename(file, '.mol') + '.' + bindingLang;
|
|
34
|
-
const outputFilePath = path_1.default.join(outputFolderPath, outputFileName);
|
|
35
|
-
yield molSingleFile(filePath, outputFilePath, bindingLang);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
package/dist/cmd/my-scripts.d.ts
DELETED
package/dist/cmd/my-scripts.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printMyScripts = printMyScripts;
|
|
4
|
-
const toml_1 = require("../deploy/toml");
|
|
5
|
-
const util_1 = require("../deploy/util");
|
|
6
|
-
const util_2 = require("../scripts/util");
|
|
7
|
-
const base_1 = require("../type/base");
|
|
8
|
-
const validator_1 = require("../util/validator");
|
|
9
|
-
function printMyScripts(option = { network: base_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
|
-
}
|
package/dist/cmd/node.d.ts
DELETED
package/dist/cmd/node.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
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.node = node;
|
|
13
|
-
const child_process_1 = require("child_process");
|
|
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 base_1 = require("../type/base");
|
|
20
|
-
function node(_a) {
|
|
21
|
-
return __awaiter(this, arguments, void 0, function* ({ version, noProxyServer }) {
|
|
22
|
-
var _b, _c;
|
|
23
|
-
const settings = (0, setting_1.readSettings)();
|
|
24
|
-
const ckbVersion = version || settings.bins.defaultCKBVersion;
|
|
25
|
-
yield (0, install_1.installCKBBinary)(ckbVersion);
|
|
26
|
-
yield (0, init_chain_1.initChainIfNeeded)();
|
|
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}`;
|
|
31
|
-
try {
|
|
32
|
-
// Run first command
|
|
33
|
-
const ckbProcess = (0, child_process_1.exec)(ckbCmd);
|
|
34
|
-
// Log first command's output
|
|
35
|
-
(_b = ckbProcess.stdout) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
36
|
-
console.log('CKB:', data.toString());
|
|
37
|
-
});
|
|
38
|
-
(_c = ckbProcess.stderr) === null || _c === void 0 ? void 0 : _c.on('data', (data) => {
|
|
39
|
-
console.error('CKB error:', data.toString());
|
|
40
|
-
});
|
|
41
|
-
// Start the second command after 3 seconds
|
|
42
|
-
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
try {
|
|
45
|
-
// Run second command
|
|
46
|
-
const minerProcess = (0, child_process_1.exec)(minerCmd);
|
|
47
|
-
(_a = minerProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
48
|
-
console.log('CKB-Miner:', data.toString());
|
|
49
|
-
});
|
|
50
|
-
(_b = minerProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
51
|
-
console.error('CKB-Miner error:', data.toString());
|
|
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)(base_1.Network.devnet, ckbRpc, port);
|
|
58
|
-
proxy.start();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
console.error('Error running CKB-Miner:', error);
|
|
63
|
-
}
|
|
64
|
-
}), 3000);
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
console.error('Error:', error);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
package/dist/cmd/proxy-rpc.d.ts
DELETED
package/dist/cmd/proxy-rpc.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.proxyRpc = proxyRpc;
|
|
4
|
-
const setting_1 = require("../cfg/setting");
|
|
5
|
-
const rpc_proxy_1 = require("../tools/rpc-proxy");
|
|
6
|
-
const base_1 = require("../type/base");
|
|
7
|
-
function proxyRpc(options) {
|
|
8
|
-
const settings = (0, setting_1.readSettings)();
|
|
9
|
-
const network = options.network || base_1.Network.devnet;
|
|
10
|
-
let ckbRpc = options.ckbRpc;
|
|
11
|
-
if (!ckbRpc) {
|
|
12
|
-
ckbRpc =
|
|
13
|
-
network === base_1.Network.devnet
|
|
14
|
-
? settings.devnet.rpcUrl
|
|
15
|
-
: network === base_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
|
-
}
|
package/dist/cmd/repl.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ccc } from '@ckb-ccc/core';
|
|
2
|
-
import { Network, NetworkOption } from '../type/base';
|
|
3
|
-
export interface ReplProp extends NetworkOption {
|
|
4
|
-
proxyRpc?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare function repl({ network, proxyRpc }: ReplProp): void;
|
|
7
|
-
export declare function initGlobalClientBuilder(proxyRpc: boolean): {
|
|
8
|
-
new: (network: Network) => ccc.ClientPublicTestnet | ccc.ClientPublicMainnet;
|
|
9
|
-
fromUrl: (rpcUrl: string, network: Network) => ccc.ClientPublicTestnet | ccc.ClientPublicMainnet;
|
|
10
|
-
};
|
|
11
|
-
export declare function printHelpText(): void;
|
|
12
|
-
export declare function buildSystemScripts(): {
|
|
13
|
-
new: (network: Network) => import("../scripts/type").SystemScriptsRecord | undefined;
|
|
14
|
-
};
|
|
15
|
-
export declare function buildMyScripts(): {
|
|
16
|
-
new: (network: Network) => import("../scripts/type").MyScriptsRecord;
|
|
17
|
-
};
|