@offckb/cli 0.3.0 → 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/cli.js +1 -1
- package/dist/cmd/deploy.js +2 -3
- package/dist/cmd/repl.d.ts +7 -1
- package/dist/cmd/repl.js +41 -4
- package/dist/deploy/index.js +3 -3
- package/dist/tools/rpc-proxy.js +20 -0
- package/dist/util/fs.d.ts +1 -0
- package/dist/util/fs.js +17 -7
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -146,7 +146,7 @@ program
|
|
|
146
146
|
.command('deploy')
|
|
147
147
|
.description('Deploy contracts to different networks, only supports devnet and testnet')
|
|
148
148
|
.option('--network <network>', 'Specify the network to deploy to', 'devnet')
|
|
149
|
-
.option('--target <target>', 'Specify the
|
|
149
|
+
.option('--target <target>', 'Specify the script binaries file/folder path to deploy')
|
|
150
150
|
.option('--config <config>', 'Specify the offckb.config.ts file path for deployment', undefined)
|
|
151
151
|
.option('-t, --type-id', 'Specify if use upgradable type id to deploy the script')
|
|
152
152
|
.option('--privkey <privkey>', 'Specify the private key to deploy scripts')
|
package/dist/cmd/deploy.js
CHANGED
|
@@ -34,9 +34,8 @@ function deploy(opt = { network: base_1.Network.devnet, typeId: false, target: u
|
|
|
34
34
|
const configPath = opt.config;
|
|
35
35
|
const targetFolder = opt.target;
|
|
36
36
|
if (targetFolder) {
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const binPaths = bins.map((bin) => path_1.default.resolve(binFolder, bin));
|
|
37
|
+
const binFilesOrFolder = (0, fs_1.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(process.cwd(), targetFolder);
|
|
38
|
+
const binPaths = (0, fs_1.getBinaryFilesFromPath)(binFilesOrFolder);
|
|
40
39
|
const results = yield (0, deploy_1.deployBinaries)(binPaths, privateKey, enableTypeId, ckb);
|
|
41
40
|
// record the deployed contract infos
|
|
42
41
|
(0, deploy_1.recordDeployResult)(results, network); // we don't update my-scripts.json since we don't know where the file is
|
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/deploy/index.js
CHANGED
|
@@ -26,11 +26,11 @@ function getToDeployBinsPath(userOffCKBConfigPath) {
|
|
|
26
26
|
const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/);
|
|
27
27
|
if (match && match[1]) {
|
|
28
28
|
const contractBinFolderValue = match[1];
|
|
29
|
-
const
|
|
29
|
+
const binFileOrFolderPath = (0, fs_1.isAbsolutePath)(contractBinFolderValue)
|
|
30
30
|
? contractBinFolderValue
|
|
31
31
|
: path_1.default.resolve(userOffCKBConfigPath, contractBinFolderValue);
|
|
32
|
-
const bins = (0, fs_1.
|
|
33
|
-
return bins
|
|
32
|
+
const bins = (0, fs_1.getBinaryFilesFromPath)(binFileOrFolderPath);
|
|
33
|
+
return bins;
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
console.log('contractBinFolder value not found in offckb.config.ts');
|
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/dist/util/fs.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export declare function copyFileSync(source: string, target: string): void;
|
|
|
4
4
|
export declare function copyFilesWithExclusion(sourceDir: string, destinationDir: string, excludedFolders: string[]): Promise<void>;
|
|
5
5
|
export declare function copyRecursive(source: string, destination: string, excludedFolders: string[]): Promise<void>;
|
|
6
6
|
export declare function readFileToUint8Array(filePath: string): Promise<Uint8Array>;
|
|
7
|
+
export declare function getBinaryFilesFromPath(fileOrFolderPath: string): string[];
|
|
7
8
|
export declare function listBinaryFilesInFolder(folderPath: string): string[];
|
|
8
9
|
export declare function isBinaryFile(filePath: string): boolean;
|
|
9
10
|
export declare function isAbsolutePath(filePath: string): boolean;
|
package/dist/util/fs.js
CHANGED
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.getSubfolders = exports.findFileInFolder = exports.isAbsolutePath = exports.isBinaryFile = exports.listBinaryFilesInFolder = exports.readFileToUint8Array = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
|
|
35
|
+
exports.getSubfolders = exports.findFileInFolder = exports.isAbsolutePath = exports.isBinaryFile = exports.listBinaryFilesInFolder = exports.getBinaryFilesFromPath = exports.readFileToUint8Array = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
|
|
36
36
|
const fs = __importStar(require("fs"));
|
|
37
37
|
const path = __importStar(require("path"));
|
|
38
38
|
function isFolderExists(folderPath) {
|
|
@@ -135,19 +135,29 @@ function readFileToUint8Array(filePath) {
|
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
exports.readFileToUint8Array = readFileToUint8Array;
|
|
138
|
+
function getBinaryFilesFromPath(fileOrFolderPath) {
|
|
139
|
+
if (!fs.existsSync(fileOrFolderPath)) {
|
|
140
|
+
throw new Error(`File or Folder not exits ${fileOrFolderPath}`);
|
|
141
|
+
}
|
|
142
|
+
// Check if the provided path is a directory
|
|
143
|
+
if (fs.lstatSync(fileOrFolderPath).isDirectory()) {
|
|
144
|
+
return listBinaryFilesInFolder(fileOrFolderPath);
|
|
145
|
+
}
|
|
146
|
+
if (fs.lstatSync(fileOrFolderPath).isFile() && isBinaryFile(fileOrFolderPath)) {
|
|
147
|
+
return [fileOrFolderPath];
|
|
148
|
+
}
|
|
149
|
+
throw new Error(`${fileOrFolderPath} is not a valid path to deploy scripts.`);
|
|
150
|
+
}
|
|
151
|
+
exports.getBinaryFilesFromPath = getBinaryFilesFromPath;
|
|
138
152
|
function listBinaryFilesInFolder(folderPath) {
|
|
139
153
|
// Check if the provided path is a directory
|
|
140
154
|
if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
|
|
141
155
|
throw new Error(`${folderPath} is not a valid directory.`);
|
|
142
156
|
}
|
|
143
157
|
// Read the contents of the directory
|
|
144
|
-
const files = fs.readdirSync(folderPath);
|
|
158
|
+
const files = fs.readdirSync(folderPath).map((f) => path.join(folderPath, f));
|
|
145
159
|
// Filter out only the binary files (assuming they have extensions like .exe, .bin, .dll, etc.)
|
|
146
|
-
const binaryFiles = files.filter((file) =>
|
|
147
|
-
const filePath = path.join(folderPath, file);
|
|
148
|
-
// Check if the file is a regular file and not a directory
|
|
149
|
-
return fs.statSync(filePath).isFile() && isBinaryFile(filePath);
|
|
150
|
-
});
|
|
160
|
+
const binaryFiles = files.filter((file) => fs.statSync(file).isFile() && isBinaryFile(file));
|
|
151
161
|
return binaryFiles;
|
|
152
162
|
}
|
|
153
163
|
exports.listBinaryFilesInFolder = listBinaryFilesInFolder;
|
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",
|