From 62329e5348cef849904756af25c49c2edd8539c7 Mon Sep 17 00:00:00 2001 From: r8d8 Date: Mon, 27 Aug 2018 13:17:47 +0300 Subject: [PATCH 1/5] Update chain id arg --- Cargo.toml | 4 ++-- README.md | 2 +- cli.bats | 4 ++-- cli.yml | 2 +- docs/usage.adoc | 16 ++++++++++++++-- src/cmd/mod.rs | 2 +- usage.txt | 43 ------------------------------------------- 7 files changed, 21 insertions(+), 52 deletions(-) delete mode 100644 usage.txt diff --git a/Cargo.toml b/Cargo.toml index f69c12c..e4ba218 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "emerald-cli" -version = "0.23.0" +version = "0.24.0" authors = ["Constantine Kryvomaz "] description = "Console utility for secure account management" homepage = "http://etcdevteam.com" @@ -27,7 +27,7 @@ hex = "0.2" lazy_static = "0.2" serde_json = "1.0" serde_derive = "1.0" -emerald-rs = "0.23.0" +emerald-rs = { path = "../emerald-rs" } regex = "0.2" hyper = "0.10" reqwest = "0.6" diff --git a/README.md b/README.md index 2bcbde9..b982601 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ FLAGS: OPTIONS: -p, --base-path Set path for chain storage - -c, --chain Sets a chain name [default: mainnet] + -c, --chain Sets a chain name [default: etc] SUBCOMMANDS: account Account related commands diff --git a/cli.bats b/cli.bats index 6843629..e68d371 100644 --- a/cli.bats +++ b/cli.bats @@ -43,8 +43,8 @@ teardown() { [[ "$output" == *"Created new account"* ]] } -@test "succeeds: --chain=mainnet new --security=high --name='Test account' --description='Some description'" { - run $EMERALD_CLI --chain=mainnet \ +@test "succeeds: --chain=etc new --security=high --name='Test account' --description='Some description'" { + run $EMERALD_CLI --chain=etc \ account new \ --security-level=high \ --name="Test account" \ diff --git a/cli.yml b/cli.yml index f4265e3..d210ff5 100644 --- a/cli.yml +++ b/cli.yml @@ -22,7 +22,7 @@ args: short: c long: chain help: Sets a chain name - default_value: mainnet + default_value: etc takes_value: true subcommands: - server: diff --git a/docs/usage.adoc b/docs/usage.adoc index 34a3bec..4b48618 100644 --- a/docs/usage.adoc +++ b/docs/usage.adoc @@ -19,7 +19,7 @@ FLAGS: OPTIONS: -p, --base-path Set path for chain storage - -c, --chain Sets a chain name [default: mainnet] + -c, --chain Sets a chain name [default: etc-main] SUBCOMMANDS: account Account related commands @@ -64,13 +64,25 @@ Environment variables allow you to redefine the default settings: * `EMERALD_HOST` - RPC server listen host * `EMERALD_PORT` - RPC server listen port -* `EMERALD_CHAIN` - chain name (`mainnet` | `morden`), has a higher priority relative to `EMERALD_CHAIN_ID` +* `EMERALD_CHAIN` - chain name (see Table.1, `CLI argument` column), has a higher priority relative to `EMERALD_CHAIN_ID` * `EMERALD_CHAIN_ID` - chain id number, has a lower priority relative to `EMERALD_CHAIN` * `EMERALD_GAS` - maximum gas limit to use by transaction * `EMERALD_GAS_PRICE` - gas cost to use by transaction (in Gwei) * `EMERALD_SECURITY_LEVEL` - security level (`normal` | `high` | `ultra`) * `EMERALD_NODE` - url to upstream node. Used for sign and send of transactions +| Chain id | Description | CLI argument | +|-----------|-----------------------------------|----------------| +| 1 | Ethereum mainnet | eth | +| 2 | Morden (disused), Expanse mainnet | morden | +| 3 | Ropsten | ropsten | +| 4 | Rinkeby | rinkeby | +| 30 | Rootstock mainnet | rootstock-main | +| 31 | Rootstock testnet | rootstock-test | +| 42 | Kovan | kovan | +| 61 | Ethereum Classic mainnet | etc-main | +| 62 | Ethereum Classic testnet | etc-test | + Table 1. Chain id and name ## Output details level diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 1fe47c9..19be4e6 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -23,7 +23,7 @@ use std::sync::Arc; type ExecResult = Result<(), Error>; -const DEFAULT_CHAIN_NAME: &str = "mainnet"; +const DEFAULT_CHAIN_NAME: &str = "etc"; const DEFAULT_UPSTREAM: &str = "127.0.0.1:8545"; /// Create new command executor diff --git a/usage.txt b/usage.txt deleted file mode 100644 index dde5e39..0000000 --- a/usage.txt +++ /dev/null @@ -1,43 +0,0 @@ -Emerald offline wallet command line interface. - -Usage: - emerald mnemonic - emerald server [--chain=] [--port=] [--host=] [--base-path=] [-v | --verbose] [-q | --quite] - emerald new [--chain=] ([[--security-level=] [--name=] [--description=]] | --raw ) - emerald list [--chain=] [--show-hidden] - emerald hide [--chain=]
- emerald unhide [--chain=] ([-a | --all] |
) - emerald strip [--chain=]
- emerald import [--chain=] [-a | --all] [-f | --force] - emerald export [--chain=] ([-a | --all] |
) - emerald update [--chain=]
[--name=] [--description=] - emerald transaction [--chain=] [--gas=] [--gas-price=] [--data=]\ - (--nonce= | --upstream=) (--raw [ | - ]) - emerald balance
[--upstream=] - emerald -V | --version - emerald -h | --help - -Options: - -a, --all Apply action to all accounts - -c, --chain= Chain name - -f, --force Override existing keystore file - -h, --help Show this message - -V, --version Show current version - -r, --raw Use raw input as value (ex.: private key, rlp-encoded signed transaction) - -q, --quiet Only errors printed to the output - -v, --verbose Verbose output - --data= Optional data included in a transaction - --name= Account name - --description= Account description - --host= Listen host [default: 127.0.0.1] - --port= Listen port [default: 1920] - --base-path= Base directory path, if omitted default os-specific value will be used: - + Mac OS X: ~/Library/Emerald - + Linux: ~/.emerald - + Windows: %USERDIR%\.emerald - --security-level= Level of security for cryptographic operations [default: ultra] - --show-hidden Include hidden keyfiles - --upstream= URL to ethereum node - --gas= Gas limit for transaction, hex-encoded value in `wei` - --gas-price= Gas price for transaction, hex-encoded value in `wei` - --nonce= Transaction count of sender From 23b886b67d4f15ab31cec3daf4eee3e7488b7a7e Mon Sep 17 00:00:00 2001 From: r8d8 Date: Wed, 29 Aug 2018 13:25:06 +0300 Subject: [PATCH 2/5] Add migrattion command --- .gitignore | 2 +- cli.yml | 2 ++ docs/usage.adoc | 2 +- src/cmd/migrate.rs | 33 +++++++++++++++++++++++++++++++++ src/cmd/mod.rs | 5 ++++- 5 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/cmd/migrate.rs diff --git a/.gitignore b/.gitignore index 6d910f3..8f32ce7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /target/ -**/*.rs.bk +*.rs.bk .idea/ *.iml Cargo.lock diff --git a/cli.yml b/cli.yml index d210ff5..9d80240 100644 --- a/cli.yml +++ b/cli.yml @@ -25,6 +25,8 @@ args: default_value: etc takes_value: true subcommands: + - migrate: + about: Migrate to a new storage structure - server: about: Start local RPC server args: diff --git a/docs/usage.adoc b/docs/usage.adoc index 4b48618..dd9ce6f 100644 --- a/docs/usage.adoc +++ b/docs/usage.adoc @@ -94,4 +94,4 @@ Will set verbose level to 1 - only info messages. # emerald -vv -Will set verbose level to 2 - info and debug messages. \ No newline at end of file +Will set verbose level to 2 - info and debug messages. diff --git a/src/cmd/migrate.rs b/src/cmd/migrate.rs new file mode 100644 index 0000000..1e8c0dc --- /dev/null +++ b/src/cmd/migrate.rs @@ -0,0 +1,33 @@ +//! # Storage migration related commands + +use std::path::Path; +use super::ExecResult; + +/// Migrate storage from old scheme to new +/// +/// # Arguments: +/// +/// * +/// +// /home/k2/.emerald +// ├── [4.0K] mainnet +// │   ├── [4.0K] addressbook +// │   ├── [4.0K] contracts +// │   │   ├── [1.8K] 0x0047201aed0b69875b24b614dda0270bcd9f11cc.json +// │   │   └── [ 78] 0x085fb4f24031eaedbc2b611aa528f22343eb52db.json +// │   └── [4.0K] keystore +// ├── [4.0K] morden +// │   ├── [4.0K] addressbook +// │   ├── [4.0K] contracts +// │   └── [4.0K] keystore +// └── [4.0K] testnet +// ├── [4.0K] contracts +// └── [4.0K] keystore + +pub fn migrate_cmd() -> ExecResult { + println!("{}", Path::new("/home/.emerald/mainnet").exists()); + println!("{}", Path::new("/home/.emerald/morden").exists()); + println!("{}", Path::new("/home/.emerald/testnet").exists()); + + Ok(()) +} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 19be4e6..5af8542 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -3,9 +3,11 @@ mod account; mod error; mod transaction; +mod migrate; #[macro_use] mod arg_handlers; +use self::migrate::migrate_cmd; use self::account::account_cmd; pub use self::arg_handlers::*; pub use self::error::Error; @@ -23,7 +25,7 @@ use std::sync::Arc; type ExecResult = Result<(), Error>; -const DEFAULT_CHAIN_NAME: &str = "etc"; +const DEFAULT_CHAIN_NAME: &str = "etc-main"; const DEFAULT_UPSTREAM: &str = "127.0.0.1:8545"; /// Create new command executor @@ -46,6 +48,7 @@ pub fn execute(matches: &ArgMatches) -> ExecResult { let keystore = storage_ctrl.get_keystore(chain)?; match matches.subcommand() { + ("migrate", Some(sub_m)) => migrate_cmd(), ("server", Some(sub_m)) => server_cmd(sub_m, storage_ctrl.clone(), chain), ("account", Some(sub_m)) => account_cmd(sub_m, keystore, &env), ("transaction", Some(sub_m)) => transaction_cmd(sub_m, keystore, &env, chain), From 9512ebb68f1abd693a5a58641c4e95fd6f5afbed Mon Sep 17 00:00:00 2001 From: r8d8 Date: Mon, 3 Sep 2018 16:51:44 +0300 Subject: [PATCH 3/5] Update bats tests to use new chain id --- cli.bats | 32 ++++++++++++++++---------------- cli.yml | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cli.bats b/cli.bats index a02bcb6..25b77fb 100644 --- a/cli.bats +++ b/cli.bats @@ -37,14 +37,14 @@ teardown() { [[ "$output" == *"SUBCOMMANDS"* ]] } -@test "succeeds: --chain=morden account new [empty options]" { - run $EMERALD_CLI --chain=morden account new <<< $'foo\n' +@test "succeeds: --chain=etc-test account new [empty options]" { + run $EMERALD_CLI --chain=etc-test account new <<< $'foo\n' [ "$status" -eq 0 ] [[ "$output" == *"Created new account"* ]] } -@test "succeeds: --chain=etc new --security=high --name='Test account' --description='Some description'" { - run $EMERALD_CLI --chain=etc \ +@test "succeeds: --chain=etc-main new --security=high --name='Test account' --description='Some description'" { + run $EMERALD_CLI --chain=etc-main \ account new \ --security-level=high \ --name="Test account" \ @@ -55,7 +55,7 @@ teardown() { } @test "succeeds: account list" { - run $EMERALD_CLI --chain=morden \ + run $EMERALD_CLI --chain=etc-test \ account new \ <<< $'foo\n' [ "$status" -eq 0 ] @@ -69,7 +69,7 @@ teardown() { [[ "$address" != "" ]] [[ "$address" == *"0x"* ]] - run $EMERALD_CLI --chain=morden account list + run $EMERALD_CLI --chain=etc-test account list echo "$output" # prints in case fails echo "$address" @@ -78,7 +78,7 @@ teardown() { } @test "succeeds: account update" { - run $EMERALD_CLI --chain=morden account new \ + run $EMERALD_CLI --chain=etc-test account new \ <<< $'foo\n' [ "$status" -eq 0 ] [[ "$output" == *"Created new account"* ]] @@ -91,20 +91,20 @@ teardown() { [[ "$address" != "" ]] [[ "$address" == *"0x"* ]] - run $EMERALD_CLI --chain=morden account update \ + run $EMERALD_CLI --chain=etc-test account update \ "$address" \ --name="new name" \ --description="new description" [ "$status" -eq 0 ] - run $EMERALD_CLI --chain=morden account list + run $EMERALD_CLI --chain=etc-test account list [ "$status" -eq 0 ] [[ "$output" == *"new name"* ]] } @test "succeeds: account strip" { - run $EMERALD_CLI --chain=morden account new \ + run $EMERALD_CLI --chain=etc-test account new \ <<< $'foo\n' [ "$status" -eq 0 ] [[ "$output" == *"Created new account"* ]] @@ -117,7 +117,7 @@ teardown() { [[ "$address" != "" ]] [[ "$address" == *"0x"* ]] - run $EMERALD_CLI --chain=morden account strip \ + run $EMERALD_CLI --chain=etc-test account strip \ "$address" \ <<< $'foo\n' @@ -126,7 +126,7 @@ teardown() { } @test "succeeds: account hide && unhide" { - run $EMERALD_CLI --chain=morden account new \ + run $EMERALD_CLI --chain=etc-test account new \ <<< $'foo\n' [ "$status" -eq 0 ] [[ "$output" == *"Created new account"* ]] @@ -140,22 +140,22 @@ teardown() { [[ "$address" == *"0x"* ]] # Hide account. - run $EMERALD_CLI --chain=morden account hide \ + run $EMERALD_CLI --chain=etc-test account hide \ "$address" [ "$status" -eq 0 ] # Ensure is hidden; doesn't show up in list. - run $EMERALD_CLI --chain=morden account list \ + run $EMERALD_CLI --chain=etc-test account list \ [ "$status" -eq 0 ] [[ "$output" != *"$address"* ]] # Unhide account. - run $EMERALD_CLI --chain=morden account unhide \ + run $EMERALD_CLI --chain=etc-test account unhide \ "$address" # Ensure is not hidden; shows up in list. - run $EMERALD_CLI --chain=morden account list + run $EMERALD_CLI --chain=etc-test account list [ "$status" -eq 0 ] [[ "$output" == *"$address"* ]] diff --git a/cli.yml b/cli.yml index 9d80240..a9573d2 100644 --- a/cli.yml +++ b/cli.yml @@ -22,7 +22,7 @@ args: short: c long: chain help: Sets a chain name - default_value: etc + default_value: etc-main takes_value: true subcommands: - migrate: From 71258dc23c74529a988e289324e5b5f8ae72dc3b Mon Sep 17 00:00:00 2001 From: r8d8 Date: Mon, 29 Oct 2018 16:06:45 +0200 Subject: [PATCH 4/5] Update formatting --- src/cmd/migrate.rs | 2 +- src/cmd/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/migrate.rs b/src/cmd/migrate.rs index 1e8c0dc..7afc42c 100644 --- a/src/cmd/migrate.rs +++ b/src/cmd/migrate.rs @@ -1,7 +1,7 @@ //! # Storage migration related commands -use std::path::Path; use super::ExecResult; +use std::path::Path; /// Migrate storage from old scheme to new /// diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 5af8542..965e2f0 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -2,15 +2,15 @@ mod account; mod error; -mod transaction; mod migrate; +mod transaction; #[macro_use] mod arg_handlers; -use self::migrate::migrate_cmd; use self::account::account_cmd; pub use self::arg_handlers::*; pub use self::error::Error; +use self::migrate::migrate_cmd; use self::transaction::transaction_cmd; use super::emerald::keystore::{KdfDepthLevel, KeyFile}; use super::emerald::mnemonic::{gen_entropy, Language, Mnemonic, ENTROPY_BYTE_LENGTH}; From b8fe97dee034e3d8e4d2a424552391d63020ba32 Mon Sep 17 00:00:00 2001 From: r8d8 Date: Wed, 31 Oct 2018 12:19:19 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d834d5f..08b4ca3 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ FLAGS: OPTIONS: -p, --base-path Set path for chain storage - -c, --chain Sets a chain name [default: etc] + -c, --chain Sets a chain name [default: etc-main] SUBCOMMANDS: account Account related commands