Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Feb 8, 2024
1 parent 0c759bd commit 25bc15d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions moksha-core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! The `Token` struct represents a token, with an optional `mint` field for the URL of the Mint and a `proofs` field for the proofs associated with the token.
use std::str::FromStr;

use base64::{engine::general_purpose, Engine as _};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::skip_serializing_none;
Expand Down Expand Up @@ -138,6 +140,14 @@ impl TryFrom<String> for TokenV3 {
}
}

impl FromStr for TokenV3 {
type Err = MokshaCoreError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::deserialize(s)
}
}

impl From<(Url, Proofs)> for TokenV3 {
fn from(from: (Url, Proofs)) -> Self {
Self {
Expand Down
3 changes: 2 additions & 1 deletion moksha-wallet/examples/receive_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use moksha_wallet::{
localstore::sqlite::SqliteLocalStore,
wallet::{Wallet, WalletBuilder},
};
use std::str::FromStr;
use url::Url;

#[tokio::main]
Expand All @@ -18,7 +19,7 @@ async fn main() -> anyhow::Result<()> {
.with_mint_url(Url::parse("https://mint.mutinynet.moksha.cash")?)
.build()
.await?;
let tokens = TokenV3::deserialize("cashuAeyJ0b2tlbiI6IFt7InByb29mcyI6IFt7ImlkIjogIjAwOTkxZjRmMjc3MzMzOGMiLCAiYW1vdW50IjogMiwgInNlY3JldCI6ICI5ZmFjZWE0Y2QzN2I3ZWRlOGE4NmQzYWY1ZWIxZTczNzIxMDNmZDE2YTQ1M2E5NDQ5YjE0MDFkZDhhMzAzMWJiIiwgIkMiOiAiMDM2ZTVhOWJhOWE1ZjYxZmQ5MTk3YzM2OTgzZjc1YzAzYTUyYzc0YTJmZmM2NTBmNzg5MjJlMDcyZWY1MTI0YjZlIn1dLCAibWludCI6ICJodHRwczovL21pbnQubXV0aW55bmV0Lm1va3NoYS5jYXNoOjMzMzgifV19")?;
let tokens = TokenV3::from_str("cashuAeyJ0b2tlbiI6IFt7InByb29mcyI6IFt7ImlkIjogIjAwOTkxZjRmMjc3MzMzOGMiLCAiYW1vdW50IjogMiwgInNlY3JldCI6ICI5ZmFjZWE0Y2QzN2I3ZWRlOGE4NmQzYWY1ZWIxZTczNzIxMDNmZDE2YTQ1M2E5NDQ5YjE0MDFkZDhhMzAzMWJiIiwgIkMiOiAiMDM2ZTVhOWJhOWE1ZjYxZmQ5MTk3YzM2OTgzZjc1YzAzYTUyYzc0YTJmZmM2NTBmNzg5MjJlMDcyZWY1MTI0YjZlIn1dLCAibWludCI6ICJodHRwczovL21pbnQubXV0aW55bmV0Lm1va3NoYS5jYXNoOjMzMzgifV19")?;
wallet.receive_tokens(&tokens).await?;
let balance = wallet.get_balance().await?;
println!("New balance: {} sats", balance);
Expand Down

0 comments on commit 25bc15d

Please sign in to comment.