@offckb/cli 0.4.0-canary-61d5d83.0 → 0.4.0-canary-9c69784.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
CHANGED
|
@@ -108,6 +108,14 @@ offckb node
|
|
|
108
108
|
|
|
109
109
|
Once you start the devnet, there is a RPC server running at `http://127.0.0.1:8114`. There is also a RPC proxy server running at `http://127.0.0.1:28114` which will proxy all the requests to the RPC server. The meaning of using a proxy RPC server is to record request and automatically dump failed transactions so you can debug them easily later.
|
|
110
110
|
|
|
111
|
+
In the same way, you can also start proxy RPC server for `testnet` and `mainnet` by running:
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
offckb node --network <testnet or mainnet>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Using a local proxy RPC server for public testnet/mainnet is also very helpful for debugging the requests and the automatically recorded dump transactions.
|
|
118
|
+
|
|
111
119
|
### List scripts info
|
|
112
120
|
|
|
113
121
|
Print all the predefined scripts for the local blockchain:
|
package/build/index.js
CHANGED
|
@@ -221,24 +221,18 @@ exports.defaultSettings = {
|
|
|
221
221
|
dataPath: path.resolve(exports.dataPath, 'devnet/data'),
|
|
222
222
|
debugFullTransactionsPath: path.resolve(exports.dataPath, 'devnet/full-transactions'),
|
|
223
223
|
transactionsPath: path.resolve(exports.dataPath, 'devnet/transactions'),
|
|
224
|
-
failedTransactionsPath: path.resolve(exports.dataPath, 'devnet/failed-transactions'),
|
|
225
|
-
contractsPath: path.resolve(exports.dataPath, 'devnet/contracts'),
|
|
226
224
|
},
|
|
227
225
|
testnet: {
|
|
228
226
|
rpcUrl: 'https://testnet.ckb.dev',
|
|
229
227
|
rpcProxyPort: 38114,
|
|
230
228
|
debugFullTransactionsPath: path.resolve(exports.dataPath, 'testnet/full-transactions'),
|
|
231
229
|
transactionsPath: path.resolve(exports.dataPath, 'testnet/transactions'),
|
|
232
|
-
failedTransactionsPath: path.resolve(exports.dataPath, 'testnet/failed-transactions'),
|
|
233
|
-
contractsPath: path.resolve(exports.dataPath, 'testnet/contracts'),
|
|
234
230
|
},
|
|
235
231
|
mainnet: {
|
|
236
232
|
rpcUrl: 'https://mainnet.ckb.dev',
|
|
237
233
|
rpcProxyPort: 48114,
|
|
238
234
|
debugFullTransactionsPath: path.resolve(exports.dataPath, 'mainnet/full-transactions'),
|
|
239
235
|
transactionsPath: path.resolve(exports.dataPath, 'mainnet/transactions'),
|
|
240
|
-
failedTransactionsPath: path.resolve(exports.dataPath, 'mainnet/failed-transactions'),
|
|
241
|
-
contractsPath: path.resolve(exports.dataPath, 'mainnet/contracts'),
|
|
242
236
|
},
|
|
243
237
|
tools: {
|
|
244
238
|
ckbDebugger: {
|
|
@@ -337,8 +331,9 @@ program.name('offckb').description(description).version(version).enablePositiona
|
|
|
337
331
|
program
|
|
338
332
|
.command('node [CKB-Version]')
|
|
339
333
|
.description('Use the CKB to start devnet')
|
|
340
|
-
.
|
|
341
|
-
|
|
334
|
+
.option('--network <network>', 'Specify the network to deploy to', 'devnet')
|
|
335
|
+
.action((version, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
336
|
+
return (0, node_1.startNode)({ version, network: options.network });
|
|
342
337
|
}));
|
|
343
338
|
program
|
|
344
339
|
.command('create [project-name]')
|
|
@@ -999,7 +994,7 @@ function buildTxFileOptionBy(txHash, network) {
|
|
|
999
994
|
const settings = (0, setting_1.readSettings)();
|
|
1000
995
|
const outputFilePath = buildDebugFullTransactionFilePath(network, txHash);
|
|
1001
996
|
if (!fs_1.default.existsSync(outputFilePath)) {
|
|
1002
|
-
const rpc = settings.
|
|
997
|
+
const rpc = settings[network].rpcUrl;
|
|
1003
998
|
const txJsonFilePath = buildTransactionJsonFilePath(network, txHash);
|
|
1004
999
|
if (!fs_1.default.existsSync(outputFilePath)) {
|
|
1005
1000
|
fs_1.default.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
@@ -1113,8 +1108,7 @@ function deploy() {
|
|
|
1113
1108
|
var _a;
|
|
1114
1109
|
const network = opt.network;
|
|
1115
1110
|
(0, validator_1.validateNetworkOpt)(network);
|
|
1116
|
-
|
|
1117
|
-
const ckb = new ckb_1.CKB({ network, isEnableProxyRpc: network === base_1.Network.devnet });
|
|
1111
|
+
const ckb = new ckb_1.CKB({ network });
|
|
1118
1112
|
// we use deployerAccount to deploy contract by default
|
|
1119
1113
|
const privateKey = opt.privkey || account_1.deployerAccount.privkey;
|
|
1120
1114
|
const enableTypeId = (_a = opt.typeId) !== null && _a !== void 0 ? _a : false;
|
|
@@ -1150,7 +1144,7 @@ function deploy() {
|
|
|
1150
1144
|
logger_1.logger.info('Deployment cancelled.');
|
|
1151
1145
|
return;
|
|
1152
1146
|
}
|
|
1153
|
-
const results = yield (0, deploy_1.deployBinaries)(binPaths, privateKey, enableTypeId, ckb);
|
|
1147
|
+
const results = yield (0, deploy_1.deployBinaries)(outputFolder, binPaths, privateKey, enableTypeId, ckb);
|
|
1154
1148
|
logger_1.logger.info('');
|
|
1155
1149
|
// record the deployed contract infos
|
|
1156
1150
|
(0, deploy_1.saveArtifacts)(outputFolder, results, network);
|
|
@@ -1280,7 +1274,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
1280
1274
|
});
|
|
1281
1275
|
};
|
|
1282
1276
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1283
|
-
exports.
|
|
1277
|
+
exports.startNode = startNode;
|
|
1278
|
+
exports.nodeDevnet = nodeDevnet;
|
|
1279
|
+
exports.nodeTestnet = nodeTestnet;
|
|
1280
|
+
exports.nodeMainnet = nodeMainnet;
|
|
1284
1281
|
const child_process_1 = __nccwpck_require__(35317);
|
|
1285
1282
|
const init_chain_1 = __nccwpck_require__(1360);
|
|
1286
1283
|
const install_1 = __nccwpck_require__(65611);
|
|
@@ -1289,7 +1286,19 @@ const encoding_1 = __nccwpck_require__(6851);
|
|
|
1289
1286
|
const rpc_proxy_1 = __nccwpck_require__(46589);
|
|
1290
1287
|
const base_1 = __nccwpck_require__(69951);
|
|
1291
1288
|
const logger_1 = __nccwpck_require__(65370);
|
|
1292
|
-
function
|
|
1289
|
+
function startNode({ version, network = base_1.Network.devnet }) {
|
|
1290
|
+
switch (network) {
|
|
1291
|
+
case base_1.Network.devnet:
|
|
1292
|
+
return nodeDevnet({ version });
|
|
1293
|
+
case base_1.Network.testnet:
|
|
1294
|
+
return nodeTestnet();
|
|
1295
|
+
case base_1.Network.mainnet:
|
|
1296
|
+
return nodeMainnet();
|
|
1297
|
+
default:
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
function nodeDevnet(_a) {
|
|
1293
1302
|
return __awaiter(this, arguments, void 0, function* ({ version }) {
|
|
1294
1303
|
var _b, _c;
|
|
1295
1304
|
const settings = (0, setting_1.readSettings)();
|
|
@@ -1339,6 +1348,28 @@ function node(_a) {
|
|
|
1339
1348
|
}
|
|
1340
1349
|
});
|
|
1341
1350
|
}
|
|
1351
|
+
function nodeTestnet() {
|
|
1352
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1353
|
+
// todo: maybe we can actually start a node for testnet later
|
|
1354
|
+
// by default we start a proxy server for testnet
|
|
1355
|
+
const settings = (0, setting_1.readSettings)();
|
|
1356
|
+
const ckbRpc = settings.testnet.rpcUrl;
|
|
1357
|
+
const port = settings.testnet.rpcProxyPort;
|
|
1358
|
+
const proxy = (0, rpc_proxy_1.createRPCProxy)(base_1.Network.testnet, ckbRpc, port);
|
|
1359
|
+
proxy.start();
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
function nodeMainnet() {
|
|
1363
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1364
|
+
// todo: maybe we can actually start a node for mainnet later
|
|
1365
|
+
// by default we start a proxy server for mainnet
|
|
1366
|
+
const settings = (0, setting_1.readSettings)();
|
|
1367
|
+
const ckbRpc = settings.mainnet.rpcUrl;
|
|
1368
|
+
const port = settings.mainnet.rpcProxyPort;
|
|
1369
|
+
const proxy = (0, rpc_proxy_1.createRPCProxy)(base_1.Network.mainnet, ckbRpc, port);
|
|
1370
|
+
proxy.start();
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1342
1373
|
|
|
1343
1374
|
|
|
1344
1375
|
/***/ }),
|
|
@@ -1754,27 +1785,27 @@ function saveArtifacts(artifactsPath, results, network) {
|
|
|
1754
1785
|
logger_1.logger.info('🎉 All deployment artifacts saved successfully!');
|
|
1755
1786
|
});
|
|
1756
1787
|
}
|
|
1757
|
-
function deployBinaries(binPaths, privateKey, enableTypeId, ckb) {
|
|
1788
|
+
function deployBinaries(outputFolder, binPaths, privateKey, enableTypeId, ckb) {
|
|
1758
1789
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1759
1790
|
if (binPaths.length === 0) {
|
|
1760
1791
|
logger_1.logger.info('No binary to deploy.');
|
|
1761
1792
|
}
|
|
1762
1793
|
const results = [];
|
|
1763
1794
|
for (const bin of binPaths) {
|
|
1764
|
-
const result = yield deployBinary(bin, privateKey, enableTypeId, ckb);
|
|
1795
|
+
const result = yield deployBinary(outputFolder, bin, privateKey, enableTypeId, ckb);
|
|
1765
1796
|
results.push(result);
|
|
1766
1797
|
}
|
|
1767
1798
|
return results;
|
|
1768
1799
|
});
|
|
1769
1800
|
}
|
|
1770
|
-
function deployBinary(binPath, privateKey, enableTypeId, ckb) {
|
|
1801
|
+
function deployBinary(outputFolder, binPath, privateKey, enableTypeId, ckb) {
|
|
1771
1802
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1772
1803
|
const bin = yield (0, fs_1.readFileToUint8Array)(binPath);
|
|
1773
1804
|
const contractName = path_1.default.basename(binPath);
|
|
1774
1805
|
const result = !enableTypeId
|
|
1775
1806
|
? yield ckb.deployScript(bin, privateKey)
|
|
1776
|
-
: migration_1.Migration.isDeployedWithTypeId(contractName, ckb.network)
|
|
1777
|
-
? yield ckb.upgradeTypeIdScript(contractName, bin, privateKey)
|
|
1807
|
+
: migration_1.Migration.isDeployedWithTypeId(outputFolder, contractName, ckb.network)
|
|
1808
|
+
? yield ckb.upgradeTypeIdScript(outputFolder, contractName, bin, privateKey)
|
|
1778
1809
|
: yield ckb.deployNewTypeIDScript(bin, privateKey);
|
|
1779
1810
|
logger_1.logger.info(`contract ${contractName} deployed, tx hash:`, result.txHash);
|
|
1780
1811
|
logger_1.logger.info('wait for tx confirmed on-chain...');
|
|
@@ -1863,7 +1894,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
1863
1894
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1864
1895
|
exports.Migration = void 0;
|
|
1865
1896
|
exports.generateDeploymentMigrationFileInPath = generateDeploymentMigrationFileInPath;
|
|
1866
|
-
exports.generateDeploymentMigrationFile = generateDeploymentMigrationFile;
|
|
1867
1897
|
exports.readDeploymentMigrationFile = readDeploymentMigrationFile;
|
|
1868
1898
|
exports.getFormattedMigrationDate = getFormattedMigrationDate;
|
|
1869
1899
|
exports.getMigrationFolderPath = getMigrationFolderPath;
|
|
@@ -1873,27 +1903,26 @@ exports.deploymentRecipeFromJson = deploymentRecipeFromJson;
|
|
|
1873
1903
|
const base_1 = __nccwpck_require__(69951);
|
|
1874
1904
|
const path_1 = __importStar(__nccwpck_require__(16928));
|
|
1875
1905
|
const fs_1 = __importDefault(__nccwpck_require__(79896));
|
|
1876
|
-
const util_1 = __nccwpck_require__(591);
|
|
1877
1906
|
const logger_1 = __nccwpck_require__(65370);
|
|
1878
1907
|
class Migration {
|
|
1879
|
-
static find(scriptName, network = base_1.Network.devnet) {
|
|
1880
|
-
const filePath = getMigrationFolderPath(scriptName, network);
|
|
1908
|
+
static find(baseFolder, scriptName, network = base_1.Network.devnet) {
|
|
1909
|
+
const filePath = getMigrationFolderPath(baseFolder, scriptName, network);
|
|
1881
1910
|
const migrationFile = getNewestMigrationFile(filePath);
|
|
1882
1911
|
if (migrationFile == null)
|
|
1883
1912
|
return null;
|
|
1884
1913
|
return readDeploymentMigrationFile(migrationFile);
|
|
1885
1914
|
}
|
|
1886
|
-
static isDeployed(scriptName, network = base_1.Network.devnet) {
|
|
1887
|
-
const deploymentReceipt = Migration.find(scriptName, network);
|
|
1915
|
+
static isDeployed(baseFolder, scriptName, network = base_1.Network.devnet) {
|
|
1916
|
+
const deploymentReceipt = Migration.find(baseFolder, scriptName, network);
|
|
1888
1917
|
if (deploymentReceipt == null)
|
|
1889
1918
|
return false;
|
|
1890
1919
|
return true;
|
|
1891
1920
|
}
|
|
1892
|
-
static isDeployedWithTypeId(scriptName, network = base_1.Network.devnet) {
|
|
1893
|
-
const isDeployed = this.isDeployed(scriptName, network);
|
|
1921
|
+
static isDeployedWithTypeId(baseFolder, scriptName, network = base_1.Network.devnet) {
|
|
1922
|
+
const isDeployed = this.isDeployed(baseFolder, scriptName, network);
|
|
1894
1923
|
if (isDeployed === false)
|
|
1895
1924
|
return false;
|
|
1896
|
-
const deploymentReceipt = Migration.find(scriptName, network);
|
|
1925
|
+
const deploymentReceipt = Migration.find(baseFolder, scriptName, network);
|
|
1897
1926
|
const typeId = deploymentReceipt.cellRecipes[0].typeId;
|
|
1898
1927
|
if (typeId == null)
|
|
1899
1928
|
return false;
|
|
@@ -1911,10 +1940,6 @@ function generateDeploymentMigrationFileInPath(deploymentRecipe, outputFilePath)
|
|
|
1911
1940
|
fs_1.default.writeFileSync(outputFilePath, jsonString);
|
|
1912
1941
|
logger_1.logger.info(`- Migration json file ${outputFilePath} generated successfully.`);
|
|
1913
1942
|
}
|
|
1914
|
-
function generateDeploymentMigrationFile(name, deploymentRecipe, network = base_1.Network.devnet) {
|
|
1915
|
-
const outputFilePath = `${(0, util_1.getContractsPath)(network)}/${name}/migrations/${getFormattedMigrationDate()}.json`;
|
|
1916
|
-
return generateDeploymentMigrationFileInPath(deploymentRecipe, outputFilePath);
|
|
1917
|
-
}
|
|
1918
1943
|
function readDeploymentMigrationFile(filePath) {
|
|
1919
1944
|
const jsonString = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
1920
1945
|
const data = JSON.parse(jsonString);
|
|
@@ -1930,9 +1955,8 @@ function getFormattedMigrationDate() {
|
|
|
1930
1955
|
const seconds = String(now.getSeconds()).padStart(2, '0');
|
|
1931
1956
|
return `${year}-${month}-${day}-${hours}${minutes}${seconds}`;
|
|
1932
1957
|
}
|
|
1933
|
-
function getMigrationFolderPath(scriptName, network) {
|
|
1934
|
-
|
|
1935
|
-
return path_1.default.resolve(contractsPath, `${scriptName}/migrations`);
|
|
1958
|
+
function getMigrationFolderPath(baseFolder, scriptName, network) {
|
|
1959
|
+
return path_1.default.resolve(baseFolder, `${network}/${scriptName}/migrations`);
|
|
1936
1960
|
}
|
|
1937
1961
|
function getNewestMigrationFile(folderPath) {
|
|
1938
1962
|
if (!fs_1.default.existsSync(folderPath) || !fs_1.default.lstatSync(folderPath).isDirectory()) {
|
|
@@ -2052,13 +2076,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
2052
2076
|
};
|
|
2053
2077
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2054
2078
|
exports.generateDeploymentTomlInPath = generateDeploymentTomlInPath;
|
|
2055
|
-
exports.generateDeploymentToml = generateDeploymentToml;
|
|
2056
2079
|
exports.readDeploymentTomlInPath = readDeploymentTomlInPath;
|
|
2057
|
-
exports.readDeploymentToml = readDeploymentToml;
|
|
2058
2080
|
const fs_1 = __importDefault(__nccwpck_require__(79896));
|
|
2059
2081
|
const toml_1 = __importDefault(__nccwpck_require__(2811));
|
|
2060
2082
|
const path_1 = __nccwpck_require__(16928);
|
|
2061
|
-
const util_1 = __nccwpck_require__(591);
|
|
2062
2083
|
const logger_1 = __nccwpck_require__(65370);
|
|
2063
2084
|
function generateDeploymentTomlInPath(options, outputFilePath) {
|
|
2064
2085
|
const data = {
|
|
@@ -2086,10 +2107,6 @@ function generateDeploymentTomlInPath(options, outputFilePath) {
|
|
|
2086
2107
|
logger_1.logger.info(`- ${options.name} deployment.toml file ${outputFilePath} generated successfully.`);
|
|
2087
2108
|
}
|
|
2088
2109
|
}
|
|
2089
|
-
function generateDeploymentToml(options, network) {
|
|
2090
|
-
const outputFilePath = `${(0, util_1.getContractsPath)(network)}/${options.name}/deployment.toml`;
|
|
2091
|
-
return generateDeploymentTomlInPath(options, outputFilePath);
|
|
2092
|
-
}
|
|
2093
2110
|
function readDeploymentTomlInPath(filePath) {
|
|
2094
2111
|
const file = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
2095
2112
|
const data = toml_1.default.parse(file);
|
|
@@ -2110,36 +2127,6 @@ function readDeploymentTomlInPath(filePath) {
|
|
|
2110
2127
|
},
|
|
2111
2128
|
};
|
|
2112
2129
|
}
|
|
2113
|
-
function readDeploymentToml(scriptName, network) {
|
|
2114
|
-
const filePath = `${(0, util_1.getContractsPath)(network)}/${scriptName}/deployment.toml`;
|
|
2115
|
-
return readDeploymentTomlInPath(filePath);
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
/***/ }),
|
|
2120
|
-
|
|
2121
|
-
/***/ 591:
|
|
2122
|
-
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
2123
|
-
|
|
2124
|
-
"use strict";
|
|
2125
|
-
|
|
2126
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2127
|
-
exports.getContractsPath = getContractsPath;
|
|
2128
|
-
const setting_1 = __nccwpck_require__(25546);
|
|
2129
|
-
const base_1 = __nccwpck_require__(69951);
|
|
2130
|
-
function getContractsPath(network) {
|
|
2131
|
-
const settings = (0, setting_1.readSettings)();
|
|
2132
|
-
if (network === base_1.Network.devnet) {
|
|
2133
|
-
return settings.devnet.contractsPath;
|
|
2134
|
-
}
|
|
2135
|
-
if (network === base_1.Network.testnet) {
|
|
2136
|
-
return settings.testnet.contractsPath;
|
|
2137
|
-
}
|
|
2138
|
-
if (network === base_1.Network.mainnet) {
|
|
2139
|
-
return settings.mainnet.contractsPath;
|
|
2140
|
-
}
|
|
2141
|
-
throw new Error(`invalid network ${network}`);
|
|
2142
|
-
}
|
|
2143
2130
|
|
|
2144
2131
|
|
|
2145
2132
|
/***/ }),
|
|
@@ -2500,13 +2487,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
2500
2487
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
2501
2488
|
exports.genSystemScripts = genSystemScripts;
|
|
2502
2489
|
exports.genSystemScriptsJsonFile = genSystemScriptsJsonFile;
|
|
2503
|
-
exports.genMyScripts = genMyScripts;
|
|
2504
|
-
exports.genMyScriptsJsonFile = genMyScriptsJsonFile;
|
|
2505
2490
|
const fs = __importStar(__nccwpck_require__(79896));
|
|
2506
2491
|
const public_1 = __importDefault(__nccwpck_require__(84535));
|
|
2507
2492
|
const path_1 = __importDefault(__nccwpck_require__(16928));
|
|
2508
|
-
const base_1 = __nccwpck_require__(69951);
|
|
2509
|
-
const util_1 = __nccwpck_require__(58642);
|
|
2510
2493
|
const fs_1 = __nccwpck_require__(37293);
|
|
2511
2494
|
const private_1 = __nccwpck_require__(5835);
|
|
2512
2495
|
function genSystemScripts() {
|
|
@@ -2530,19 +2513,6 @@ function genSystemScriptsJsonFile(filePath) {
|
|
|
2530
2513
|
fs.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
|
|
2531
2514
|
fs.writeFileSync(outputFilePath, JSON.stringify(scripts, null, 2));
|
|
2532
2515
|
}
|
|
2533
|
-
function genMyScripts() {
|
|
2534
|
-
const networkMyScripts = {
|
|
2535
|
-
devnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.devnet),
|
|
2536
|
-
testnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.testnet),
|
|
2537
|
-
mainnet: (0, util_1.readUserDeployedScriptsInfo)(base_1.Network.mainnet),
|
|
2538
|
-
};
|
|
2539
|
-
return networkMyScripts;
|
|
2540
|
-
}
|
|
2541
|
-
function genMyScriptsJsonFile(filePath) {
|
|
2542
|
-
const scripts = genMyScripts();
|
|
2543
|
-
fs.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
|
|
2544
|
-
fs.writeFileSync(filePath, JSON.stringify(scripts, null, 2));
|
|
2545
|
-
}
|
|
2546
2516
|
|
|
2547
2517
|
|
|
2548
2518
|
/***/ }),
|
|
@@ -3018,11 +2988,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3018
2988
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
3019
2989
|
exports.readDeployedScriptInfoFrom = readDeployedScriptInfoFrom;
|
|
3020
2990
|
exports.getScriptInfoFrom = getScriptInfoFrom;
|
|
3021
|
-
exports.readUserDeployedScriptsInfo = readUserDeployedScriptsInfo;
|
|
3022
2991
|
const fs = __importStar(__nccwpck_require__(79896));
|
|
3023
|
-
const util_1 = __nccwpck_require__(591);
|
|
3024
2992
|
const migration_1 = __nccwpck_require__(76679);
|
|
3025
|
-
const fs_1 = __nccwpck_require__(37293);
|
|
3026
2993
|
const path_1 = __importDefault(__nccwpck_require__(16928));
|
|
3027
2994
|
const logger_1 = __nccwpck_require__(65370);
|
|
3028
2995
|
function readDeployedScriptInfoFrom(contractDeploymentFolderPath) {
|
|
@@ -3088,59 +3055,6 @@ function getScriptInfoFrom(recipe) {
|
|
|
3088
3055
|
scriptsInfo,
|
|
3089
3056
|
};
|
|
3090
3057
|
}
|
|
3091
|
-
function readUserDeployedScriptsInfo(network) {
|
|
3092
|
-
const deployedScriptsInfo = {};
|
|
3093
|
-
// Read all files in the folder
|
|
3094
|
-
const folder = (0, util_1.getContractsPath)(network);
|
|
3095
|
-
if (!fs.existsSync(folder)) {
|
|
3096
|
-
return deployedScriptsInfo;
|
|
3097
|
-
}
|
|
3098
|
-
const contractNames = (0, fs_1.getSubfolders)(folder);
|
|
3099
|
-
for (const contractName of contractNames) {
|
|
3100
|
-
const folderPath = (0, migration_1.getMigrationFolderPath)(contractName, network); // Replace with your function to get the folder path
|
|
3101
|
-
const newestFilePath = (0, migration_1.getNewestMigrationFile)(folderPath);
|
|
3102
|
-
if (newestFilePath) {
|
|
3103
|
-
try {
|
|
3104
|
-
// Read the file content
|
|
3105
|
-
const recipe = (0, migration_1.readDeploymentMigrationFile)(newestFilePath);
|
|
3106
|
-
// todo: handle multiple cell recipes?
|
|
3107
|
-
const firstCell = recipe.cellRecipes[0];
|
|
3108
|
-
const isDepCode = recipe.depGroupRecipes.length > 0;
|
|
3109
|
-
deployedScriptsInfo[firstCell.name] = {
|
|
3110
|
-
codeHash: (firstCell.typeId ? firstCell.typeId : firstCell.dataHash),
|
|
3111
|
-
hashType: firstCell.typeId ? 'type' : 'data1',
|
|
3112
|
-
cellDeps: !isDepCode
|
|
3113
|
-
? [
|
|
3114
|
-
{
|
|
3115
|
-
cellDep: {
|
|
3116
|
-
outPoint: {
|
|
3117
|
-
txHash: firstCell.txHash,
|
|
3118
|
-
index: +firstCell.index,
|
|
3119
|
-
},
|
|
3120
|
-
depType: 'code',
|
|
3121
|
-
},
|
|
3122
|
-
},
|
|
3123
|
-
]
|
|
3124
|
-
: recipe.depGroupRecipes.map((depGroupRecipe) => {
|
|
3125
|
-
return {
|
|
3126
|
-
cellDep: {
|
|
3127
|
-
outPoint: {
|
|
3128
|
-
txHash: depGroupRecipe.txHash,
|
|
3129
|
-
index: +depGroupRecipe.index,
|
|
3130
|
-
},
|
|
3131
|
-
depType: 'depGroup',
|
|
3132
|
-
},
|
|
3133
|
-
};
|
|
3134
|
-
}),
|
|
3135
|
-
};
|
|
3136
|
-
}
|
|
3137
|
-
catch (error) {
|
|
3138
|
-
logger_1.logger.error([`Error reading or parsing file '${newestFilePath}':`, error.toString()]);
|
|
3139
|
-
}
|
|
3140
|
-
}
|
|
3141
|
-
}
|
|
3142
|
-
return deployedScriptsInfo;
|
|
3143
|
-
}
|
|
3144
3058
|
|
|
3145
3059
|
|
|
3146
3060
|
/***/ }),
|
|
@@ -3184,13 +3098,16 @@ class CKB {
|
|
|
3184
3098
|
if (isEnableProxyRpc === true) {
|
|
3185
3099
|
this.client =
|
|
3186
3100
|
network === 'mainnet'
|
|
3187
|
-
? new core_1.ccc.ClientPublicMainnet({ url: network_1.networks.mainnet.proxy_rpc_url })
|
|
3101
|
+
? new core_1.ccc.ClientPublicMainnet({ url: network_1.networks.mainnet.proxy_rpc_url, fallbacks: [network_1.networks.mainnet.rpc_url] }) // we keep the fallbacks in case the proxy rpc is not started
|
|
3188
3102
|
: network === 'testnet'
|
|
3189
|
-
? new core_1.ccc.ClientPublicTestnet({
|
|
3103
|
+
? new core_1.ccc.ClientPublicTestnet({
|
|
3104
|
+
url: network_1.networks.testnet.proxy_rpc_url,
|
|
3105
|
+
fallbacks: [network_1.networks.testnet.rpc_url],
|
|
3106
|
+
}) // we keep the fallbacks in case the proxy rpc is not started
|
|
3190
3107
|
: new core_1.ccc.ClientPublicTestnet({
|
|
3191
3108
|
url: network_1.networks.devnet.proxy_rpc_url,
|
|
3192
3109
|
scripts: (0, private_1.buildCCCDevnetKnownScripts)(),
|
|
3193
|
-
fallbacks: [],
|
|
3110
|
+
fallbacks: [network_1.networks.devnet.rpc_url],
|
|
3194
3111
|
});
|
|
3195
3112
|
}
|
|
3196
3113
|
else {
|
|
@@ -3208,6 +3125,7 @@ class CKB {
|
|
|
3208
3125
|
: new core_1.ccc.ClientPublicTestnet({
|
|
3209
3126
|
url: network_1.networks.devnet.rpc_url,
|
|
3210
3127
|
scripts: (0, private_1.buildCCCDevnetKnownScripts)(),
|
|
3128
|
+
fallbacks: [], // pass it to avoid using websocket and fallback RPCs
|
|
3211
3129
|
});
|
|
3212
3130
|
}
|
|
3213
3131
|
}
|
|
@@ -3342,10 +3260,10 @@ class CKB {
|
|
|
3342
3260
|
return { txHash, tx: typeIdTx, scriptOutputCellIndex: 0, isTypeId: true, typeId: typeIdTx.outputs[0].type };
|
|
3343
3261
|
});
|
|
3344
3262
|
}
|
|
3345
|
-
upgradeTypeIdScript(scriptName, newScriptBinBytes, privateKey) {
|
|
3263
|
+
upgradeTypeIdScript(baseFolder, scriptName, newScriptBinBytes, privateKey) {
|
|
3346
3264
|
return __awaiter(this, void 0, void 0, function* () {
|
|
3347
3265
|
var _a;
|
|
3348
|
-
const deploymentReceipt = migration_1.Migration.find(scriptName, this.network);
|
|
3266
|
+
const deploymentReceipt = migration_1.Migration.find(baseFolder, scriptName, this.network);
|
|
3349
3267
|
if (deploymentReceipt == null)
|
|
3350
3268
|
throw new Error("no migration file, can't be updated.");
|
|
3351
3269
|
const outpoint = {
|
|
@@ -4641,7 +4559,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
4641
4559
|
exports.createRPCProxy = createRPCProxy;
|
|
4642
4560
|
const http_proxy_1 = __importDefault(__nccwpck_require__(1291));
|
|
4643
4561
|
const http_1 = __importDefault(__nccwpck_require__(58611));
|
|
4644
|
-
const base_1 = __nccwpck_require__(69951);
|
|
4645
4562
|
const fs_1 = __importDefault(__nccwpck_require__(79896));
|
|
4646
4563
|
const setting_1 = __nccwpck_require__(25546);
|
|
4647
4564
|
const path_1 = __importDefault(__nccwpck_require__(16928));
|
|
@@ -4651,6 +4568,7 @@ const { cccA } = __nccwpck_require__(1630);
|
|
|
4651
4568
|
function createRPCProxy(network, targetRpcUrl, port) {
|
|
4652
4569
|
const proxy = http_proxy_1.default.createProxyServer({
|
|
4653
4570
|
target: targetRpcUrl, // Target RPC server
|
|
4571
|
+
changeOrigin: true, // for https target to work
|
|
4654
4572
|
});
|
|
4655
4573
|
proxy.on('proxyReq', (_, req) => {
|
|
4656
4574
|
let reqData = '';
|
|
@@ -4667,18 +4585,15 @@ function createRPCProxy(network, targetRpcUrl, port) {
|
|
|
4667
4585
|
logger_1.logger.info('RPC Req: ', method);
|
|
4668
4586
|
if (method === 'send_transaction') {
|
|
4669
4587
|
const tx = params[0];
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
if (!fs_1.default.existsSync(settings.devnet.transactionsPath)) {
|
|
4676
|
-
fs_1.default.mkdirSync(settings.devnet.transactionsPath);
|
|
4677
|
-
}
|
|
4678
|
-
const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
|
|
4679
|
-
fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
|
|
4680
|
-
logger_1.logger.debug(`RPC Req: store tx ${txHash}`);
|
|
4588
|
+
const cccTx = cccA.JsonRpcTransformers.transactionTo(tx);
|
|
4589
|
+
const txHash = cccTx.hash();
|
|
4590
|
+
const settings = (0, setting_1.readSettings)();
|
|
4591
|
+
if (!fs_1.default.existsSync(settings[network].transactionsPath)) {
|
|
4592
|
+
fs_1.default.mkdirSync(settings[network].transactionsPath);
|
|
4681
4593
|
}
|
|
4594
|
+
const txFile = path_1.default.resolve(settings[network].transactionsPath, `${txHash}.json`);
|
|
4595
|
+
fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
|
|
4596
|
+
logger_1.logger.info(`RPC Req: store tx ${txHash}`);
|
|
4682
4597
|
}
|
|
4683
4598
|
}
|
|
4684
4599
|
catch (err) {
|
|
@@ -4692,9 +4607,13 @@ function createRPCProxy(network, targetRpcUrl, port) {
|
|
|
4692
4607
|
body.push(chunk);
|
|
4693
4608
|
});
|
|
4694
4609
|
proxyRes.on('end', function () {
|
|
4695
|
-
const res = Buffer.concat(body).toString();
|
|
4610
|
+
const res = Buffer.concat(body).toString('utf-8');
|
|
4696
4611
|
if (res.length === 0)
|
|
4697
4612
|
return;
|
|
4613
|
+
if (proxyRes.headers['content-type'] !== 'application/json')
|
|
4614
|
+
return;
|
|
4615
|
+
if (!res.trim().startsWith('{') && !res.trim().startsWith('['))
|
|
4616
|
+
return;
|
|
4698
4617
|
try {
|
|
4699
4618
|
const jsonRpcResponse = JSON.parse(res);
|
|
4700
4619
|
const error = jsonRpcResponse.error;
|
|
@@ -130793,7 +130712,7 @@ module.exports = {"version":"3.17.0"};
|
|
|
130793
130712
|
/***/ ((module) => {
|
|
130794
130713
|
|
|
130795
130714
|
"use strict";
|
|
130796
|
-
module.exports = /*#__PURE__*/JSON.parse('{"rE":"0.4.0-
|
|
130715
|
+
module.exports = /*#__PURE__*/JSON.parse('{"rE":"0.4.0-rc6","h_":"ckb development network for your first try"}');
|
|
130797
130716
|
|
|
130798
130717
|
/***/ })
|
|
130799
130718
|
|
package/package.json
CHANGED
|
@@ -18,14 +18,21 @@ const buildClient = (network) => {
|
|
|
18
18
|
switch (network) {
|
|
19
19
|
case "devnet":
|
|
20
20
|
return new ccc.ClientPublicTestnet({
|
|
21
|
-
url: "http://127.0.0.1:28114", // the
|
|
21
|
+
url: "http://127.0.0.1:28114", // the proxy RPC from offckb devnet
|
|
22
22
|
scripts: DEVNET_SCRIPTS,
|
|
23
|
-
fallbacks: [], //
|
|
23
|
+
fallbacks: ["http://127.0.0.1:8114"], // use non-proxy RPC for fallbacks if proxy server has trouble
|
|
24
24
|
});
|
|
25
25
|
case "testnet":
|
|
26
|
-
return new ccc.ClientPublicTestnet(
|
|
26
|
+
return new ccc.ClientPublicTestnet({
|
|
27
|
+
url: "http://127.0.0.1:38114", // proxy RPC from offckb, make sure you start the testnet node by running: `offckb node --network testnet`
|
|
28
|
+
fallbacks: ["https://testnet.ckb.dev"], // use non-proxy RPC for fallbacks if proxy server has trouble
|
|
29
|
+
});
|
|
27
30
|
case "mainnet":
|
|
28
|
-
return new ccc.ClientPublicMainnet(
|
|
31
|
+
return new ccc.ClientPublicMainnet({
|
|
32
|
+
url: "http://127.0.0.1:48114", // proxy RPC from offckb, make sure you start the mainnet node by running: `offckb node --network mainnet`
|
|
33
|
+
fallbacks: ["https://mainnet.ckb.dev"], // use non-proxy RPC for fallbacks if proxy server has trouble
|
|
34
|
+
});
|
|
35
|
+
|
|
29
36
|
|
|
30
37
|
default:
|
|
31
38
|
throw new Error(`Unsupported network: ${network}`);
|
|
@@ -18,14 +18,20 @@ export const buildClient = (network: "devnet" | "testnet" | "mainnet") => {
|
|
|
18
18
|
switch (network) {
|
|
19
19
|
case "devnet":
|
|
20
20
|
return new ccc.ClientPublicTestnet({
|
|
21
|
-
url: "http://127.0.0.1:28114", // the
|
|
21
|
+
url: "http://127.0.0.1:28114", // the proxy RPC from offckb devnet
|
|
22
22
|
scripts: DEVNET_SCRIPTS,
|
|
23
|
-
fallbacks: [], //
|
|
23
|
+
fallbacks: ["http://127.0.0.1:8114"], // use non-proxy RPC for fallbacks if proxy server has trouble
|
|
24
24
|
});
|
|
25
25
|
case "testnet":
|
|
26
|
-
return new ccc.ClientPublicTestnet(
|
|
26
|
+
return new ccc.ClientPublicTestnet({
|
|
27
|
+
url: "http://127.0.0.1:38114", // proxy RPC from offckb, make sure you start the testnet node by running: `offckb node --network testnet`
|
|
28
|
+
fallbacks: ["https://testnet.ckb.dev"], // use non-proxy RPC for fallbacks if proxy server has trouble
|
|
29
|
+
});
|
|
27
30
|
case "mainnet":
|
|
28
|
-
return new ccc.ClientPublicMainnet(
|
|
31
|
+
return new ccc.ClientPublicMainnet({
|
|
32
|
+
url: "http://127.0.0.1:48114", // proxy RPC from offckb, make sure you start the mainnet node by running: `offckb node --network mainnet`
|
|
33
|
+
fallbacks: ["https://mainnet.ckb.dev"], // use non-proxy RPC for fallbacks if proxy server has trouble
|
|
34
|
+
});
|
|
29
35
|
|
|
30
36
|
default:
|
|
31
37
|
throw new Error(`Unsupported network: ${network}`);
|