@offckb/cli 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmd/repl.d.ts +7 -1
- package/dist/cmd/repl.js +41 -4
- package/dist/tools/rpc-proxy.js +20 -0
- package/package.json +2 -2
package/dist/cmd/repl.d.ts
CHANGED
|
@@ -4,8 +4,14 @@ export interface ReplProp extends NetworkOption {
|
|
|
4
4
|
proxyRpc?: boolean;
|
|
5
5
|
}
|
|
6
6
|
export declare function repl({ network, proxyRpc }: ReplProp): void;
|
|
7
|
-
export declare function initGlobalClientBuilder(): {
|
|
7
|
+
export declare function initGlobalClientBuilder(proxyRpc: boolean): {
|
|
8
8
|
new: (network: Network) => ccc.ClientPublicTestnet | ccc.ClientPublicMainnet;
|
|
9
9
|
fromUrl: (rpcUrl: string, network: Network) => ccc.ClientPublicTestnet | ccc.ClientPublicMainnet;
|
|
10
10
|
};
|
|
11
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
|
+
};
|
package/dist/cmd/repl.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.printHelpText = exports.initGlobalClientBuilder = exports.repl = void 0;
|
|
6
|
+
exports.buildMyScripts = exports.buildSystemScripts = exports.printHelpText = exports.initGlobalClientBuilder = exports.repl = void 0;
|
|
7
7
|
const repl_1 = require("repl");
|
|
8
8
|
const core_1 = require("@ckb-ccc/core");
|
|
9
9
|
const advanced_1 = require("@ckb-ccc/core/advanced");
|
|
@@ -12,6 +12,8 @@ const base_1 = require("../type/base");
|
|
|
12
12
|
const private_1 = require("../scripts/private");
|
|
13
13
|
const account_json_1 = __importDefault(require("../../account/account.json"));
|
|
14
14
|
const validator_1 = require("../util/validator");
|
|
15
|
+
const gen_1 = require("../scripts/gen");
|
|
16
|
+
const util_1 = require("../scripts/util");
|
|
15
17
|
function repl({ network = base_1.Network.devnet, proxyRpc = false }) {
|
|
16
18
|
(0, validator_1.validateNetworkOpt)(network);
|
|
17
19
|
console.log(
|
|
@@ -25,15 +27,27 @@ function repl({ network = base_1.Network.devnet, proxyRpc = false }) {
|
|
|
25
27
|
context.ccc = core_1.ccc;
|
|
26
28
|
context.cccA = advanced_1.cccA;
|
|
27
29
|
context.networks = network_1.networks;
|
|
28
|
-
context.Client = initGlobalClientBuilder();
|
|
29
|
-
context.client = initGlobalClientBuilder().new(network);
|
|
30
|
+
context.Client = initGlobalClientBuilder(proxyRpc);
|
|
31
|
+
context.client = initGlobalClientBuilder(proxyRpc).new(network);
|
|
30
32
|
context.accounts = account_json_1.default;
|
|
33
|
+
context.myScripts = buildMyScripts().new(network);
|
|
34
|
+
context.systemScripts = buildSystemScripts().new(network);
|
|
31
35
|
context.help = printHelpText;
|
|
32
36
|
}
|
|
33
37
|
exports.repl = repl;
|
|
34
|
-
function initGlobalClientBuilder() {
|
|
38
|
+
function initGlobalClientBuilder(proxyRpc) {
|
|
35
39
|
return {
|
|
36
40
|
new: (network) => {
|
|
41
|
+
if (proxyRpc) {
|
|
42
|
+
return network === 'mainnet'
|
|
43
|
+
? new core_1.ccc.ClientPublicMainnet({ url: network_1.networks.mainnet.proxy_rpc_url })
|
|
44
|
+
: network === 'testnet'
|
|
45
|
+
? new core_1.ccc.ClientPublicTestnet({ url: network_1.networks.testnet.proxy_rpc_url })
|
|
46
|
+
: new core_1.ccc.ClientPublicTestnet({
|
|
47
|
+
url: network_1.networks.devnet.proxy_rpc_url,
|
|
48
|
+
scripts: (0, private_1.buildCCCDevnetKnownScripts)(),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
37
51
|
return network === 'mainnet'
|
|
38
52
|
? new core_1.ccc.ClientPublicMainnet()
|
|
39
53
|
: network === 'testnet'
|
|
@@ -69,7 +83,30 @@ Global Variables to use:
|
|
|
69
83
|
const myClient = Client.fromUrl('<your rpc url>', 'devnet' | 'testnet' | 'mainnet');
|
|
70
84
|
- accounts, test accounts array from OffCKB
|
|
71
85
|
- networks, network information configs
|
|
86
|
+
- myScripts, user-deployed scripts information via offckb deploy
|
|
87
|
+
- systemScripts, built-in scripts information in the blockchain
|
|
72
88
|
- help, print this help message
|
|
73
89
|
`);
|
|
74
90
|
}
|
|
75
91
|
exports.printHelpText = printHelpText;
|
|
92
|
+
function buildSystemScripts() {
|
|
93
|
+
return {
|
|
94
|
+
new: (network) => {
|
|
95
|
+
const systemScripts = (0, gen_1.genSystemScripts)();
|
|
96
|
+
return network === base_1.Network.devnet
|
|
97
|
+
? systemScripts === null || systemScripts === void 0 ? void 0 : systemScripts.devnet
|
|
98
|
+
: network === base_1.Network.testnet
|
|
99
|
+
? systemScripts === null || systemScripts === void 0 ? void 0 : systemScripts.testnet
|
|
100
|
+
: systemScripts === null || systemScripts === void 0 ? void 0 : systemScripts.mainnet;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
exports.buildSystemScripts = buildSystemScripts;
|
|
105
|
+
function buildMyScripts() {
|
|
106
|
+
return {
|
|
107
|
+
new: (network) => {
|
|
108
|
+
return (0, util_1.readUserDeployedScriptsInfo)(network);
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
exports.buildMyScripts = buildMyScripts;
|
package/dist/tools/rpc-proxy.js
CHANGED
|
@@ -39,6 +39,7 @@ function createRPCProxy(network, targetRpcUrl, port) {
|
|
|
39
39
|
}
|
|
40
40
|
const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
|
|
41
41
|
fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
|
|
42
|
+
console.debug(`RPC Req: store tx ${txHash}`);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -47,6 +48,25 @@ function createRPCProxy(network, targetRpcUrl, port) {
|
|
|
47
48
|
}
|
|
48
49
|
});
|
|
49
50
|
});
|
|
51
|
+
proxy.on('proxyRes', function (proxyRes, _req, _res) {
|
|
52
|
+
const body = [];
|
|
53
|
+
proxyRes.on('data', function (chunk) {
|
|
54
|
+
body.push(chunk);
|
|
55
|
+
});
|
|
56
|
+
proxyRes.on('end', function () {
|
|
57
|
+
const res = Buffer.concat(body).toString();
|
|
58
|
+
try {
|
|
59
|
+
const jsonRpcResponse = JSON.parse(res);
|
|
60
|
+
const error = jsonRpcResponse.error;
|
|
61
|
+
if (error) {
|
|
62
|
+
console.debug('RPC Response: ', jsonRpcResponse);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error('Error parsing JSON-RPC content:', err);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
50
70
|
const server = http_1.default.createServer((req, res) => {
|
|
51
71
|
proxy.web(req, res, {}, (err) => {
|
|
52
72
|
if (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@offckb/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "ckb development network for your first try",
|
|
5
5
|
"author": "CKB EcoFund",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"@types/http-proxy": "^1.17.15",
|
|
68
68
|
"adm-zip": "^0.5.10",
|
|
69
69
|
"child_process": "^1.0.2",
|
|
70
|
-
"ckb-transaction-dumper": "^0.4.
|
|
70
|
+
"ckb-transaction-dumper": "^0.4.2",
|
|
71
71
|
"commander": "^12.0.0",
|
|
72
72
|
"cpu-features": "^0.0.10",
|
|
73
73
|
"http-proxy": "^1.18.1",
|