From 93d9b6204a8d75a13409d5e0485a940670f64910 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 30 Jun 2022 09:46:33 +0200 Subject: [PATCH 1/5] Add option to set the coin type --- src/command/account_manager.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/command/account_manager.rs b/src/command/account_manager.rs index 717bee1..3d7969e 100644 --- a/src/command/account_manager.rs +++ b/src/command/account_manager.rs @@ -3,10 +3,14 @@ use std::{fs::File, io::prelude::*}; -use clap::{Args, Parser, Subcommand}; +use clap::{ArgEnum, Args, Parser, Subcommand}; use iota_wallet::{ account_manager::AccountManager, - iota_client::{constants::SHIMMER_COIN_TYPE, secret::SecretManager, utils::generate_mnemonic}, + iota_client::{ + constants::{IOTA_COIN_TYPE, SHIMMER_COIN_TYPE}, + secret::SecretManager, + utils::generate_mnemonic, + }, ClientOptions, }; use log::LevelFilter; @@ -26,8 +30,8 @@ pub struct AccountManagerCli { #[derive(Debug, Clone, Subcommand)] pub enum AccountManagerCommand { - /// Initialize the wallet with a mnemonic and node url, if nothing is provided, a new mnemonic will be generated and "http://localhost:14265" used. - Init(MnemonicAndUrl), + /// Parameters for the init command. + Init(InitParameters), /// Create a new account with an optional alias. New { alias: Option }, /// Set the node to use. @@ -37,31 +41,42 @@ pub enum AccountManagerCommand { } #[derive(Debug, Clone, Args)] -pub struct MnemonicAndUrl { +pub struct InitParameters { #[clap(short, long)] pub mnemonic: Option, #[clap(short, long)] pub node: Option, + #[clap(short, long, arg_enum, value_parser)] + pub coin_type: Option, +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ArgEnum)] +pub enum CoinType { + Iota, + Shimmer, } pub async fn init_command( secret_manager: SecretManager, storage_path: String, - mnemonic_url: MnemonicAndUrl, + parameters: InitParameters, ) -> Result { let account_manager = AccountManager::builder() .with_secret_manager(secret_manager) .with_client_options( ClientOptions::new() - .with_node(mnemonic_url.node.as_deref().unwrap_or("http://localhost:14265"))? + .with_node(parameters.node.as_deref().unwrap_or("http://localhost:14265"))? .with_node_sync_disabled(), ) .with_storage_path(&storage_path) - .with_coin_type(SHIMMER_COIN_TYPE) + .with_coin_type(match parameters.coin_type { + Some(CoinType::Iota) => IOTA_COIN_TYPE, + Some(CoinType::Shimmer) | None => SHIMMER_COIN_TYPE, + }) .finish() .await?; - let mnemonic = match mnemonic_url.mnemonic { + let mnemonic = match parameters.mnemonic { Some(mnemonic) => mnemonic, None => generate_mnemonic()?, }; From 90397e1048ce8b686f17ffd4c22c440023d7d17e Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 30 Jun 2022 09:52:02 +0200 Subject: [PATCH 2/5] Docs --- documentation/docs/02_account_manager.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/documentation/docs/02_account_manager.md b/documentation/docs/02_account_manager.md index 34d3014..8456fab 100644 --- a/documentation/docs/02_account_manager.md +++ b/documentation/docs/02_account_manager.md @@ -53,10 +53,11 @@ When just initialised, the wallet has no account yet, use the `new` command to c #### Parameters -| Name | Optional | Default | Example | -| ----------- | --------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `mnemonic` | ✓ | Randomly generated | "aunt middle impose faith ramp kid olive good practice motor grab ready group episode oven matrix silver rhythm avocado assume humble tiger shiver hurt" (DO NOT USE THIS MNEMONIC) | -| `node` | ✓ | "http://localhost:14265/" | "http://localhost:14265/" | +| Name | Optional | Default | Example | +| ----------- | ----------- |------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `mnemonic` | ✓ | Randomly generated | "aunt middle impose faith ramp kid olive good practice motor grab ready group episode oven matrix silver rhythm avocado assume humble tiger shiver hurt" (DO NOT USE THIS MNEMONIC) | +| `node` | ✓ | "http://localhost:14265/" | "http://localhost:14265/" | +| `coin-type` | ✓ | "shimmer" | "iota" | #### Examples @@ -76,6 +77,11 @@ Initialise the wallet with a randomly generated mnemonic and a given node. $ ./wallet init --node "http://localhost:14265/" ``` +Initialise the wallet with a given coin type. +```sh +$ ./wallet init --coin-type "iota" +``` + ### `./wallet new` Creates a new account. From 193504ff98fff034cffeddc3964c68e875198f8d Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 30 Jun 2022 09:59:14 +0200 Subject: [PATCH 3/5] Remove match --- src/command/account_manager.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/command/account_manager.rs b/src/command/account_manager.rs index 3d7969e..d7cf401 100644 --- a/src/command/account_manager.rs +++ b/src/command/account_manager.rs @@ -51,9 +51,10 @@ pub struct InitParameters { } #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ArgEnum)] +#[repr(u32)] pub enum CoinType { - Iota, - Shimmer, + Iota = IOTA_COIN_TYPE, + Shimmer = SHIMMER_COIN_TYPE, } pub async fn init_command( @@ -69,10 +70,7 @@ pub async fn init_command( .with_node_sync_disabled(), ) .with_storage_path(&storage_path) - .with_coin_type(match parameters.coin_type { - Some(CoinType::Iota) => IOTA_COIN_TYPE, - Some(CoinType::Shimmer) | None => SHIMMER_COIN_TYPE, - }) + .with_coin_type(parameters.coin_type.unwrap_or(CoinType::Shimmer) as u32) .finish() .await?; From c8c85e64ed35806e3fbdc9890159c8a076e64e15 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 30 Jun 2022 10:32:44 +0200 Subject: [PATCH 4/5] Make coin-type u32 --- documentation/docs/02_account_manager.md | 12 ++++++------ src/command/account_manager.rs | 21 +++++---------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/documentation/docs/02_account_manager.md b/documentation/docs/02_account_manager.md index 8456fab..c65265a 100644 --- a/documentation/docs/02_account_manager.md +++ b/documentation/docs/02_account_manager.md @@ -53,11 +53,11 @@ When just initialised, the wallet has no account yet, use the `new` command to c #### Parameters -| Name | Optional | Default | Example | -| ----------- | ----------- |------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `mnemonic` | ✓ | Randomly generated | "aunt middle impose faith ramp kid olive good practice motor grab ready group episode oven matrix silver rhythm avocado assume humble tiger shiver hurt" (DO NOT USE THIS MNEMONIC) | -| `node` | ✓ | "http://localhost:14265/" | "http://localhost:14265/" | -| `coin-type` | ✓ | "shimmer" | "iota" | +| Name | Optional | Default | Example | +| ----------- | ----------- |----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `mnemonic` | ✓ | Randomly generated | "aunt middle impose faith ramp kid olive good practice motor grab ready group episode oven matrix silver rhythm avocado assume humble tiger shiver hurt" (DO NOT USE THIS MNEMONIC) | +| `node` | ✓ | "http://localhost:14265/" | "http://localhost:14265/" | +| `coin-type` | ✓ | 4219 | 4218 | #### Examples @@ -79,7 +79,7 @@ $ ./wallet init --node "http://localhost:14265/" Initialise the wallet with a given coin type. ```sh -$ ./wallet init --coin-type "iota" +$ ./wallet init --coin-type 4219 ``` ### `./wallet new` diff --git a/src/command/account_manager.rs b/src/command/account_manager.rs index d7cf401..569f731 100644 --- a/src/command/account_manager.rs +++ b/src/command/account_manager.rs @@ -3,14 +3,10 @@ use std::{fs::File, io::prelude::*}; -use clap::{ArgEnum, Args, Parser, Subcommand}; +use clap::{Args, Parser, Subcommand}; use iota_wallet::{ account_manager::AccountManager, - iota_client::{ - constants::{IOTA_COIN_TYPE, SHIMMER_COIN_TYPE}, - secret::SecretManager, - utils::generate_mnemonic, - }, + iota_client::{constants::SHIMMER_COIN_TYPE, secret::SecretManager, utils::generate_mnemonic}, ClientOptions, }; use log::LevelFilter; @@ -46,15 +42,8 @@ pub struct InitParameters { pub mnemonic: Option, #[clap(short, long)] pub node: Option, - #[clap(short, long, arg_enum, value_parser)] - pub coin_type: Option, -} - -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ArgEnum)] -#[repr(u32)] -pub enum CoinType { - Iota = IOTA_COIN_TYPE, - Shimmer = SHIMMER_COIN_TYPE, + #[clap(short, long)] + pub coin_type: Option, } pub async fn init_command( @@ -70,7 +59,7 @@ pub async fn init_command( .with_node_sync_disabled(), ) .with_storage_path(&storage_path) - .with_coin_type(parameters.coin_type.unwrap_or(CoinType::Shimmer) as u32) + .with_coin_type(parameters.coin_type.unwrap_or(SHIMMER_COIN_TYPE)) .finish() .await?; From d33b73ada7dd2fa86bba7dbf0cb638b9f5081da0 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 30 Jun 2022 10:39:36 +0200 Subject: [PATCH 5/5] Improve docs --- documentation/docs/02_account_manager.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/docs/02_account_manager.md b/documentation/docs/02_account_manager.md index c65265a..2c80fa1 100644 --- a/documentation/docs/02_account_manager.md +++ b/documentation/docs/02_account_manager.md @@ -57,7 +57,7 @@ When just initialised, the wallet has no account yet, use the `new` command to c | ----------- | ----------- |----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `mnemonic` | ✓ | Randomly generated | "aunt middle impose faith ramp kid olive good practice motor grab ready group episode oven matrix silver rhythm avocado assume humble tiger shiver hurt" (DO NOT USE THIS MNEMONIC) | | `node` | ✓ | "http://localhost:14265/" | "http://localhost:14265/" | -| `coin-type` | ✓ | 4219 | 4218 | +| `coin-type` | ✓ | 4219 (=Shimmer) | 4218 (=IOTA) | #### Examples @@ -78,6 +78,7 @@ $ ./wallet init --node "http://localhost:14265/" ``` Initialise the wallet with a given coin type. +See [SLIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) for all registered coin types. ```sh $ ./wallet init --coin-type 4219 ```