Skip to content

Commit 01857a4

Browse files
authored
Merge pull request #334 from ckb-devrel/develop
Merge v0.4.2 to master
2 parents b52af5a + ae2d63a commit 01857a4

28 files changed

Lines changed: 3272 additions & 1873 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist/
77
.vscode
88
templates/temp-clone-folder
99
build/
10+
package-lock.json

README.md

Lines changed: 17 additions & 8 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:
@@ -125,7 +134,7 @@ Using a proxy RPC server for Testnet/Mainnet is especially helpful for debugging
125134

126135
### 2. Create a New Contract Project {#create-project}
127136

128-
Generate a ready-to-use project in JS/TS using templates:
137+
Generate a ready-to-use smart-contract project in JS/TS using templates:
129138
```sh
130139
offckb create <your-project-name> -c <your-contract-name>
131140
```
@@ -258,7 +267,7 @@ Example result:
258267
Pay attention to the `devnet.configPath` and `devnet.dataPath`.
259268

260269
2. `cd` into the `devnet.configPath` . Modify the config files as needed. See [Custom Devnet Setup](https://docs.nervos.org/docs/node/run-devnet-node#custom-devnet-setup) and [Configure CKB](https://github.com/nervosnetwork/ckb/blob/develop/docs/configure.md) for details.
261-
3. After modifications, remove everything in the `devnet.dataPath` folder to reset chain data.
270+
3. After modifications, run `offckb clean -d` to remove the chain data if needed while keeping the updated config files.
262271
4. Restart local blockchain by running `offckb node`
263272

264273

ckb/ckb-js-vm

Submodule ckb-js-vm updated 47 files

ckb/devnet/specs/ckb_js_vm

8 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@offckb/cli",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "ckb development network for your first try",
55
"author": "CKB EcoFund",
66
"license": "MIT",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

Lines changed: 12 additions & 3 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
@@ -56,6 +60,7 @@ program
5660
.option('-o, --output <output>', 'Specify the output folder path for the deployment record files', './deployment')
5761
.option('-t, --type-id', 'Specify if use upgradable type id to deploy the script')
5862
.option('--privkey <privkey>', 'Specify the private key to deploy scripts')
63+
.option('-y, --yes', 'Skip confirmation prompt and deploy immediately')
5964
.action((options: DeployOptions) => deploy(options));
6065

6166
program
@@ -100,7 +105,11 @@ program
100105
return printSystemScripts({ style: exportStyle, network });
101106
});
102107

103-
program.command('clean').description('Clean the devnet data, need to stop running the chain first').action(clean);
108+
program
109+
.command('clean')
110+
.description('Clean the devnet data, need to stop running the chain first')
111+
.option('-d, --data', 'Only remove chain data, keep devnet config files')
112+
.action((options: { data?: boolean }) => clean(options));
104113
program.command('accounts').description('Print account list info').action(accounts);
105114

106115
program

src/cmd/clean.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,42 @@ import { isFolderExists } from '../util/fs';
33
import { readSettings } from '../cfg/setting';
44
import { logger } from '../util/logger';
55

6-
export function clean() {
6+
export interface CleanOptions {
7+
data?: boolean;
8+
}
9+
10+
export function clean(options?: CleanOptions) {
711
const settings = readSettings();
812
const allDevnetDataPath = settings.devnet.configPath;
9-
// this is the root folder of devnet, it contains config, data, debugFullTransactions, transactions, failed-transactions, contracts
10-
if (isFolderExists(allDevnetDataPath)) {
11-
try {
12-
fs.rmSync(allDevnetDataPath, { recursive: true });
13-
logger.info(`Chain data cleaned.`);
14-
} catch (error: unknown) {
15-
logger.info(`Did you stop running the chain first?`);
16-
logger.error((error as Error).message);
13+
const dataOnly = options?.data || false;
14+
15+
if (dataOnly) {
16+
// Only clean the chain data subdirectory
17+
const chainDataPath = settings.devnet.dataPath;
18+
if (isFolderExists(chainDataPath)) {
19+
try {
20+
fs.rmSync(chainDataPath, { recursive: true });
21+
logger.info(`Chain data cleaned. Devnet config files preserved.`);
22+
} catch (error: unknown) {
23+
logger.info(`Did you stop running the chain first?`);
24+
logger.error((error as Error).message);
25+
}
26+
} else {
27+
logger.info(`Nothing to clean. Chain data directory ${chainDataPath} not found.`);
1728
}
1829
} else {
19-
logger.info(`Nothing to clean. Devnet data directory ${allDevnetDataPath} not found.`);
30+
// Clean everything - the original behavior
31+
// this is the root folder of devnet, it contains config, data, debugFullTransactions, transactions, failed-transactions, contracts
32+
if (isFolderExists(allDevnetDataPath)) {
33+
try {
34+
fs.rmSync(allDevnetDataPath, { recursive: true });
35+
logger.info(`Chain data cleaned.`);
36+
} catch (error: unknown) {
37+
logger.info(`Did you stop running the chain first?`);
38+
logger.error((error as Error).message);
39+
}
40+
} else {
41+
logger.info(`Nothing to clean. Devnet data directory ${allDevnetDataPath} not found.`);
42+
}
2043
}
2144
}

src/cmd/deploy.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface DeployOptions extends NetworkOption {
1313
output?: string;
1414
privkey?: string | null;
1515
typeId?: boolean;
16+
yes?: boolean;
1617
}
1718

1819
export async function deploy(
@@ -55,13 +56,16 @@ export async function deploy(
5556
` 🔄 Type ID: ${enableTypeId ? 'enabled (upgradable)' : 'disabled (immutable)'}`,
5657
]);
5758

58-
const res = await confirm({
59-
message: 'Are you sure you want to deploy these contracts?',
60-
});
59+
// Skip confirmation if -y flag is provided
60+
if (!opt.yes) {
61+
const res = await confirm({
62+
message: 'Are you sure you want to deploy these contracts?',
63+
});
6164

62-
if (!res) {
63-
logger.info('Deployment cancelled.');
64-
return;
65+
if (!res) {
66+
logger.info('Deployment cancelled.');
67+
return;
68+
}
6569
}
6670

6771
const results = await deployBinaries(outputFolder, binPaths, privateKey, enableTypeId, ckb);

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)