Skip to content
Snippets Groups Projects
Commit 5070aa05 authored by Hugo Trentesaux's avatar Hugo Trentesaux Committed by Hugo Trentesaux
Browse files

doc add examples

parent d22714af
No related branches found
No related tags found
1 merge request!7Big refacto
......@@ -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
......
......@@ -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 } => {
......
......@@ -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,
......
......@@ -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 => {
......
......@@ -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?;
}
};
......
......@@ -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,8 +153,18 @@ impl Data {
match self.args.secret.clone() {
None => {}
Some(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() {
// other secret type
......
......@@ -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())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment