Skip to content

Commit

Permalink
chore: update cdk
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jun 3, 2024
1 parent 3e60a33 commit 53cdd08
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 52 deletions.
102 changes: 58 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ time = "0.3.22"
chrono = "0.4.26"
clap = { version = "4.3.14", features = ["env", "default", "derive"]}
anyhow = "1.0.71"
cdk = { git = "https://github.com/thesimplekid/cashu-crab", rev = "664776f", default-features = false, features = ["mint", "all-nuts", "redb"] }
# cdk = { path = "../cashu-crab/nut09/crates/cashu-sdk", default-features = false, features = ["mint", "all-nuts", "redb"] }
cdk = { git = "https://github.com/cashubtc/cdk", rev = "efd9b39", default-features = false, features = ["mint"] }
cdk-redb = { git = "https://github.com/cashubtc/cdk", rev = "efd9b39", default-features = false, features = ["mint"] }
# cdk = { path = "../../cdk/nut14/crates/cdk", default-features = false, features = ["mint", "all-nuts"] }
# cdk-redb = { path = "../../cdk/nut14/crates/cdk-redb" }

bitcoin = { version = "0.30.0", features = ["no-std"] }
serde = "1.0.164"
serde_json = "1.0.96"
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl IntoResponse for Error {
}
}

pub fn into_response(error: cdk::mint::Error) -> Response {
pub fn into_response(error: cdk::mint::error::Error) -> Response {
(
StatusCode::INTERNAL_SERVER_ERROR,
Json::<ErrorResponse>(error.into()),
Expand Down
16 changes: 11 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashSet;
use std::fs::{self, File};
use std::io::Write;
use std::net::{Ipv4Addr, SocketAddr};
Expand All @@ -17,13 +16,15 @@ use axum::routing::{get, post};
use axum::Router;
use bip39::Mnemonic;
use cdk::amount::Amount;
use cdk::mint::{LocalStore, Mint, RedbLocalStore};
use cdk::cdk_database::MintDatabase;
use cdk::mint::Mint;
use cdk::nuts::nut02::Id;
use cdk::nuts::{
CheckStateRequest, CheckStateResponse, MeltBolt11Request, MeltBolt11Response,
MintBolt11Request, MintBolt11Response, SwapRequest, SwapResponse, *,
};
use cdk::types::MintQuote;
use cdk_redb::MintRedbDatabase;
use clap::Parser;
use error::into_response;
use futures::StreamExt;
Expand Down Expand Up @@ -61,22 +62,23 @@ async fn main() -> anyhow::Result<()> {

let settings = config::Settings::new(&Some(config_file_arg));

let mint_url = settings.info.url.clone();

let db_path = match args.db {
Some(path) => PathBuf::from_str(&path)?,
None => settings.info.clone().db_path,
};

let localstore = RedbLocalStore::new(db_path.to_str().unwrap())?;
let localstore = MintRedbDatabase::new(db_path.to_str().unwrap())?;
let mint_info = MintInfo::default();
//settings.mint_info.clone();
localstore.set_mint_info(&mint_info).await?;

let mnemonic = Mnemonic::from_str(&settings.info.mnemonic)?;

let mint = Mint::new(
&mnemonic.to_seed_normalized(""),
Arc::new(localstore),
mnemonic,
HashSet::new(),
Amount::ZERO,
0.0,
)
Expand Down Expand Up @@ -145,6 +147,7 @@ async fn main() -> anyhow::Result<()> {
let state = MintState {
ln,
mint: Arc::new(Mutex::new(mint)),
mint_url,
};

let mint_service = Router::new()
Expand Down Expand Up @@ -194,6 +197,7 @@ async fn handle_paid_invoice(mint: Arc<Mint>, request: &str) -> anyhow::Result<(
if quote.request.eq(request) {
let q = MintQuote {
id: quote.id,
mint_url: quote.mint_url,
amount: quote.amount,
unit: quote.unit,
request: quote.request,
Expand All @@ -212,6 +216,7 @@ async fn handle_paid_invoice(mint: Arc<Mint>, request: &str) -> anyhow::Result<(
struct MintState {
ln: Ln,
mint: Arc<Mutex<Mint>>,
mint_url: String,
}

async fn get_keys(State(state): State<MintState>) -> Result<Json<KeysResponse>, Response> {
Expand Down Expand Up @@ -273,6 +278,7 @@ async fn get_mint_bolt11_quote(
.lock()
.await
.new_mint_quote(
state.mint_url.into(),
invoice.to_string(),
payload.unit,
payload.amount,
Expand Down

0 comments on commit 53cdd08

Please sign in to comment.