@offckb/cli 0.1.1 → 0.1.2-canary-a369f24.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/account/ckb-miner-and-faucet.key +1 -0
- package/ckb/devnet/ckb.toml +3 -0
- package/dist/cfg/account.d.ts +55 -0
- package/dist/cfg/account.js +66 -0
- package/dist/cfg/const.d.ts +6 -1
- package/dist/cfg/const.js +7 -2
- package/dist/cli.js +69 -21
- package/dist/cmd/balance.d.ts +4 -0
- package/dist/cmd/balance.js +28 -0
- package/dist/cmd/clean.js +3 -2
- package/dist/cmd/create.d.ts +3 -0
- package/dist/cmd/create.js +56 -0
- package/dist/cmd/deploy.d.ts +6 -0
- package/dist/cmd/deploy.js +137 -0
- package/dist/cmd/deposit.d.ts +4 -0
- package/dist/cmd/deposit.js +95 -0
- package/dist/cmd/develop/build-account.d.ts +1 -0
- package/dist/cmd/develop/build-account.js +9 -0
- package/dist/cmd/{genkey.d.ts → develop/genkey.d.ts} +1 -0
- package/dist/cmd/{genkey.js → develop/genkey.js} +3 -2
- package/dist/cmd/{init-chain.js → develop/init-chain.js} +4 -4
- package/dist/cmd/{install.js → develop/install.js} +1 -1
- package/dist/cmd/develop/lumos-config.d.ts +4 -0
- package/dist/cmd/{build-lumos-config.js → develop/lumos-config.js} +25 -13
- package/dist/cmd/init.d.ts +3 -2
- package/dist/cmd/init.js +17 -10
- package/dist/cmd/inject-config.d.ts +4 -0
- package/dist/cmd/inject-config.js +99 -0
- package/dist/cmd/list-hashes.js +2 -2
- package/dist/cmd/node.js +2 -2
- package/dist/cmd/transfer.d.ts +5 -0
- package/dist/cmd/transfer.js +41 -0
- package/dist/cmd/update-config.d.ts +1 -0
- package/dist/cmd/update-config.js +19 -0
- package/dist/util/ckb.d.ts +77 -0
- package/dist/util/ckb.js +299 -0
- package/dist/util/config.d.ts +8 -0
- package/dist/util/config.js +127 -0
- package/dist/util/fs.d.ts +12 -0
- package/dist/{util.js → util/fs.js} +86 -65
- package/dist/util/git.d.ts +2 -0
- package/dist/util/git.js +85 -0
- package/dist/util/link.d.ts +1 -0
- package/dist/util/link.js +7 -0
- package/dist/util/template.d.ts +14 -0
- package/dist/util/template.js +43 -0
- package/dist/util/type.d.ts +8 -0
- package/dist/util/type.js +10 -0
- package/dist/util/validator.d.ts +4 -0
- package/dist/util/validator.js +59 -0
- package/package.json +1 -1
- package/templates/offckb.config.ts +193 -0
- package/dist/cmd/build-lumos-config.d.ts +0 -99
- package/dist/util.d.ts +0 -13
- /package/dist/cmd/{init-chain.d.ts → develop/init-chain.d.ts} +0 -0
- /package/dist/cmd/{install.d.ts → develop/install.d.ts} +0 -0
- /package/dist/{encoding.d.ts → util/encoding.d.ts} +0 -0
- /package/dist/{encoding.js → util/encoding.js} +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
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.deposit = void 0;
|
|
16
|
+
const ckb_1 = require("../util/ckb");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const genkey_1 = require("./develop/genkey");
|
|
19
|
+
const account_1 = require("../cfg/account");
|
|
20
|
+
const type_1 = require("../util/type");
|
|
21
|
+
const link_1 = require("../util/link");
|
|
22
|
+
const validator_1 = require("../util/validator");
|
|
23
|
+
function deposit(toAddress, amount, opt = { network: type_1.Network.devnet }) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const network = opt.network;
|
|
26
|
+
(0, validator_1.validateNetworkOpt)(network);
|
|
27
|
+
const ckb = new ckb_1.CKB(network);
|
|
28
|
+
const lumosConfig = ckb.getLumosConfig();
|
|
29
|
+
if (network === 'testnet') {
|
|
30
|
+
return yield depositFromTestnetFaucet(toAddress, ckb);
|
|
31
|
+
}
|
|
32
|
+
// deposit from devnet miner
|
|
33
|
+
const from = ckb_1.CKB.generateAccountFromPrivateKey(account_1.ckbDevnetMinerAccount.privkey, lumosConfig);
|
|
34
|
+
const txHash = yield ckb.transfer({
|
|
35
|
+
from: from.address,
|
|
36
|
+
to: toAddress,
|
|
37
|
+
privKey: from.privKey,
|
|
38
|
+
amount,
|
|
39
|
+
}, lumosConfig);
|
|
40
|
+
console.log('tx hash: ', txHash);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.deposit = deposit;
|
|
44
|
+
function depositFromTestnetFaucet(ckbAddress, ckb) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
console.log('testnet faucet only supports fixed-amount claim: 10,000 CKB');
|
|
47
|
+
const lumosConfig = ckb.getLumosConfig();
|
|
48
|
+
const randomAccountPrivateKey = '0x' + (0, genkey_1.generateHex)(64);
|
|
49
|
+
const randomAccount = ckb_1.CKB.generateAccountFromPrivateKey(randomAccountPrivateKey, lumosConfig);
|
|
50
|
+
console.log(`use random account to claim from faucet: \n\nprivate key: ${randomAccountPrivateKey}\n\n address: ${randomAccount.address}`);
|
|
51
|
+
try {
|
|
52
|
+
yield sendClaimRequest(randomAccount.address);
|
|
53
|
+
console.log('Wait for 4 blocks to transfer all from random account to your account..');
|
|
54
|
+
console.log('You can transfer by yourself if it ends up fails..');
|
|
55
|
+
yield ckb.indexer.waitForSync(-4);
|
|
56
|
+
const txHash = yield ckb.transferAll(randomAccount.privKey, ckbAddress, lumosConfig);
|
|
57
|
+
console.log(`Done, check ${(0, link_1.buildTestnetTxLink)(txHash)} for details.`);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.log(error);
|
|
61
|
+
throw new Error('request failed.');
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function sendClaimRequest(toAddress) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const url = 'https://faucet-api.nervos.org/claim_events'; // Replace 'YOUR_API_ENDPOINT' with the actual API endpoint
|
|
68
|
+
const headers = {
|
|
69
|
+
'User-Agent': 'axios-requests/2.31.0',
|
|
70
|
+
'Accept-Encoding': 'gzip, deflate',
|
|
71
|
+
Accept: '*/*',
|
|
72
|
+
Connection: 'keep-alive',
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
};
|
|
75
|
+
const body = JSON.stringify({
|
|
76
|
+
claim_event: {
|
|
77
|
+
address_hash: toAddress,
|
|
78
|
+
amount: '10000',
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const config = {
|
|
82
|
+
method: 'post',
|
|
83
|
+
url: url,
|
|
84
|
+
headers: headers,
|
|
85
|
+
data: body,
|
|
86
|
+
};
|
|
87
|
+
try {
|
|
88
|
+
const response = yield (0, axios_1.default)(config);
|
|
89
|
+
console.log('send claim request, status: ', response.status); // Handle the response data here
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
console.error('Error:', error);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildAccount(privKey: string): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildAccount = void 0;
|
|
4
|
+
const genkey_1 = require("./genkey");
|
|
5
|
+
function buildAccount(privKey) {
|
|
6
|
+
const account = (0, genkey_1.genAccount)(privKey);
|
|
7
|
+
console.log(account);
|
|
8
|
+
}
|
|
9
|
+
exports.buildAccount = buildAccount;
|
|
@@ -7,6 +7,7 @@ interface Account {
|
|
|
7
7
|
address: Address;
|
|
8
8
|
}
|
|
9
9
|
export declare function genkey(): void;
|
|
10
|
+
export declare function generateHex(length: number): string;
|
|
10
11
|
export declare function buildAccounts(): Promise<void>;
|
|
11
12
|
export declare function genAccount(privkey: HexString): Account;
|
|
12
13
|
export declare function printIssueSectionForToml(): void;
|
|
@@ -39,10 +39,10 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
39
39
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.printIssueSectionForToml = exports.genAccount = exports.buildAccounts = exports.genkey = void 0;
|
|
42
|
+
exports.printIssueSectionForToml = exports.genAccount = exports.buildAccounts = exports.generateHex = exports.genkey = void 0;
|
|
43
43
|
const fs = __importStar(require("fs"));
|
|
44
44
|
const path = __importStar(require("path"));
|
|
45
|
-
const const_1 = require("
|
|
45
|
+
const const_1 = require("../../cfg/const");
|
|
46
46
|
const lumos_1 = require("@ckb-lumos/lumos");
|
|
47
47
|
const readline = __importStar(require("readline"));
|
|
48
48
|
function genkey() {
|
|
@@ -60,6 +60,7 @@ function generateHex(length) {
|
|
|
60
60
|
}
|
|
61
61
|
return result;
|
|
62
62
|
}
|
|
63
|
+
exports.generateHex = generateHex;
|
|
63
64
|
function generateKeysFile(numKeys, keyLength) {
|
|
64
65
|
const targetDir = path.join(const_1.accountTargetDir, `keys`);
|
|
65
66
|
const stream = fs.createWriteStream(targetDir);
|
|
@@ -37,12 +37,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.initChainIfNeeded = void 0;
|
|
39
39
|
const fs = __importStar(require("fs"));
|
|
40
|
-
const const_1 = require("
|
|
40
|
+
const const_1 = require("../../cfg/const");
|
|
41
41
|
const path_1 = __importDefault(require("path"));
|
|
42
|
-
const
|
|
42
|
+
const fs_1 = require("../../util/fs");
|
|
43
43
|
function initChainIfNeeded() {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
if (!(0,
|
|
45
|
+
if (!(0, fs_1.isFolderExists)(const_1.devnetPath)) {
|
|
46
46
|
yield doInitChain();
|
|
47
47
|
}
|
|
48
48
|
});
|
|
@@ -50,7 +50,7 @@ function initChainIfNeeded() {
|
|
|
50
50
|
exports.initChainIfNeeded = initChainIfNeeded;
|
|
51
51
|
function doInitChain() {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
yield (0,
|
|
53
|
+
yield (0, fs_1.copyFilesWithExclusion)(const_1.devnetSourcePath, const_1.devnetPath, ['data']);
|
|
54
54
|
console.debug(`init devnet config folder: ${const_1.devnetPath}`);
|
|
55
55
|
copyAndEditMinerToml();
|
|
56
56
|
});
|
|
@@ -44,7 +44,7 @@ const semver_1 = __importDefault(require("semver"));
|
|
|
44
44
|
const os_1 = __importDefault(require("os"));
|
|
45
45
|
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
46
46
|
const tar = __importStar(require("tar"));
|
|
47
|
-
const const_1 = require("
|
|
47
|
+
const const_1 = require("../../cfg/const");
|
|
48
48
|
const BINARY = const_1.ckbBinPath;
|
|
49
49
|
const MINIMAL_VERSION = const_1.minimalRequiredCKBVersion;
|
|
50
50
|
// Function to download and install the dependency binary
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { config } from '@ckb-lumos/lumos';
|
|
2
|
+
export declare function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock: string, secondTxHashInGenesisBlock: string): config.Config;
|
|
3
|
+
export declare function fetchDevnetLumosConfig(): Promise<config.Config>;
|
|
4
|
+
export declare function writePredefinedDevnetLumosConfig(): Promise<void>;
|
|
@@ -12,11 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.writePredefinedDevnetLumosConfig = exports.fetchDevnetLumosConfig = exports.devnetLumosConfigTemplate = void 0;
|
|
16
16
|
const fs_1 = __importDefault(require("fs"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const const_1 = require("
|
|
19
|
-
const
|
|
18
|
+
const const_1 = require("../../cfg/const");
|
|
19
|
+
const config_1 = require("../../util/config");
|
|
20
|
+
const ckb_1 = require("../../util/ckb");
|
|
21
|
+
const type_1 = require("../../util/type");
|
|
20
22
|
function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock, secondTxHashInGenesisBlock) {
|
|
21
23
|
const devnetConfig = {
|
|
22
24
|
PREFIX: 'ckt',
|
|
@@ -119,23 +121,33 @@ function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock, secondTxHashInG
|
|
|
119
121
|
return devnetConfig;
|
|
120
122
|
}
|
|
121
123
|
exports.devnetLumosConfigTemplate = devnetLumosConfigTemplate;
|
|
122
|
-
function
|
|
124
|
+
function fetchDevnetLumosConfig() {
|
|
123
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
-
const
|
|
125
|
-
const rpc =
|
|
126
|
+
const ckb = new ckb_1.CKB(type_1.Network.devnet);
|
|
127
|
+
const rpc = ckb.rpc;
|
|
126
128
|
const chainInfo = yield rpc.getBlockchainInfo();
|
|
127
129
|
const genesisBlock = yield rpc.getBlockByNumber('0x0');
|
|
128
130
|
const cellBaseTxHashInGenesisBlock = genesisBlock.transactions[0].hash;
|
|
129
131
|
const secondTxHashInGenesisBlock = genesisBlock.transactions[1].hash;
|
|
130
132
|
if (chainInfo.chain === 'offckb') {
|
|
131
133
|
const config = devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock, secondTxHashInGenesisBlock);
|
|
132
|
-
|
|
133
|
-
fs_1.default.writeFile(filePath, JSON.stringify(config, null, 2), 'utf8', (err) => {
|
|
134
|
-
if (err) {
|
|
135
|
-
return console.error('Error writing file:', err);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
134
|
+
return config;
|
|
138
135
|
}
|
|
136
|
+
throw new Error('not a devnet!');
|
|
139
137
|
});
|
|
140
138
|
}
|
|
141
|
-
exports.
|
|
139
|
+
exports.fetchDevnetLumosConfig = fetchDevnetLumosConfig;
|
|
140
|
+
function writePredefinedDevnetLumosConfig() {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
const config = yield fetchDevnetLumosConfig();
|
|
143
|
+
const filePath = path_1.default.resolve(const_1.dappTemplatePath, 'config.json');
|
|
144
|
+
fs_1.default.writeFile(filePath, JSON.stringify(config, null, 2), 'utf8', (err) => {
|
|
145
|
+
if (err) {
|
|
146
|
+
return console.error('Error writing file:', err);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
// update the offckb.config.ts too
|
|
150
|
+
(0, config_1.updateScriptInfoInOffCKBConfigTs)(config, const_1.predefinedOffCKBConfigTsPath, type_1.Network.devnet);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.writePredefinedDevnetLumosConfig = writePredefinedDevnetLumosConfig;
|
package/dist/cmd/init.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
1
|
+
import { TutorialOption } from '../util/template';
|
|
2
|
+
export declare function init(name: string, template: TutorialOption): void;
|
|
3
|
+
export declare function selectTemplate(): Promise<TutorialOption>;
|
package/dist/cmd/init.js
CHANGED
|
@@ -15,29 +15,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.selectTemplate = exports.init = void 0;
|
|
16
16
|
const const_1 = require("../cfg/const");
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const util_1 = require("../util");
|
|
19
18
|
const select_1 = __importDefault(require("@inquirer/select"));
|
|
20
|
-
const
|
|
19
|
+
const template_1 = require("../util/template");
|
|
20
|
+
const fs_1 = require("../util/fs");
|
|
21
|
+
const git_1 = require("../util/git");
|
|
21
22
|
function init(name, template) {
|
|
22
23
|
const targetPath = path_1.default.resolve(const_1.currentExecPath, name);
|
|
23
|
-
const dappTemplateFolderPath = `${const_1.dappTemplateGitFolder}/${template}`;
|
|
24
|
-
(0,
|
|
24
|
+
const dappTemplateFolderPath = `${const_1.dappTemplateGitFolder}/${template.value}`;
|
|
25
|
+
(0, git_1.gitCloneAndDownloadFolderSync)(const_1.dappTemplateGitUrl, const_1.dappTemplateGitBranch, dappTemplateFolderPath, targetPath);
|
|
25
26
|
// add some common code files
|
|
26
27
|
const ckbDotTs = path_1.default.resolve(const_1.dappTemplatePath, 'ckb.ts');
|
|
27
28
|
const configJson = path_1.default.resolve(const_1.dappTemplatePath, 'config.json');
|
|
28
|
-
(0,
|
|
29
|
-
(0,
|
|
29
|
+
(0, fs_1.copyFileSync)(ckbDotTs, targetPath);
|
|
30
|
+
(0, fs_1.copyFileSync)(configJson, targetPath);
|
|
30
31
|
console.log(`init CKB dapp project: ${targetPath}`);
|
|
31
32
|
}
|
|
32
33
|
exports.init = init;
|
|
33
34
|
function selectTemplate() {
|
|
34
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const opts = yield (0,
|
|
36
|
+
const opts = yield (0, template_1.loadTutorialOpts)();
|
|
36
37
|
const answer = yield (0, select_1.default)({
|
|
37
|
-
message: 'Select
|
|
38
|
-
choices: opts
|
|
38
|
+
message: 'Select an example dApp',
|
|
39
|
+
choices: opts.map((opt) => {
|
|
40
|
+
return {
|
|
41
|
+
name: opt.name,
|
|
42
|
+
value: opt.value,
|
|
43
|
+
description: opt.description,
|
|
44
|
+
};
|
|
45
|
+
}),
|
|
39
46
|
});
|
|
40
|
-
return answer;
|
|
47
|
+
return opts.find((opt) => opt.value === answer);
|
|
41
48
|
});
|
|
42
49
|
}
|
|
43
50
|
exports.selectTemplate = selectTemplate;
|
|
@@ -0,0 +1,99 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.installLumosPackage = exports.readLumosVersionFromOffCKBConfig = exports.injectConfig = void 0;
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
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");
|
|
35
|
+
const validator_1 = require("../util/validator");
|
|
36
|
+
const type_1 = require("../util/type");
|
|
37
|
+
function injectConfig() {
|
|
38
|
+
const targetPath = const_1.currentExecPath;
|
|
39
|
+
(0, validator_1.validateTypescriptWorkspace)();
|
|
40
|
+
// inject the offckb.config.ts file into users workspace
|
|
41
|
+
// copy config template
|
|
42
|
+
(0, fs_1.copyFileSync)(const_1.predefinedOffCKBConfigTsPath, targetPath);
|
|
43
|
+
// update the config
|
|
44
|
+
const devnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.devnet);
|
|
45
|
+
const testnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.testnet);
|
|
46
|
+
const mainnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.mainnet);
|
|
47
|
+
(0, config_1.updateScriptInfoInOffCKBConfigTs)(devnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.devnet);
|
|
48
|
+
(0, config_1.updateScriptInfoInOffCKBConfigTs)(testnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.testnet);
|
|
49
|
+
(0, config_1.updateScriptInfoInOffCKBConfigTs)(mainnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.mainnet);
|
|
50
|
+
console.log(`Inject offckb.config.ts file.`);
|
|
51
|
+
// todo: select yarn/npm/pnpm to install the lumos version from user
|
|
52
|
+
const version = readLumosVersionFromOffCKBConfig();
|
|
53
|
+
installLumosPackage(version);
|
|
54
|
+
console.log(`\n\nAll good. You can now use it in your project like:
|
|
55
|
+
|
|
56
|
+
import offCKB from "offckb.config";
|
|
57
|
+
|
|
58
|
+
const lumosConfig = offCKB.lumosConfig;
|
|
59
|
+
const indexer = offCKB.indexer;
|
|
60
|
+
const rpc = offCKB.rpc;
|
|
61
|
+
|
|
62
|
+
Check example at https://github.com/nervosnetwork/docs.nervos.org/tree/develop-v2/examples/create-dob
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
exports.injectConfig = injectConfig;
|
|
66
|
+
function readLumosVersionFromOffCKBConfig() {
|
|
67
|
+
const fileContent = fs_1.default.readFileSync(const_1.userOffCKBConfigPath, 'utf-8');
|
|
68
|
+
const match = fileContent.match(/lumosVersion:\s*['"]([^'"]+)['"]/);
|
|
69
|
+
if (match && match[1]) {
|
|
70
|
+
return match[1];
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
console.log('lumosVersion value not found in offckb.config.ts', match);
|
|
74
|
+
return const_1.defaultLumosVersion;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.readLumosVersionFromOffCKBConfig = readLumosVersionFromOffCKBConfig;
|
|
78
|
+
function installLumosPackage(version) {
|
|
79
|
+
// Check if package.json exists
|
|
80
|
+
const packageJsonPath = path_1.default.join(const_1.currentExecPath, 'package.json');
|
|
81
|
+
if (!fs_1.default.existsSync(packageJsonPath)) {
|
|
82
|
+
throw new Error('package.json not found in the current directory');
|
|
83
|
+
}
|
|
84
|
+
const packageLock = path_1.default.join(const_1.currentExecPath, 'package-lock.json');
|
|
85
|
+
if (fs_1.default.existsSync(packageLock)) {
|
|
86
|
+
return (0, child_process_1.execSync)(`npm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
|
|
87
|
+
}
|
|
88
|
+
const yarnLock = path_1.default.join(const_1.currentExecPath, 'yarn.lock');
|
|
89
|
+
if (fs_1.default.existsSync(yarnLock)) {
|
|
90
|
+
console.log(`yarn add @ckb-lumos/lumos@${version}`);
|
|
91
|
+
return (0, child_process_1.execSync)(`yarn add @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
|
|
92
|
+
}
|
|
93
|
+
const pnpmLock = path_1.default.join(const_1.currentExecPath, 'pnpm-lock.json');
|
|
94
|
+
if (fs_1.default.existsSync(pnpmLock)) {
|
|
95
|
+
return (0, child_process_1.execSync)(`pnpm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
|
|
96
|
+
}
|
|
97
|
+
return (0, child_process_1.execSync)(`pnpm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
|
|
98
|
+
}
|
|
99
|
+
exports.installLumosPackage = installLumosPackage;
|
package/dist/cmd/list-hashes.js
CHANGED
|
@@ -12,8 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.listHashes = void 0;
|
|
13
13
|
const child_process_1 = require("child_process");
|
|
14
14
|
const const_1 = require("../cfg/const");
|
|
15
|
-
const install_1 = require("./install");
|
|
16
|
-
const init_chain_1 = require("./init-chain");
|
|
15
|
+
const install_1 = require("./develop/install");
|
|
16
|
+
const init_chain_1 = require("./develop/init-chain");
|
|
17
17
|
function listHashes() {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
yield (0, install_1.installDependency)();
|
package/dist/cmd/node.js
CHANGED
|
@@ -12,8 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.node = void 0;
|
|
13
13
|
const child_process_1 = require("child_process");
|
|
14
14
|
const const_1 = require("../cfg/const");
|
|
15
|
-
const init_chain_1 = require("./init-chain");
|
|
16
|
-
const install_1 = require("./install");
|
|
15
|
+
const init_chain_1 = require("./develop/init-chain");
|
|
16
|
+
const install_1 = require("./develop/install");
|
|
17
17
|
function node() {
|
|
18
18
|
var _a, _b;
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,41 @@
|
|
|
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.transfer = void 0;
|
|
13
|
+
const ckb_1 = require("../util/ckb");
|
|
14
|
+
const type_1 = require("../util/type");
|
|
15
|
+
const link_1 = require("../util/link");
|
|
16
|
+
const validator_1 = require("../util/validator");
|
|
17
|
+
function transfer(toAddress, amount, opt = { network: type_1.Network.devnet }) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const network = opt.network;
|
|
20
|
+
(0, validator_1.validateNetworkOpt)(network);
|
|
21
|
+
if (opt.privkey == null) {
|
|
22
|
+
throw new Error('--privkey is required!');
|
|
23
|
+
}
|
|
24
|
+
const privateKey = opt.privkey;
|
|
25
|
+
const ckb = new ckb_1.CKB(network);
|
|
26
|
+
const lumosConfig = ckb.getLumosConfig();
|
|
27
|
+
const from = ckb_1.CKB.generateAccountFromPrivateKey(privateKey, lumosConfig);
|
|
28
|
+
const txHash = yield ckb.transfer({
|
|
29
|
+
from: from.address,
|
|
30
|
+
to: toAddress,
|
|
31
|
+
amount: amount,
|
|
32
|
+
privKey: privateKey,
|
|
33
|
+
}, lumosConfig);
|
|
34
|
+
if (network === 'testnet') {
|
|
35
|
+
console.log(`Successfully transfer, check ${(0, link_1.buildTestnetTxLink)(txHash)} for details.`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.log('Successfully transfer, txHash:', txHash);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.transfer = transfer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function updateConfig(): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateConfig = void 0;
|
|
4
|
+
const const_1 = require("../cfg/const");
|
|
5
|
+
const config_1 = require("../util/config");
|
|
6
|
+
const type_1 = require("../util/type");
|
|
7
|
+
const validator_1 = require("../util/validator");
|
|
8
|
+
function updateConfig() {
|
|
9
|
+
(0, validator_1.validateExecDappEnvironment)();
|
|
10
|
+
// update the offckb.config.ts file in users workspace
|
|
11
|
+
const devnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.devnet);
|
|
12
|
+
const testnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.testnet);
|
|
13
|
+
const mainnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.mainnet);
|
|
14
|
+
(0, config_1.updateScriptInfoInOffCKBConfigTs)(devnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.devnet);
|
|
15
|
+
(0, config_1.updateScriptInfoInOffCKBConfigTs)(testnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.testnet);
|
|
16
|
+
(0, config_1.updateScriptInfoInOffCKBConfigTs)(mainnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.mainnet);
|
|
17
|
+
console.log('offCKB config updated.');
|
|
18
|
+
}
|
|
19
|
+
exports.updateConfig = updateConfig;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Address, BI, Indexer, RPC, Script, config } from '@ckb-lumos/lumos';
|
|
2
|
+
import { Network } from './type';
|
|
3
|
+
export type Account = {
|
|
4
|
+
lockScript: Script;
|
|
5
|
+
address: Address;
|
|
6
|
+
pubKey: string;
|
|
7
|
+
privKey: string;
|
|
8
|
+
};
|
|
9
|
+
interface Options {
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
amount: string;
|
|
13
|
+
privKey: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class CKB {
|
|
16
|
+
network: Network;
|
|
17
|
+
rpc_url: string;
|
|
18
|
+
rpc: RPC;
|
|
19
|
+
indexer: Indexer;
|
|
20
|
+
constructor(network?: Network);
|
|
21
|
+
static generateAccountFromPrivateKey(privKey: string, lumosConfig: config.Config): Account;
|
|
22
|
+
getLumosConfig(): config.Config | {
|
|
23
|
+
PREFIX: string;
|
|
24
|
+
SCRIPTS: {
|
|
25
|
+
SECP256K1_BLAKE160: {
|
|
26
|
+
CODE_HASH: string;
|
|
27
|
+
HASH_TYPE: "type";
|
|
28
|
+
TX_HASH: string;
|
|
29
|
+
INDEX: string;
|
|
30
|
+
DEP_TYPE: "depGroup";
|
|
31
|
+
SHORT_ID: number;
|
|
32
|
+
};
|
|
33
|
+
SECP256K1_BLAKE160_MULTISIG: {
|
|
34
|
+
CODE_HASH: string;
|
|
35
|
+
HASH_TYPE: "type";
|
|
36
|
+
TX_HASH: string;
|
|
37
|
+
INDEX: string;
|
|
38
|
+
DEP_TYPE: "depGroup";
|
|
39
|
+
SHORT_ID: number;
|
|
40
|
+
};
|
|
41
|
+
DAO: {
|
|
42
|
+
CODE_HASH: string;
|
|
43
|
+
HASH_TYPE: "type";
|
|
44
|
+
TX_HASH: string;
|
|
45
|
+
INDEX: string;
|
|
46
|
+
DEP_TYPE: "code";
|
|
47
|
+
};
|
|
48
|
+
SUDT: {
|
|
49
|
+
CODE_HASH: string;
|
|
50
|
+
HASH_TYPE: "type";
|
|
51
|
+
TX_HASH: string;
|
|
52
|
+
INDEX: string;
|
|
53
|
+
DEP_TYPE: "code";
|
|
54
|
+
};
|
|
55
|
+
ANYONE_CAN_PAY: {
|
|
56
|
+
CODE_HASH: string;
|
|
57
|
+
HASH_TYPE: "type";
|
|
58
|
+
TX_HASH: string;
|
|
59
|
+
INDEX: string;
|
|
60
|
+
DEP_TYPE: "depGroup";
|
|
61
|
+
SHORT_ID: number;
|
|
62
|
+
};
|
|
63
|
+
OMNILOCK: {
|
|
64
|
+
CODE_HASH: string;
|
|
65
|
+
HASH_TYPE: "type";
|
|
66
|
+
TX_HASH: string;
|
|
67
|
+
INDEX: string;
|
|
68
|
+
DEP_TYPE: "code";
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
initializedLumosConfig(): void;
|
|
73
|
+
capacityOf(address: string, lumosConfig: config.Config): Promise<BI>;
|
|
74
|
+
transfer(options: Options, lumosConfig: config.Config): Promise<string>;
|
|
75
|
+
transferAll(privateKey: string, toAddress: string, lumosConfig: config.Config): Promise<string>;
|
|
76
|
+
}
|
|
77
|
+
export {};
|