Skip to content

Commit

Permalink
fix(cli): the sub-command is useless
Browse files Browse the repository at this point in the history
  • Loading branch information
yangby-cryptape committed Jul 13, 2023
1 parent bf7bea4 commit b11530e
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/openzeppelin_test_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
- name: Run prepare
id: runtest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/openzeppelin_test_16_19.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
- name: Run prepare
id: runtest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/openzeppelin_test_1_5_and_12_15.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
- name: Run prepare
id: runtest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/openzeppelin_test_6_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
- name: Run prepare
id: runtest
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/somking_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Start axon
run: |
cd ${{ github.workspace }}/axon
./axon --config ${{ github.workspace }}/axon/config.toml --genesis ${{ github.workspace }}/axon/genesis_single_node.json > /tmp/log 2>&1 &
./axon run --config ${{ github.workspace }}/axon/config.toml --genesis ${{ github.workspace }}/axon/genesis_single_node.json > /tmp/log 2>&1 &
sleep 120
- name: Check Axon Status
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/v3_core_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
- name: Install dependencies
run: |
cd /home/runner/work/axon/axon/v3-core
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/web3_compatible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
- name: Run Test
run: |
cd /home/runner/work/axon/axon/axon-test
Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
run: |
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
- name: Run Test
run: |
cd /home/runner/work/axon/axon/axon-test
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ RUN set -eux; \
COPY --from=builder /build/target/release/axon /app/axon
COPY --from=builder /build/devtools /app/devtools

CMD ./axon -c=/app/devtools/chain/config.toml -g=/app/devtools/chain/genesis_single_node.json
CMD ./axon run -c=/app/devtools/chain/config.toml -g=/app/devtools/chain/genesis_single_node.json


4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ e2e-test-lint:
e2e-test:
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
cd tests/e2e && yarn
cd tests/e2e/src && yarn exec http-server &
cd tests/e2e && yarn exec wait-on -t 5000 tcp:8000 && yarn exec wait-on -t 5000 tcp:8080 && yarn test
Expand All @@ -73,7 +73,7 @@ e2e-test:
e2e-test-ci:
cargo build
rm -rf ./devtools/chain/data
./target/debug/axon --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
./target/debug/axon run --config devtools/chain/config.toml --genesis devtools/chain/genesis_single_node.json > /tmp/log 2>&1 &
cd tests/e2e && yarn
cd tests/e2e/src && yarn exec http-server &
cd tests/e2e && yarn exec wait-on -t 5000 tcp:8000 && yarn exec wait-on -t 5000 tcp:8080 && HEADLESS=true yarn test
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Openness and mobility are the foundation of social development, so is blockchain

### Staking on Layer 1 CKB

Axon supports a Proof-of-Stake (PoS) consensus mechanism and requires each Axon-based appchain to issue native Extensible User Defined Tokens (xUDTs), which are designed and customized by the app chain's development team and released on CKB. For simplicity, the xUDTs on Axon-based chains are referred to as Axon tokens (AT tokens) below. Holders of AT tokens can stake to become validators and/or delegate their tokens to other validators in exchange for rewards. Unlike other sidechains where staking takes place on Layer 2, Axon's staking is grounded on Layer 1 CKB. Validators and other participants stake their native AT tokens on CKB, which uses a Proof-of-Work (PoW) consensus mechanism. This unique staking design helps Axon-based appchains enjoy the highest degree of decentralization and security from Layer 1 while maintain their high performance and sovereignty as independent Layer 2 networks.
Axon supports a Proof-of-Stake (PoS) consensus mechanism and requires each Axon-based appchain to issue native Extensible User Defined Tokens (xUDTs), which are designed and customized by the app chain's development team and released on CKB. For simplicity, the xUDTs on Axon-based chains are referred to as Axon tokens (AT tokens) below. Holders of AT tokens can stake to become validators and/or delegate their tokens to other validators in exchange for rewards. Unlike other sidechains where staking takes place on Layer 2, Axon's staking is grounded on Layer 1 CKB. Validators and other participants stake their native AT tokens on CKB, which uses a Proof-of-Work (PoW) consensus mechanism. This unique staking design helps Axon-based appchains enjoy the highest degree of decentralization and security from Layer 1 while maintain their high performance and sovereignty as independent Layer 2 networks.

