Forráskód Böngészése

Merge pull request #559 from thesimplekid/fix_multi_mint_token_check

fix: multi mint check
thesimplekid 2 hónapja
szülő
commit
a66454c387

+ 1 - 0
CHANGELOG.md

@@ -32,6 +32,7 @@
 * `Wallet::receive_raw` which receives raw binary tokens ([lollerfirst]).
 
 ### Fixed
+* Multimint unit check when wallet receiving token ([thesimplekid])
 
 ### Removed
 

+ 4 - 0
crates/cashu/src/nuts/nut00/token.rs

@@ -272,6 +272,10 @@ impl TokenV3 {
 
         mint_urls
     }
+
+    pub fn is_multi_mint(&self) -> bool {
+        self.token.len() > 1
+    }
 }
 
 impl FromStr for TokenV3 {

+ 9 - 6
crates/cdk/src/wallet/receive.rs

@@ -190,20 +190,23 @@ impl Wallet {
         p2pk_signing_keys: &[SecretKey],
         preimages: &[String],
     ) -> Result<Amount, Error> {
-        let token_data = Token::from_str(encoded_token)?;
+        let token = Token::from_str(encoded_token)?;
 
-        let unit = token_data.unit().unwrap_or_default();
+        let unit = token.unit().unwrap_or_default();
 
         if unit != self.unit {
             return Err(Error::UnitUnsupported);
         }
 
-        let proofs = token_data.proofs();
-        if proofs.len() != 1 {
-            return Err(Error::MultiMintTokenNotSupported);
+        let proofs = token.proofs();
+
+        if let Token::TokenV3(token) = &token {
+            if token.is_multi_mint() {
+                return Err(Error::MultiMintTokenNotSupported);
+            }
         }
 
-        if self.mint_url != token_data.mint_url()? {
+        if self.mint_url != token.mint_url()? {
             return Err(Error::IncorrectMint);
         }