Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Update chain id arguments handling #129

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target/
**/*.rs.bk
*.rs.bk
.idea/
*.iml
Cargo.lock
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ FLAGS:

OPTIONS:
-p, --base-path <base-path> Set path for chain storage
-c, --chain <chain> Sets a chain name [default: mainnet]
-c, --chain <chain> Sets a chain name [default: etc]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ETH and ETC can't share same name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but ETH is ETH, not mainnet, it's different name. I mean it's ok to have etc as a synonym to mainnet, but it shouldn't eliminate mainnet, because it's what expected to use for mainnet

Copy link
Contributor Author

@r8d8 r8d8 Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see. Will make then prefix for specific blockchain (etc-..|eth-...) and leave as is for distinctive name.


SUBCOMMANDS:
account Account related commands
Expand Down
32 changes: 16 additions & 16 deletions cli.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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-test account new [empty options]" {
splix marked this conversation as resolved.
Show resolved Hide resolved
run $EMERALD_CLI --chain=etc-test account new <<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
}

@test "succeeds: --chain=mainnet new --security=high --name='Test account' --description='Some description'" {
run $EMERALD_VAULT --chain=mainnet \
@test "succeeds: --chain=etc-main new --security=high --name='Test account' --description='Some description'" {
run $EMERALD_CLI --chain=etc-main \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

@r8d8 r8d8 Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ETH and ETC can't share same name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

account new \
--security-level=high \
--name="Test account" \
Expand All @@ -55,7 +55,7 @@ teardown() {
}

@test "succeeds: account list" {
run $EMERALD_VAULT --chain=morden \
run $EMERALD_CLI --chain=etc-test \
account new \
<<< $'foo\n'
[ "$status" -eq 0 ]
Expand All @@ -69,7 +69,7 @@ teardown() {
[[ "$address" != "" ]]
[[ "$address" == *"0x"* ]]

run $EMERALD_VAULT --chain=morden account list
run $EMERALD_CLI --chain=etc-test account list
echo "$output" # prints in case fails
echo "$address"

Expand All @@ -78,7 +78,7 @@ teardown() {
}

@test "succeeds: account update" {
run $EMERALD_VAULT --chain=morden account new \
run $EMERALD_CLI --chain=etc-test account new \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
Expand All @@ -91,20 +91,20 @@ teardown() {
[[ "$address" != "" ]]
[[ "$address" == *"0x"* ]]

run $EMERALD_VAULT --chain=morden account update \
run $EMERALD_CLI --chain=etc-test account update \
"$address" \
--name="new name" \
--description="new description"
[ "$status" -eq 0 ]

run $EMERALD_VAULT --chain=morden account list
run $EMERALD_CLI --chain=etc-test account list

[ "$status" -eq 0 ]
[[ "$output" == *"new name"* ]]
}

@test "succeeds: account strip" {
run $EMERALD_VAULT --chain=morden account new \
run $EMERALD_CLI --chain=etc-test account new \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
Expand All @@ -117,7 +117,7 @@ teardown() {
[[ "$address" != "" ]]
[[ "$address" == *"0x"* ]]

run $EMERALD_VAULT --chain=morden account strip \
run $EMERALD_CLI --chain=etc-test account strip \
"$address" \
<<< $'foo\n'

Expand All @@ -126,7 +126,7 @@ teardown() {
}

@test "succeeds: account hide && unhide" {
run $EMERALD_VAULT --chain=morden account new \
run $EMERALD_CLI --chain=etc-test account new \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
Expand All @@ -140,22 +140,22 @@ teardown() {
[[ "$address" == *"0x"* ]]

# Hide account.
run $EMERALD_VAULT --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_VAULT --chain=morden account list \
run $EMERALD_CLI --chain=etc-test account list \

[ "$status" -eq 0 ]
[[ "$output" != *"$address"* ]]

# Unhide account.
run $EMERALD_VAULT --chain=morden account unhide \
run $EMERALD_CLI --chain=etc-test account unhide \
"$address"

# Ensure is not hidden; shows up in list.
run $EMERALD_VAULT --chain=morden account list
run $EMERALD_CLI --chain=etc-test account list

[ "$status" -eq 0 ]
[[ "$output" == *"$address"* ]]
Expand Down
4 changes: 3 additions & 1 deletion cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 15 additions & 3 deletions docs/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ FLAGS:

OPTIONS:
-p, --base-path <base-path> Set path for chain storage
-c, --chain <chain> Sets a chain name [default: mainnet]
-c, --chain <chain> Sets a chain name [default: etc-main]

SUBCOMMANDS:
account Account related commands
Expand Down Expand Up @@ -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 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geth uses morden, why vault has own testnet instead?

Copy link
Contributor Author

@r8d8 r8d8 Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ETH morden chain id is 2, ETC morden - 62

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should (or is?) CLI argument etc be synonym for etc-main?

like eth is implicit for eth-main?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and let's use mainet/testnet instead of main/test, to avoid confusion. I mean etc-mainnet (as a synonym to simple mainnet), not etc-main which will be a totally new name

Table 1. Chain id and name

## Output details level

Expand All @@ -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.
Will set verbose level to 2 - info and debug messages.
33 changes: 33 additions & 0 deletions src/cmd/migrate.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
5 changes: 4 additions & 1 deletion src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

mod account;
mod error;
mod migrate;
mod transaction;
#[macro_use]
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};
Expand All @@ -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
Expand All @@ -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),
Expand Down
43 changes: 0 additions & 43 deletions usage.txt

This file was deleted.