From 38e137bf3e9b0ab6b4ca96f42524b750a0c78b20 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 17 Aug 2021 17:11:42 +1000 Subject: [PATCH 1/2] Use baru 0.4 from crates.io --- Cargo.lock | 3 ++- extension/wallet/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f398696..713ad6df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,7 +133,8 @@ dependencies = [ [[package]] name = "baru" version = "0.4.0" -source = "git+https://github.com/comit-network/baru.git?rev=43b7a057ed030c555ca3599c753ba7a66a703428#43b7a057ed030c555ca3599c753ba7a66a703428" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b45e969d512f4797d62c9a353c673cad386bc195a46243d5d233cadc5ee46ccd" dependencies = [ "aes-gcm-siv", "anyhow", diff --git a/extension/wallet/Cargo.toml b/extension/wallet/Cargo.toml index 3f46c1e9..c7faa9bd 100644 --- a/extension/wallet/Cargo.toml +++ b/extension/wallet/Cargo.toml @@ -14,7 +14,7 @@ default = ["console_error_panic_hook"] aes-gcm-siv = { version = "0.9", features = ["std"] } anyhow = "1" async-trait = "0.1" -baru = { git = "https://github.com/comit-network/baru.git", rev = "43b7a057ed030c555ca3599c753ba7a66a703428" } +baru = "0.4" bip32 = { version = "0.2", features = ["secp256k1-ffi", "bip39"], default-features = false } conquer-once = "0.3" console_error_panic_hook = { version = "0.1.6", optional = true } From 1c9f0e1a8b1b69e0678c2a5918b9863624cc35f5 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 17 Aug 2021 17:14:55 +1000 Subject: [PATCH 2/2] Return balances as expected by frontend --- extension/wallet/src/wallet/get_balances.rs | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/extension/wallet/src/wallet/get_balances.rs b/extension/wallet/src/wallet/get_balances.rs index baf6b454..c6870ebe 100644 --- a/extension/wallet/src/wallet/get_balances.rs +++ b/extension/wallet/src/wallet/get_balances.rs @@ -1,8 +1,10 @@ use crate::{ + assets, esplora::EsploraClient, - wallet::{current, BalanceEntry, Wallet}, + wallet::{current, Wallet}, }; use anyhow::Result; +use elements::AssetId; use futures::lock::Mutex; pub async fn get_balances( @@ -13,7 +15,23 @@ pub async fn get_balances( let mut wallet = current(name, current_wallet).await?; wallet.sync(client).await?; - let balances = wallet.compute_balances(); + let balances = wallet + .compute_balances() + .into_iter() + .map(|e| BalanceEntry { + asset: e.asset, + value: e.value, + ticker: assets::lookup(e.asset).map(|(ticker, _)| ticker.to_owned()), + }) + .collect(); Ok(balances) } + +/// A single balance entry as returned by [`get_balances`]. +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, PartialEq)] +pub struct BalanceEntry { + pub asset: AssetId, + pub value: u64, + pub ticker: Option, +}