Skip to content

Commit 41ed923

Browse files
authored
feat(node): support specify the path to a CKB binary (#317)
* feat(node): support specify the path to a CKB binary * apply review suggestion
1 parent 2093e67 commit 41ed923

3 files changed

Lines changed: 38 additions & 14 deletions

File tree

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ There are BREAKING CHANGES between v0.3.x and v0.4.x, make sure to read the [mig
2424
- [Install](#install)
2525
- [Usage](#usage)
2626
- [Get started](#get-started)
27-
- [Run a Local CKB Devnet](#running-ckb)
28-
- [Create a CKB Smart Contract Project](#create-project)
29-
- [Deploy a CKB Smart Contract](#deploy-contract)
30-
- [Debug a CKB Smart Contract](#debug-contract)
31-
- [Explore built-in Scripts info](#explore-scripts)
32-
- [Tweak Devnet Config](#tweak-devnet-config)
27+
- [1. Run a Local CKB Devnet {#running-ckb}](#1-run-a-local-ckb-devnet-running-ckb)
28+
- [2. Create a New Contract Project {#create-project}](#2-create-a-new-contract-project-create-project)
29+
- [3. Deploy Your Contract {#deploy-contract}](#3-deploy-your-contract-deploy-contract)
30+
- [4. Debug Your Contract {#debug-contract}](#4-debug-your-contract-debug-contract)
31+
- [5. Explore Built-in Scripts {#explore-scripts}](#5-explore-built-in-scripts-explore-scripts)
32+
- [6. Tweak Devnet Config {#tweak-devnet-config}](#6-tweak-devnet-config-tweak-devnet-config)
3333
- [Config Setting](#config-setting)
3434
- [List All Settings](#list-all-settings)
3535
- [Set CKB version](#set-ckb-version)
@@ -107,6 +107,15 @@ Or set a default version globally:
107107
offckb config set ckb-version 0.201.0
108108
offckb node
109109
```
110+
111+
Or specify the path to your locally compiled CKB binary:
112+
113+
```sh
114+
offckb node --binary-path /path/to/your/ckb/binary
115+
```
116+
117+
When using `--binary-path`, it will ignore the specified version and network, and only work for devnet.
118+
110119
**RPC & Proxy RPC**
111120

112121
When the Devnet starts:

src/cli.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ program
3131
.command('node [CKB-Version]')
3232
.description('Use the CKB to start devnet')
3333
.option('--network <network>', 'Specify the network to deploy to', 'devnet')
34-
.action(async (version: string, options: { network: Network }) => {
35-
return startNode({ version, network: options.network });
34+
.option(
35+
'-b, --binary-path <binaryPath>',
36+
'Specify the CKB binary path to use, only for devnet, when set, will ignore version and network',
37+
)
38+
.action(async (version: string, options: { network: Network; binaryPath?: string }) => {
39+
return startNode({ version, network: options.network, binaryPath: options.binaryPath });
3640
});
3741

3842
program

src/cmd/node.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ import { logger } from '../util/logger';
1010
export interface NodeProp {
1111
version?: string;
1212
network?: Network;
13+
binaryPath?: string;
1314
}
1415

15-
export function startNode({ version, network = Network.devnet }: NodeProp) {
16+
export function startNode({ version, network = Network.devnet, binaryPath }: NodeProp) {
17+
if (binaryPath && network !== Network.devnet) {
18+
logger.warn('Custom binaryPath is only supported for devnet. The provided binaryPath will be ignored.');
19+
}
20+
1621
switch (network) {
1722
case Network.devnet:
18-
return nodeDevnet({ version });
23+
return nodeDevnet({ version, binaryPath });
1924
case Network.testnet:
2025
return nodeTestnet();
2126
case Network.mainnet:
@@ -25,13 +30,19 @@ export function startNode({ version, network = Network.devnet }: NodeProp) {
2530
}
2631
}
2732

28-
export async function nodeDevnet({ version }: NodeProp) {
33+
export async function nodeDevnet({ version, binaryPath }: NodeProp) {
2934
const settings = readSettings();
3035
const ckbVersion = version || settings.bins.defaultCKBVersion;
31-
await installCKBBinary(ckbVersion);
32-
await initChainIfNeeded();
36+
let ckbBinPath = '';
3337

34-
const ckbBinPath = encodeBinPathForTerminal(getCKBBinaryPath(ckbVersion));
38+
if (binaryPath) {
39+
ckbBinPath = encodeBinPathForTerminal(binaryPath);
40+
logger.info(`Using custom CKB binary path: ${ckbBinPath}`);
41+
} else {
42+
await installCKBBinary(ckbVersion);
43+
ckbBinPath = encodeBinPathForTerminal(getCKBBinaryPath(ckbVersion));
44+
}
45+
await initChainIfNeeded();
3546
const devnetConfigPath = encodeBinPathForTerminal(settings.devnet.configPath);
3647

3748
const ckbCmd = `${ckbBinPath} run -C ${devnetConfigPath}`;

0 commit comments

Comments
 (0)