Skip to content

Commit

Permalink
Add option to set the coin type (#116)
Browse files Browse the repository at this point in the history
* Add option to set the coin type

* Docs

* Remove match

* Make coin-type u32

* Improve docs
  • Loading branch information
thibault-martinez authored Jun 30, 2022
1 parent e44051e commit c69b3e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
15 changes: 11 additions & 4 deletions documentation/docs/02_account_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` || 4219 (=Shimmer) | 4218 (=IOTA) |

#### Examples

Expand All @@ -76,6 +77,12 @@ 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.
See [SLIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md) for all registered coin types.
```sh
$ ./wallet init --coin-type 4219
```

### `./wallet new`

Creates a new account.
Expand Down
16 changes: 9 additions & 7 deletions src/command/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,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<String> },
/// Set the node to use.
Expand All @@ -37,31 +37,33 @@ pub enum AccountManagerCommand {
}

#[derive(Debug, Clone, Args)]
pub struct MnemonicAndUrl {
pub struct InitParameters {
#[clap(short, long)]
pub mnemonic: Option<String>,
#[clap(short, long)]
pub node: Option<String>,
#[clap(short, long)]
pub coin_type: Option<u32>,
}

pub async fn init_command(
secret_manager: SecretManager,
storage_path: String,
mnemonic_url: MnemonicAndUrl,
parameters: InitParameters,
) -> Result<AccountManager, Error> {
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(parameters.coin_type.unwrap_or(SHIMMER_COIN_TYPE))
.finish()
.await?;

let mnemonic = match mnemonic_url.mnemonic {
let mnemonic = match parameters.mnemonic {
Some(mnemonic) => mnemonic,
None => generate_mnemonic()?,
};
Expand Down

0 comments on commit c69b3e6

Please sign in to comment.