wallet: check proofs status

This commit is contained in:
thesimplekid
2023-09-02 09:45:39 +01:00
parent adee91e55a
commit 1d7bc0cda9
13 changed files with 162 additions and 11 deletions

View File

@@ -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"
};
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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