feat(wallet): send returns token instead of string

This commit is contained in:
thesimplekid
2024-07-15 14:58:06 +01:00
parent 023adee215
commit 6e22426c6a
6 changed files with 17 additions and 9 deletions

View File

@@ -27,6 +27,7 @@
### Summary ### Summary
### Changed ### Changed
- cdk(wallet): `fn send` returns `Token` so the user can use the struct of convert it to a v3 or v4 string.
### Added ### Added
- cdk(NUT-11): Add `Copy` on `SigFlag` ([thesimplekid]). - cdk(NUT-11): Add `Copy` on `SigFlag` ([thesimplekid]).

View File

@@ -219,7 +219,8 @@ impl JsWallet {
let target = split_target_amount let target = split_target_amount
.map(|a| SplitTarget::Value(*a.deref())) .map(|a| SplitTarget::Value(*a.deref()))
.unwrap_or_default(); .unwrap_or_default();
self.inner Ok(self
.inner
.send( .send(
Amount::from(amount), Amount::from(amount),
memo, memo,
@@ -229,7 +230,8 @@ impl JsWallet {
false, false,
) )
.await .await
.map_err(into_err) .map_err(into_err)?
.to_string())
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]

View File

@@ -5,7 +5,7 @@ use std::str::FromStr;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use cdk::amount::SplitTarget; use cdk::amount::SplitTarget;
use cdk::nuts::{Conditions, PublicKey, SpendingConditions, Token}; use cdk::nuts::{Conditions, PublicKey, SpendingConditions};
use cdk::wallet::types::SendKind; use cdk::wallet::types::SendKind;
use cdk::wallet::Wallet; use cdk::wallet::Wallet;
use cdk::{Amount, UncheckedUrl}; use cdk::{Amount, UncheckedUrl};
@@ -176,7 +176,7 @@ pub async fn send(
match sub_command_args.v3 { match sub_command_args.v3 {
true => { true => {
let token = Token::from_str(&token)?; let token = token;
println!("{}", token.to_v3_string()); println!("{}", token.to_v3_string());
} }

View File

@@ -63,7 +63,7 @@ async fn main() -> Result<(), Error> {
println!("{}", token); println!("{}", token);
let amount = wallet let amount = wallet
.receive(&token, SplitTarget::default(), &[secret], &[]) .receive(&token.to_string(), SplitTarget::default(), &[secret], &[])
.await .await
.unwrap(); .unwrap();

View File

@@ -965,14 +965,19 @@ impl Wallet {
/// Send specific proofs /// Send specific proofs
#[instrument(skip(self))] #[instrument(skip(self))]
pub async fn send_proofs(&self, memo: Option<String>, proofs: Proofs) -> Result<String, Error> { pub async fn send_proofs(&self, memo: Option<String>, proofs: Proofs) -> Result<Token, Error> {
for proof in proofs.iter() { for proof in proofs.iter() {
self.localstore self.localstore
.set_proof_state(proof.y()?, State::Reserved) .set_proof_state(proof.y()?, State::Reserved)
.await?; .await?;
} }
Ok(Token::new(self.mint_url.clone(), proofs, memo, Some(self.unit)).to_string()) Ok(Token::new(
self.mint_url.clone(),
proofs,
memo,
Some(self.unit),
))
} }
/// Send /// Send
@@ -985,7 +990,7 @@ impl Wallet {
amount_split_target: &SplitTarget, amount_split_target: &SplitTarget,
send_kind: &SendKind, send_kind: &SendKind,
include_fees: bool, include_fees: bool,
) -> Result<String, Error> { ) -> Result<Token, Error> {
// If online send check mint for current keysets fees // If online send check mint for current keysets fees
if matches!( if matches!(
send_kind, send_kind,

View File

@@ -125,7 +125,7 @@ impl MultiMintWallet {
conditions: Option<SpendingConditions>, conditions: Option<SpendingConditions>,
send_kind: SendKind, send_kind: SendKind,
include_fees: bool, include_fees: bool,
) -> Result<String, Error> { ) -> Result<Token, Error> {
let wallet = self let wallet = self
.get_wallet(wallet_key) .get_wallet(wallet_key)
.await .await