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.bats b/cli.bats index 48282f8..5afc288 100644 --- a/cli.bats +++ b/cli.bats @@ -37,14 +37,14 @@ teardown() { [[ "$output" == *"SUBCOMMANDS"* ]] } -@test "succeeds: --chain=morden account new [empty options]" { - run $EMERALD_VAULT --chain=morden account new <<< $'foo\n' +@test "succeeds: --chain=etc-morden account new [empty options]" { + run $EMERALD_CLI --chain=etc-morden account new <<< $'foo\n' [ "$status" -eq 0 ] [[ "$output" == *"Created new account"* ]] } -@test "succeeds: --chain=etc-main new --security=high --name='Test account' --description='Some description'" { - run $EMERALD_VAULT --chain=etc-main \ +@test "succeeds: --chain=etc new --security=high --name='Test account' --description='Some description'" { + run $EMERALD_VAULT --chain=etc \ account new \ --security-level=high \ --name="Test account" \ @@ -55,7 +55,7 @@ teardown() { } @test "succeeds: account list" { - run $EMERALD_VAULT --chain=morden \ + run $EMERALD_CLI --chain=etc-morden \ account new \ <<< $'foo\n' [ "$status" -eq 0 ] @@ -69,7 +69,7 @@ teardown() { [[ "$address" != "" ]] [[ "$address" == *"0x"* ]] - run $EMERALD_VAULT --chain=morden account list + run $EMERALD_CLI --chain=etc-morden account list echo "$output" # prints in case fails echo "$address" @@ -78,7 +78,7 @@ teardown() { } @test "succeeds: account update" { - run $EMERALD_VAULT --chain=morden account new \ + run $EMERALD_CLI --chain=etc-morden account new \ <<< $'foo\n' [ "$status" -eq 0 ] [[ "$output" == *"Created new account"* ]] @@ -91,20 +91,20 @@ teardown() { [[ "$address" != "" ]] [[ "$address" == *"0x"* ]] - run $EMERALD_VAULT --chain=morden account update \ + run $EMERALD_CLI --chain=etc-morden account update \ "$address" \ --name="new name" \ --description="new description" [ "$status" -eq 0 ] - run $EMERALD_VAULT --chain=morden account list + run $EMERALD_CLI --chain=etc-morden account list [ "$status" -eq 0 ] [[ "$output" == *"new name"* ]] } @test "succeeds: account strip" { - run $EMERALD_VAULT --chain=morden account new \ + run $EMERALD_CLI --chain=etc-morden account new \ <<< $'foo\n' [ "$status" -eq 0 ] [[ "$output" == *"Created new account"* ]] @@ -117,7 +117,7 @@ teardown() { [[ "$address" != "" ]] [[ "$address" == *"0x"* ]] - run $EMERALD_VAULT --chain=morden account strip \ + run $EMERALD_CLI --chain=etc-morden account strip \ "$address" \ <<< $'foo\n' @@ -126,7 +126,7 @@ teardown() { } @test "succeeds: account hide && unhide" { - run $EMERALD_VAULT --chain=morden account new \ + run $EMERALD_CLI --chain=etc-morden account new \ <<< $'foo\n' [ "$status" -eq 0 ] [[ "$output" == *"Created new account"* ]] @@ -140,22 +140,22 @@ teardown() { [[ "$address" == *"0x"* ]] # Hide account. - run $EMERALD_VAULT --chain=morden account hide \ + run $EMERALD_CLI --chain=etc-morden account hide \ "$address" [ "$status" -eq 0 ] # Ensure is hidden; doesn't show up in list. - run $EMERALD_VAULT --chain=morden account list \ + run $EMERALD_CLI --chain=etc-morden account list \ [ "$status" -eq 0 ] [[ "$output" != *"$address"* ]] # Unhide account. - run $EMERALD_VAULT --chain=morden account unhide \ + run $EMERALD_CLI --chain=etc-morden account unhide \ "$address" # Ensure is not hidden; shows up in list. - run $EMERALD_VAULT --chain=morden account list + run $EMERALD_CLI --chain=etc-morden account list [ "$status" -eq 0 ] [[ "$output" == *"$address"* ]] diff --git a/cli.yml b/cli.yml index 45a1cb3..cdc881a 100644 --- a/cli.yml +++ b/cli.yml @@ -22,9 +22,11 @@ args: short: c long: chain help: Sets a chain name - default_value: mainnet + default_value: etc-main 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 9a3589d..1706b2f 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 @@ -82,4 +94,4 @@ Will set verbose level to 1 - only info messages. # emerald-vault -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..7afc42c --- /dev/null +++ b/src/cmd/migrate.rs @@ -0,0 +1,33 @@ +//! # Storage migration related commands + +use super::ExecResult; +use std::path::Path; + +/// 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 1fe47c9..965e2f0 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -2,6 +2,7 @@ mod account; mod error; +mod migrate; mod transaction; #[macro_use] mod arg_handlers; @@ -9,6 +10,7 @@ mod arg_handlers; 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}; @@ -23,7 +25,7 @@ use std::sync::Arc; type ExecResult = Result<(), Error>; -const DEFAULT_CHAIN_NAME: &str = "mainnet"; +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), 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