diff --git a/doc/example.md b/doc/example.md index 01d1d40fe64927998f5ee5948163badd031c2711..b53a28727ec2052413a42b2d4bb1b407e451c49b 100644 --- a/doc/example.md +++ b/doc/example.md @@ -2,27 +2,6 @@ Useful when developing: replace `gcli` by `cargo run --` to build in debug mode and launch gcli. -## Mnemonics - -Used in duniter-indexer genesis config: -`pipe paddle ketchup filter life ice feel embody glide quantum ride usage` - -with derivations: - -- `//2` → `test1` -- `//4` → `test2` -- `//6` → `test3` - -Used in substrate for Alice, Bob and Co: -`bottom drive obey lake curtain smoke basket hold race lonely fit walk` - -with derivations: - -- `//Alice` -- `//Bob` -- `//Charlie` -- ... - ## Configuration It can be handful to use Gcli with a configuration file to avoid passing arguments on every command. @@ -36,17 +15,27 @@ gcli config where gcli --network gdev config save # save config to use Alice predefined secret gcli -S predefined -s Alice config save +# these can be combined +gcli --network local -S predefined -s test1 config save ``` +In the following, we assume this last command was run. + ## Commands ```sh # get duniter current block -gcli current-block -# get balance of test1 account -gcli --address 5FeggKqw2AbnGZF9Y9WPM2QTgzENS3Hit94Ewgmzdg5a3LNa account balance +gcli blockchain current-block +# get balance of configured account +gcli account balance +# get identity information without indexer +gcli --no-indexer identity get -a 5Hn2LeMZXPFitMwrmrGucwtAPSLEiP4o5zTF7kHzMBtEkJUr # get information about test1 identity (needs indexer) gcli identity get --username test1 +# claim universal dividends +gcli ud claim +# transfer 5000 units +gcli account transfer 5000 5E4i8vcNjnrDp21Sbnp32WHm2gz8YP3GGFwmdpfg5bHd8Whb ``` ## Indexer commands diff --git a/src/commands/account.rs b/src/commands/account.rs index 04d058ef4e43b40a277f0c9556db1db0e8bda28a..15650a8ef881f1091297fccf9ecd82aa14e572b8 100644 --- a/src/commands/account.rs +++ b/src/commands/account.rs @@ -39,7 +39,6 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( dest, keep_alive, } => { - data = data; commands::transfer::transfer(&data, amount, dest, keep_alive).await?; } Subcommand::TransferMultiple { amount, dests } => { diff --git a/src/commands/blockchain.rs b/src/commands/blockchain.rs index ec869d2e7606b750147a658ea60bd785e4134fcf..7befecd498e602af22695e30fc8944dcf4b6eb12 100644 --- a/src/commands/blockchain.rs +++ b/src/commands/blockchain.rs @@ -22,7 +22,7 @@ pub enum Subcommand { /// handle blockchain commands pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> { - let mut data = data.build_client().await?.build_indexer().await?; + let mut data = data.build_client().await?; match command { Subcommand::Repart { target, diff --git a/src/commands/identity.rs b/src/commands/identity.rs index 3d676d663c6169f48a71d325c70a372b1bd2df4c..098d3d15c197dd83828c1b98b810d87df969ef09 100644 --- a/src/commands/identity.rs +++ b/src/commands/identity.rs @@ -38,7 +38,7 @@ pub enum Subcommand { /// handle identity commands pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> { - let mut data = data.build_client().await?.build_indexer().await?; + let mut data = data.build_client().await?; match command { Subcommand::Show => {} Subcommand::Get { @@ -46,6 +46,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( identity_id, ref username, } => { + data = data.build_indexer().await?; commands::identity::get_identity( &data, account_id.clone(), @@ -55,11 +56,9 @@ pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<( .await? } Subcommand::Create { target } => { - data = data; commands::identity::create_identity(data.keypair(), data.client(), target).await?; } Subcommand::Confirm { name } => { - data = data; commands::identity::confirm_identity(data.keypair(), data.client(), name).await?; } Subcommand::Revoke => { diff --git a/src/commands/ud.rs b/src/commands/ud.rs index 7bc6d9faf5e1a60d00fb9512cfd676eecab44ef6..1a7d143023a2f45a75fb550da8a2e50a96bb3bdd 100644 --- a/src/commands/ud.rs +++ b/src/commands/ud.rs @@ -11,11 +11,10 @@ pub enum Subcommand { /// handle ud commands pub async fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> { // build indexer because it is needed for all subcommands - let mut data = data.build_client().await?; + let data = data.build_client().await?; // match subcommand match command { Subcommand::Claim => { - data = data; claim_ud(data).await?; } }; diff --git a/src/data.rs b/src/data.rs index 16901cdca612cfce799197a8cd64d09ff1e1da87..5f56111e01d3c76cdce962812520ef6c8d3efafd 100644 --- a/src/data.rs +++ b/src/data.rs @@ -6,6 +6,8 @@ use indexer::Indexer; // consts pub const SUBSTRATE_MNEMONIC: &str = "bottom drive obey lake curtain smoke basket hold race lonely fit walk"; +pub const TEST_MNEMONIC: &str = + "pipe paddle ketchup filter life ice feel embody glide quantum ride usage"; pub const LOCAL_DUNITER_ENDPOINT: &str = "ws://localhost:9944"; pub const LOCAL_INDEXER_ENDPOINT: &str = "http://localhost:8080/v1/graphql"; @@ -151,7 +153,17 @@ impl Data { match self.args.secret.clone() { None => {} Some(derivation) => { - self.cfg.secret = Some(format!("{SUBSTRATE_MNEMONIC}//{derivation}")); + if derivation.starts_with("test") { + let derivation = match &derivation[..] { + "test1" => "2", + "test2" => "4", + "test3" => "3", + _ => "" + }; + self.cfg.secret = Some(format!("{TEST_MNEMONIC}//{derivation}")); + } else { + self.cfg.secret = Some(format!("{SUBSTRATE_MNEMONIC}//{derivation}")); + } } }; } else if let Some(secret) = self.args.secret.clone() { diff --git a/src/main.rs b/src/main.rs index 3633553b7598cf71d4754d930f9e1d4c482e26fc..bbf47a9256bef88d0c21e335e770e2e2f2baf56c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,27 +97,25 @@ async fn main() -> Result<(), GcliError> { // match subcommands match data.args.subcommand.clone() { - Subcommand::DoNothing => {} + Subcommand::DoNothing => {Ok(())} Subcommand::Account(subcommand) => { - commands::account::handle_command(data, subcommand).await? + commands::account::handle_command(data, subcommand).await } Subcommand::Identity(subcommand) => { - commands::identity::handle_command(data, subcommand).await? + commands::identity::handle_command(data, subcommand).await } - Subcommand::Smith(subcommand) => commands::smith::handle_command(data, subcommand).await?, + Subcommand::Smith(subcommand) => commands::smith::handle_command(data, subcommand).await, Subcommand::Tech(subcommand) => { - commands::collective::handle_command(data, subcommand).await? + commands::collective::handle_command(data, subcommand).await } - Subcommand::Ud(subcommand) => commands::ud::handle_command(data, subcommand).await?, + Subcommand::Ud(subcommand) => commands::ud::handle_command(data, subcommand).await, Subcommand::Oneshot(subcommand) => { - commands::oneshot::handle_command(data, subcommand).await? + commands::oneshot::handle_command(data, subcommand).await } Subcommand::Blockchain(subcommand) => { - commands::blockchain::handle_command(data, subcommand).await? + commands::blockchain::handle_command(data, subcommand).await } - Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?, - Subcommand::Config(subcommand) => conf::handle_command(data, subcommand)?, - } - - Ok(()) + Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await, + Subcommand::Config(subcommand) => conf::handle_command(data, subcommand), + }.map_err(|e| dbg!(e).into()) }