Bladeren bron

wallet: check proofs status

thesimplekid 1 jaar geleden
bovenliggende
commit
1d7bc0cda9

+ 3 - 2
bindings/cashu-ffi/src/cashu.udl

@@ -213,7 +213,7 @@ interface MintVersion {
 };
 
 interface MintInfo {
-	constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence<sequence<string>> contact, sequence<string> nuts, string? motd);
+	constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence<sequence<string>>? contact, sequence<string> nuts, string? motd);
 };
 
 enum InvoiceStatus {
@@ -221,4 +221,5 @@ enum InvoiceStatus {
 	"Paid",
 	"Expired",
 	"InFlight"
-};
+};
+

+ 1 - 0
bindings/cashu-ffi/src/lib.rs

@@ -27,6 +27,7 @@ mod ffi {
     pub use crate::nuts::nut09::{MintInfo, MintVersion};
     pub use crate::types::amount::Amount;
     pub use crate::types::Bolt11Invoice;
+
     pub use cashu::types::InvoiceStatus;
 
     // UDL

+ 1 - 1
bindings/cashu-ffi/src/nuts/nut09/mod.rs

@@ -54,7 +54,7 @@ impl MintInfo {
         version: Option<Arc<MintVersion>>,
         description: Option<String>,
         description_long: Option<String>,
-        contact: Vec<Vec<String>>,
+        contact: Option<Vec<Vec<String>>>,
         nuts: Vec<String>,
         motd: Option<String>,
     ) -> Self {

+ 41 - 0
bindings/cashu-ffi/src/types/proofs_status.rs

@@ -0,0 +1,41 @@
+use std::{ops::Deref, sync::Arc};
+
+use cashu::types::ProofsStatus as ProofsStatusSdk;
+
+use crate::MintProof;
+
+pub struct ProofsStatus {
+    inner: ProofsStatusSdk,
+}
+
+impl ProofsStatus {
+    pub fn new(spendable: Vec<Arc<MintProof>>, spent: Vec<Arc<MintProof>>) -> Self {
+        Self {
+            inner: ProofsStatusSdk {
+                spendable: spendable
+                    .iter()
+                    .map(|p| p.as_ref().deref().clone())
+                    .collect(),
+                spent: spent.iter().map(|p| p.as_ref().deref().clone()).collect(),
+            },
+        }
+    }
+
+    pub fn spendable(&self) -> Vec<Arc<MintProof>> {
+        self.inner
+            .spendable
+            .clone()
+            .into_iter()
+            .map(|p| Arc::new(p.into()))
+            .collect()
+    }
+
+    pub fn spent(&self) -> Vec<Arc<MintProof>> {
+        self.inner
+            .spent
+            .clone()
+            .into_iter()
+            .map(|p| Arc::new(p.into()))
+            .collect()
+    }
+}

+ 0 - 0
bindings/cashu-sdk-ffi/README.md


+ 50 - 0
bindings/cashu-sdk-ffi/bindings-python/README.md

@@ -0,0 +1,50 @@
+Cashu Sdk Python bindings
+
+
+**ALPHA** This library is in early development, the api will change.
+
+## Supported Nuts:
+
+Check: [https://github.com/thesimplekid/cashu-crab#implemented-nuts](https://github.com/thesimplekid/cashu-crab#implemented-nuts)
+
+## Build the package
+
+```shell
+just python
+```
+
+## Getting Started
+
+For now this is not published as a package as it is still in early development. So you will have to build it as above. In the future this will be pulished and pip can be used to install. 
+
+```python
+from cashu_sdk import Wallet, Client, Amount
+
+client = Client("https://mutinynet-cashu.thesimplekid.space")
+
+mint_keys = client.get_keys()
+
+wallet = Wallet(client, mint_keys)
+
+mint_request = wallet.request_mint(Amount.from_sat(10))
+
+print(mint_request.invoice())
+
+print(mint_request.hash())
+
+```
+
+
+## License
+
+Code is under the [BSD 3-Clause License](LICENSE)
+
+## Contribution
+
+All contributions welcome.
+
+Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.
+
+## Contact
+
+I can be contacted for comments or questions on nostr at _@thesimplekid.com (npub1qjgcmlpkeyl8mdkvp4s0xls4ytcux6my606tgfx9xttut907h0zs76lgjw) or via email tsk@thesimplekid.com.

+ 0 - 3
bindings/cashu-sdk-ffi/bindings-python/examples/test.py

@@ -1,3 +0,0 @@
-import cashu_sdk;
-
-help(cashu_sdk)

+ 13 - 0
bindings/cashu-sdk-ffi/bindings-python/examples/wallet.py

@@ -0,0 +1,13 @@
+from cashu_sdk import Wallet, Client, Amount
+
+client = Client("https://mutinynet-cashu.thesimplekid.space")
+
+mint_keys = client.get_keys()
+
+wallet = Wallet(client, mint_keys)
+
+mint_request = wallet.request_mint(Amount.from_sat(10))
+
+print(mint_request.invoice())
+
+print(mint_request.hash())

+ 7 - 2
bindings/cashu-sdk-ffi/src/cashu_sdk.udl

@@ -216,7 +216,7 @@ interface MintVersion {
 };
 
 interface MintInfo {
-	constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence<sequence<string>> contact, sequence<string> nuts, string? motd);
+	constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence<sequence<string>>? contact, sequence<string> nuts, string? motd);
 };
 
 enum InvoiceStatus {
@@ -226,6 +226,12 @@ enum InvoiceStatus {
 	"InFlight"
 };
 
+interface ProofsStatus {
+	constructor(sequence<MintProof> spendable, sequence<MintProof> spent);
+	sequence<MintProof> spendable();
+	sequence<MintProof> spent();
+};
+
 // Cashu Sdk
 
 
@@ -272,7 +278,6 @@ interface Client {
 
 interface Wallet {
 	constructor(Client client, Keys mint_keys);
-    // TODO: ProofStatus type
 	// [Throws=CashuSdkError]
 	// ProofsStatus check_proofs_spent(sequence<MintProof> proofs);
     [Throws=CashuSdkError]

+ 1 - 1
bindings/cashu-sdk-ffi/src/lib.rs

@@ -15,7 +15,7 @@ mod ffi {
 
     pub use crate::client::Client;
     pub use crate::error::CashuSdkError;
-    pub use crate::types::{Melted, SendProofs};
+    pub use crate::types::{Melted, ProofsStatus, SendProofs};
     pub use crate::wallet::Wallet;
 
     // UDL

+ 2 - 0
bindings/cashu-sdk-ffi/src/types/mod.rs

@@ -1,5 +1,7 @@
 pub mod melted;
+pub mod proofs_status;
 pub mod send_proofs;
 
 pub use melted::Melted;
+pub use proofs_status::ProofsStatus;
 pub use send_proofs::SendProofs;

+ 41 - 0
bindings/cashu-sdk-ffi/src/types/proofs_status.rs

@@ -0,0 +1,41 @@
+use std::{ops::Deref, sync::Arc};
+
+use cashu_sdk::types::ProofsStatus as ProofsStatusSdk;
+
+use crate::MintProof;
+
+pub struct ProofsStatus {
+    inner: ProofsStatusSdk,
+}
+
+impl ProofsStatus {
+    pub fn new(spendable: Vec<Arc<MintProof>>, spent: Vec<Arc<MintProof>>) -> Self {
+        Self {
+            inner: ProofsStatusSdk {
+                spendable: spendable
+                    .iter()
+                    .map(|p| p.as_ref().deref().clone())
+                    .collect(),
+                spent: spent.iter().map(|p| p.as_ref().deref().clone()).collect(),
+            },
+        }
+    }
+
+    pub fn spendable(&self) -> Vec<Arc<MintProof>> {
+        self.inner
+            .spendable
+            .clone()
+            .into_iter()
+            .map(|p| Arc::new(p.into()))
+            .collect()
+    }
+
+    pub fn spent(&self) -> Vec<Arc<MintProof>> {
+        self.inner
+            .spent
+            .clone()
+            .into_iter()
+            .map(|p| Arc::new(p.into()))
+            .collect()
+    }
+}

+ 2 - 2
crates/cashu/src/nuts/nut09.rs

@@ -58,8 +58,8 @@ pub struct MintInfo {
     #[serde(skip_serializing_if = "Option::is_none")]
     pub description_long: Option<String>,
     /// contact methods to reach the mint operator
-    #[serde(skip_serializing_if = "Vec::is_empty")]
-    pub contact: Vec<Vec<String>>,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub contact: Option<Vec<Vec<String>>>,
     /// shows which NUTs the mint supports
     #[serde(skip_serializing_if = "Vec::is_empty")]
     pub nuts: Vec<String>,