@offckb/cli 0.3.0-rc4 → 0.3.0-rc6
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/README.md +22 -21
- package/dist/cfg/setting.d.ts +11 -2
- package/dist/cfg/setting.js +2 -2
- package/dist/cli.js +19 -6
- package/dist/cmd/balance.d.ts +1 -1
- package/dist/cmd/balance.js +6 -8
- package/dist/cmd/debug.d.ts +1 -1
- package/dist/cmd/debug.js +5 -5
- package/dist/cmd/deploy.d.ts +2 -1
- package/dist/cmd/deploy.js +4 -3
- package/dist/cmd/deposit.d.ts +3 -2
- package/dist/cmd/deposit.js +30 -31
- package/dist/cmd/list-hashes.d.ts +1 -1
- package/dist/cmd/my-scripts.d.ts +1 -1
- package/dist/cmd/my-scripts.js +2 -2
- package/dist/cmd/node.js +2 -2
- package/dist/cmd/proxy-rpc.d.ts +1 -1
- package/dist/cmd/proxy-rpc.js +4 -4
- package/dist/cmd/system-scripts.d.ts +70 -2
- package/dist/cmd/system-scripts.js +4 -0
- package/dist/cmd/transfer-all.d.ts +6 -0
- package/dist/cmd/transfer-all.js +38 -0
- package/dist/cmd/transfer.d.ts +3 -2
- package/dist/cmd/transfer.js +9 -11
- package/dist/deploy/index.d.ts +2 -2
- package/dist/deploy/index.js +3 -3
- package/dist/deploy/migration.d.ts +2 -2
- package/dist/deploy/migration.js +5 -5
- package/dist/deploy/toml.d.ts +7 -3
- package/dist/deploy/util.d.ts +1 -1
- package/dist/deploy/util.js +4 -4
- package/dist/node/install.js +3 -4
- package/dist/scripts/gen.js +4 -4
- package/dist/scripts/util.d.ts +1 -1
- package/dist/sdk/ckb.d.ts +17 -4
- package/dist/sdk/ckb.js +79 -5
- package/dist/template/option.js +17 -5
- package/dist/tools/moleculec-es.js +3 -4
- package/dist/tools/rpc-proxy.d.ts +1 -2
- package/dist/tools/rpc-proxy.js +32 -45
- package/dist/{util/type.d.ts → type/base.d.ts} +2 -0
- package/dist/util/request.d.ts +6 -6
- package/dist/util/request.js +15 -11
- package/dist/util/validator.js +2 -2
- package/package.json +5 -4
- package/dist/template/option.json +0 -16
- package/dist/util/ckb.d.ts +0 -141
- package/dist/util/ckb.js +0 -312
- /package/dist/{util/type.js → type/base.js} +0 -0
package/dist/cmd/transfer.js
CHANGED
|
@@ -10,27 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.transfer = void 0;
|
|
13
|
-
const ckb_1 = require("../
|
|
14
|
-
const
|
|
13
|
+
const ckb_1 = require("../sdk/ckb");
|
|
14
|
+
const base_1 = require("../type/base");
|
|
15
15
|
const link_1 = require("../util/link");
|
|
16
16
|
const validator_1 = require("../util/validator");
|
|
17
|
-
function transfer(toAddress,
|
|
17
|
+
function transfer(toAddress, amountInCKB, opt = { network: base_1.Network.devnet, proxyRpc: false }) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
const network = opt.network;
|
|
20
20
|
(0, validator_1.validateNetworkOpt)(network);
|
|
21
21
|
if (opt.privkey == null) {
|
|
22
22
|
throw new Error('--privkey is required!');
|
|
23
23
|
}
|
|
24
|
+
const isEnableProxyRpc = opt.proxyRpc;
|
|
24
25
|
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);
|
|
26
|
+
const ckb = new ckb_1.CKB({ network, isEnableProxyRpc });
|
|
28
27
|
const txHash = yield ckb.transfer({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}, lumosConfig);
|
|
28
|
+
toAddress,
|
|
29
|
+
amountInCKB,
|
|
30
|
+
privateKey,
|
|
31
|
+
});
|
|
34
32
|
if (network === 'testnet') {
|
|
35
33
|
console.log(`Successfully transfer, check ${(0, link_1.buildTestnetTxLink)(txHash)} for details.`);
|
|
36
34
|
return;
|
package/dist/deploy/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DeploymentOptions } from '../deploy/toml';
|
|
2
2
|
import { DeploymentRecipe } from '../deploy/migration';
|
|
3
|
-
import {
|
|
4
|
-
import { Network } from '../util/type';
|
|
3
|
+
import { Network } from '../type/base';
|
|
5
4
|
import { CKB } from '../sdk/ckb';
|
|
5
|
+
import { HexString } from '../type/base';
|
|
6
6
|
export type DeployBinaryReturnType = ReturnType<typeof deployBinary>;
|
|
7
7
|
export type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
|
|
8
8
|
export type DeployedInterfaceType = UnwrapPromise<DeployBinaryReturnType>;
|
package/dist/deploy/index.js
CHANGED
|
@@ -15,12 +15,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.deployBinary = exports.deployBinaries = exports.recordDeployResult = exports.getToDeployBinsPath = void 0;
|
|
16
16
|
const toml_1 = require("../deploy/toml");
|
|
17
17
|
const migration_1 = require("../deploy/migration");
|
|
18
|
-
const utils_1 = require("@ckb-lumos/lumos/utils");
|
|
19
18
|
const gen_1 = require("../scripts/gen");
|
|
20
19
|
const offckb_config_1 = require("../template/offckb-config");
|
|
21
20
|
const fs_1 = require("../util/fs");
|
|
22
21
|
const path_1 = __importDefault(require("path"));
|
|
23
22
|
const fs_2 = __importDefault(require("fs"));
|
|
23
|
+
const core_1 = require("@ckb-ccc/core");
|
|
24
24
|
function getToDeployBinsPath() {
|
|
25
25
|
const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
|
|
26
26
|
const fileContent = fs_2.default.readFileSync(userOffCKBConfigPath, 'utf-8');
|
|
@@ -98,7 +98,7 @@ function deployBinary(binPath, privateKey, enableTypeId, ckb) {
|
|
|
98
98
|
if (enableTypeId && typeIdScript == null) {
|
|
99
99
|
throw new Error('type id script is null while enableTypeId is true.');
|
|
100
100
|
}
|
|
101
|
-
const typeIdScriptHash = enableTypeId ?
|
|
101
|
+
const typeIdScriptHash = enableTypeId ? core_1.ccc.Script.from(typeIdScript).hash() : undefined;
|
|
102
102
|
// todo: handle multiple cell recipes?
|
|
103
103
|
return {
|
|
104
104
|
deploymentOptions: {
|
|
@@ -114,7 +114,7 @@ function deployBinary(binPath, privateKey, enableTypeId, ckb) {
|
|
|
114
114
|
txHash,
|
|
115
115
|
index: '0x' + index.toString(16),
|
|
116
116
|
occupiedCapacity,
|
|
117
|
-
dataHash:
|
|
117
|
+
dataHash: core_1.ccc.hashCkb(tx.outputsData[+index]),
|
|
118
118
|
typeId: typeIdScriptHash,
|
|
119
119
|
},
|
|
120
120
|
],
|
package/dist/deploy/migration.js
CHANGED
|
@@ -27,25 +27,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.deploymentRecipeFromJson = exports.deploymentRecipeToJson = exports.getNewestMigrationFile = exports.getMigrationFolderPath = exports.getFormattedMigrationDate = exports.readDeploymentMigrationFile = exports.generateDeploymentMigrationFile = exports.Migration = void 0;
|
|
30
|
-
const
|
|
30
|
+
const base_1 = require("../type/base");
|
|
31
31
|
const path_1 = __importStar(require("path"));
|
|
32
32
|
const fs_1 = __importDefault(require("fs"));
|
|
33
33
|
const util_1 = require("./util");
|
|
34
34
|
class Migration {
|
|
35
|
-
static find(scriptName, network =
|
|
35
|
+
static find(scriptName, network = base_1.Network.devnet) {
|
|
36
36
|
const filePath = getMigrationFolderPath(scriptName, network);
|
|
37
37
|
const migrationFile = getNewestMigrationFile(filePath);
|
|
38
38
|
if (migrationFile == null)
|
|
39
39
|
return null;
|
|
40
40
|
return readDeploymentMigrationFile(migrationFile);
|
|
41
41
|
}
|
|
42
|
-
static isDeployed(scriptName, network =
|
|
42
|
+
static isDeployed(scriptName, network = base_1.Network.devnet) {
|
|
43
43
|
const deploymentReceipt = Migration.find(scriptName, network);
|
|
44
44
|
if (deploymentReceipt == null)
|
|
45
45
|
return false;
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
|
-
static isDeployedWithTypeId(scriptName, network =
|
|
48
|
+
static isDeployedWithTypeId(scriptName, network = base_1.Network.devnet) {
|
|
49
49
|
const isDeployed = this.isDeployed(scriptName, network);
|
|
50
50
|
if (isDeployed === false)
|
|
51
51
|
return false;
|
|
@@ -57,7 +57,7 @@ class Migration {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
exports.Migration = Migration;
|
|
60
|
-
function generateDeploymentMigrationFile(name, deploymentRecipe, network =
|
|
60
|
+
function generateDeploymentMigrationFile(name, deploymentRecipe, network = base_1.Network.devnet) {
|
|
61
61
|
const cellRecipes = deploymentRecipe.cellRecipes;
|
|
62
62
|
const depGroupRecipes = deploymentRecipe.depGroupRecipes;
|
|
63
63
|
const jsonString = JSON.stringify(deploymentRecipeToJson({ cellRecipes, depGroupRecipes }), null, 2);
|
package/dist/deploy/toml.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Network } from '../util/type';
|
|
1
|
+
import { Network } from '../type/base';
|
|
3
2
|
import { HashType } from '@ckb-ccc/core';
|
|
3
|
+
import { HexString } from '../type/base';
|
|
4
4
|
export interface DeploymentOptions {
|
|
5
5
|
name: string;
|
|
6
6
|
binFilePath: string;
|
|
7
7
|
enableTypeId: boolean;
|
|
8
|
-
lockScript:
|
|
8
|
+
lockScript: {
|
|
9
|
+
codeHash: HexString;
|
|
10
|
+
hashType: HashType;
|
|
11
|
+
args: HexString;
|
|
12
|
+
};
|
|
9
13
|
}
|
|
10
14
|
export interface DeploymentToml {
|
|
11
15
|
cells: {
|
package/dist/deploy/util.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Network } from '../
|
|
1
|
+
import { Network } from '../type/base';
|
|
2
2
|
export declare function getContractsPath(network: Network): string;
|
package/dist/deploy/util.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getContractsPath = void 0;
|
|
4
4
|
const setting_1 = require("../cfg/setting");
|
|
5
|
-
const
|
|
5
|
+
const base_1 = require("../type/base");
|
|
6
6
|
function getContractsPath(network) {
|
|
7
7
|
const settings = (0, setting_1.readSettings)();
|
|
8
|
-
if (network ===
|
|
8
|
+
if (network === base_1.Network.devnet) {
|
|
9
9
|
return settings.devnet.contractsPath;
|
|
10
10
|
}
|
|
11
|
-
if (network ===
|
|
11
|
+
if (network === base_1.Network.testnet) {
|
|
12
12
|
return settings.testnet.contractsPath;
|
|
13
13
|
}
|
|
14
|
-
if (network ===
|
|
14
|
+
if (network === base_1.Network.mainnet) {
|
|
15
15
|
return settings.mainnet.contractsPath;
|
|
16
16
|
}
|
|
17
17
|
throw new Error(`invalid network ${network}`);
|
package/dist/node/install.js
CHANGED
|
@@ -97,10 +97,9 @@ exports.downloadCKBBinaryAndUnzip = downloadCKBBinaryAndUnzip;
|
|
|
97
97
|
function downloadAndSaveCKBBinary(version, tempFilePath) {
|
|
98
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
99
|
const downloadURL = buildDownloadUrl(version);
|
|
100
|
-
const response = yield request_1.Request.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
fs.writeFileSync(tempFilePath, response.data);
|
|
100
|
+
const response = yield request_1.Request.send(downloadURL);
|
|
101
|
+
const arrayBuffer = yield response.arrayBuffer();
|
|
102
|
+
fs.writeFileSync(tempFilePath, Buffer.from(arrayBuffer));
|
|
104
103
|
});
|
|
105
104
|
}
|
|
106
105
|
exports.downloadAndSaveCKBBinary = downloadAndSaveCKBBinary;
|
package/dist/scripts/gen.js
CHANGED
|
@@ -31,7 +31,7 @@ const fs = __importStar(require("fs"));
|
|
|
31
31
|
const public_1 = __importDefault(require("./public"));
|
|
32
32
|
const system_scripts_1 = require("../cmd/system-scripts");
|
|
33
33
|
const path_1 = __importDefault(require("path"));
|
|
34
|
-
const
|
|
34
|
+
const base_1 = require("../type/base");
|
|
35
35
|
const util_1 = require("./util");
|
|
36
36
|
function genSystemScripts() {
|
|
37
37
|
const devnetScripts = (0, system_scripts_1.getSystemScriptsFromListHashes)();
|
|
@@ -54,9 +54,9 @@ function genSystemScriptsJsonFile(filePath) {
|
|
|
54
54
|
exports.genSystemScriptsJsonFile = genSystemScriptsJsonFile;
|
|
55
55
|
function genMyScripts() {
|
|
56
56
|
const networkMyScripts = {
|
|
57
|
-
devnet: (0, util_1.readUserDeployedScriptsInfo)(
|
|
58
|
-
testnet: (0, util_1.readUserDeployedScriptsInfo)(
|
|
59
|
-
mainnet: (0, util_1.readUserDeployedScriptsInfo)(
|
|
57
|
+
devnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.devnet),
|
|
58
|
+
testnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.testnet),
|
|
59
|
+
mainnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.mainnet),
|
|
60
60
|
};
|
|
61
61
|
return networkMyScripts;
|
|
62
62
|
}
|
package/dist/scripts/util.d.ts
CHANGED
package/dist/sdk/ckb.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ccc, Script } from '@ckb-ccc/core';
|
|
2
|
-
import { Network } from '../
|
|
3
|
-
import { HexString } from '@ckb-lumos/lumos';
|
|
2
|
+
import { Network, HexNumber, HexString } from '../type/base';
|
|
4
3
|
export declare class CKBProps {
|
|
5
4
|
network?: Network;
|
|
5
|
+
feeRate?: number;
|
|
6
6
|
isEnableProxyRpc?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export interface DeploymentResult {
|
|
@@ -12,12 +12,25 @@ export interface DeploymentResult {
|
|
|
12
12
|
isTypeId: boolean;
|
|
13
13
|
typeId?: Script;
|
|
14
14
|
}
|
|
15
|
+
export interface TransferOption {
|
|
16
|
+
privateKey: HexString;
|
|
17
|
+
toAddress: string;
|
|
18
|
+
amountInCKB: HexNumber;
|
|
19
|
+
}
|
|
20
|
+
export type TransferAllOption = Pick<TransferOption, 'privateKey' | 'toAddress'>;
|
|
15
21
|
export declare class CKB {
|
|
16
22
|
network: Network;
|
|
23
|
+
feeRate: number;
|
|
24
|
+
isEnableProxyRpc: boolean;
|
|
17
25
|
private client;
|
|
18
|
-
constructor({ network, isEnableProxyRpc }: CKBProps);
|
|
19
|
-
|
|
26
|
+
constructor({ network, feeRate, isEnableProxyRpc }: CKBProps);
|
|
27
|
+
buildSigner(privateKey: HexString): ccc.SignerCkbPrivateKey;
|
|
28
|
+
buildSecp256k1Address(privateKey: HexString): Promise<string>;
|
|
20
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>;
|
|
21
34
|
deployScript(scriptBinBytes: Uint8Array, privateKey: string): Promise<DeploymentResult>;
|
|
22
35
|
deployNewTypeIDScript(scriptBinBytes: Uint8Array, privateKey: string): Promise<DeploymentResult>;
|
|
23
36
|
upgradeTypeIdScript(scriptName: string, newScriptBinBytes: Uint8Array, privateKey: HexString): Promise<DeploymentResult>;
|
package/dist/sdk/ckb.js
CHANGED
|
@@ -13,20 +13,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.CKB = exports.CKBProps = void 0;
|
|
15
15
|
const core_1 = require("@ckb-ccc/core");
|
|
16
|
-
const type_1 = require("../util/type");
|
|
17
16
|
const validator_1 = require("../util/validator");
|
|
18
17
|
const network_1 = require("./network");
|
|
19
18
|
const private_1 = require("../scripts/private");
|
|
20
19
|
const migration_1 = require("../deploy/migration");
|
|
20
|
+
const base_1 = require("../type/base");
|
|
21
21
|
class CKBProps {
|
|
22
22
|
}
|
|
23
23
|
exports.CKBProps = CKBProps;
|
|
24
24
|
class CKB {
|
|
25
|
-
constructor({ network =
|
|
25
|
+
constructor({ network = base_1.Network.devnet, feeRate = 1000, isEnableProxyRpc = false }) {
|
|
26
26
|
if (!(0, validator_1.isValidNetworkString)(network)) {
|
|
27
27
|
throw new Error('invalid network option');
|
|
28
28
|
}
|
|
29
29
|
this.network = network;
|
|
30
|
+
this.feeRate = feeRate;
|
|
31
|
+
this.isEnableProxyRpc = isEnableProxyRpc;
|
|
30
32
|
if (isEnableProxyRpc === true) {
|
|
31
33
|
this.client =
|
|
32
34
|
network === 'mainnet'
|
|
@@ -54,6 +56,13 @@ class CKB {
|
|
|
54
56
|
const signer = new core_1.ccc.SignerCkbPrivateKey(this.client, privateKey);
|
|
55
57
|
return signer;
|
|
56
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
|
+
}
|
|
57
66
|
waitForTxConfirm(txHash, timeout = 60000) {
|
|
58
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
68
|
const query = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -68,6 +77,71 @@ class CKB {
|
|
|
68
77
|
return waitFor(query, timeout, 5000);
|
|
69
78
|
});
|
|
70
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
|
+
}
|
|
71
145
|
deployScript(scriptBinBytes, privateKey) {
|
|
72
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
147
|
const signer = this.buildSigner(privateKey);
|
|
@@ -81,7 +155,7 @@ class CKB {
|
|
|
81
155
|
outputsData: [scriptBinBytes],
|
|
82
156
|
});
|
|
83
157
|
yield tx.completeInputsByCapacity(signer);
|
|
84
|
-
yield tx.completeFeeBy(signer,
|
|
158
|
+
yield tx.completeFeeBy(signer, this.feeRate);
|
|
85
159
|
const txHash = yield signer.sendTransaction(tx);
|
|
86
160
|
return { txHash, tx, scriptOutputCellIndex: 0, isTypeId: false };
|
|
87
161
|
});
|
|
@@ -104,7 +178,7 @@ class CKB {
|
|
|
104
178
|
throw new Error('Unexpected disappeared output');
|
|
105
179
|
}
|
|
106
180
|
typeIdTx.outputs[0].type.args = core_1.ccc.hashTypeId(typeIdTx.inputs[0], 0);
|
|
107
|
-
yield typeIdTx.completeFeeBy(signer,
|
|
181
|
+
yield typeIdTx.completeFeeBy(signer, this.feeRate);
|
|
108
182
|
const txHash = yield signer.sendTransaction(typeIdTx);
|
|
109
183
|
return { txHash, tx: typeIdTx, scriptOutputCellIndex: 0, isTypeId: true, typeId: typeIdTx.outputs[0].type };
|
|
110
184
|
});
|
|
@@ -152,7 +226,7 @@ class CKB {
|
|
|
152
226
|
throw new Error('Unexpected disappeared output');
|
|
153
227
|
}
|
|
154
228
|
typeIdTx.outputs[0].type.args = typeIdArgs;
|
|
155
|
-
yield typeIdTx.completeFeeBy(signer,
|
|
229
|
+
yield typeIdTx.completeFeeBy(signer, this.feeRate);
|
|
156
230
|
const txHash = yield signer.sendTransaction(typeIdTx);
|
|
157
231
|
return { txHash, tx: typeIdTx, scriptOutputCellIndex: 0, isTypeId: true, typeId: typeIdTx.outputs[0].type };
|
|
158
232
|
});
|
package/dist/template/option.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.loadBareTemplateOpts = void 0;
|
|
7
|
-
const
|
|
4
|
+
const templates = [
|
|
5
|
+
{
|
|
6
|
+
name: 'Remix-Vite Bare Templates',
|
|
7
|
+
value: 'remix-vite-template',
|
|
8
|
+
description: 'A full-stack template with Remix-vite and ckb-script-templates',
|
|
9
|
+
tag: ['remix', 'vite', 'tailwindcss', 'ckb-script-templates', 'typescript', 'rust'],
|
|
10
|
+
author: 'retric@cryptape.com',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'Next.js Bare Templates',
|
|
14
|
+
value: 'next-js-template',
|
|
15
|
+
description: 'A full-stack template with Next.js framework and ckb-script-templates',
|
|
16
|
+
tag: ['next.js', 'tailwindcss', 'ckb-script-templates', 'typescript', 'rust'],
|
|
17
|
+
author: 'retric@cryptape.com',
|
|
18
|
+
},
|
|
19
|
+
];
|
|
8
20
|
function loadBareTemplateOpts() {
|
|
9
|
-
return
|
|
21
|
+
return templates;
|
|
10
22
|
}
|
|
11
23
|
exports.loadBareTemplateOpts = loadBareTemplateOpts;
|
|
@@ -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.
|
|
61
|
-
|
|
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,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import http from 'http';
|
|
3
|
-
import { Network } from '../
|
|
3
|
+
import { Network } from '../type/base';
|
|
4
4
|
export declare function createRPCProxy(network: Network, targetRpcUrl: string, port: number): {
|
|
5
|
-
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
6
5
|
network: Network;
|
|
7
6
|
start: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
8
7
|
stop: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
package/dist/tools/rpc-proxy.js
CHANGED
|
@@ -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
|
|
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"));
|
|
@@ -16,6 +16,37 @@ function createRPCProxy(network, targetRpcUrl, port) {
|
|
|
16
16
|
const proxy = http_proxy_1.default.createProxyServer({
|
|
17
17
|
target: targetRpcUrl, // Target RPC server
|
|
18
18
|
});
|
|
19
|
+
proxy.on('proxyReq', (_, req) => {
|
|
20
|
+
let reqData = '';
|
|
21
|
+
req.on('data', (chunk) => {
|
|
22
|
+
reqData += chunk;
|
|
23
|
+
});
|
|
24
|
+
req.on('end', () => {
|
|
25
|
+
try {
|
|
26
|
+
const jsonRpcContent = JSON.parse(reqData);
|
|
27
|
+
const method = jsonRpcContent.method;
|
|
28
|
+
const params = jsonRpcContent.params;
|
|
29
|
+
console.debug('RPC Req: ', method);
|
|
30
|
+
if (method === 'send_transaction') {
|
|
31
|
+
const tx = params[0];
|
|
32
|
+
// todo: record tx
|
|
33
|
+
if (network === base_1.Network.devnet) {
|
|
34
|
+
const cccTx = cccA.JsonRpcTransformers.transactionTo(tx);
|
|
35
|
+
const txHash = cccTx.hash();
|
|
36
|
+
const settings = (0, setting_1.readSettings)();
|
|
37
|
+
if (!fs_1.default.existsSync(settings.devnet.transactionsPath)) {
|
|
38
|
+
fs_1.default.mkdirSync(settings.devnet.transactionsPath);
|
|
39
|
+
}
|
|
40
|
+
const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
|
|
41
|
+
fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.error('Error parsing JSON-RPC content:', err);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
19
50
|
const server = http_1.default.createServer((req, res) => {
|
|
20
51
|
proxy.web(req, res, {}, (err) => {
|
|
21
52
|
if (err) {
|
|
@@ -24,52 +55,8 @@ function createRPCProxy(network, targetRpcUrl, port) {
|
|
|
24
55
|
res.end('Proxy error');
|
|
25
56
|
}
|
|
26
57
|
});
|
|
27
|
-
proxy.on('proxyReq', (_, req) => {
|
|
28
|
-
let reqData = '';
|
|
29
|
-
req.on('data', (chunk) => {
|
|
30
|
-
reqData += chunk;
|
|
31
|
-
});
|
|
32
|
-
req.on('end', () => {
|
|
33
|
-
try {
|
|
34
|
-
const jsonRpcContent = JSON.parse(reqData);
|
|
35
|
-
console.debug('Incoming Request: ', jsonRpcContent);
|
|
36
|
-
const method = jsonRpcContent.method;
|
|
37
|
-
const params = jsonRpcContent.params;
|
|
38
|
-
if (method === 'send_transaction') {
|
|
39
|
-
const tx = params[0];
|
|
40
|
-
// todo: record tx
|
|
41
|
-
if (network === type_1.Network.devnet) {
|
|
42
|
-
const cccTx = cccA.JsonRpcTransformers.transactionTo(tx);
|
|
43
|
-
const txHash = cccTx.hash();
|
|
44
|
-
const settings = (0, setting_1.readSettings)();
|
|
45
|
-
console.log('txHash: ', txHash, settings, settings.devnet.transactionsPath);
|
|
46
|
-
if (!fs_1.default.existsSync(settings.devnet.transactionsPath)) {
|
|
47
|
-
fs_1.default.mkdirSync(settings.devnet.transactionsPath);
|
|
48
|
-
}
|
|
49
|
-
const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
|
|
50
|
-
fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
catch (err) {
|
|
55
|
-
console.error('Error parsing JSON-RPC content:', err);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
// Capture the content from the response (or request)
|
|
60
|
-
proxy.on('proxyRes', (proxyRes) => {
|
|
61
|
-
let data = '';
|
|
62
|
-
proxyRes.on('data', (chunk) => {
|
|
63
|
-
data += chunk;
|
|
64
|
-
});
|
|
65
|
-
proxyRes.on('end', () => {
|
|
66
|
-
console.log('Captured content:', data);
|
|
67
|
-
// Do something with the captured content
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
58
|
});
|
|
71
59
|
return {
|
|
72
|
-
server,
|
|
73
60
|
network,
|
|
74
61
|
start: () => {
|
|
75
62
|
return server.listen(port, () => {
|
package/dist/util/request.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ProxyConfig } from '../cfg/setting';
|
|
2
|
+
import fetch, { RequestInit } from 'node-fetch';
|
|
2
3
|
export declare class Request {
|
|
3
|
-
static proxy:
|
|
4
|
-
static send(
|
|
5
|
-
static
|
|
6
|
-
static
|
|
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
|
}
|
package/dist/util/request.js
CHANGED
|
@@ -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(
|
|
20
|
+
static send(url, options = {}) {
|
|
20
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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) {
|
package/dist/util/validator.js
CHANGED
|
@@ -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
|
|
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 ===
|
|
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
|
}
|