Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ckb must loads config files from file system. #468

Merged
merged 1 commit into from
Apr 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ tags
/ckb-miner.toml
/data
/specs
/ckb-dev
/ckb-testnet
/ckb-mainnet
1 change: 1 addition & 0 deletions docker/hub/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ COPY --from=ckb-builder \
/usr/lib/x86_64-linux-gnu/libcrypto.so.* \
/usr/lib/x86_64-linux-gnu/
COPY --from=ckb-builder /ckb/target/release/ckb /bin/ckb
RUN /bin/ckb init --force

USER ckb

Expand Down
2 changes: 1 addition & 1 deletion docs/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CKB looks for configuration files in `<config-dir>`, which is the current workin

Command line argument `-C <path>` sets the value of `<config-dir>` to `<path>`.

If CKB could not find the config file, it will use the default bundled ones.
Command `ckb init` initializes a directory by exporting the config files.

Some config file may refer to other files, for example, `chain.spec` in
`ckb.toml` and `system_cells` in chain spec file. The file is referred via
Expand Down
14 changes: 12 additions & 2 deletions docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
Following steps will assume that the shell can find the executable `ckb`, see
how to [get CKB](get-ckb.md).

CKB uses current directory to store data. It is recommended to setup the
directory with default config files:
First creates a directory to run CKB

```shell
mkdir ckb-dev
cd ckb-dev
```

All the following commands will run in this same directory.

Then init the directory with the default config files.

```shell
ckb init
Expand All @@ -14,6 +22,8 @@ See how to [configure CKB](configure.md) if you like to tweak the options.

## Start Node

Start the node from the directory

```shell
ckb run
```
Expand Down
7 changes: 7 additions & 0 deletions resource/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ pub enum Resource {
}

impl Resource {
pub fn is_bundled(&self) -> bool {
match self {
Resource::Bundled(_) => true,
_ => false,
}
}

/// Gets resource content
pub fn get(&self) -> Result<Cow<'static, [u8]>> {
match self {
Expand Down
4 changes: 4 additions & 0 deletions src/setup/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ pub struct ChainConfig {
}

impl AppConfig {
pub fn is_bundled(&self) -> bool {
self.resource.is_bundled()
}

pub fn load_for_subcommand(
locator: &ResourceLocator,
subcommand_name: &str,
Expand Down
4 changes: 4 additions & 0 deletions src/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ impl Setup {

let resource_locator = locator_from_matches(matches)?;
let config = AppConfig::load_for_subcommand(&resource_locator, subcommand_name)?;
if config.is_bundled() {
eprintln!("Not a CKB directory, initialize one with `ckb init`.");
return Err(ExitCode::Config);
}

Ok(Setup {
subcommand_name: subcommand_name.to_string(),
Expand Down