소스 검색

feat: add fee and fee to keys response (#1502)

* feat: add fee and fee to keys response

* feat: remove from MintKeyset to Keyset
tsk 2 주 전
부모
커밋
87dd8e064e

+ 13 - 16
crates/cashu/src/nuts/nut02.rs

@@ -469,6 +469,15 @@ pub struct KeySet {
     pub id: Id,
     /// Keyset [`CurrencyUnit`]
     pub unit: CurrencyUnit,
+    /// Keyset state - indicates whether the mint will sign new outputs with this keyset
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub active: Option<bool>,
+    /// Input fee in parts per thousand (ppk) per input spent from this keyset
+    #[serde(
+        deserialize_with = "deserialize_input_fee_ppk",
+        default = "default_input_fee_ppk"
+    )]
+    pub input_fee_ppk: u64,
     /// Keyset [`Keys`]
     pub keys: Keys,
     /// Expiry
@@ -495,18 +504,6 @@ impl KeySet {
     }
 }
 
-#[cfg(feature = "mint")]
-impl From<MintKeySet> for KeySet {
-    fn from(keyset: MintKeySet) -> Self {
-        Self {
-            id: keyset.id,
-            unit: keyset.unit,
-            keys: Keys::from(keyset.keys),
-            final_expiry: keyset.final_expiry,
-        }
-    }
-}
-
 /// KeySetInfo
 #[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize, Serialize)]
 #[cfg_attr(feature = "swagger", derive(utoipa::ToSchema))]
@@ -687,10 +684,10 @@ impl MintKeySet {
 #[cfg(feature = "mint")]
 impl From<MintKeySet> for Id {
     fn from(keyset: MintKeySet) -> Id {
-        let keys: super::KeySet = keyset.into();
-        match keys.id.version {
-            KeySetVersion::Version00 => Id::v1_from_keys(&keys.keys),
-            KeySetVersion::Version01 => Id::v2_from_data(&keys.keys, &keys.unit, keys.final_expiry),
+        let keys: Keys = keyset.keys.into();
+        match keyset.id.version {
+            KeySetVersion::Version00 => Id::v1_from_keys(&keys),
+            KeySetVersion::Version01 => Id::v2_from_data(&keys, &keyset.unit, keyset.final_expiry),
         }
     }
 }

+ 6 - 0
crates/cdk-common/src/database/wallet/test/mod.rs

@@ -285,6 +285,8 @@ where
     let keyset = cashu::KeySet {
         id: keyset_id,
         unit: CurrencyUnit::Sat,
+        active: None,
+        input_fee_ppk: 0,
         keys: keys.clone(),
         final_expiry: None,
     };
@@ -309,6 +311,8 @@ where
     let keyset = cashu::KeySet {
         id: keyset_id,
         unit: CurrencyUnit::Sat,
+        active: None,
+        input_fee_ppk: 0,
         keys: keys.clone(),
         final_expiry: None,
     };
@@ -333,6 +337,8 @@ where
     let keyset = cashu::KeySet {
         id: keyset_id,
         unit: CurrencyUnit::Sat,
+        active: None,
+        input_fee_ppk: 0,
         keys,
         final_expiry: None,
     };

+ 8 - 0
crates/cdk-ffi/src/types/keys.rs

@@ -161,6 +161,10 @@ pub struct KeySet {
     pub id: String,
     /// Currency unit
     pub unit: CurrencyUnit,
+    /// Keyset state - indicates whether the mint will sign new outputs with this keyset
+    pub active: Option<bool>,
+    /// Input fee in parts per thousand (ppk) per input spent from this keyset
+    pub input_fee_ppk: u64,
     /// The keys (map of amount to public key hex)
     pub keys: HashMap<u64, String>,
     /// Optional expiry timestamp
@@ -172,6 +176,8 @@ impl From<cdk::nuts::KeySet> for KeySet {
         Self {
             id: keyset.id.to_string(),
             unit: keyset.unit.into(),
+            active: keyset.active,
+            input_fee_ppk: keyset.input_fee_ppk,
             keys: keyset
                 .keys
                 .keys()
@@ -210,6 +216,8 @@ impl TryFrom<KeySet> for cdk::nuts::KeySet {
         Ok(cdk::nuts::KeySet {
             id,
             unit,
+            active: keyset.active,
+            input_fee_ppk: keyset.input_fee_ppk,
             keys,
             final_expiry: keyset.final_expiry,
         })

+ 2 - 0
crates/cdk-signatory/src/proto/convert.rs

@@ -316,6 +316,8 @@ impl TryInto<cdk_common::KeySet> for KeySet {
                 .ok_or(cdk_common::error::Error::Custom(INTERNAL_ERROR.to_owned()))?
                 .try_into()
                 .map_err(|_| cdk_common::Error::Custom("Invalid unit encoding".to_owned()))?,
+            active: Some(self.active),
+            input_fee_ppk: self.input_fee_ppk,
             keys: cdk_common::Keys::new(
                 self.keys
                     .ok_or(cdk_common::error::Error::Custom(INTERNAL_ERROR.to_owned()))?

+ 2 - 0
crates/cdk-signatory/src/signatory.rs

@@ -90,6 +90,8 @@ impl From<SignatoryKeySet> for KeySet {
         KeySet {
             id: val.id,
             unit: val.unit,
+            active: Some(val.active),
+            input_fee_ppk: val.input_fee_ppk,
             keys: val.keys,
             final_expiry: val.final_expiry,
         }

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
crates/cdk/src/mint/mod.rs


+ 2 - 0
crates/cdk/src/wallet/mint_metadata_cache.rs

@@ -495,6 +495,8 @@ impl MintMetadataCache {
                 let keyset = KeySet {
                     id: *keyset_id,
                     unit: keyset_info.unit.clone(),
+                    active: Some(keyset_info.active),
+                    input_fee_ppk: keyset_info.input_fee_ppk,
                     final_expiry: keyset_info.final_expiry,
                     keys: (**keys).clone(),
                 };

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.