diff --git a/moksha-cli/src/bin/moksha-cli.rs b/moksha-cli/src/bin/moksha-cli.rs index 86f8291c..e5e46706 100644 --- a/moksha-cli/src/bin/moksha-cli.rs +++ b/moksha-cli/src/bin/moksha-cli.rs @@ -118,6 +118,10 @@ async fn main() -> anyhow::Result<()> { Command::Receive { token } => { let token: TokenV3 = TokenV3::from_str(&token)?; let mint_urls = wallet.get_mint_urls().await?; + let currency = match &token.currency_unit { + Some(currency) => currency, + None => &CurrencyUnit::Sat, + }; let token_mint_url = match token.mint() { Some(url) => url, @@ -152,14 +156,15 @@ async fn main() -> anyhow::Result<()> { let wallet_keysets = wallet.get_wallet_keysets().await?; let wallet_keyset = wallet_keysets - .get_active(&token_mint_url, &CurrencyUnit::Sat) + .get_active(&token_mint_url, currency) .expect("no active keyset found"); wallet.receive_tokens(wallet_keyset, &token).await?; cli::show_total_balance(&wallet).await?; } Command::Send { amount } => { - let mint_url = choose_mint(&wallet, &CurrencyUnit::Sat).await?; + let currency_unit = CurrencyUnit::Sat; + let mint_url = choose_mint(&wallet, ¤cy_unit).await?; if mint_url.1 < amount { term.write_line("Error: Not enough tokens in selected mint")?; @@ -170,7 +175,7 @@ async fn main() -> anyhow::Result<()> { let wallet_keysets = wallet.get_wallet_keysets().await?; let wallet_keyset = wallet_keysets - .get_active(&mint_url, &CurrencyUnit::Sat) + .get_active(&mint_url, ¤cy_unit) .expect("no active keyset found"); term.write_line(&format!("Using tokens from mint: {mint_url}"))?; @@ -243,7 +248,8 @@ async fn main() -> anyhow::Result<()> { } Command::PayOnchain { address, amount } => { // FIXME remove redundant code - let mint_url = choose_mint(&wallet, &CurrencyUnit::Sat).await?; + let currency = CurrencyUnit::Sat; + let mint_url = choose_mint(&wallet, ¤cy).await?; if mint_url.1 < amount { term.write_line("Error: Not enough tokens in selected mint")?; @@ -253,7 +259,7 @@ async fn main() -> anyhow::Result<()> { let wallet_keysets = wallet.get_wallet_keysets().await?; let wallet_keyset = wallet_keysets - .get_active(&mint_url, &CurrencyUnit::Sat) + .get_active(&mint_url, ¤cy) .expect("Keyset not found"); let info = wallet.get_mint_info(&mint_url).await?; @@ -309,7 +315,8 @@ async fn main() -> anyhow::Result<()> { } } Command::Mint { amount } => { - let mint_url = choose_mint(&wallet, &CurrencyUnit::Sat).await?.0; + let currency = CurrencyUnit::Sat; + let mint_url = choose_mint(&wallet, ¤cy).await?.0; let info = wallet.get_mint_info(&mint_url).await?; @@ -396,7 +403,7 @@ async fn main() -> anyhow::Result<()> { let wallet_keysets = wallet.get_wallet_keysets().await?; let wallet_keyset = wallet_keysets - .get_active(&mint_url, &CurrencyUnit::Sat) + .get_active(&mint_url, ¤cy) .expect("Keyset not found"); let progress_bar = cli::progress_bar()?; diff --git a/moksha-core/src/token.rs b/moksha-core/src/token.rs index 2e5f1572..bd1b2ad8 100644 --- a/moksha-core/src/token.rs +++ b/moksha-core/src/token.rs @@ -53,7 +53,8 @@ where pub struct TokenV3 { #[serde(rename = "token")] pub tokens: Vec, - pub unit: Option, + #[serde(rename = "unit")] + pub currency_unit: Option, pub memo: Option, } @@ -62,7 +63,7 @@ impl TokenV3 { Self { tokens: vec![token], memo: None, - unit: None, + currency_unit: None, } } @@ -70,7 +71,7 @@ impl TokenV3 { Self { tokens: vec![], memo: None, - unit: None, + currency_unit: None, } } @@ -160,7 +161,7 @@ impl From<(Url, Proofs)> for TokenV3 { proofs: from.1, }], memo: None, - unit: None, + currency_unit: None, } } } @@ -173,7 +174,7 @@ impl From<(Url, CurrencyUnit, Proofs)> for TokenV3 { proofs: from.2, }], memo: None, - unit: Some(from.1), + currency_unit: Some(from.1), } } } @@ -227,7 +228,9 @@ mod tests { Some(Url::parse("https://8333.space:3338")?) ); assert_eq!(token.tokens[0].proofs.len(), 2); - assert_eq!(token.unit, Some(CurrencyUnit::Sat)); + assert_eq!(token.currency_unit, Some(CurrencyUnit::Sat)); + assert_eq!(token.memo, Some("Thank you.".to_string())); + assert_eq!(token.total_amount(), 10); let token_serialized = token.serialize()?; let fixture = read_fixture("token_nut_example.cashu")?; @@ -284,7 +287,7 @@ mod tests { let tokens = super::TokenV3 { tokens: vec![token], memo: Some("my memo".to_string()), - unit: None, + currency_unit: None, }; let serialized: String = tokens.try_into()?; diff --git a/moksha-wallet/src/wallet.rs b/moksha-wallet/src/wallet.rs index 08a38e2a..e918d0ea 100644 --- a/moksha-wallet/src/wallet.rs +++ b/moksha-wallet/src/wallet.rs @@ -1034,12 +1034,12 @@ mod tests { let first = result.0; - assert_eq!(CurrencyUnit::Sat, first.clone().unit.unwrap()); + assert_eq!(CurrencyUnit::Sat, first.clone().currency_unit.unwrap()); assert_eq!(24, first.total_amount()); let second = result.1; - assert_eq!(CurrencyUnit::Sat, second.clone().unit.unwrap()); + assert_eq!(CurrencyUnit::Sat, second.clone().currency_unit.unwrap()); assert_eq!(40, second.total_amount()); Ok(()) }