thesimplekid 1 year ago
parent
commit
eaf339c4b0
7 changed files with 27 additions and 27 deletions
  1. 1 1
      README.md
  2. 1 1
      integration_test/Cargo.toml
  3. 4 4
      integration_test/src/main.rs
  4. 4 4
      src/cashu_mint.rs
  5. 8 8
      src/cashu_wallet.rs
  6. 2 2
      src/types.rs
  7. 7 7
      tests/integration_test.rs

+ 1 - 1
README.md

@@ -4,7 +4,7 @@
 Cashu Crab is a rust library for [Cashu](https://github.com/cashubtc) wallets written in Rust.
 Modeled after [Cashu-ts](https://github.com/cashubtc/cashu-ts.
 
-**ALPHA** This libary is in early development and should not be seen as stable, the api will change hopefully along with the name.
+**ALPHA** This library is in early development and should not be seen as stable, the api will change hopefully along with the name.
 
 ## Implemented [NUTs](https://github.com/cashubtc/nuts/):
 

+ 1 - 1
integration_test/Cargo.toml

@@ -7,7 +7,7 @@ edition = "2021"
 
 [dependencies]
 bitcoin = "0.30.0"
-cashu-rs = {path = ".."}
+cashu-crab = {path = ".."}
 tokio = { version = "1.28.0", features = ["full"] }
 url = "2.3.1"
 lightning-invoice = { version = "0.22.0", features=["serde"] }

+ 4 - 4
integration_test/src/main.rs

@@ -5,9 +5,9 @@ use std::thread;
 use std::time::Duration;
 
 use bitcoin::Amount;
-use cashu_rs::cashu_mint::CashuMint;
-use cashu_rs::cashu_wallet::CashuWallet;
-use cashu_rs::types::{BlindedMessages, MintKeys, ProofsStatus, Token, TokenData};
+use cashu_crab::cashu_mint::CashuMint;
+use cashu_crab::cashu_wallet::CashuWallet;
+use cashu_crab::types::{BlindedMessages, MintKeys, ProofsStatus, Token, TokenData};
 use lightning_invoice::Invoice;
 use url::Url;
 
@@ -56,7 +56,7 @@ async fn test_mint(wallet: &CashuWallet) -> String {
     let mint_req = wallet.request_mint(Amount::from_sat(21)).await.unwrap();
     println!("Mint Req: {:?}", mint_req.pr.to_string());
 
-    // Since before the mint happens the invoice in the mint req has to be payed this wait is here
+    // Since before the mint happens the invoice in the mint req has to be paid this wait is here
     // probally some way to simulate this in a better way
     // but for now pay it quick
     thread::sleep(Duration::from_secs(30));

+ 4 - 4
src/cashu_mint.rs

@@ -10,7 +10,7 @@ use crate::{
     error::Error,
     types::{
         BlindedMessage, BlindedMessages, CheckFeesRequest, CheckFeesResponse,
-        CheckSpendableRequest, CheckSpendableResponse, MeltRequest, MeltResposne, MintInfo,
+        CheckSpendableRequest, CheckSpendableResponse, MeltRequest, MeltResponse, MintInfo,
         MintKeySets, MintKeys, MintRequest, PostMintResponse, Proof, RequestMintResponse,
         SplitRequest, SplitResponse,
     },
@@ -98,7 +98,7 @@ impl CashuMint {
         proofs: Vec<Proof>,
         invoice: Invoice,
         outputs: Option<Vec<BlindedMessage>>,
-    ) -> Result<MeltResposne, Error> {
+    ) -> Result<MeltResponse, Error> {
         let url = self.url.join("melt")?;
 
         let request = MeltRequest {
@@ -110,7 +110,7 @@ impl CashuMint {
         Ok(minreq::post(url)
             .with_json(&request)?
             .send()?
-            .json::<MeltResposne>()?)
+            .json::<MeltResponse>()?)
     }
 
     /// Split Token [NUT-06]
@@ -123,7 +123,7 @@ impl CashuMint {
             .json::<Value>()?;
 
         // TODO: need to handle response error
-        // specfically token already spent
+        // specifically token already spent
         println!("{:?}", res);
 
         Ok(serde_json::from_value(res).unwrap())

+ 8 - 8
src/cashu_wallet.rs

@@ -26,7 +26,7 @@ impl CashuWallet {
     pub async fn check_proofs_spent(&self, proofs: Vec<Proof>) -> Result<ProofsStatus, Error> {
         let spendable = self.mint.check_spendable(&proofs).await?;
 
-        // Seperate proofs in spent and unspent based on mint response
+        // Separate proofs in spent and unspent based on mint response
         let (spendable, spent): (Vec<_>, Vec<_>) = proofs
             .iter()
             .zip(spendable.spendable.iter())
@@ -160,31 +160,31 @@ impl CashuWallet {
 
     /// Send
     pub async fn send(&self, amount: Amount, proofs: Vec<Proof>) -> Result<SendProofs, Error> {
-        let mut amount_avaliable = Amount::ZERO;
+        let mut amount_available = Amount::ZERO;
         let mut send_proofs = SendProofs::default();
 
         for proof in proofs {
-            if amount_avaliable > amount {
+            if amount_available > amount {
                 send_proofs.change_proofs.push(proof);
                 break;
             } else {
-                amount_avaliable += proof.amount;
+                amount_available += proof.amount;
                 send_proofs.send_proofs.push(proof);
             }
         }
 
-        if amount_avaliable.lt(&amount) {
+        if amount_available.lt(&amount) {
             println!("Not enough funds");
             return Err(Error::InsufficantFunds);
         }
 
-        // If amount avaliable is EQUAL to send amount no need to split
-        if amount_avaliable.eq(&amount) {
+        // If amount available is EQUAL to send amount no need to split
+        if amount_available.eq(&amount) {
             println!("Equal Proofs: {:#?}", send_proofs);
             return Ok(send_proofs);
         }
 
-        let amount_to_keep = amount_avaliable - amount;
+        let amount_to_keep = amount_available - amount;
         let amount_to_send = amount;
 
         let split_payload = self

+ 2 - 2
src/types.rs

@@ -179,14 +179,14 @@ pub struct MeltRequest {
     /// bollt11
     pub pr: Invoice,
     /// Blinded Message that can be used to return change [NUT-08]
-    /// Amount feild of blindedMessages `SHOULD` be set to zero
+    /// Amount field of blindedMessages `SHOULD` be set to zero
     pub outputs: Option<Vec<BlindedMessage>>,
 }
 
 /// Melt Response [NUT-05]
 /// Lightning fee return [NUT-08] if change is defined
 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
-pub struct MeltResposne {
+pub struct MeltResponse {
     pub paid: bool,
     pub preimage: String,
     pub change: Option<Promise>,

+ 7 - 7
tests/integration_test.rs

@@ -49,7 +49,7 @@ async fn test_mint() {
     let mint_req = mint.request_mint(Amount::from_sat(21)).await.unwrap();
     println!("Mint Req: {:?}", mint_req.pr.to_string());
 
-    // Since before the mint happens the invoice in the mint req has to be payed this wait is here
+    // Since before the mint happens the invoice in the mint req has to be paid this wait is here
     // probally some way to simulate this in a better way
     // but for now pay it quick
     thread::sleep(Duration::from_secs(30));
@@ -80,9 +80,9 @@ async fn test_receive() {
     let mint_keys = mint.get_keys().await.unwrap();
 
     let wallet = CashuWallet::new(mint, mint_keys);
-    // FIXME: Have to manully paste an unspent token
+    // FIXME: Have to manually paste an unspent token
     let token = 
-    "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6Im9DV2NkWXJyeVRrUiIsImFtb3VudCI6MiwiQyI6IjAyOTMwNTJhNWEwN2FjMTkxMDgyODQyZTExMDVkOTQ2MzliNWI5NmE3MTU3NTQzZTllMjdkOTg3MWU5YjE2NDJkNCIsInNlY3JldCI6IlQxZ0lYUWlpZnBNY21OMU9ENnV4Nk1rMS93bXIxU3VHU2tvVXIyTkpqZE09In1dLCJtaW50IjoiaHR0cHM6Ly9sZWdlbmQubG5iaXRzLmNvbS9jYXNodS9hcGkvdjEvU0t2SFJ1czlkbWpXSGhzdEhyc2F6VyJ9XX0=";
+    "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6Im9DV2NkWXJyeVRrUiIsImFtb3VudCI6MiwiQyI6IjAyOTMwNTJhNWEwN2FjMTkxMDgyODQyZTExMDVkOTQ2MzliNWI5NmE3MTU3NTQzZTllMjdkOTg3MWU5YjE2ANDJkNCIsInNlY3JldCI6IlQxZ0lYUWlpZnBNY21OMU9ENnV4Nk1rMS93bXIxU3VHU2tvVXIyTkpqZE09In1dLCJtaW50IjoiaHR0cHM6Ly9sZWdlbmQubG5iaXRzLmNvbS9jYXNodS9hcGkvdjEvU0t2SFJ1czlkbWpXSGhzdEhyc2F6VyJ9XX0=";
 
     let prom = wallet.receive(token).await.unwrap();
     // println!("{:?}", prom);
@@ -96,7 +96,7 @@ async fn test_check_spendable() {
     let mint_keys = mint.get_keys().await.unwrap();
 
     let wallet = CashuWallet::new(mint, mint_keys);
-    // FIXME: Have to manully paste an unspent token
+    // FIXME: Have to manually paste an unspent token
     let token = 
         "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6Im9DV2NkWXJyeVRrUiIsImFtb3VudCI6MiwiQyI6IjAyNGQ0ZDUxNWIxYzk2MWZkYzYxY2M5MDFmNzBkOGUwZDA0ZWIwYTI2MzBhNWYxYTdmM2I5ZmRhODdmMGJkNjNmNyIsInNlY3JldCI6IkVUc2pXSGJheXYyTUJQeXo1b0toay85dVdoaldIeXJkODdBQy9XY3VjbkE9In1dLCJtaW50IjoiaHR0cHM6Ly9sZWdlbmQubG5iaXRzLmNvbS9jYXNodS9hcGkvdjEvU0t2SFJ1czlkbWpXSGhzdEhyc2F6VyJ9XX0=";
 
@@ -114,9 +114,9 @@ async fn test_split() {
     let mint_keys = mint.get_keys().await.unwrap();
 
     let wallet = CashuWallet::new(mint.clone(), mint_keys);
-    // FIXME: Have to manully paste an unspent token
+    // FIXME: Have to manually paste an unspent token
     let token = 
-    "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6Im9DV2NkWXJyeVRrUiIsImFtb3VudCI6MiwiQyI6IjAyNDVjYjBhYzhlMWNmNGViMjk2ZjAyMTFiMDdjYTBjNTczOWM1MTMwMDEzMzM3MjczOTE1ZTVlMDY2NjZlOTBiZCIsInNlY3JldCI6ImRWNThLbU5VOWE0UU45c0QyVDd5bGkvam9qcWpwb3o0VVhkSGR6dkdRZ289In1dLCJtaW50IjoiaHR0cHM6Ly9sZWdlbmQubG5iaXRzLmNvbS9jYXNodS9hcGkvdjEvU0t2SFJ1czlkbWpXSGhzdEhyc2F6VyJ9XX0=";
+    "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6Im9DV2NkWXJyeVRrUiIsImFtb3VudCI6MiwiQyI6IjAyANDVjYjBhYzhlMWNmNGViMjk2ZjAyMTFiMDdjYTBjNTczOWM1MTMwMDEzMzM3MjczOTE1ZTVlMDY2NjZlOTBiZCIsInNlY3JldCI6ImRWNThLbU5VOWE0UU45c0QyVDd5bGkvam9qcWpwb3o0VVhkSGR6dkdRZ289In1dLCJtaW50IjoiaHR0cHM6Ly9sZWdlbmQubG5iaXRzLmNvbS9jYXNodS9hcGkvdjEvU0t2SFJ1czlkbWpXSGhzdEhyc2F6VyJ9XX0=";
     let proofs = wallet.receive(token).await.unwrap();
 
     let split = wallet.create_split(Amount::ONE_SAT, Amount::ONE_SAT, proofs).await.unwrap();
@@ -137,7 +137,7 @@ async fn test_send() {
     let mint_keys = mint.get_keys().await.unwrap();
 
     let wallet = CashuWallet::new(mint, mint_keys);
-    // FIXME: Have to manully paste an unspent token
+    // FIXME: Have to manually paste an unspent token
     let token = 
     "cashuAeyJ0b2tlbiI6W3sicHJvb2ZzIjpbeyJpZCI6Im9DV2NkWXJyeVRrUiIsImFtb3VudCI6MiwiQyI6IjAzMGI4NWFhYjI5MDY2MGRlNDk4NTEzODZmYTJhZWY2MTk3YzM2MzRkZDE4OGMzMjM2ZDI2YTFhNDdmODZlNzQxNCIsInNlY3JldCI6IjNET0c3eHM2T2RRYno1Nmk1c0lRQjhndHUzbjRMdjRGSU5TeEtLUkJ6UzA9In1dLCJtaW50IjoiaHR0cHM6Ly9sZWdlbmQubG5iaXRzLmNvbS9jYXNodS9hcGkvdjEvU0t2SFJ1czlkbWpXSGhzdEhyc2F6VyJ9XX0=";
     let prom = wallet.receive(token).await.unwrap();