From 5070aa05a6db2f6667e257e7d3b5e41a6c788cfa Mon Sep 17 00:00:00 2001 From: Hugo Trentesaux <hugo@trentesaux.fr> Date: Thu, 8 Jun 2023 13:22:08 +0200 Subject: [PATCH] doc add examples --- doc/example.md | 37 +++++++++++++------------------------ src/commands/account.rs | 1 - src/commands/blockchain.rs | 2 +- src/commands/identity.rs | 5 ++--- src/commands/ud.rs | 3 +-- src/data.rs | 14 +++++++++++++- src/main.rs | 24 +++++++++++------------- 7 files changed, 41 insertions(+), 45 deletions(-) diff --git a/doc/example.md b/doc/example.md index 01d1d40..b53a287 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 04d058e..15650a8 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 ec869d2..7befecd 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 3d676d6..098d3d1 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 7bc6d9f..1a7d143 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 16901cd..5f56111 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 3633553..bbf47a9 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()) } -- GitLab