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
### Changed
- cdk(wallet): `fn send` returns `Token` so the user can use the struct of convert it to a v3 or v4 string.
### Added
- cdk(NUT-11): Add `Copy` on `SigFlag` ([thesimplekid]).

View File

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

View File

@@ -5,7 +5,7 @@ use std::str::FromStr;
use anyhow::{bail, Result};
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::Wallet;
use cdk::{Amount, UncheckedUrl};
@@ -176,7 +176,7 @@ pub async fn send(
match sub_command_args.v3 {
true => {
let token = Token::from_str(&token)?;
let token = token;
println!("{}", token.to_v3_string());
}

View File

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

View File

@@ -965,14 +965,19 @@ impl Wallet {
/// Send specific proofs
#[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() {
self.localstore
.set_proof_state(proof.y()?, State::Reserved)
.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
@@ -985,7 +990,7 @@ impl Wallet {
amount_split_target: &SplitTarget,
send_kind: &SendKind,
include_fees: bool,
) -> Result<String, Error> {
) -> Result<Token, Error> {
// If online send check mint for current keysets fees
if matches!(
send_kind,

View File

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