@offckb/cli 0.3.4 → 0.4.0-canary-113bf31.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/README.md +17 -138
- package/build/build/Release/cpufeatures.node +0 -0
- package/build/build/Release/secp256k1.node +0 -0
- package/build/index.js +114977 -0
- package/package.json +12 -6
- package/dist/cfg/account.d.ts +0 -55
- package/dist/cfg/account.js +0 -66
- package/dist/cfg/env-path.d.ts +0 -9
- package/dist/cfg/env-path.js +0 -63
- package/dist/cfg/setting.d.ts +0 -67
- package/dist/cfg/setting.js +0 -147
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -224
- package/dist/cmd/accounts.d.ts +0 -1
- package/dist/cmd/accounts.js +0 -40
- package/dist/cmd/balance.d.ts +0 -4
- package/dist/cmd/balance.js +0 -25
- package/dist/cmd/clean.d.ts +0 -1
- package/dist/cmd/clean.js +0 -27
- package/dist/cmd/config.d.ts +0 -11
- package/dist/cmd/config.js +0 -107
- package/dist/cmd/create.d.ts +0 -7
- package/dist/cmd/create.js +0 -77
- package/dist/cmd/debug.d.ts +0 -16
- package/dist/cmd/debug.js +0 -120
- package/dist/cmd/deploy.d.ts +0 -9
- package/dist/cmd/deploy.js +0 -76
- package/dist/cmd/deposit.d.ts +0 -5
- package/dist/cmd/deposit.js +0 -97
- package/dist/cmd/inject-config.d.ts +0 -4
- package/dist/cmd/inject-config.js +0 -72
- package/dist/cmd/list-hashes.d.ts +0 -25
- package/dist/cmd/list-hashes.js +0 -39
- package/dist/cmd/mol.d.ts +0 -2
- package/dist/cmd/mol.js +0 -38
- package/dist/cmd/my-scripts.d.ts +0 -4
- package/dist/cmd/my-scripts.js +0 -24
- package/dist/cmd/node.d.ts +0 -5
- package/dist/cmd/node.js +0 -70
- package/dist/cmd/proxy-rpc.d.ts +0 -7
- package/dist/cmd/proxy-rpc.js +0 -22
- package/dist/cmd/repl.d.ts +0 -17
- package/dist/cmd/repl.js +0 -111
- package/dist/cmd/sync-scripts.d.ts +0 -4
- package/dist/cmd/sync-scripts.js +0 -30
- package/dist/cmd/system-scripts.d.ts +0 -99
- package/dist/cmd/system-scripts.js +0 -301
- package/dist/cmd/transfer-all.d.ts +0 -6
- package/dist/cmd/transfer-all.js +0 -37
- package/dist/cmd/transfer.d.ts +0 -6
- package/dist/cmd/transfer.js +0 -38
- package/dist/deploy/index.d.ts +0 -18
- package/dist/deploy/index.js +0 -127
- package/dist/deploy/migration.d.ts +0 -50
- package/dist/deploy/migration.js +0 -178
- package/dist/deploy/toml.d.ts +0 -42
- package/dist/deploy/toml.js +0 -59
- package/dist/deploy/util.d.ts +0 -2
- package/dist/deploy/util.js +0 -18
- package/dist/molecule/mol.d.ts +0 -9
- package/dist/molecule/mol.js +0 -149
- package/dist/node/init-chain.d.ts +0 -1
- package/dist/node/init-chain.js +0 -40
- package/dist/node/install.d.ts +0 -11
- package/dist/node/install.js +0 -235
- package/dist/scripts/gen.d.ts +0 -5
- package/dist/scripts/gen.js +0 -78
- package/dist/scripts/private.d.ts +0 -4
- package/dist/scripts/private.js +0 -13
- package/dist/scripts/public.d.ts +0 -8
- package/dist/scripts/public.js +0 -229
- package/dist/scripts/type.d.ts +0 -51
- package/dist/scripts/type.js +0 -19
- package/dist/scripts/util.d.ts +0 -3
- package/dist/scripts/util.js +0 -93
- package/dist/sdk/ckb.d.ts +0 -37
- package/dist/sdk/ckb.js +0 -254
- package/dist/sdk/network.d.ts +0 -17
- package/dist/sdk/network.js +0 -22
- package/dist/template/offckb-config.d.ts +0 -4
- package/dist/template/offckb-config.js +0 -70
- package/dist/template/option.d.ts +0 -8
- package/dist/template/option.js +0 -22
- package/dist/tools/ckb-debugger.d.ts +0 -12
- package/dist/tools/ckb-debugger.js +0 -31
- package/dist/tools/ckb-tx-dumper.d.ts +0 -6
- package/dist/tools/ckb-tx-dumper.js +0 -20
- package/dist/tools/moleculec-es.d.ts +0 -8
- package/dist/tools/moleculec-es.js +0 -100
- package/dist/tools/moleculec-go.d.ts +0 -5
- package/dist/tools/moleculec-go.js +0 -35
- package/dist/tools/moleculec-rust.d.ts +0 -5
- package/dist/tools/moleculec-rust.js +0 -35
- package/dist/tools/rpc-proxy.d.ts +0 -7
- package/dist/tools/rpc-proxy.js +0 -90
- package/dist/type/base.d.ts +0 -11
- package/dist/type/base.js +0 -10
- package/dist/util/encoding.d.ts +0 -2
- package/dist/util/encoding.js +0 -24
- package/dist/util/fs.d.ts +0 -13
- package/dist/util/fs.js +0 -218
- package/dist/util/git.d.ts +0 -2
- package/dist/util/git.js +0 -106
- package/dist/util/link.d.ts +0 -1
- package/dist/util/link.js +0 -6
- package/dist/util/request.d.ts +0 -8
- package/dist/util/request.js +0 -61
- package/dist/util/validator.d.ts +0 -5
- package/dist/util/validator.js +0 -67
- package/npm-shrinkwrap.json +0 -4514
package/dist/deploy/index.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
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.getToDeployBinsPath = getToDeployBinsPath;
|
|
16
|
-
exports.recordDeployResult = recordDeployResult;
|
|
17
|
-
exports.deployBinaries = deployBinaries;
|
|
18
|
-
exports.deployBinary = deployBinary;
|
|
19
|
-
const toml_1 = require("../deploy/toml");
|
|
20
|
-
const migration_1 = require("../deploy/migration");
|
|
21
|
-
const gen_1 = require("../scripts/gen");
|
|
22
|
-
const offckb_config_1 = require("../template/offckb-config");
|
|
23
|
-
const fs_1 = require("../util/fs");
|
|
24
|
-
const path_1 = __importDefault(require("path"));
|
|
25
|
-
const fs_2 = __importDefault(require("fs"));
|
|
26
|
-
const core_1 = require("@ckb-ccc/core");
|
|
27
|
-
function getToDeployBinsPath(userOffCKBConfigPath) {
|
|
28
|
-
const fileContent = fs_2.default.readFileSync(userOffCKBConfigPath, 'utf-8');
|
|
29
|
-
const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/);
|
|
30
|
-
if (match && match[1]) {
|
|
31
|
-
const contractBinFolderValue = match[1];
|
|
32
|
-
const folderPath = path_1.default.dirname(userOffCKBConfigPath);
|
|
33
|
-
const binFileOrFolderPath = (0, fs_1.isAbsolutePath)(contractBinFolderValue)
|
|
34
|
-
? contractBinFolderValue
|
|
35
|
-
: path_1.default.resolve(folderPath, contractBinFolderValue);
|
|
36
|
-
const bins = (0, fs_1.getBinaryFilesFromPath)(binFileOrFolderPath);
|
|
37
|
-
return bins;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
console.log('contractBinFolder value not found in offckb.config.ts');
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function recordDeployResult(results, network, userOffCKBConfigPath) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
if (results.length === 0) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
for (const result of results) {
|
|
50
|
-
(0, toml_1.generateDeploymentToml)(result.deploymentOptions, network);
|
|
51
|
-
(0, migration_1.generateDeploymentMigrationFile)(result.deploymentOptions.name, result.deploymentRecipe, network);
|
|
52
|
-
}
|
|
53
|
-
// update my-scripts.json
|
|
54
|
-
if (userOffCKBConfigPath) {
|
|
55
|
-
if (!fs_2.default.existsSync(userOffCKBConfigPath)) {
|
|
56
|
-
throw new Error(`config file not exits: ${userOffCKBConfigPath}`);
|
|
57
|
-
}
|
|
58
|
-
const folder = offckb_config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
|
|
59
|
-
if (folder) {
|
|
60
|
-
const myScriptsFilePath = path_1.default.resolve(folder, 'my-scripts.json');
|
|
61
|
-
(0, gen_1.genMyScriptsJsonFile)(myScriptsFilePath);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
console.log('done.');
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function deployBinaries(binPaths, privateKey, enableTypeId, ckb) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
if (binPaths.length === 0) {
|
|
70
|
-
console.log('No binary to deploy.');
|
|
71
|
-
}
|
|
72
|
-
const results = [];
|
|
73
|
-
for (const bin of binPaths) {
|
|
74
|
-
const result = yield deployBinary(bin, privateKey, enableTypeId, ckb);
|
|
75
|
-
results.push(result);
|
|
76
|
-
}
|
|
77
|
-
return results;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function deployBinary(binPath, privateKey, enableTypeId, ckb) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
const bin = yield (0, fs_1.readFileToUint8Array)(binPath);
|
|
83
|
-
const contractName = path_1.default.basename(binPath);
|
|
84
|
-
const result = !enableTypeId
|
|
85
|
-
? yield ckb.deployScript(bin, privateKey)
|
|
86
|
-
: migration_1.Migration.isDeployedWithTypeId(contractName, ckb.network)
|
|
87
|
-
? yield ckb.upgradeTypeIdScript(contractName, bin, privateKey)
|
|
88
|
-
: yield ckb.deployNewTypeIDScript(bin, privateKey);
|
|
89
|
-
console.log(`contract ${contractName} deployed, tx hash:`, result.txHash);
|
|
90
|
-
console.log('wait for tx confirmed on-chain...');
|
|
91
|
-
yield ckb.waitForTxConfirm(result.txHash);
|
|
92
|
-
console.log('tx committed.');
|
|
93
|
-
const txHash = result.txHash;
|
|
94
|
-
const typeIdScript = result.typeId;
|
|
95
|
-
const index = result.scriptOutputCellIndex;
|
|
96
|
-
const tx = result.tx;
|
|
97
|
-
const dataByteLen = BigInt(tx.outputsData[+index].slice(2).length / 2);
|
|
98
|
-
const dataShannonLen = dataByteLen * BigInt('100000000');
|
|
99
|
-
const occupiedCapacity = '0x' + dataShannonLen.toString(16);
|
|
100
|
-
if (enableTypeId && typeIdScript == null) {
|
|
101
|
-
throw new Error('type id script is null while enableTypeId is true.');
|
|
102
|
-
}
|
|
103
|
-
const typeIdScriptHash = enableTypeId ? core_1.ccc.Script.from(typeIdScript).hash() : undefined;
|
|
104
|
-
// todo: handle multiple cell recipes?
|
|
105
|
-
return {
|
|
106
|
-
deploymentOptions: {
|
|
107
|
-
name: contractName,
|
|
108
|
-
binFilePath: binPath,
|
|
109
|
-
enableTypeId: enableTypeId,
|
|
110
|
-
lockScript: tx.outputs[+index].lock,
|
|
111
|
-
},
|
|
112
|
-
deploymentRecipe: {
|
|
113
|
-
cellRecipes: [
|
|
114
|
-
{
|
|
115
|
-
name: contractName,
|
|
116
|
-
txHash,
|
|
117
|
-
index: '0x' + index.toString(16),
|
|
118
|
-
occupiedCapacity,
|
|
119
|
-
dataHash: core_1.ccc.hashCkb(tx.outputsData[+index]),
|
|
120
|
-
typeId: typeIdScriptHash,
|
|
121
|
-
},
|
|
122
|
-
],
|
|
123
|
-
depGroupRecipes: [],
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
});
|
|
127
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Network } from '../type/base';
|
|
2
|
-
import { HexNumber } from '../type/base';
|
|
3
|
-
export interface CellRecipe {
|
|
4
|
-
name: string;
|
|
5
|
-
txHash: string;
|
|
6
|
-
index: HexNumber;
|
|
7
|
-
occupiedCapacity: HexNumber;
|
|
8
|
-
dataHash: string;
|
|
9
|
-
typeId?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface DepGroupRecipe {
|
|
12
|
-
name: string;
|
|
13
|
-
txHash: string;
|
|
14
|
-
index: HexNumber;
|
|
15
|
-
dataHash: string;
|
|
16
|
-
occupiedCapacity: HexNumber;
|
|
17
|
-
}
|
|
18
|
-
export interface DeploymentRecipe {
|
|
19
|
-
cellRecipes: CellRecipe[];
|
|
20
|
-
depGroupRecipes: DepGroupRecipe[];
|
|
21
|
-
}
|
|
22
|
-
export interface MigrationJson {
|
|
23
|
-
cell_recipes: {
|
|
24
|
-
name: string;
|
|
25
|
-
tx_hash: string;
|
|
26
|
-
index: number;
|
|
27
|
-
occupied_capacity: number;
|
|
28
|
-
data_hash: string;
|
|
29
|
-
type_id?: string;
|
|
30
|
-
}[];
|
|
31
|
-
dep_group_recipes: {
|
|
32
|
-
name: string;
|
|
33
|
-
tx_hash: string;
|
|
34
|
-
index: number;
|
|
35
|
-
data_hash: string;
|
|
36
|
-
occupied_capacity: number;
|
|
37
|
-
}[];
|
|
38
|
-
}
|
|
39
|
-
export declare class Migration {
|
|
40
|
-
static find(scriptName: string, network?: Network): DeploymentRecipe | null;
|
|
41
|
-
static isDeployed(scriptName: string, network?: Network): boolean;
|
|
42
|
-
static isDeployedWithTypeId(scriptName: string, network?: Network): boolean;
|
|
43
|
-
}
|
|
44
|
-
export declare function generateDeploymentMigrationFile(name: string, deploymentRecipe: DeploymentRecipe, network?: Network): void;
|
|
45
|
-
export declare function readDeploymentMigrationFile(filePath: string): DeploymentRecipe;
|
|
46
|
-
export declare function getFormattedMigrationDate(): string;
|
|
47
|
-
export declare function getMigrationFolderPath(scriptName: string, network: Network): string;
|
|
48
|
-
export declare function getNewestMigrationFile(folderPath: string): string | null;
|
|
49
|
-
export declare function deploymentRecipeToJson(recipe: DeploymentRecipe): MigrationJson;
|
|
50
|
-
export declare function deploymentRecipeFromJson(json: MigrationJson): DeploymentRecipe;
|
package/dist/deploy/migration.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Migration = void 0;
|
|
40
|
-
exports.generateDeploymentMigrationFile = generateDeploymentMigrationFile;
|
|
41
|
-
exports.readDeploymentMigrationFile = readDeploymentMigrationFile;
|
|
42
|
-
exports.getFormattedMigrationDate = getFormattedMigrationDate;
|
|
43
|
-
exports.getMigrationFolderPath = getMigrationFolderPath;
|
|
44
|
-
exports.getNewestMigrationFile = getNewestMigrationFile;
|
|
45
|
-
exports.deploymentRecipeToJson = deploymentRecipeToJson;
|
|
46
|
-
exports.deploymentRecipeFromJson = deploymentRecipeFromJson;
|
|
47
|
-
const base_1 = require("../type/base");
|
|
48
|
-
const path_1 = __importStar(require("path"));
|
|
49
|
-
const fs_1 = __importDefault(require("fs"));
|
|
50
|
-
const util_1 = require("./util");
|
|
51
|
-
class Migration {
|
|
52
|
-
static find(scriptName, network = base_1.Network.devnet) {
|
|
53
|
-
const filePath = getMigrationFolderPath(scriptName, network);
|
|
54
|
-
const migrationFile = getNewestMigrationFile(filePath);
|
|
55
|
-
if (migrationFile == null)
|
|
56
|
-
return null;
|
|
57
|
-
return readDeploymentMigrationFile(migrationFile);
|
|
58
|
-
}
|
|
59
|
-
static isDeployed(scriptName, network = base_1.Network.devnet) {
|
|
60
|
-
const deploymentReceipt = Migration.find(scriptName, network);
|
|
61
|
-
if (deploymentReceipt == null)
|
|
62
|
-
return false;
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
static isDeployedWithTypeId(scriptName, network = base_1.Network.devnet) {
|
|
66
|
-
const isDeployed = this.isDeployed(scriptName, network);
|
|
67
|
-
if (isDeployed === false)
|
|
68
|
-
return false;
|
|
69
|
-
const deploymentReceipt = Migration.find(scriptName, network);
|
|
70
|
-
const typeId = deploymentReceipt.cellRecipes[0].typeId;
|
|
71
|
-
if (typeId == null)
|
|
72
|
-
return false;
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.Migration = Migration;
|
|
77
|
-
function generateDeploymentMigrationFile(name, deploymentRecipe, network = base_1.Network.devnet) {
|
|
78
|
-
const cellRecipes = deploymentRecipe.cellRecipes;
|
|
79
|
-
const depGroupRecipes = deploymentRecipe.depGroupRecipes;
|
|
80
|
-
const jsonString = JSON.stringify(deploymentRecipeToJson({ cellRecipes, depGroupRecipes }), null, 2);
|
|
81
|
-
const outputFilePath = `${(0, util_1.getContractsPath)(network)}/${name}/migrations/${getFormattedMigrationDate()}.json`;
|
|
82
|
-
if (outputFilePath) {
|
|
83
|
-
if (!fs_1.default.existsSync((0, path_1.dirname)(outputFilePath))) {
|
|
84
|
-
fs_1.default.mkdirSync((0, path_1.dirname)(outputFilePath), { recursive: true });
|
|
85
|
-
}
|
|
86
|
-
fs_1.default.writeFileSync(outputFilePath, jsonString);
|
|
87
|
-
console.log(`${name} migration json file ${outputFilePath} generated successfully.`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function readDeploymentMigrationFile(filePath) {
|
|
91
|
-
const jsonString = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
92
|
-
const data = JSON.parse(jsonString);
|
|
93
|
-
return deploymentRecipeFromJson(data);
|
|
94
|
-
}
|
|
95
|
-
function getFormattedMigrationDate() {
|
|
96
|
-
const now = new Date();
|
|
97
|
-
const year = now.getFullYear();
|
|
98
|
-
const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero-based
|
|
99
|
-
const day = String(now.getDate()).padStart(2, '0');
|
|
100
|
-
const hours = String(now.getHours()).padStart(2, '0');
|
|
101
|
-
const minutes = String(now.getMinutes()).padStart(2, '0');
|
|
102
|
-
const seconds = String(now.getSeconds()).padStart(2, '0');
|
|
103
|
-
return `${year}-${month}-${day}-${hours}${minutes}${seconds}`;
|
|
104
|
-
}
|
|
105
|
-
function getMigrationFolderPath(scriptName, network) {
|
|
106
|
-
const contractsPath = (0, util_1.getContractsPath)(network);
|
|
107
|
-
return path_1.default.resolve(contractsPath, `${scriptName}/migrations`);
|
|
108
|
-
}
|
|
109
|
-
function getNewestMigrationFile(folderPath) {
|
|
110
|
-
if (!fs_1.default.existsSync(folderPath) || !fs_1.default.lstatSync(folderPath).isDirectory()) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
const files = fs_1.default
|
|
114
|
-
.readdirSync(folderPath)
|
|
115
|
-
.filter((file) => file.endsWith('.json')) // Ensure only JSON files are considered
|
|
116
|
-
.sort((a, b) => {
|
|
117
|
-
// Extract the timestamp part of the filename and compare them
|
|
118
|
-
const timestampA = a.split('.json')[0];
|
|
119
|
-
const timestampB = b.split('.json')[0];
|
|
120
|
-
return timestampA.localeCompare(timestampB);
|
|
121
|
-
});
|
|
122
|
-
// Return the full path of the newest file (last in sorted array) or undefined if no files
|
|
123
|
-
return files.length > 0 ? path_1.default.join(folderPath, files[files.length - 1]) : null;
|
|
124
|
-
}
|
|
125
|
-
function deploymentRecipeToJson(recipe) {
|
|
126
|
-
return {
|
|
127
|
-
cell_recipes: recipe.cellRecipes.map((val) => {
|
|
128
|
-
if (BigInt(val.occupiedCapacity) > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
129
|
-
// CKB blocksize limit is 500k, so it should be impossible to have a cell occupied data larger than Number.MAX_SAFE_INTEGER which is 9007,1992,5474,0991
|
|
130
|
-
console.error(`invalid occupiedCapacity: ${val.occupiedCapacity}, the cell_recipes json might be incorrect for cell outpoint ${val.txHash}:${+val.index}`);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
name: val.name,
|
|
134
|
-
tx_hash: val.txHash,
|
|
135
|
-
index: +val.index,
|
|
136
|
-
occupied_capacity: +BigInt(val.occupiedCapacity).toString(10),
|
|
137
|
-
data_hash: val.dataHash,
|
|
138
|
-
type_id: val.typeId,
|
|
139
|
-
};
|
|
140
|
-
}),
|
|
141
|
-
dep_group_recipes: recipe.depGroupRecipes.map((val) => {
|
|
142
|
-
if (BigInt(val.occupiedCapacity) > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
143
|
-
// CKB blocksize limit is 500k, so it should be impossible to have a cell occupied data larger than Number.MAX_SAFE_INTEGER which is 9007,1992,5474,0991
|
|
144
|
-
console.error(`invalid occupiedCapacity: ${val.occupiedCapacity}, the dep_group_recipes json might be incorrect for cell outpoint ${val.txHash}:${+val.index}`);
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
name: val.name,
|
|
148
|
-
tx_hash: val.txHash,
|
|
149
|
-
index: +val.index,
|
|
150
|
-
data_hash: val.dataHash,
|
|
151
|
-
occupied_capacity: +BigInt(val.occupiedCapacity).toString(10),
|
|
152
|
-
};
|
|
153
|
-
}),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function deploymentRecipeFromJson(json) {
|
|
157
|
-
return {
|
|
158
|
-
cellRecipes: json.cell_recipes.map((val) => {
|
|
159
|
-
return {
|
|
160
|
-
name: val.name,
|
|
161
|
-
txHash: val.tx_hash,
|
|
162
|
-
index: '0x' + val.index.toString(16),
|
|
163
|
-
occupiedCapacity: '0x' + val.occupied_capacity.toString(16),
|
|
164
|
-
dataHash: val.data_hash,
|
|
165
|
-
typeId: val.type_id,
|
|
166
|
-
};
|
|
167
|
-
}),
|
|
168
|
-
depGroupRecipes: json.dep_group_recipes.map((val) => {
|
|
169
|
-
return {
|
|
170
|
-
name: val.name,
|
|
171
|
-
txHash: val.tx_hash,
|
|
172
|
-
index: '0x' + val.index.toString(16),
|
|
173
|
-
dataHash: val.data_hash,
|
|
174
|
-
occupiedCapacity: '0x' + val.occupied_capacity.toString(16),
|
|
175
|
-
};
|
|
176
|
-
}),
|
|
177
|
-
};
|
|
178
|
-
}
|
package/dist/deploy/toml.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Network } from '../type/base';
|
|
2
|
-
import { HashType } from '@ckb-ccc/core';
|
|
3
|
-
import { HexString } from '../type/base';
|
|
4
|
-
export interface DeploymentOptions {
|
|
5
|
-
name: string;
|
|
6
|
-
binFilePath: string;
|
|
7
|
-
enableTypeId: boolean;
|
|
8
|
-
lockScript: {
|
|
9
|
-
codeHash: HexString;
|
|
10
|
-
hashType: HashType;
|
|
11
|
-
args: HexString;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export interface DeploymentToml {
|
|
15
|
-
cells: {
|
|
16
|
-
name: string;
|
|
17
|
-
enable_type_id: boolean;
|
|
18
|
-
location: {
|
|
19
|
-
file: string;
|
|
20
|
-
};
|
|
21
|
-
}[];
|
|
22
|
-
lock: {
|
|
23
|
-
code_hash: string;
|
|
24
|
-
args: string;
|
|
25
|
-
hash_type: HashType;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export declare function generateDeploymentToml(options: DeploymentOptions, network: Network): void;
|
|
29
|
-
export declare function readDeploymentToml(scriptName: string, network: Network): {
|
|
30
|
-
cells: {
|
|
31
|
-
name: string;
|
|
32
|
-
enableTypeId: boolean;
|
|
33
|
-
location: {
|
|
34
|
-
file: string;
|
|
35
|
-
};
|
|
36
|
-
}[];
|
|
37
|
-
lock: {
|
|
38
|
-
codeHash: string;
|
|
39
|
-
args: string;
|
|
40
|
-
hashType: string;
|
|
41
|
-
};
|
|
42
|
-
};
|
package/dist/deploy/toml.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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.generateDeploymentToml = generateDeploymentToml;
|
|
7
|
-
exports.readDeploymentToml = readDeploymentToml;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const toml_1 = __importDefault(require("@iarna/toml"));
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
const util_1 = require("./util");
|
|
12
|
-
function generateDeploymentToml(options, network) {
|
|
13
|
-
const data = {
|
|
14
|
-
cells: [
|
|
15
|
-
{
|
|
16
|
-
name: options.name,
|
|
17
|
-
enable_type_id: options.enableTypeId,
|
|
18
|
-
location: {
|
|
19
|
-
file: options.binFilePath,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
lock: {
|
|
24
|
-
code_hash: options.lockScript.codeHash,
|
|
25
|
-
args: options.lockScript.args,
|
|
26
|
-
hash_type: options.lockScript.hashType,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
const tomlString = toml_1.default.stringify(data);
|
|
30
|
-
const outputFilePath = `${(0, util_1.getContractsPath)(network)}/${options.name}/deployment.toml`;
|
|
31
|
-
if (outputFilePath) {
|
|
32
|
-
if (!fs_1.default.existsSync((0, path_1.dirname)(outputFilePath))) {
|
|
33
|
-
fs_1.default.mkdirSync((0, path_1.dirname)(outputFilePath), { recursive: true });
|
|
34
|
-
}
|
|
35
|
-
fs_1.default.writeFileSync(outputFilePath, tomlString);
|
|
36
|
-
console.log(`${options.name} deployment.toml file ${outputFilePath} generated successfully.`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function readDeploymentToml(scriptName, network) {
|
|
40
|
-
const filePath = `${(0, util_1.getContractsPath)(network)}/${scriptName}/deployment.toml`;
|
|
41
|
-
const file = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
42
|
-
const data = toml_1.default.parse(file);
|
|
43
|
-
return {
|
|
44
|
-
cells: [
|
|
45
|
-
{
|
|
46
|
-
name: data.cells[0].name,
|
|
47
|
-
enableTypeId: data.cells[0].enable_type_id,
|
|
48
|
-
location: {
|
|
49
|
-
file: data.cells[0].location.file,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
lock: {
|
|
54
|
-
codeHash: data.lock.code_hash,
|
|
55
|
-
args: data.lock.args,
|
|
56
|
-
hashType: data.lock.hash_type,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
package/dist/deploy/util.d.ts
DELETED
package/dist/deploy/util.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getContractsPath = getContractsPath;
|
|
4
|
-
const setting_1 = require("../cfg/setting");
|
|
5
|
-
const base_1 = require("../type/base");
|
|
6
|
-
function getContractsPath(network) {
|
|
7
|
-
const settings = (0, setting_1.readSettings)();
|
|
8
|
-
if (network === base_1.Network.devnet) {
|
|
9
|
-
return settings.devnet.contractsPath;
|
|
10
|
-
}
|
|
11
|
-
if (network === base_1.Network.testnet) {
|
|
12
|
-
return settings.testnet.contractsPath;
|
|
13
|
-
}
|
|
14
|
-
if (network === base_1.Network.mainnet) {
|
|
15
|
-
return settings.mainnet.contractsPath;
|
|
16
|
-
}
|
|
17
|
-
throw new Error(`invalid network ${network}`);
|
|
18
|
-
}
|
package/dist/molecule/mol.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare enum BindingLanguage {
|
|
2
|
-
rust = "rs",
|
|
3
|
-
c = "c",
|
|
4
|
-
typescript = "ts",
|
|
5
|
-
javascript = "js",
|
|
6
|
-
go = "go"
|
|
7
|
-
}
|
|
8
|
-
export declare function generateMolBindings(schemeFilePath: string, outputFilePath: string | undefined, bindingLanguage: BindingLanguage): Promise<void>;
|
|
9
|
-
export declare function installMolToolsIfNeeded(): Promise<void>;
|
package/dist/molecule/mol.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.BindingLanguage = void 0;
|
|
49
|
-
exports.generateMolBindings = generateMolBindings;
|
|
50
|
-
exports.installMolToolsIfNeeded = installMolToolsIfNeeded;
|
|
51
|
-
const child_process_1 = require("child_process");
|
|
52
|
-
const moleculec_es_1 = require("../tools/moleculec-es");
|
|
53
|
-
const moleculec_rust_1 = require("../tools/moleculec-rust");
|
|
54
|
-
const setting_1 = require("../cfg/setting");
|
|
55
|
-
const path_1 = __importDefault(require("path"));
|
|
56
|
-
const fs = __importStar(require("fs"));
|
|
57
|
-
const moleculec_go_1 = require("../tools/moleculec-go");
|
|
58
|
-
var BindingLanguage;
|
|
59
|
-
(function (BindingLanguage) {
|
|
60
|
-
BindingLanguage["rust"] = "rs";
|
|
61
|
-
BindingLanguage["c"] = "c";
|
|
62
|
-
BindingLanguage["typescript"] = "ts";
|
|
63
|
-
BindingLanguage["javascript"] = "js";
|
|
64
|
-
BindingLanguage["go"] = "go";
|
|
65
|
-
})(BindingLanguage || (exports.BindingLanguage = BindingLanguage = {}));
|
|
66
|
-
function generateMolBindings(schemeFilePath, outputFilePath, bindingLanguage) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
yield installMolToolsIfNeeded();
|
|
69
|
-
const settings = (0, setting_1.readSettings)();
|
|
70
|
-
if (bindingLanguage === BindingLanguage.typescript) {
|
|
71
|
-
const jsonFilePath = path_1.default.join(settings.tools.moleculeES.cachePath, 'schema.json');
|
|
72
|
-
fs.mkdirSync(path_1.default.dirname(jsonFilePath), { recursive: true });
|
|
73
|
-
if (outputFilePath) {
|
|
74
|
-
fs.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
75
|
-
}
|
|
76
|
-
(0, child_process_1.execSync)(`moleculec --language - --schema-file ${schemeFilePath} --format json > ${jsonFilePath}`);
|
|
77
|
-
(0, child_process_1.execSync)(`${moleculec_es_1.MoleculecES.bin} -generateTypeScriptDefinition -hasBigInt -inputFile ${jsonFilePath} -outputFile ${outputFilePath || '-'}`, { stdio: 'inherit' });
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (bindingLanguage === BindingLanguage.javascript) {
|
|
81
|
-
const jsonFilePath = path_1.default.join(settings.tools.moleculeES.cachePath, 'schema.json');
|
|
82
|
-
fs.mkdirSync(path_1.default.dirname(jsonFilePath), { recursive: true });
|
|
83
|
-
if (outputFilePath) {
|
|
84
|
-
fs.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
85
|
-
}
|
|
86
|
-
(0, child_process_1.execSync)(`moleculec --language - --schema-file ${schemeFilePath} --format json > ${jsonFilePath}`, {
|
|
87
|
-
stdio: 'inherit',
|
|
88
|
-
});
|
|
89
|
-
(0, child_process_1.execSync)(`${moleculec_es_1.MoleculecES.bin} -hasBigInt -inputFile ${jsonFilePath} -outputFile ${outputFilePath || '-'}`, {
|
|
90
|
-
stdio: 'inherit',
|
|
91
|
-
});
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (bindingLanguage === BindingLanguage.c) {
|
|
95
|
-
if (!outputFilePath) {
|
|
96
|
-
(0, child_process_1.execSync)(`moleculec --language c --schema-file ${schemeFilePath}`, {
|
|
97
|
-
stdio: 'inherit',
|
|
98
|
-
});
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
fs.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
102
|
-
(0, child_process_1.execSync)(`moleculec --language c --schema-file ${schemeFilePath} > ${outputFilePath}`, {
|
|
103
|
-
stdio: 'inherit',
|
|
104
|
-
});
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (bindingLanguage === BindingLanguage.rust) {
|
|
108
|
-
if (!outputFilePath) {
|
|
109
|
-
(0, child_process_1.execSync)(`moleculec --language rust --schema-file ${schemeFilePath}`, {
|
|
110
|
-
stdio: 'inherit',
|
|
111
|
-
});
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
fs.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
115
|
-
(0, child_process_1.execSync)(`moleculec --language rust --schema-file ${schemeFilePath} > ${outputFilePath}`, {
|
|
116
|
-
stdio: 'inherit',
|
|
117
|
-
});
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (bindingLanguage === BindingLanguage.go) {
|
|
121
|
-
if (!outputFilePath) {
|
|
122
|
-
(0, child_process_1.execSync)(`moleculec --language go --schema-file ${schemeFilePath}`, {
|
|
123
|
-
stdio: 'inherit',
|
|
124
|
-
});
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
fs.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
128
|
-
(0, child_process_1.execSync)(`moleculec --language go --schema-file ${schemeFilePath} | gofmt > ${outputFilePath}`, {
|
|
129
|
-
stdio: 'inherit',
|
|
130
|
-
});
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
throw new Error(`Unsupported binding language: ${bindingLanguage}`);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
function installMolToolsIfNeeded() {
|
|
137
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
if (!moleculec_es_1.MoleculecES.isBinaryInstalled()) {
|
|
139
|
-
const version = '0.4.6';
|
|
140
|
-
yield moleculec_es_1.MoleculecES.installMoleculeES(version);
|
|
141
|
-
}
|
|
142
|
-
if (!moleculec_rust_1.MoleculecRust.isBinaryInstalled()) {
|
|
143
|
-
moleculec_rust_1.MoleculecRust.installBinary();
|
|
144
|
-
}
|
|
145
|
-
if (!moleculec_go_1.MoleculecGo.isBinaryInstalled()) {
|
|
146
|
-
moleculec_go_1.MoleculecGo.installBinary();
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function initChainIfNeeded(): Promise<void>;
|