## Roadmap

Expand All @@ -52,7 +52,7 @@ Axon provides the compiled binary on the [release page](`https://github.com/axon
# Clone from GitHub
git clone https://github.com/axonweb3/axon.git && cd axon
# Run release binary for single node
cargo run --release -- -c devtools/chain/config.toml -g devtools/chain/genesis_single_node.json
cargo run --release -- run -c devtools/chain/config.toml -g devtools/chain/genesis_single_node.json

```

Expand Down Expand Up @@ -81,7 +81,7 @@ The following ways are a great spot to ask questions about Axon:

## Socials

All Axon related accounts are displayed via [linktree](https://linktr.ee/axonweb3).
All Axon related accounts are displayed via [linktree](https://linktr.ee/axonweb3).

## License

Expand Down
92 changes: 53 additions & 39 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum Error {
GettingParent,
#[error("parsing genesis: {0}")]
ParsingGenesis(#[source] ParseError),
#[error("unknown subcommand: {0}")]
UnknownSubcommand(String),

#[error(transparent)]
Running(ProtocolError),
Expand All @@ -53,23 +55,27 @@ impl AxonCli {
pub fn init(axon_version: Version, cli_version: &'static str) -> Self {
let matches = Command::new("axon")
.version(cli_version)
.arg(
Arg::new("config_path")
.short('c')
.long("config")
.help("Axon config path")
.required(true)
.num_args(1),
)
.arg(
Arg::new("genesis_path")
.short('g')
.long("genesis")
.help("Axon genesis path")
.required(true)
.num_args(1),
)
.subcommand(Command::new("run").about("Run axon process"));
.subcommand_required(true)
.subcommand(
Command::new("run")
.about("Run axon process")
.arg(
Arg::new("config_path")
.short('c')
.long("config")
.help("Axon config path")
.required(true)
.num_args(1),
)
.arg(
Arg::new("genesis_path")
.short('g')
.long("genesis")
.help("Axon genesis path")
.required(true)
.num_args(1),
),
);

AxonCli {
version: axon_version,
Expand All @@ -85,29 +91,37 @@ impl AxonCli {
&self,
key_provider: Option<K>,
) -> Result<()> {
let config_path = self.matches.get_one::<String>("config_path").unwrap();
let path = Path::new(&config_path)
.parent()
.ok_or(Error::GettingParent)?;
let mut config: Config = parse_file(config_path, false).map_err(Error::ParsingConfig)?;

if let Some(ref mut f) = config.rocksdb.options_file {
*f = path.join(&f)
if let Some((cmd, matches)) = self.matches.subcommand() {
match cmd {
"run" => {
let config_path = matches.get_one::<String>("config_path").unwrap();
let path = Path::new(&config_path)
.parent()
.ok_or(Error::GettingParent)?;
let mut config: Config =
parse_file(config_path, false).map_err(Error::ParsingConfig)?;

if let Some(ref mut f) = config.rocksdb.options_file {
*f = path.join(&f)
}
let genesis: RichBlock =
parse_file(matches.get_one::<String>("genesis_path").unwrap(), true)
.map_err(Error::ParsingGenesis)?;

self.check_version(&config)?;

register_log(&config);

Axon::new(config, genesis)
.run(key_provider)
.map_err(Error::Running)
}
_ => Err(Error::UnknownSubcommand(cmd.to_owned())),
}
} else {
// Since `clap.subcommand_required(true)`.
unreachable!();
}
let genesis: RichBlock = parse_file(
self.matches.get_one::<String>("genesis_path").unwrap(),
true,
)
.map_err(Error::ParsingGenesis)?;

self.check_version(&config)?;

register_log(&config);

Axon::new(config, genesis)
.run(key_provider)
.map_err(Error::Running)?;
Ok(())
}

fn check_version(&self, config: &Config) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
- ./devtools:/app/devtools
networks:
- axon-net
command: ./axon -c=/app/devtools/chain/config.toml -g=/app/devtools/chain/genesis_single_node.json
command: ./axon run -c=/app/devtools/chain/config.toml -g=/app/devtools/chain/genesis_single_node.json


networks:
Expand Down

0 comments on commit b11530e

Please sign in to comment.