Commit ce062ab7 authored by Éloïs's avatar Éloïs
Browse files

deps: upgrade dubp-client

parent aa6b9c6a
Pipeline #11309 passed with stages
in 11 minutes and 16 seconds
......@@ -101,6 +101,17 @@ dependencies = [
"tokio",
]
[[package]]
name = "async-trait"
version = "0.1.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "atty"
version = "0.2.14"
......@@ -339,12 +350,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bb454f0228b18c7f4c3b0ebbee346ed9c52e7443b0999cd543ff3571205701d"
[[package]]
name = "dubp-client"
version = "0.1.0"
source = "git+https://git.duniter.org/libs/dubp-rs-client-lib?branch=master#d1fc66c39c6109ef1291aa18ff34fa9002305a30"
name = "dubp"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3e3fe6a250aaa17de9d86c77028ae2b22f4f7d3b9716659d89d82fb72b2db68"
dependencies = [
"dubp-common",
"dubp-documents",
"dubp-documents-parser",
"dubp-wallet",
"dup-crypto",
]
[[package]]
name = "dubp-client"
version = "0.1.0"
source = "git+https://git.duniter.org/libs/dubp-rs-client-lib?branch=master#787229ae4a94fdb4278e86f8f47af15388345f90"
dependencies = [
"async-trait",
"dubp",
"graphql_client",
"maybe-async",
"mockall 0.9.1",
......@@ -355,9 +379,9 @@ dependencies = [
[[package]]
name = "dubp-common"
version = "0.47.0"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6129b6390317f4d82e04c7154e4d33566d30369871d867ad7fd1f10136ac601"
checksum = "c83386c1914b8f3d4a1fb2895b6e31899019b05de3fb6c7ec45d0f13238e6c64"
dependencies = [
"dup-crypto",
"serde",
......@@ -368,9 +392,9 @@ dependencies = [
[[package]]
name = "dubp-documents"
version = "0.47.0"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ab8de546678145b64b521094f5f4901d93d9270ff8d68ecd71db5f68ccbe9ee"
checksum = "eeabf1395e31c3e2a1dfabc1f97a933c361312e65f65ca843092b94a32e4ce19"
dependencies = [
"beef",
"dubp-wallet",
......@@ -382,9 +406,9 @@ dependencies = [
[[package]]
name = "dubp-documents-parser"
version = "0.47.0"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bdc20246a391211616d949cfd2219e74eab95effe2cf9c90a3d0f31b5269640"
checksum = "f441e42514531d4b04001ff95e20d9b681198bc8f13872af24281c350d2e96f2"
dependencies = [
"dubp-documents",
"json-pest-parser",
......@@ -396,9 +420,9 @@ dependencies = [
[[package]]
name = "dubp-wallet"
version = "0.47.0"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0c8044481a682172e4ee7ec9f9e16bf144063b606282e5df0ecb1920b41891"
checksum = "b89b1d3262a26156de5edcd97e20c2cd747a24ee1244e929b5ac3aada5519b94"
dependencies = [
"byteorder",
"dubp-common",
......@@ -410,9 +434,9 @@ dependencies = [
[[package]]
name = "dup-crypto"
version = "0.47.0"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0ff835eaa4f2af01e612d12c2c711b75a1fa060d31ec0eae9b5df13d78a57c6"
checksum = "093aa174cc3792e029e5deabf83986842595279840e5eab58e845efe33d75b48"
dependencies = [
"aes",
"arrayvec",
......
......@@ -10,13 +10,13 @@ description = "A command line client written in Rust that use Duniter GVA API."
[dependencies]
anyhow = "1.0.32"
dubp-client = { git = "https://git.duniter.org/libs/dubp-rs-client-lib", branch = "master", features = ["blocking"] }
#dubp-client= { path = "../dubp-rs-client-lib", features = ["blocking"] }
#dubp-client= { path = "../dubp-rs-client-lib", features = ["blocking"], default-features = false }
rpassword = "5.0.1"
serde = { version = "1.0.105", features = ["derive"] }
structopt = "0.3.18"
[dev-dependencies]
dubp-client = { git = "https://git.duniter.org/libs/dubp-rs-client-lib", branch = "master", features = ["blocking", "mock"] }
#dubp-client= { path = "../dubp-rs-client-lib", features = ["blocking", "mock"] }
#dubp-client= { path = "../dubp-rs-client-lib", features = ["blocking", "mock"], default-features = false }
mockall = "0.8.0"
......@@ -15,11 +15,10 @@
use crate::*;
pub(crate) fn balance<W: Write>(
gva_endpoint: &str,
pub(crate) fn balance<C: GvaClient, W: Write>(
gva_client: &C,
out: &mut W,
pubkey_or_script: &str,
requestor: &GvaRequestor,
ud_unit: bool,
) -> anyhow::Result<()> {
let pubkey_or_script = PubkeyOrScript::from_str(pubkey_or_script)?;
......@@ -28,7 +27,7 @@ pub(crate) fn balance<W: Write>(
if let Some(AccountBalance {
amount,
ud_amount_opt,
}) = requestor.account_balance(gva_endpoint, &pubkey_or_script, ud_unit)?
}) = gva_client.account_balance(&pubkey_or_script, ud_unit)?
{
println!(
"The server responded in {} ms.",
......@@ -68,15 +67,15 @@ mod tests {
#[test]
fn test_balance() -> anyhow::Result<()> {
let mut client = GvaRequestor::default();
client.expect_account_balance().returning(|_, _, _| {
let mut client = MockGvaClient::default();
client.expect_account_balance().returning(|_, _| {
Ok(Some(AccountBalance {
amount: SourceAmount::new(2046, 0),
ud_amount_opt: None,
}))
});
let mut out = Vec::new();
balance("", &mut out, "toto", &client, false)?;
balance(&client, &mut out, "toto", false)?;
let output = std::str::from_utf8(&out)?;
assert_eq!(output, "The balance of account 'SIG(toto)' is 20.46 Ğ1 !\n");
......@@ -86,15 +85,15 @@ mod tests {
#[test]
fn test_balance_with_ud_unit() -> anyhow::Result<()> {
let mut client = GvaRequestor::default();
client.expect_account_balance().returning(|_, _, _| {
let mut client = MockGvaClient::default();
client.expect_account_balance().returning(|_, _| {
Ok(Some(AccountBalance {
amount: SourceAmount::new(2_046, 0),
ud_amount_opt: Some(SourceAmount::new(1_023, 0)),
}))
});
let mut out = Vec::new();
balance("", &mut out, "toto", &client, true)?;
balance(&client, &mut out, "toto", true)?;
let output = std::str::from_utf8(&out)?;
assert_eq!(
......
......@@ -15,13 +15,12 @@
use crate::*;
pub(crate) fn current_ud<W: Write>(
gva_endpoint: &str,
pub(crate) fn current_ud<C: GvaClient, W: Write>(
gva_client: &C,
out: &mut W,
requestor: &GvaRequestor,
) -> anyhow::Result<()> {
let req_time = Instant::now();
if let Some(current_ud) = requestor.current_ud(gva_endpoint)? {
if let Some(current_ud) = gva_client.current_ud()? {
println!(
"The server responded in {} ms.",
req_time.elapsed().as_millis()
......@@ -47,10 +46,10 @@ mod tests {
#[test]
fn test_current_ud() -> anyhow::Result<()> {
let mut client = GvaRequestor::default();
client.expect_current_ud().returning(|_| Ok(Some(1_023)));
let mut client = MockGvaClient::default();
client.expect_current_ud().returning(|| Ok(Some(1_023)));
let mut out = Vec::new();
current_ud("", &mut out, &client)?;
current_ud(&client, &mut out)?;
let output = std::str::from_utf8(&out)?;
assert_eq!(output, "The current UD value is 10.23 Ğ1 !\n");
......
......@@ -15,11 +15,10 @@
use crate::*;
pub(crate) fn idty<W: Write>(
gva_endpoint: &str,
pub(crate) fn idty<C: GvaClient, W: Write>(
gva_client: &C,
out: &mut W,
pubkey: &str,
requestor: &GvaRequestor,
) -> anyhow::Result<()> {
let pubkey = PublicKey::from_base58(pubkey)?;
......@@ -28,7 +27,7 @@ pub(crate) fn idty<W: Write>(
is_member,
username,
..
}) = requestor.idty_by_pubkey(gva_endpoint, pubkey)?
}) = gva_client.idty_by_pubkey(pubkey)?
{
println!(
"The server responded in {} ms.",
......
......@@ -15,13 +15,12 @@
use crate::*;
pub(crate) fn members_count<W: Write>(
gva_endpoint: &str,
pub(crate) fn members_count<C: GvaClient, W: Write>(
gva_client: &C,
out: &mut W,
requestor: &GvaRequestor,
) -> anyhow::Result<()> {
let req_time = Instant::now();
let members_count = requestor.members_count(gva_endpoint)?;
let members_count = gva_client.members_count()?;
println!(
"The server responded in {} ms.",
req_time.elapsed().as_millis()
......@@ -44,10 +43,10 @@ mod tests {
#[test]
fn test_member_count() -> anyhow::Result<()> {
let mut client = GvaRequestor::default();
client.expect_members_count().returning(|_| Ok(10_000));
let mut client = MockGvaClient::default();
client.expect_members_count().returning(|| Ok(10_000));
let mut out = Vec::new();
members_count("", &mut out, &client)?;
members_count(&client, &mut out)?;
let output = std::str::from_utf8(&out)?;
assert_eq!(output, "There is currently 10000 members in Ğ1 WoT!\n");
......
......@@ -31,15 +31,12 @@ use commands::{
balance::balance, current_ud::current_ud, idty::idty, members_count::members_count,
wallet::wallet,
};
#[cfg(test)]
use dubp_client::MockGvaClient;
use dubp_client::{
crypto::keys::{ed25519::PublicKey, PublicKey as _},
AccountBalance, Idty, PubkeyOrScript,
AccountBalance, GvaClient, Idty, NaiveGvaClient, PubkeyOrScript,
};
#[cfg(not(test))]
use dubp_client::GvaRequestor;
#[cfg(test)]
use dubp_client::MockGvaRequestor as GvaRequestor;
use std::{
env::var_os,
fs::File,
......@@ -65,23 +62,17 @@ struct CliArgs {
fn main() -> anyhow::Result<()> {
let cli_args = CliArgs::from_args();
let gva_requestor = GvaRequestor::new();
let gva_client = NaiveGvaClient::new(&cli_args.server)?;
let mut out = std::io::stdout();
match cli_args.command {
Command::Balance {
pubkey_or_script,
ud_unit,
} => balance(
&cli_args.server,
&mut out,
&pubkey_or_script,
&gva_requestor,
ud_unit,
)?,
Command::CurrentUd => current_ud(&cli_args.server, &mut out, &gva_requestor)?,
Command::Idty { pubkey } => idty(&cli_args.server, &mut out, &pubkey, &gva_requestor)?,
Command::MembersCount => members_count(&cli_args.server, &mut out, &gva_requestor)?,
} => balance(&gva_client, &mut out, &pubkey_or_script, ud_unit)?,
Command::CurrentUd => current_ud(&gva_client, &mut out)?,
Command::Idty { pubkey } => idty(&gva_client, &mut out, &pubkey)?,
Command::MembersCount => members_count(&gva_client, &mut out)?,
Command::Wallet { command } => wallet(&mut out, command)?,
}
Ok(())
......
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