Skip to content

Commit

Permalink
Merge main into multiple_bolt12
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Nov 17, 2024
2 parents f427ba6 + 4e7f55e commit c488db2
Show file tree
Hide file tree
Showing 56 changed files with 648 additions and 294 deletions.
31 changes: 31 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
### Description

<!-- Describe the purpose of this PR, what's being adding and/or fixed -->

-----

### Notes to the reviewers

<!-- In this section you can include notes directed to the reviewers, like explaining why some parts
of the PR were done in a specific way -->

-----

### Suggested [CHANGELOG](https://github.com/cashubtc/cdk/blob/main/CHANGELOG.md) Updates

<!-- Please do not edit the actual changelog but note what you changed here. -->

#### CHANGED

#### ADDED

#### REMOVED

#### FIXED

----

### Checklist

* [ ] I followed the [code style guidelines](https://github.com/cashubtc/cdk/blob/main/CODE_STYLE.md)
* [ ] I ran `just final-check` before committing
13 changes: 10 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-mode: true

pre-commit-checks:
name: "Pre-commit checks: cargo fmt, typos"
name: "Cargo fmt, typos"
runs-on: ubuntu-latest
steps:
- name: checkout
Expand All @@ -32,8 +32,15 @@ jobs:
uses: DeterminateSystems/magic-nix-cache-action@v6
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Pre-commit checks
run: nix develop -i -L .#stable --command pre-commit run --all-files
- name: Cargo fmt
run: |
nix develop -i -L .#nightly --command bash -c '
# Force use of Nix-provided rustfmt
export RUSTFMT=$(command -v rustfmt)
cargo fmt --check
'
- name: typos
run: nix develop -i -L .#nightly --command typos

clippy:
name: "Stable build, clippy and test"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.redb
*.sqlite*
config.toml
.pre-commit-config.yaml
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- cdk: Use `MintUrl` directly in wallet client ([ok300]).
- cdk-cli: Change cdk-cli pay command to melt ([mubarak23]).
- cdk: Rename `Wallet::get_proofs` to `Wallet::get_unspent_proofs` ([ok300]).
- cdk: `Id` to `u32` changed from `TryFrom` to `From` ([vnrpc]).


### Added
Expand All @@ -47,7 +48,7 @@
- cdk: Add description for mint quote ([lollerfirst]).
- cdk-axum: Add cache to some endpoints ([lollerfirst]).
- cdk: Add Proofs trait ([ok300]).
- cdk: Wallet verifiys keyset id when first fetching keys ([thesimplekid]).
- cdk: Wallet verifies keyset id when first fetching keys ([thesimplekid]).
- cdk-mind: Add swagger docs ([ok300]).
- cdk: NUT18 payment request support ([thesimplekid]).
- cdk: Add `Wallet::get_proofs_with` ([ok300]).
Expand Down Expand Up @@ -198,4 +199,5 @@ Additionally, this release introduces a Mint binary cdk-mintd that uses the cdk-
[lollerfirst]: https://github.com/lollerfirst
[prusnak]: https://github.com/prusnak
[mubarak23]: https://github.com/mubarak23
[vnprc]: https://github.com/vnprc

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The project is split up into several crates in the `crates/` directory:
* [**cdk-lnd**](./crates/cdk-lnd/): Lnd Lightning backend for mint.
* [**cdk-strike**](./crates/cdk-strike/): Strike Lightning backend for mint.
* [**cdk-lnbits**](./crates/cdk-lnbits/): [LNbits](https://lnbits.com/) Lightning backend for mint.
* [**cdk-phoenixd**](./crates/cdk-phoenixd/): Phoenixd Lightning backend for mint.
* [**cdk-fake-wallet**](./crates/cdk-fake-wallet/): Fake Lightning backend for mint. To be used only for testing, quotes are automatically filled.
* Binaries:
* [**cdk-cli**](./crates/cdk-cli/): Cashu wallet CLI.
Expand Down Expand Up @@ -70,7 +71,7 @@ Code is under the [MIT License](LICENSE)

## Contribution

All contributions welcome.
All contributions are 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.

Expand Down
5 changes: 1 addition & 4 deletions crates/cdk-axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ mod swagger_imports {
pub use cdk::nuts::nut01::{Keys, KeysResponse, PublicKey, SecretKey};
pub use cdk::nuts::nut02::{Id, KeySet, KeySetInfo, KeySetVersion, KeysetResponse};
pub use cdk::nuts::nut03::{SwapRequest, SwapResponse};
pub use cdk::nuts::nut04;
pub use cdk::nuts::nut04::{
MintBolt11Request, MintBolt11Response, MintMethodSettings, MintQuoteBolt11Request,
MintQuoteBolt11Response,
};
pub use cdk::nuts::nut05;
pub use cdk::nuts::nut05::{
MeltBolt11Request, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteBolt11Response,
};
Expand All @@ -46,9 +44,8 @@ mod swagger_imports {
pub use cdk::nuts::nut11::P2PKWitness;
pub use cdk::nuts::nut12::{BlindSignatureDleq, ProofDleq};
pub use cdk::nuts::nut14::HTLCWitness;
pub use cdk::nuts::nut15;
pub use cdk::nuts::nut15::{Mpp, MppMethodSettings};
pub use cdk::nuts::{MeltQuoteState, MintQuoteState};
pub use cdk::nuts::{nut04, nut05, nut15, MeltQuoteState, MintQuoteState};
}

#[cfg(feature = "swagger")]
Expand Down
6 changes: 4 additions & 2 deletions crates/cdk-axum/src/router_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use axum::extract::{ws::WebSocketUpgrade, Json, Path, State};
use axum::extract::ws::WebSocketUpgrade;
use axum::extract::{Json, Path, State};
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use cdk::error::ErrorResponse;
Expand All @@ -13,7 +14,8 @@ use cdk::util::unix_time;
use cdk::Error;
use paste::paste;

use crate::{ws::main_websocket, MintState};
use crate::ws::main_websocket;
use crate::MintState;

macro_rules! post_cache_wrapper {
($handler:ident, $request_type:ty, $response_type:ty) => {
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk-axum/src/ws/handler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{WsContext, WsError, JSON_RPC_VERSION};
use serde::Serialize;

use super::{WsContext, WsError, JSON_RPC_VERSION};

impl From<WsError> for WsErrorResponse {
fn from(val: WsError) -> Self {
let (id, message) = match val {
Expand Down
6 changes: 4 additions & 2 deletions crates/cdk-axum/src/ws/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use crate::MintState;
use std::collections::HashMap;

use axum::extract::ws::{Message, WebSocket};
use cdk::nuts::nut17::{NotificationPayload, SubId};
use futures::StreamExt;
use handler::{WsHandle, WsNotification};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use subscribe::Notification;
use tokio::sync::mpsc;

use crate::MintState;

mod error;
mod handler;
mod subscribe;
Expand Down
33 changes: 24 additions & 9 deletions crates/cdk-axum/src/ws/subscribe.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
use super::{
handler::{WsHandle, WsNotification},
WsContext, WsError, JSON_RPC_VERSION,
};
use cdk::{
nuts::nut17::{NotificationPayload, Params},
pub_sub::SubId,
};
use cdk::nuts::nut17::{NotificationPayload, Params};
use cdk::pub_sub::SubId;

use super::handler::{WsHandle, WsNotification};
use super::{WsContext, WsError, JSON_RPC_VERSION};

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Method(Params);

#[derive(Debug, Clone, serde::Serialize)]
/// The response to a subscription request
pub struct Response {
/// Status
status: String,
/// Subscription ID
#[serde(rename = "subId")]
sub_id: SubId,
}

#[derive(Debug, Clone, serde::Serialize)]
/// The notification
///
/// This is the notification that is sent to the client when an event matches a
/// subscription
pub struct Notification {
/// The subscription ID
#[serde(rename = "subId")]
pub sub_id: SubId,

/// The notification payload
pub payload: NotificationPayload,
}

Expand All @@ -39,12 +45,21 @@ impl From<(SubId, NotificationPayload)> for WsNotification<Notification> {
impl WsHandle for Method {
type Response = Response;

/// The `handle` method is called when a client sends a subscription request
async fn handle(self, context: &mut WsContext) -> Result<Self::Response, WsError> {
let sub_id = self.0.id.clone();
if context.subscriptions.contains_key(&sub_id) {
// Subscription ID already exits. Returns an error instead of
// replacing the other subscription or avoiding it.
return Err(WsError::InvalidParams);
}
let mut subscription = context.state.mint.pubsub_manager.subscribe(self.0).await;

let mut subscription = context
.state
.mint
.pubsub_manager
.subscribe(self.0.clone())
.await;
let publisher = context.publisher.clone();
context.subscriptions.insert(
sub_id.clone(),
Expand Down
4 changes: 3 additions & 1 deletion crates/cdk-axum/src/ws/unsubscribe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::{handler::WsHandle, WsContext, WsError};
use cdk::pub_sub::SubId;

use super::handler::WsHandle;
use super::{WsContext, WsError};

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Method {
#[serde(rename = "subId")]
Expand Down
12 changes: 5 additions & 7 deletions crates/cdk-cli/src/sub_commands/create_request.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use anyhow::Result;
use cdk::{
nuts::{
nut18::TransportType, CurrencyUnit, PaymentRequest, PaymentRequestPayload, Token, Transport,
},
wallet::MultiMintWallet,
};
use cdk::nuts::nut18::TransportType;
use cdk::nuts::{CurrencyUnit, PaymentRequest, PaymentRequestPayload, Token, Transport};
use cdk::wallet::MultiMintWallet;
use clap::Args;
use nostr_sdk::nips::nip19::Nip19Profile;
use nostr_sdk::prelude::*;
use nostr_sdk::{nips::nip19::Nip19Profile, Client as NostrClient, Filter, Keys, ToBech32};
use nostr_sdk::{Client as NostrClient, Filter, Keys, ToBech32};

#[derive(Args)]
pub struct CreateRequestSubCommand {
Expand Down
8 changes: 3 additions & 5 deletions crates/cdk-cli/src/sub_commands/list_mint_proofs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::collections::BTreeMap;

use anyhow::Result;
use cdk::{
mint_url::MintUrl,
nuts::{CurrencyUnit, Proof},
wallet::multi_mint_wallet::MultiMintWallet,
};
use cdk::mint_url::MintUrl;
use cdk::nuts::{CurrencyUnit, Proof};
use cdk::wallet::multi_mint_wallet::MultiMintWallet;

pub async fn proofs(multi_mint_wallet: &MultiMintWallet) -> Result<()> {
list_proofs(multi_mint_wallet).await?;
Expand Down
12 changes: 6 additions & 6 deletions crates/cdk-cli/src/sub_commands/pay_request.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::io::{self, Write};

use anyhow::{anyhow, Result};
use cdk::{
amount::SplitTarget,
nuts::{nut18::TransportType, PaymentRequest, PaymentRequestPayload},
wallet::{MultiMintWallet, SendKind},
};
use cdk::amount::SplitTarget;
use cdk::nuts::nut18::TransportType;
use cdk::nuts::{PaymentRequest, PaymentRequestPayload};
use cdk::wallet::{MultiMintWallet, SendKind};
use clap::Args;
use nostr_sdk::{nips::nip19::Nip19Profile, Client as NostrClient, EventBuilder, FromBech32, Keys};
use nostr_sdk::nips::nip19::Nip19Profile;
use nostr_sdk::{Client as NostrClient, EventBuilder, FromBech32, Keys};
use reqwest::Client;

#[derive(Args)]
Expand Down
3 changes: 2 additions & 1 deletion crates/cdk-integration-tests/src/bin/fake_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::env;

use anyhow::Result;
use cdk::cdk_database::mint_memory::MintMemoryDatabase;
use cdk_integration_tests::{init_fake_wallet::start_fake_mint, init_regtest::get_temp_dir};
use cdk_integration_tests::init_fake_wallet::start_fake_mint;
use cdk_integration_tests::init_regtest::get_temp_dir;
use cdk_redb::MintRedbDatabase;
use cdk_sqlite::MintSqliteDatabase;

Expand Down
18 changes: 7 additions & 11 deletions crates/cdk-integration-tests/src/init_fake_wallet.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use anyhow::Result;
use axum::Router;
use cdk::{
cdk_database::{self, MintDatabase},
cdk_lightning::MintLightning,
mint::FeeReserve,
nuts::CurrencyUnit,
types::LnKey,
};
use cdk::cdk_database::{self, MintDatabase};
use cdk::cdk_lightning::MintLightning;
use cdk::mint::FeeReserve;
use cdk::nuts::CurrencyUnit;
use cdk::types::LnKey;
use cdk_fake_wallet::FakeWallet;
use tokio::sync::Notify;
use tower_http::cors::CorsLayer;
Expand Down
27 changes: 15 additions & 12 deletions crates/cdk-integration-tests/src/init_regtest.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use std::{collections::HashMap, env, path::PathBuf, sync::Arc};
use std::collections::HashMap;
use std::env;
use std::path::PathBuf;
use std::sync::Arc;

use anyhow::Result;
use axum::Router;
use bip39::Mnemonic;
use cdk::{
cdk_database::{self, MintDatabase},
cdk_lightning::MintLightning,
mint::{FeeReserve, Mint},
nuts::{CurrencyUnit, MintInfo},
types::{LnKey, QuoteTTL},
};
use cdk::cdk_database::{self, MintDatabase};
use cdk::cdk_lightning::MintLightning;
use cdk::mint::{FeeReserve, Mint};
use cdk::nuts::{CurrencyUnit, MintInfo};
use cdk::types::{LnKey, QuoteTTL};
use cdk_cln::Cln as CdkCln;
use ln_regtest_rs::{
bitcoin_client::BitcoinClient, bitcoind::Bitcoind, cln::Clnd, cln_client::ClnClient, lnd::Lnd,
lnd_client::LndClient,
};
use ln_regtest_rs::bitcoin_client::BitcoinClient;
use ln_regtest_rs::bitcoind::Bitcoind;
use ln_regtest_rs::cln::Clnd;
use ln_regtest_rs::cln_client::ClnClient;
use ln_regtest_rs::lnd::Lnd;
use ln_regtest_rs::lnd_client::LndClient;
use tokio::sync::Notify;
use tower_http::cors::CorsLayer;
use tracing_subscriber::EnvFilter;
Expand Down
19 changes: 8 additions & 11 deletions crates/cdk-integration-tests/tests/fake_wallet.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use std::{sync::Arc, time::Duration};
use std::sync::Arc;
use std::time::Duration;

use anyhow::Result;
use bip39::Mnemonic;
use cdk::{
amount::SplitTarget,
cdk_database::WalletMemoryDatabase,
nuts::{
CurrencyUnit, MeltBolt11Request, MeltQuoteState, MintQuoteState, PreMintSecrets, State,
},
wallet::{
client::{HttpClient, HttpClientMethods},
Wallet,
},
use cdk::amount::SplitTarget;
use cdk::cdk_database::WalletMemoryDatabase;
use cdk::nuts::{
CurrencyUnit, MeltBolt11Request, MeltQuoteState, MintQuoteState, PreMintSecrets, State,
};
use cdk::wallet::client::{HttpClient, HttpClientMethods};
use cdk::wallet::Wallet;
use cdk_fake_wallet::{create_fake_invoice, FakeInvoiceDescription};
use cdk_integration_tests::attempt_to_swap_pending;
use tokio::time::sleep;
Expand Down
Loading

0 comments on commit c488db2

Please sign in to comment.