mirror of
https://github.com/aljazceru/cdk.git
synced 2026-01-03 21:15:22 +01:00
cashu-sdk: improve: mint active_keyset_puvkeys returns response type
This commit is contained in:
@@ -130,6 +130,11 @@ interface MintKeySet {
|
||||
constructor(string secret, string derivation_path, u8 max_order);
|
||||
};
|
||||
|
||||
|
||||
interface KeysResponse {
|
||||
constructor(Keys keys);
|
||||
};
|
||||
|
||||
interface KeySetResponse {
|
||||
constructor(sequence<Id> keyset_ids);
|
||||
sequence<Id> keyset_ids();
|
||||
|
||||
@@ -11,7 +11,7 @@ mod ffi {
|
||||
pub use crate::nuts::nut00::proof::{mint::Proof as MintProof, Proof};
|
||||
pub use crate::nuts::nut00::token::Token;
|
||||
pub use crate::nuts::nut01::key_pair::KeyPair;
|
||||
pub use crate::nuts::nut01::keys::Keys;
|
||||
pub use crate::nuts::nut01::keys::{Keys, KeysResponse};
|
||||
pub use crate::nuts::nut01::public_key::PublicKey;
|
||||
pub use crate::nuts::nut01::secret_key::SecretKey;
|
||||
pub use crate::nuts::nut02::{Id, KeySet, KeySetResponse, MintKeySet};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{collections::HashMap, ops::Deref, sync::Arc};
|
||||
|
||||
use crate::{Amount, PublicKey};
|
||||
use cashu::nuts::nut01::Keys as KeysSdk;
|
||||
use cashu::nuts::nut01::{Keys as KeysSdk, Response as KeysResponseSdk};
|
||||
use cashu::Amount as AmountSdk;
|
||||
|
||||
pub struct Keys {
|
||||
@@ -15,6 +15,24 @@ impl Deref for Keys {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keys> for KeysSdk {
|
||||
fn from(keys: Keys) -> KeysSdk {
|
||||
keys.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KeysSdk> for Keys {
|
||||
fn from(keys: KeysSdk) -> Keys {
|
||||
let keys = keys
|
||||
.keys()
|
||||
.into_iter()
|
||||
.map(|(amount, pk)| (amount.to_sat().to_string(), Arc::new(pk.into())))
|
||||
.collect();
|
||||
|
||||
Keys::new(keys)
|
||||
}
|
||||
}
|
||||
|
||||
impl Keys {
|
||||
pub fn new(keys: HashMap<String, Arc<PublicKey>>) -> Self {
|
||||
let keys = keys
|
||||
@@ -55,20 +73,35 @@ impl Keys {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Keys> for KeysSdk {
|
||||
fn from(keys: Keys) -> KeysSdk {
|
||||
pub struct KeysResponse {
|
||||
inner: KeysResponseSdk,
|
||||
}
|
||||
|
||||
impl Deref for KeysResponse {
|
||||
type Target = KeysResponseSdk;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KeysResponse> for KeysResponseSdk {
|
||||
fn from(keys: KeysResponse) -> KeysResponseSdk {
|
||||
keys.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl From<KeysSdk> for Keys {
|
||||
fn from(keys: KeysSdk) -> Keys {
|
||||
let keys = keys
|
||||
.keys()
|
||||
.into_iter()
|
||||
.map(|(amount, pk)| (amount.to_sat().to_string(), Arc::new(pk.into())))
|
||||
.collect();
|
||||
|
||||
Keys::new(keys)
|
||||
impl From<KeysResponseSdk> for KeysResponse {
|
||||
fn from(keys: KeysResponseSdk) -> KeysResponse {
|
||||
KeysResponse { inner: keys }
|
||||
}
|
||||
}
|
||||
|
||||
impl KeysResponse {
|
||||
pub fn new(keys: Arc<Keys>) -> Self {
|
||||
Self {
|
||||
inner: KeysResponseSdk {
|
||||
keys: keys.as_ref().deref().clone(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,11 @@ interface MintKeySet {
|
||||
constructor(string secret, string derivation_path, u8 max_order);
|
||||
};
|
||||
|
||||
|
||||
interface KeysResponse {
|
||||
constructor(Keys keys);
|
||||
};
|
||||
|
||||
interface KeySetResponse {
|
||||
constructor(sequence<Id> keyset_ids);
|
||||
sequence<Id> keyset_ids();
|
||||
@@ -326,7 +331,7 @@ interface Wallet {
|
||||
interface Mint {
|
||||
[Throws=CashuSdkError]
|
||||
constructor(string secret, string derivation_path, record<string, MintKeySet> inactive_keysets, sequence<Secret> spent_secrets, u8 max_order, Amount min_fee_reserve, f32 percent_fee_reserve);
|
||||
KeySet active_keyset_pubkeys();
|
||||
KeysResponse active_keyset_pubkeys();
|
||||
KeySetResponse keysets();
|
||||
MintKeySet active_keyset();
|
||||
KeySet? keyset(Id id);
|
||||
|
||||
@@ -8,10 +8,10 @@ mod ffi {
|
||||
pub use cashu_ffi::{
|
||||
Amount, BlindedMessage, BlindedMessages, BlindedSignature, Bolt11Invoice, CashuError,
|
||||
CheckFeesRequest, CheckFeesResponse, CheckSpendableRequest, CheckSpendableResponse, Id,
|
||||
InvoiceStatus, KeyPair, KeySet, KeySetResponse, Keys, MeltRequest, MeltResponse, MintInfo,
|
||||
MintKeySet, MintProof, MintProofs, MintRequest, MintVersion, Nut05MeltRequest,
|
||||
Nut05MeltResponse, PostMintResponse, Proof, PublicKey, RequestMintResponse, Secret,
|
||||
SecretKey, SplitRequest, SplitResponse, Token,
|
||||
InvoiceStatus, KeyPair, KeySet, KeySetResponse, Keys, KeysResponse, MeltRequest,
|
||||
MeltResponse, MintInfo, MintKeySet, MintProof, MintProofs, MintRequest, MintVersion,
|
||||
Nut05MeltRequest, Nut05MeltResponse, PostMintResponse, Proof, PublicKey,
|
||||
RequestMintResponse, Secret, SecretKey, SplitRequest, SplitResponse, Token,
|
||||
};
|
||||
|
||||
pub use crate::client::Client;
|
||||
|
||||
@@ -5,8 +5,9 @@ use std::{
|
||||
};
|
||||
|
||||
use cashu_ffi::{
|
||||
Amount, CheckSpendableRequest, CheckSpendableResponse, Id, KeySet, KeySetResponse, MeltRequest,
|
||||
MeltResponse, MintKeySet, MintRequest, PostMintResponse, Secret, SplitRequest, SplitResponse,
|
||||
Amount, CheckSpendableRequest, CheckSpendableResponse, Id, KeySet, KeySetResponse,
|
||||
KeysResponse, MeltRequest, MeltResponse, MintKeySet, MintRequest, PostMintResponse, Secret,
|
||||
SplitRequest, SplitResponse,
|
||||
};
|
||||
use cashu_sdk::mint::Mint as MintSdk;
|
||||
use cashu_sdk::nuts::nut02::Id as IdSdk;
|
||||
@@ -54,7 +55,7 @@ impl Mint {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn active_keyset_pubkeys(&self) -> Arc<KeySet> {
|
||||
pub fn active_keyset_pubkeys(&self) -> Arc<KeysResponse> {
|
||||
Arc::new(self.inner.read().unwrap().active_keyset_pubkeys().into())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user