Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit 3c09b927 authored by Éloïs's avatar Éloïs
Browse files

feat(balance): add option --ud-unit

parent 925f55e1
query BalanceQuery($script: String!) {
query BalanceQuery($script: String!, $withUd: Boolean!) {
balance(script: $script) {
amount
base
}
currentUd @include(if: $withUd) {
amount
}
}
query CurrentUdQuery {
currentUd {
amount
base
}
}
......@@ -57,6 +57,8 @@ enum SubCommand {
/// Get account balance
Balance {
pubkey_or_script: String,
#[structopt(short, long)]
ud_unit: bool,
},
/// Get current UD value
CurrentUd,
......@@ -68,27 +70,41 @@ fn main() -> anyhow::Result<()> {
let client = Client::new();
match cli_args.command {
SubCommand::Balance { pubkey_or_script } => {
SubCommand::Balance {
pubkey_or_script,
ud_unit,
} => {
let request_body = BalanceQuery::build_query(balance_query::Variables {
script: pubkey_or_script.clone(),
with_ud: ud_unit,
});
let balance_query::ResponseData {
balance: balance_query::BalanceQueryBalance { amount, .. },
balance: balance_query::BalanceQueryBalance { amount },
current_ud: current_ud_opt,
} = client.send_gql_query(&request_body, &cli_args.server)?;
let int_part = amount / 100;
let dec_part = amount % 100;
println!(
"The balance of account '{}' is {}.{} Ğ1 !",
pubkey_or_script, int_part, dec_part
);
if let Some(balance_query::BalanceQueryCurrentUd { amount: ud_amount }) = current_ud_opt
{
println!(
"The balance of account '{}' is {:.2} UDĞ1 !",
pubkey_or_script,
amount as f64 / ud_amount as f64,
);
} else {
println!(
"The balance of account '{}' is {}.{} Ğ1 !",
pubkey_or_script,
amount / 100,
amount % 100
);
}
}
SubCommand::CurrentUd => {
let request_body = CurrentUdQuery::build_query(current_ud_query::Variables);
if let current_ud_query::ResponseData {
current_ud: Some(current_ud_query::CurrentUdQueryCurrentUd { amount, .. }),
current_ud: Some(current_ud_query::CurrentUdQueryCurrentUd { amount }),
} = client.send_gql_query(&request_body, &cli_args.server)?
{
let int_part = amount / 100;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment