@offckb/cli 0.3.0-rc3 → 0.3.0-rc5

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.
Files changed (52) hide show
  1. package/README.md +27 -20
  2. package/dist/cfg/setting.d.ts +11 -2
  3. package/dist/cli.js +16 -6
  4. package/dist/cmd/balance.d.ts +1 -1
  5. package/dist/cmd/balance.js +6 -8
  6. package/dist/cmd/debug.d.ts +1 -1
  7. package/dist/cmd/debug.js +5 -5
  8. package/dist/cmd/deploy.d.ts +2 -1
  9. package/dist/cmd/deploy.js +15 -116
  10. package/dist/cmd/deposit.d.ts +2 -2
  11. package/dist/cmd/deposit.js +29 -31
  12. package/dist/cmd/list-hashes.d.ts +1 -1
  13. package/dist/cmd/my-scripts.d.ts +1 -1
  14. package/dist/cmd/my-scripts.js +2 -2
  15. package/dist/cmd/node.js +2 -2
  16. package/dist/cmd/proxy-rpc.d.ts +1 -1
  17. package/dist/cmd/proxy-rpc.js +4 -4
  18. package/dist/cmd/system-scripts.d.ts +70 -2
  19. package/dist/cmd/system-scripts.js +4 -0
  20. package/dist/cmd/transfer-all.d.ts +5 -0
  21. package/dist/cmd/transfer-all.js +37 -0
  22. package/dist/cmd/transfer.d.ts +2 -2
  23. package/dist/cmd/transfer.js +8 -11
  24. package/dist/deploy/index.d.ts +18 -0
  25. package/dist/deploy/index.js +126 -0
  26. package/dist/deploy/migration.d.ts +17 -12
  27. package/dist/deploy/migration.js +52 -15
  28. package/dist/deploy/toml.d.ts +8 -4
  29. package/dist/deploy/toml.js +2 -2
  30. package/dist/deploy/util.d.ts +1 -1
  31. package/dist/deploy/util.js +4 -4
  32. package/dist/node/install.js +3 -4
  33. package/dist/scripts/gen.js +4 -4
  34. package/dist/scripts/private.d.ts +4 -0
  35. package/dist/scripts/private.js +14 -0
  36. package/dist/scripts/util.d.ts +1 -1
  37. package/dist/scripts/util.js +1 -1
  38. package/dist/sdk/ckb.d.ts +37 -0
  39. package/dist/sdk/ckb.js +254 -0
  40. package/dist/sdk/network.d.ts +17 -0
  41. package/dist/sdk/network.js +22 -0
  42. package/dist/tools/moleculec-es.js +3 -4
  43. package/dist/tools/rpc-proxy.d.ts +1 -1
  44. package/dist/tools/rpc-proxy.js +2 -2
  45. package/dist/{util/type.d.ts → type/base.d.ts} +2 -0
  46. package/dist/util/request.d.ts +6 -6
  47. package/dist/util/request.js +15 -11
  48. package/dist/util/validator.js +2 -2
  49. package/package.json +5 -4
  50. package/dist/util/ckb.d.ts +0 -141
  51. package/dist/util/ckb.js +0 -312
  52. /package/dist/{util/type.js → type/base.js} +0 -0
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildCCCDevnetKnownScripts = void 0;
4
+ //todo: extract getSystemScriptsFromListHashes/toCCCKnownScripts from cmd folder
5
+ const system_scripts_1 = require("../cmd/system-scripts");
6
+ function buildCCCDevnetKnownScripts() {
7
+ const devnetSystemScripts = (0, system_scripts_1.getSystemScriptsFromListHashes)();
8
+ if (devnetSystemScripts == null) {
9
+ throw new Error('can not getSystemScriptsFromListHashes in devnet');
10
+ }
11
+ const devnetKnownScripts = (0, system_scripts_1.toCCCKnownScripts)(devnetSystemScripts);
12
+ return devnetKnownScripts;
13
+ }
14
+ exports.buildCCCDevnetKnownScripts = buildCCCDevnetKnownScripts;
@@ -1,3 +1,3 @@
1
1
  import { MyScriptsRecord } from '../scripts/type';
2
- import { Network } from '../util/type';
2
+ import { Network } from '../type/base';
3
3
  export declare function readUserDeployedScriptsInfo(network: Network): MyScriptsRecord;
@@ -42,7 +42,7 @@ function readUserDeployedScriptsInfo(network) {
42
42
  if (newestFilePath) {
43
43
  try {
44
44
  // Read the file content
45
- const recipe = (0, migration_1.readDeploymentRecipeJsonFile)(newestFilePath);
45
+ const recipe = (0, migration_1.readDeploymentMigrationFile)(newestFilePath);
46
46
  // todo: handle multiple cell recipes?
47
47
  const firstCell = recipe.cellRecipes[0];
48
48
  const isDepCode = recipe.depGroupRecipes.length > 0;
@@ -0,0 +1,37 @@
1
+ import { ccc, Script } from '@ckb-ccc/core';
2
+ import { Network, HexNumber, HexString } from '../type/base';
3
+ export declare class CKBProps {
4
+ network?: Network;
5
+ feeRate?: number;
6
+ isEnableProxyRpc?: boolean;
7
+ }
8
+ export interface DeploymentResult {
9
+ txHash: HexString;
10
+ tx: ccc.Transaction;
11
+ scriptOutputCellIndex: number;
12
+ isTypeId: boolean;
13
+ typeId?: Script;
14
+ }
15
+ export interface TransferOption {
16
+ privateKey: HexString;
17
+ toAddress: string;
18
+ amountInCKB: HexNumber;
19
+ }
20
+ export type TransferAllOption = Pick<TransferOption, 'privateKey' | 'toAddress'>;
21
+ export declare class CKB {
22
+ network: Network;
23
+ feeRate: number;
24
+ isEnableProxyRpc: boolean;
25
+ private client;
26
+ constructor({ network, feeRate, isEnableProxyRpc }: CKBProps);
27
+ buildSigner(privateKey: HexString): ccc.SignerCkbPrivateKey;
28
+ buildSecp256k1Address(privateKey: HexString): Promise<string>;
29
+ waitForTxConfirm(txHash: HexString, timeout?: number): Promise<void>;
30
+ waitForBlocksBy(interval: number): Promise<void>;
31
+ balance(address: string): Promise<string>;
32
+ transfer({ privateKey, toAddress, amountInCKB }: TransferOption): Promise<HexString>;
33
+ transferAll({ privateKey, toAddress }: TransferAllOption): Promise<HexString>;
34
+ deployScript(scriptBinBytes: Uint8Array, privateKey: string): Promise<DeploymentResult>;
35
+ deployNewTypeIDScript(scriptBinBytes: Uint8Array, privateKey: string): Promise<DeploymentResult>;
36
+ upgradeTypeIdScript(scriptName: string, newScriptBinBytes: Uint8Array, privateKey: HexString): Promise<DeploymentResult>;
37
+ }
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ // this is a rewrite for util/ckb.ts
3
+ // to replace lumos with ccc
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.CKB = exports.CKBProps = void 0;
15
+ const core_1 = require("@ckb-ccc/core");
16
+ const validator_1 = require("../util/validator");
17
+ const network_1 = require("./network");
18
+ const private_1 = require("../scripts/private");
19
+ const migration_1 = require("../deploy/migration");
20
+ const base_1 = require("../type/base");
21
+ class CKBProps {
22
+ }
23
+ exports.CKBProps = CKBProps;
24
+ class CKB {
25
+ constructor({ network = base_1.Network.devnet, feeRate = 1000, isEnableProxyRpc = false }) {
26
+ if (!(0, validator_1.isValidNetworkString)(network)) {
27
+ throw new Error('invalid network option');
28
+ }
29
+ this.network = network;
30
+ this.feeRate = feeRate;
31
+ this.isEnableProxyRpc = isEnableProxyRpc;
32
+ if (isEnableProxyRpc === true) {
33
+ this.client =
34
+ network === 'mainnet'
35
+ ? new core_1.ccc.ClientPublicMainnet({ url: network_1.networks.mainnet.proxy_rpc_url })
36
+ : network === 'testnet'
37
+ ? new core_1.ccc.ClientPublicTestnet({ url: network_1.networks.testnet.proxy_rpc_url })
38
+ : new core_1.ccc.ClientPublicTestnet({
39
+ url: network_1.networks.devnet.proxy_rpc_url,
40
+ scripts: (0, private_1.buildCCCDevnetKnownScripts)(),
41
+ });
42
+ }
43
+ else {
44
+ this.client =
45
+ network === 'mainnet'
46
+ ? new core_1.ccc.ClientPublicMainnet()
47
+ : network === 'testnet'
48
+ ? new core_1.ccc.ClientPublicTestnet()
49
+ : new core_1.ccc.ClientPublicTestnet({
50
+ url: network_1.networks.devnet.rpc_url,
51
+ scripts: (0, private_1.buildCCCDevnetKnownScripts)(),
52
+ });
53
+ }
54
+ }
55
+ buildSigner(privateKey) {
56
+ const signer = new core_1.ccc.SignerCkbPrivateKey(this.client, privateKey);
57
+ return signer;
58
+ }
59
+ buildSecp256k1Address(privateKey) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const signer = this.buildSigner(privateKey);
62
+ const address = yield signer.getAddressObjSecp256k1();
63
+ return address.toString();
64
+ });
65
+ }
66
+ waitForTxConfirm(txHash, timeout = 60000) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const query = () => __awaiter(this, void 0, void 0, function* () {
69
+ const res = yield this.client.getTransactionNoCache(txHash);
70
+ if (res && res.status === 'committed') {
71
+ return true;
72
+ }
73
+ else {
74
+ return false;
75
+ }
76
+ });
77
+ return waitFor(query, timeout, 5000);
78
+ });
79
+ }
80
+ waitForBlocksBy(interval) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ if (interval < 0)
83
+ throw new Error('interval must be number >= 0');
84
+ const timeout = interval * 50000; // block interval is 18 secs, we set limit to 30s
85
+ const tip = yield this.client.getTip();
86
+ const blockNum = tip + BigInt(interval);
87
+ const query = () => __awaiter(this, void 0, void 0, function* () {
88
+ const res = yield this.client.getBlockByNumber(blockNum);
89
+ if (res) {
90
+ return true;
91
+ }
92
+ else {
93
+ return false;
94
+ }
95
+ });
96
+ return waitFor(query, timeout, 5000);
97
+ });
98
+ }
99
+ balance(address) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ const lock = (yield core_1.ccc.Address.fromString(address, this.client)).script;
102
+ const balanceInShannon = yield this.client.getBalanceSingle(lock);
103
+ const balanceInCKB = core_1.ccc.fixedPointToString(balanceInShannon);
104
+ return balanceInCKB;
105
+ });
106
+ }
107
+ transfer({ privateKey, toAddress, amountInCKB }) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ const signer = this.buildSigner(privateKey);
110
+ const to = yield core_1.ccc.Address.fromString(toAddress, this.client);
111
+ const tx = core_1.ccc.Transaction.from({
112
+ outputs: [
113
+ {
114
+ capacity: core_1.ccc.fixedPointFrom(amountInCKB),
115
+ lock: to.script,
116
+ },
117
+ ],
118
+ });
119
+ yield tx.completeInputsByCapacity(signer);
120
+ yield tx.completeFeeBy(signer, this.feeRate);
121
+ const txHash = yield signer.sendTransaction(tx);
122
+ return txHash;
123
+ });
124
+ }
125
+ transferAll({ privateKey, toAddress }) {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ const signer = this.buildSigner(privateKey);
128
+ const to = yield core_1.ccc.Address.fromString(toAddress, this.client);
129
+ const balanceInCKB = yield this.balance((yield signer.getRecommendedAddressObj()).toString());
130
+ // leave 0.001 ckb for tx fee
131
+ const amountInCKB = core_1.ccc.fixedPointFrom(balanceInCKB) - core_1.ccc.fixedPointFrom(0.001);
132
+ const tx = core_1.ccc.Transaction.from({
133
+ outputs: [
134
+ {
135
+ capacity: core_1.ccc.fixedPointFrom(amountInCKB),
136
+ lock: to.script,
137
+ },
138
+ ],
139
+ });
140
+ yield tx.completeInputsByCapacity(signer);
141
+ const txHash = yield signer.sendTransaction(tx);
142
+ return txHash;
143
+ });
144
+ }
145
+ deployScript(scriptBinBytes, privateKey) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ const signer = this.buildSigner(privateKey);
148
+ const signerSecp256k1Address = yield signer.getAddressObjSecp256k1();
149
+ const tx = core_1.ccc.Transaction.from({
150
+ outputs: [
151
+ {
152
+ lock: signerSecp256k1Address.script,
153
+ },
154
+ ],
155
+ outputsData: [scriptBinBytes],
156
+ });
157
+ yield tx.completeInputsByCapacity(signer);
158
+ yield tx.completeFeeBy(signer, this.feeRate);
159
+ const txHash = yield signer.sendTransaction(tx);
160
+ return { txHash, tx, scriptOutputCellIndex: 0, isTypeId: false };
161
+ });
162
+ }
163
+ deployNewTypeIDScript(scriptBinBytes, privateKey) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const signer = this.buildSigner(privateKey);
166
+ const signerSecp256k1Address = yield signer.getAddressObjSecp256k1();
167
+ const typeIdTx = core_1.ccc.Transaction.from({
168
+ outputs: [
169
+ {
170
+ lock: signerSecp256k1Address.script,
171
+ type: yield core_1.ccc.Script.fromKnownScript(this.client, core_1.ccc.KnownScript.TypeId, '00'.repeat(32)),
172
+ },
173
+ ],
174
+ outputsData: [scriptBinBytes],
175
+ });
176
+ yield typeIdTx.completeInputsByCapacity(signer);
177
+ if (!typeIdTx.outputs[0].type) {
178
+ throw new Error('Unexpected disappeared output');
179
+ }
180
+ typeIdTx.outputs[0].type.args = core_1.ccc.hashTypeId(typeIdTx.inputs[0], 0);
181
+ yield typeIdTx.completeFeeBy(signer, this.feeRate);
182
+ const txHash = yield signer.sendTransaction(typeIdTx);
183
+ return { txHash, tx: typeIdTx, scriptOutputCellIndex: 0, isTypeId: true, typeId: typeIdTx.outputs[0].type };
184
+ });
185
+ }
186
+ upgradeTypeIdScript(scriptName, newScriptBinBytes, privateKey) {
187
+ var _a;
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ const deploymentReceipt = migration_1.Migration.find(scriptName, this.network);
190
+ if (deploymentReceipt == null)
191
+ throw new Error("no migration file, can't be updated.");
192
+ const outpoint = {
193
+ txHash: deploymentReceipt.cellRecipes[0].txHash,
194
+ index: deploymentReceipt.cellRecipes[0].index,
195
+ };
196
+ const typeId = deploymentReceipt.cellRecipes[0].typeId;
197
+ if (typeId == null)
198
+ throw new Error("type id in migration file is null, can't be updated.");
199
+ const cell = yield this.client.getCell(outpoint);
200
+ if (cell == null) {
201
+ throw new Error('type id cell not found!');
202
+ }
203
+ const typeIdArgs = (_a = cell.cellOutput.type) === null || _a === void 0 ? void 0 : _a.args;
204
+ if (typeIdArgs == null) {
205
+ throw new Error("type id args is null, can't be updated");
206
+ }
207
+ const typeIdFromLiveCell = core_1.ccc.Script.from(cell.cellOutput.type).hash();
208
+ if (typeId !== typeIdFromLiveCell) {
209
+ throw new Error(`type id not matched! migration file type id: ${typeId}, live cell type id: ${typeIdFromLiveCell}`);
210
+ }
211
+ const cellInput = core_1.ccc.CellInput.from({ previousOutput: cell.outPoint, since: 0 });
212
+ const signer = this.buildSigner(privateKey);
213
+ const signerSecp256k1Address = yield signer.getAddressObjSecp256k1();
214
+ const typeIdTx = core_1.ccc.Transaction.from({
215
+ inputs: [cellInput],
216
+ outputs: [
217
+ {
218
+ lock: signerSecp256k1Address.script,
219
+ type: yield core_1.ccc.Script.fromKnownScript(this.client, core_1.ccc.KnownScript.TypeId, '00'.repeat(32)),
220
+ },
221
+ ],
222
+ outputsData: [newScriptBinBytes],
223
+ });
224
+ yield typeIdTx.completeInputsByCapacity(signer);
225
+ if (!typeIdTx.outputs[0].type) {
226
+ throw new Error('Unexpected disappeared output');
227
+ }
228
+ typeIdTx.outputs[0].type.args = typeIdArgs;
229
+ yield typeIdTx.completeFeeBy(signer, this.feeRate);
230
+ const txHash = yield signer.sendTransaction(typeIdTx);
231
+ return { txHash, tx: typeIdTx, scriptOutputCellIndex: 0, isTypeId: true, typeId: typeIdTx.outputs[0].type };
232
+ });
233
+ }
234
+ }
235
+ exports.CKB = CKB;
236
+ function waitFor(query, timeout, interval) {
237
+ return __awaiter(this, void 0, void 0, function* () {
238
+ const startTime = Date.now();
239
+ while (true) {
240
+ if (Date.now() - startTime > timeout) {
241
+ throw new Error('Operation timed out');
242
+ }
243
+ try {
244
+ const result = yield query();
245
+ if (result)
246
+ break;
247
+ }
248
+ catch (error) {
249
+ console.debug(error.message);
250
+ }
251
+ yield new Promise((resolve) => setTimeout(resolve, interval));
252
+ }
253
+ });
254
+ }
@@ -0,0 +1,17 @@
1
+ export declare const networks: {
2
+ devnet: {
3
+ addr_prefix: string;
4
+ rpc_url: string;
5
+ proxy_rpc_url: string;
6
+ };
7
+ testnet: {
8
+ addr_prefix: string;
9
+ rpc_url: string;
10
+ proxy_rpc_url: string;
11
+ };
12
+ mainnet: {
13
+ addr_prefix: string;
14
+ rpc_url: string;
15
+ proxy_rpc_url: string;
16
+ };
17
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.networks = void 0;
4
+ const setting_1 = require("../cfg/setting");
5
+ const config = (0, setting_1.readSettings)();
6
+ exports.networks = {
7
+ devnet: {
8
+ addr_prefix: 'ckt',
9
+ rpc_url: config.devnet.rpcUrl,
10
+ proxy_rpc_url: `http://127.0.0.1:${config.rpc.proxyPort}`,
11
+ },
12
+ testnet: {
13
+ addr_prefix: 'ckt',
14
+ rpc_url: config.testnet.rpcUrl,
15
+ proxy_rpc_url: `http://127.0.0.1:${config.rpc.proxyPort}`,
16
+ },
17
+ mainnet: {
18
+ addr_prefix: 'ckb',
19
+ rpc_url: config.mainnet.rpcUrl,
20
+ proxy_rpc_url: `http://127.0.0.1:${config.rpc.proxyPort}`,
21
+ },
22
+ };
@@ -57,10 +57,9 @@ class MoleculecES {
57
57
  static downloadAndSaveMoleculeES(version, tempFilePath) {
58
58
  return __awaiter(this, void 0, void 0, function* () {
59
59
  const downloadURL = MoleculecES.buildDownloadUrl(version);
60
- const response = yield request_1.Request.get(downloadURL, {
61
- responseType: 'arraybuffer',
62
- });
63
- fs_1.default.writeFileSync(tempFilePath, response.data);
60
+ const response = yield request_1.Request.send(downloadURL);
61
+ const arrayBuffer = yield response.arrayBuffer();
62
+ fs_1.default.writeFileSync(tempFilePath, Buffer.from(arrayBuffer));
64
63
  });
65
64
  }
66
65
  static buildDownloadUrl(version) {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import http from 'http';
3
- import { Network } from '../util/type';
3
+ import { Network } from '../type/base';
4
4
  export declare function createRPCProxy(network: Network, targetRpcUrl: string, port: number): {
5
5
  server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
6
6
  network: Network;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createRPCProxy = void 0;
7
7
  const http_proxy_1 = __importDefault(require("http-proxy"));
8
8
  const http_1 = __importDefault(require("http"));
9
- const type_1 = require("../util/type");
9
+ const base_1 = require("../type/base");
10
10
  const fs_1 = __importDefault(require("fs"));
11
11
  const setting_1 = require("../cfg/setting");
12
12
  const path_1 = __importDefault(require("path"));
@@ -38,7 +38,7 @@ function createRPCProxy(network, targetRpcUrl, port) {
38
38
  if (method === 'send_transaction') {
39
39
  const tx = params[0];
40
40
  // todo: record tx
41
- if (network === type_1.Network.devnet) {
41
+ if (network === base_1.Network.devnet) {
42
42
  const cccTx = cccA.JsonRpcTransformers.transactionTo(tx);
43
43
  const txHash = cccTx.hash();
44
44
  const settings = (0, setting_1.readSettings)();
@@ -7,3 +7,5 @@ export interface NetworkOption {
7
7
  network: Network;
8
8
  }
9
9
  export type H256 = string;
10
+ export type HexString = string;
11
+ export type HexNumber = string;
@@ -1,8 +1,8 @@
1
- import axios, { AxiosProxyConfig, AxiosRequestConfig } from 'axios';
1
+ import { ProxyConfig } from '../cfg/setting';
2
+ import fetch, { RequestInit } from 'node-fetch';
2
3
  export declare class Request {
3
- static proxy: axios.AxiosProxyConfig | undefined;
4
- static send(_config: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
5
- static get(url: string, _config?: AxiosRequestConfig): Promise<axios.AxiosResponse<any, any>>;
6
- static parseProxyUrl(url: string): AxiosProxyConfig;
7
- static proxyConfigToUrl(proxy: AxiosProxyConfig): string;
4
+ static proxy: ProxyConfig | undefined;
5
+ static send(url: string, options?: RequestInit): Promise<fetch.Response>;
6
+ static parseProxyUrl(url: string): ProxyConfig;
7
+ static proxyConfigToUrl(proxy: ProxyConfig): string;
8
8
  }
@@ -13,20 +13,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Request = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
16
  const setting_1 = require("../cfg/setting");
17
+ const https_proxy_agent_1 = require("https-proxy-agent");
18
+ const node_fetch_1 = __importDefault(require("node-fetch"));
18
19
  class Request {
19
- static send(_config) {
20
+ static send(url, options = {}) {
20
21
  return __awaiter(this, void 0, void 0, function* () {
21
- const config = this.proxy ? Object.assign({ proxy: this.proxy }, _config) : _config;
22
- return yield (0, axios_1.default)(config);
23
- });
24
- }
25
- static get(url, _config) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const config = this.proxy ? Object.assign({ proxy: this.proxy }, _config) : _config;
28
- console.log(config);
29
- return yield axios_1.default.get(url, config);
22
+ const agent = this.proxy ? new https_proxy_agent_1.HttpsProxyAgent(this.proxyConfigToUrl(this.proxy)) : undefined;
23
+ const opt = Object.assign({ agent }, options);
24
+ try {
25
+ const response = yield (0, node_fetch_1.default)(url, opt);
26
+ if (!response.ok) {
27
+ throw new Error(`HTTP error! Status: ${response.status}, URL: ${response.url}`);
28
+ }
29
+ return yield response;
30
+ }
31
+ catch (error) {
32
+ throw new Error(`fetch error! ${error.message}`);
33
+ }
30
34
  });
31
35
  }
32
36
  static parseProxyUrl(url) {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.isValidVersion = exports.validateNetworkOpt = exports.isValidNetworkString = exports.validateExecDappEnvironment = exports.validateTypescriptWorkspace = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
- const type_1 = require("./type");
9
+ const base_1 = require("../type/base");
10
10
  function validateTypescriptWorkspace() {
11
11
  const cwd = process.cwd();
12
12
  // Check if package.json exists
@@ -50,7 +50,7 @@ function validateNetworkOpt(network) {
50
50
  if (!isValidNetworkString(network)) {
51
51
  throw new Error('invalid network option, ' + network);
52
52
  }
53
- if (network === type_1.Network.mainnet) {
53
+ if (network === base_1.Network.mainnet) {
54
54
  console.log('Mainnet not support yet. Please use CKB-CLI to operate on mainnet for better security. Check https://github.com/nervosnetwork/ckb-cli');
55
55
  process.exit(1);
56
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.3.0-rc3",
3
+ "version": "0.3.0-rc5",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",
@@ -47,6 +47,7 @@
47
47
  "devDependencies": {
48
48
  "@types/adm-zip": "^0.5.5",
49
49
  "@types/node": "^20.11.19",
50
+ "@types/node-fetch": "^2.6.11",
50
51
  "@types/semver": "^7.5.7",
51
52
  "@types/tar": "^6.1.11",
52
53
  "@typescript-eslint/eslint-plugin": "^7.0.2",
@@ -59,17 +60,17 @@
59
60
  "typescript": "^5.3.3"
60
61
  },
61
62
  "dependencies": {
62
- "@ckb-ccc/core": "^0.0.11-alpha.3",
63
- "@ckb-lumos/lumos": "0.23.0",
63
+ "@ckb-ccc/core": "^0.0.16-alpha.3",
64
64
  "@iarna/toml": "^2.2.5",
65
65
  "@inquirer/prompts": "^4.1.0",
66
66
  "@types/http-proxy": "^1.17.15",
67
67
  "adm-zip": "^0.5.10",
68
- "axios": "^1.6.7",
69
68
  "child_process": "^1.0.2",
70
69
  "ckb-transaction-dumper": "^0.4.0",
71
70
  "commander": "^12.0.0",
72
71
  "http-proxy": "^1.18.1",
72
+ "https-proxy-agent": "^7.0.5",
73
+ "node-fetch": "2",
73
74
  "semver": "^7.6.0",
74
75
  "tar": "^6.2.1"
75
76
  }
@@ -1,141 +0,0 @@
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
- XUDT: {
71
- CODE_HASH: string;
72
- HASH_TYPE: "type";
73
- TX_HASH: string;
74
- INDEX: string;
75
- DEP_TYPE: "code";
76
- };
77
- };
78
- } | {
79
- PREFIX: string;
80
- SCRIPTS: {
81
- SECP256K1_BLAKE160: {
82
- CODE_HASH: string;
83
- HASH_TYPE: "type";
84
- TX_HASH: string;
85
- INDEX: string;
86
- DEP_TYPE: "depGroup";
87
- SHORT_ID: number;
88
- };
89
- SECP256K1_BLAKE160_MULTISIG: {
90
- CODE_HASH: string;
91
- HASH_TYPE: "type";
92
- TX_HASH: string;
93
- INDEX: string;
94
- DEP_TYPE: "depGroup";
95
- SHORT_ID: number;
96
- };
97
- DAO: {
98
- CODE_HASH: string;
99
- HASH_TYPE: "type";
100
- TX_HASH: string;
101
- INDEX: string;
102
- DEP_TYPE: "code";
103
- };
104
- SUDT: {
105
- CODE_HASH: string;
106
- HASH_TYPE: "type";
107
- TX_HASH: string;
108
- INDEX: string;
109
- DEP_TYPE: "code";
110
- };
111
- ANYONE_CAN_PAY: {
112
- CODE_HASH: string;
113
- HASH_TYPE: "type";
114
- TX_HASH: string;
115
- INDEX: string;
116
- DEP_TYPE: "depGroup";
117
- SHORT_ID: number;
118
- };
119
- OMNILOCK: {
120
- CODE_HASH: string;
121
- HASH_TYPE: "type";
122
- TX_HASH: string;
123
- INDEX: string;
124
- DEP_TYPE: "code";
125
- };
126
- XUDT: {
127
- CODE_HASH: string;
128
- HASH_TYPE: "data1";
129
- TX_HASH: string;
130
- INDEX: string;
131
- DEP_TYPE: "code";
132
- };
133
- };
134
- };
135
- initializedLumosConfig(): void;
136
- capacityOf(address: string, lumosConfig: config.Config): Promise<BI>;
137
- transfer(options: Options, lumosConfig: config.Config): Promise<string>;
138
- transferAll(privateKey: string, toAddress: string, lumosConfig: config.Config): Promise<string>;
139
- }
140
- export declare function readPredefinedDevnetLumosConfig(): config.Config;
141
- export {};