Przeglądaj źródła

feat(wallet): send returns token instead of string

thesimplekid 8 miesięcy temu
rodzic
commit
6e22426c6a

+ 1 - 0
CHANGELOG.md

@@ -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]).

+ 4 - 2
bindings/cdk-js/src/wallet.rs

@@ -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)]

+ 2 - 2
crates/cdk-cli/src/sub_commands/send.rs

@@ -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());
         }

+ 1 - 1
crates/cdk/examples/p2pk.rs

@@ -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();
 

+ 8 - 3
crates/cdk/src/wallet/mod.rs

@@ -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,

+ 1 - 1
crates/cdk/src/wallet/multi_mint_wallet.rs

@@ -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