@offckb/cli 0.1.0-rc1
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/LICENSE +24 -0
- package/README.md +48 -0
- package/account/account.json +222 -0
- package/account/keys +20 -0
- package/dist/cfg/const.d.ts +11 -0
- package/dist/cfg/const.js +40 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +45 -0
- package/dist/cmd/accounts.d.ts +1 -0
- package/dist/cmd/accounts.js +12 -0
- package/dist/cmd/build-lumos-config.d.ts +64 -0
- package/dist/cmd/build-lumos-config.js +83 -0
- package/dist/cmd/genkey.d.ts +13 -0
- package/dist/cmd/genkey.js +146 -0
- package/dist/cmd/init-chain.d.ts +1 -0
- package/dist/cmd/init-chain.js +118 -0
- package/dist/cmd/init.d.ts +1 -0
- package/dist/cmd/init.js +15 -0
- package/dist/cmd/install.d.ts +1 -0
- package/dist/cmd/install.js +140 -0
- package/dist/cmd/list-hashes.d.ts +1 -0
- package/dist/cmd/list-hashes.js +32 -0
- package/dist/cmd/node.d.ts +1 -0
- package/dist/cmd/node.js +57 -0
- package/dist/util.d.ts +1 -0
- package/dist/util.js +41 -0
- package/docker/devnet/check-ckb-started-successfully.sh +21 -0
- package/docker/devnet/ckb-miner.toml +43 -0
- package/docker/devnet/ckb.toml +175 -0
- package/docker/devnet/default.db-options +18 -0
- package/docker/devnet/specs/always_success +0 -0
- package/docker/devnet/specs/anyone_can_pay +0 -0
- package/docker/devnet/specs/dev.toml +247 -0
- package/docker/devnet/specs/omni_lock +0 -0
- package/docker/devnet/specs/sudt +0 -0
- package/docker/devnet/specs/xudt_rce +0 -0
- package/docker/docker-compose.yml +37 -0
- package/package.json +69 -0
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
35
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
36
|
+
var m = o[Symbol.asyncIterator], i;
|
|
37
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
38
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
39
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.printIssueSectionForToml = exports.genAccount = exports.buildAccounts = exports.genkey = void 0;
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const const_1 = require("../cfg/const");
|
|
46
|
+
const lumos_1 = require("@ckb-lumos/lumos");
|
|
47
|
+
const readline = __importStar(require("readline"));
|
|
48
|
+
const build_lumos_config_1 = require("./build-lumos-config");
|
|
49
|
+
function genkey() {
|
|
50
|
+
const numKeys = 20; // Number of keys to generate
|
|
51
|
+
const keyLength = 64; // Length of each key
|
|
52
|
+
generateKeysFile(numKeys, keyLength);
|
|
53
|
+
console.log(`Generated ${numKeys} keys in keys file.`);
|
|
54
|
+
}
|
|
55
|
+
exports.genkey = genkey;
|
|
56
|
+
function generateHex(length) {
|
|
57
|
+
const characters = 'abcdef0123456789';
|
|
58
|
+
let result = '';
|
|
59
|
+
for (let i = 0; i < length; i++) {
|
|
60
|
+
result += characters[Math.floor(Math.random() * characters.length)];
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function generateKeysFile(numKeys, keyLength) {
|
|
65
|
+
const targetDir = path.join(const_1.accountTargetDir, `keys`);
|
|
66
|
+
const stream = fs.createWriteStream(targetDir);
|
|
67
|
+
for (let i = 0; i < numKeys; i++) {
|
|
68
|
+
const key = generateHex(keyLength);
|
|
69
|
+
stream.write(key + '\n');
|
|
70
|
+
}
|
|
71
|
+
stream.end();
|
|
72
|
+
}
|
|
73
|
+
function buildAccounts() {
|
|
74
|
+
var _a, e_1, _b, _c;
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const keysDir = path.join(const_1.accountTargetDir, `keys`);
|
|
77
|
+
// Create a Readable stream from the file
|
|
78
|
+
const fileStream = fs.createReadStream(keysDir);
|
|
79
|
+
// Create an interface for reading data from the stream line by line
|
|
80
|
+
const rl = readline.createInterface({
|
|
81
|
+
input: fileStream,
|
|
82
|
+
crlfDelay: Infinity, // Specify Infinity to read all lines without removing newlines
|
|
83
|
+
});
|
|
84
|
+
const accounts = [];
|
|
85
|
+
try {
|
|
86
|
+
// Read each line from the file
|
|
87
|
+
for (var _d = true, rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), _a = rl_1_1.done, !_a; _d = true) {
|
|
88
|
+
_c = rl_1_1.value;
|
|
89
|
+
_d = false;
|
|
90
|
+
const line = _c;
|
|
91
|
+
const privkey = `0x${line}`;
|
|
92
|
+
const account = genAccount(privkey);
|
|
93
|
+
accounts.push(account);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
97
|
+
finally {
|
|
98
|
+
try {
|
|
99
|
+
if (!_d && !_a && (_b = rl_1.return)) yield _b.call(rl_1);
|
|
100
|
+
}
|
|
101
|
+
finally { if (e_1) throw e_1.error; }
|
|
102
|
+
}
|
|
103
|
+
const accountDir = path.join(const_1.accountTargetDir, `account.json`);
|
|
104
|
+
fs.writeFile(accountDir, JSON.stringify(accounts, null, 2), 'utf8', (err) => {
|
|
105
|
+
if (err) {
|
|
106
|
+
return console.error('Error writing file:', err);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
exports.buildAccounts = buildAccounts;
|
|
112
|
+
function genAccount(privkey) {
|
|
113
|
+
const pubkey = lumos_1.hd.key.privateToPublic(privkey);
|
|
114
|
+
const args = lumos_1.hd.key.publicKeyToBlake160(pubkey);
|
|
115
|
+
const template = build_lumos_config_1.devnetConfig.SCRIPTS['SECP256K1_BLAKE160'];
|
|
116
|
+
const lockScript = {
|
|
117
|
+
codeHash: template.CODE_HASH,
|
|
118
|
+
hashType: template.HASH_TYPE,
|
|
119
|
+
args: args,
|
|
120
|
+
};
|
|
121
|
+
const address = lumos_1.helpers.encodeToAddress(lockScript, {
|
|
122
|
+
config: build_lumos_config_1.devnetConfig,
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
privkey,
|
|
126
|
+
pubkey,
|
|
127
|
+
lockScript,
|
|
128
|
+
address,
|
|
129
|
+
args,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
exports.genAccount = genAccount;
|
|
133
|
+
function printIssueSectionForToml() {
|
|
134
|
+
const config = require('../../account/account.json');
|
|
135
|
+
for (const account of config) {
|
|
136
|
+
const section = `# issue for account private key: ${account.privkey}
|
|
137
|
+
[[genesis.issued_cells]]
|
|
138
|
+
capacity = 42_000_000_00000000
|
|
139
|
+
lock.code_hash = "${account.lockScript.codeHash}"
|
|
140
|
+
lock.args = "${account.lockScript.args}"
|
|
141
|
+
lock.hash_type = "${account.lockScript.hashType}"
|
|
142
|
+
`;
|
|
143
|
+
console.log(section);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.printIssueSectionForToml = printIssueSectionForToml;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initChainIfNeeded(): Promise<void>;
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.initChainIfNeeded = void 0;
|
|
39
|
+
const fs = __importStar(require("fs"));
|
|
40
|
+
const const_1 = require("../cfg/const");
|
|
41
|
+
const path_1 = __importDefault(require("path"));
|
|
42
|
+
const util_1 = require("../util");
|
|
43
|
+
function initChainIfNeeded() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (!(0, util_1.isFolderExists)(const_1.devnetPath)) {
|
|
46
|
+
yield doInitChain();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.initChainIfNeeded = initChainIfNeeded;
|
|
51
|
+
function doInitChain() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
yield copyFilesWithExclusion(const_1.devnetSourcePath, const_1.devnetPath, ['data']);
|
|
54
|
+
console.debug(`init devnet config folder: ${const_1.devnetPath}`);
|
|
55
|
+
copyAndEditMinerToml();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function copyAndEditMinerToml() {
|
|
59
|
+
const minerToml = path_1.default.join(const_1.devnetSourcePath, 'ckb-miner.toml');
|
|
60
|
+
const newMinerToml = path_1.default.join(const_1.devnetPath, 'ckb-miner.toml');
|
|
61
|
+
// Read the content of the ckb-miner.toml file
|
|
62
|
+
fs.readFile(minerToml, 'utf8', (err, data) => {
|
|
63
|
+
if (err) {
|
|
64
|
+
return console.error('Error reading file:', err);
|
|
65
|
+
}
|
|
66
|
+
// Replace the URL
|
|
67
|
+
const modifiedData = data.replace('http://ckb:8114/', 'http://localhost:8114');
|
|
68
|
+
// Write the modified content back to the file
|
|
69
|
+
fs.writeFile(newMinerToml, modifiedData, 'utf8', (err) => {
|
|
70
|
+
if (err) {
|
|
71
|
+
return console.error('Error writing file:', err);
|
|
72
|
+
}
|
|
73
|
+
console.debug('modified ', newMinerToml);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function copyFilesWithExclusion(sourceDir, destinationDir, excludedFolders) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
try {
|
|
80
|
+
// Ensure the destination directory exists
|
|
81
|
+
yield fs.promises.mkdir(destinationDir, { recursive: true });
|
|
82
|
+
// Start copying recursively from the source directory
|
|
83
|
+
yield copyRecursive(sourceDir, destinationDir, excludedFolders);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error('An error occurred during copying files:', error);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// Function to recursively copy files and directories
|
|
91
|
+
function copyRecursive(source, destination, excludedFolders) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
// Get a list of all files and directories in the source directory
|
|
94
|
+
const files = yield fs.promises.readdir(source);
|
|
95
|
+
// Iterate through each file or directory
|
|
96
|
+
for (const file of files) {
|
|
97
|
+
const sourcePath = path_1.default.join(source, file);
|
|
98
|
+
const destPath = path_1.default.join(destination, file);
|
|
99
|
+
// Get the file's stats
|
|
100
|
+
const stats = yield fs.promises.stat(sourcePath);
|
|
101
|
+
// If it's a directory, recursively copy it (unless it's excluded)
|
|
102
|
+
if (stats.isDirectory()) {
|
|
103
|
+
if (excludedFolders.includes(file)) {
|
|
104
|
+
// Skipping directory: ${sourcePath}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// Ensure destination directory exists before copying
|
|
108
|
+
yield fs.promises.mkdir(destPath, { recursive: true });
|
|
109
|
+
yield copyRecursive(sourcePath, destPath, excludedFolders);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Otherwise, copy the file
|
|
114
|
+
yield fs.promises.copyFile(sourcePath, destPath);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(name: string): void;
|
package/dist/cmd/init.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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.init = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const const_1 = require("../cfg/const");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
function init(name) {
|
|
11
|
+
const targetPath = path_1.default.resolve(const_1.currentExecPath, name);
|
|
12
|
+
(0, child_process_1.execSync)(`cp -r ${const_1.dappTemplatePath} ${targetPath}`);
|
|
13
|
+
console.log(`init CKB dapp project with lumos: ${targetPath}`);
|
|
14
|
+
}
|
|
15
|
+
exports.init = init;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function installDependency(): Promise<void>;
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.installDependency = void 0;
|
|
39
|
+
const axios_1 = __importDefault(require("axios"));
|
|
40
|
+
const child_process_1 = require("child_process");
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const semver_1 = __importDefault(require("semver"));
|
|
44
|
+
const os_1 = __importDefault(require("os"));
|
|
45
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
46
|
+
const const_1 = require("../cfg/const");
|
|
47
|
+
const BINARY = const_1.ckbBinPath;
|
|
48
|
+
const MINIMAL_VERSION = const_1.minimalRequiredCKBVersion;
|
|
49
|
+
// Function to download and install the dependency binary
|
|
50
|
+
function installDependency() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const version = getInstalledVersion();
|
|
53
|
+
if (version) {
|
|
54
|
+
if (isVersionOutdated(version)) {
|
|
55
|
+
console.log(`${BINARY} version ${version} is outdated, download and install the new version ${MINIMAL_VERSION}..`);
|
|
56
|
+
console.log(buildDownloadUrl(MINIMAL_VERSION));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log(`${BINARY} not found, download and install the new version ${MINIMAL_VERSION}..`);
|
|
64
|
+
}
|
|
65
|
+
const arch = getArch();
|
|
66
|
+
const osname = getOS();
|
|
67
|
+
const ckbVersionOSName = `ckb_v${MINIMAL_VERSION}_${arch}-${osname}`;
|
|
68
|
+
try {
|
|
69
|
+
const downloadURL = buildDownloadUrl(MINIMAL_VERSION);
|
|
70
|
+
const response = yield axios_1.default.get(downloadURL, {
|
|
71
|
+
responseType: 'arraybuffer',
|
|
72
|
+
});
|
|
73
|
+
const tempFilePath = path.join(os_1.default.tmpdir(), `${ckbVersionOSName}.zip`);
|
|
74
|
+
fs.writeFileSync(tempFilePath, response.data);
|
|
75
|
+
// Unzip the file
|
|
76
|
+
const zip = new adm_zip_1.default(tempFilePath);
|
|
77
|
+
const extractDir = path.join(const_1.targetEnvironmentPath, `ckb_v${MINIMAL_VERSION}`);
|
|
78
|
+
zip.extractAllTo(extractDir, /*overwrite*/ true);
|
|
79
|
+
const sourcePath = path.join(extractDir, ckbVersionOSName);
|
|
80
|
+
// Install the extracted files
|
|
81
|
+
fs.renameSync(sourcePath, const_1.ckbFolderPath); // Move binary to desired location
|
|
82
|
+
fs.chmodSync(const_1.ckbBinPath, '755'); // Make the binary executable
|
|
83
|
+
console.log('CKB installed successfully.');
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error('Error installing dependency binary:', error);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
exports.installDependency = installDependency;
|
|
91
|
+
function getInstalledVersion() {
|
|
92
|
+
try {
|
|
93
|
+
const versionOutput = (0, child_process_1.execSync)(`${BINARY} --version`, {
|
|
94
|
+
encoding: 'utf-8',
|
|
95
|
+
});
|
|
96
|
+
const versionMatch = versionOutput.match(/(\d+\.\d+\.\d+)/);
|
|
97
|
+
if (versionMatch) {
|
|
98
|
+
return versionMatch[0];
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function isVersionOutdated(installedVersion) {
|
|
107
|
+
return semver_1.default.lt(installedVersion, MINIMAL_VERSION);
|
|
108
|
+
}
|
|
109
|
+
function getOS() {
|
|
110
|
+
const platform = os_1.default.platform();
|
|
111
|
+
if (platform === 'darwin') {
|
|
112
|
+
return 'apple-darwin';
|
|
113
|
+
}
|
|
114
|
+
else if (platform === 'linux') {
|
|
115
|
+
return 'unknown-linux-gnu';
|
|
116
|
+
}
|
|
117
|
+
else if (platform === 'win32') {
|
|
118
|
+
return 'pc-windows-msvc';
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
throw new Error('Unsupported operating system');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function getArch() {
|
|
125
|
+
const arch = os_1.default.arch();
|
|
126
|
+
if (arch === 'x64') {
|
|
127
|
+
return 'x86_64';
|
|
128
|
+
}
|
|
129
|
+
else if (arch === 'arm64') {
|
|
130
|
+
return 'aarch64';
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
throw new Error('Unsupported architecture');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function buildDownloadUrl(version) {
|
|
137
|
+
const os = getOS();
|
|
138
|
+
const arch = getArch();
|
|
139
|
+
return `https://github.com/nervosnetwork/ckb/releases/download/v${version}/ckb_v${version}_${arch}-${os}.zip`;
|
|
140
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function listHashes(): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
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.listHashes = void 0;
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const const_1 = require("../cfg/const");
|
|
15
|
+
const install_1 = require("./install");
|
|
16
|
+
const init_chain_1 = require("./init-chain");
|
|
17
|
+
function listHashes() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
yield (0, install_1.installDependency)();
|
|
20
|
+
yield (0, init_chain_1.initChainIfNeeded)();
|
|
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
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
exports.listHashes = listHashes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function node(): Promise<void>;
|
package/dist/cmd/node.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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 = void 0;
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const const_1 = require("../cfg/const");
|
|
15
|
+
const init_chain_1 = require("./init-chain");
|
|
16
|
+
const install_1 = require("./install");
|
|
17
|
+
function node() {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
yield (0, install_1.installDependency)();
|
|
21
|
+
yield (0, init_chain_1.initChainIfNeeded)();
|
|
22
|
+
const ckbCmd = `${const_1.ckbBinPath} run -C ${const_1.devnetPath}`;
|
|
23
|
+
const minerCmd = `${const_1.ckbBinPath} miner -C ${const_1.devnetPath}`;
|
|
24
|
+
try {
|
|
25
|
+
// Run first command
|
|
26
|
+
const ckbProcess = (0, child_process_1.exec)(ckbCmd);
|
|
27
|
+
// Log first command's output
|
|
28
|
+
(_a = ckbProcess.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (data) => {
|
|
29
|
+
console.log('CKB output:', data.toString());
|
|
30
|
+
});
|
|
31
|
+
(_b = ckbProcess.stderr) === null || _b === void 0 ? void 0 : _b.on('data', (data) => {
|
|
32
|
+
console.error('CKB error:', data.toString());
|
|
33
|
+
});
|
|
34
|
+
// Start the second command after 3 seconds
|
|
35
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
var _c, _d;
|
|
37
|
+
try {
|
|
38
|
+
// Run second command
|
|
39
|
+
const minerProcess = (0, child_process_1.exec)(minerCmd);
|
|
40
|
+
(_c = minerProcess.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (data) => {
|
|
41
|
+
console.log('CKB-Miner:', data.toString());
|
|
42
|
+
});
|
|
43
|
+
(_d = minerProcess.stderr) === null || _d === void 0 ? void 0 : _d.on('data', (data) => {
|
|
44
|
+
console.error('CKB-Miner error:', data.toString());
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error('Error running CKB-Miner:', error);
|
|
49
|
+
}
|
|
50
|
+
}), 3000);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error('Error:', error);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.node = node;
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isFolderExists(folderPath: string): boolean;
|
package/dist/util.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.isFolderExists = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
function isFolderExists(folderPath) {
|
|
29
|
+
try {
|
|
30
|
+
// Check if the path exists
|
|
31
|
+
fs.accessSync(folderPath, fs.constants.F_OK);
|
|
32
|
+
// Check if it's a directory
|
|
33
|
+
const stats = fs.statSync(folderPath);
|
|
34
|
+
return stats.isDirectory();
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
// If the access or stat fails, or if it's not a directory, return false
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.isFolderExists = isFolderExists;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
while true; do
|
|
4
|
+
sleep 1
|
|
5
|
+
|
|
6
|
+
echo '{
|
|
7
|
+
"id": 2,
|
|
8
|
+
"jsonrpc": "2.0",
|
|
9
|
+
"method": "get_tip_block_number",
|
|
10
|
+
"params": []
|
|
11
|
+
}' \
|
|
12
|
+
| tr -d '\n' \
|
|
13
|
+
| curl -H 'content-type: application/json' -d @- \
|
|
14
|
+
http://ckb:8114
|
|
15
|
+
|
|
16
|
+
if [ $? -eq 0 ]; then
|
|
17
|
+
break
|
|
18
|
+
fi
|
|
19
|
+
done
|
|
20
|
+
|
|
21
|
+
exit 0
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Config generated by `ckb init --chain dev`
|
|
2
|
+
|
|
3
|
+
data_dir = "data"
|
|
4
|
+
|
|
5
|
+
[chain]
|
|
6
|
+
# Choose the kind of chains to run, possible values:
|
|
7
|
+
# - { file = "specs/dev.toml" }
|
|
8
|
+
# - { bundled = "specs/testnet.toml" }
|
|
9
|
+
# - { bundled = "specs/mainnet.toml" }
|
|
10
|
+
spec = { file = "specs/dev.toml" }
|
|
11
|
+
|
|
12
|
+
[logger]
|
|
13
|
+
filter = "info"
|
|
14
|
+
color = true
|
|
15
|
+
log_to_file = true
|
|
16
|
+
log_to_stdout = true
|
|
17
|
+
|
|
18
|
+
[sentry]
|
|
19
|
+
# set to blank to disable sentry error collection
|
|
20
|
+
dsn = ""
|
|
21
|
+
# if you are willing to help us to improve,
|
|
22
|
+
# please leave a way to contact you when we have troubles to reproduce the errors.
|
|
23
|
+
# org_contact = ""
|
|
24
|
+
|
|
25
|
+
# # **Experimental** Monitor memory changes.
|
|
26
|
+
# [memory_tracker]
|
|
27
|
+
# # Seconds between checking the process, 0 is disable, default is 0.
|
|
28
|
+
# interval = 600
|
|
29
|
+
|
|
30
|
+
[miner.client]
|
|
31
|
+
rpc_url = "http://ckb:8114/"
|
|
32
|
+
block_on_submit = true
|
|
33
|
+
|
|
34
|
+
# block template polling interval in milliseconds
|
|
35
|
+
poll_interval = 1000
|
|
36
|
+
|
|
37
|
+
# enable listen notify mode
|
|
38
|
+
# listen = "127.0.0.1:8888"
|
|
39
|
+
|
|
40
|
+
[[miner.workers]]
|
|
41
|
+
worker_type = "Dummy"
|
|
42
|
+
delay_type = "Constant"
|
|
43
|
+
value = 5000
|