Skip to content

Commit

Permalink
Merge pull request #576 from thesimplekid/fix_mint_inflation
Browse files Browse the repository at this point in the history
Fix mint inflation
  • Loading branch information
thesimplekid authored Feb 4, 2025
2 parents 8326d3a + f495a2c commit 3a267d5
Show file tree
Hide file tree
Showing 13 changed files with 436 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@

### Removed

#[cdk:v0.6.1,cdk-mintd:v0.6.2]
### Fixed
cdk: Missing check on mint that outputs equals the quote amount ([thesimplekid]).
cdk: Reset mint quote status if in state that cannot continue ([thesimeokid]).

#[0.6.1]
### Added
cdk-mintd: Get work-dir from env var ([thesimplekid])
Expand Down
2 changes: 1 addition & 1 deletion crates/cdk-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cdk-common"
version = "0.6.0"
version = "0.6.1"
edition = "2021"
description = "CDK common types and traits"
rust-version = "1.63.0" # MSRV
Expand Down
16 changes: 8 additions & 8 deletions crates/cdk-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ pub enum Error {
/// Receive can only be used with tokens from single mint
#[error("Multiple mint tokens not supported by receive. Please deconstruct the token and use receive with_proof")]
MultiMintTokenNotSupported,
/// Unit Not supported
#[error("Unit not supported for method")]
UnitUnsupported,
/// Preimage not provided
#[error("Preimage not provided")]
PreimageNotProvided,
Expand Down Expand Up @@ -233,6 +230,9 @@ pub enum Error {
/// NUT03 error
#[error(transparent)]
NUT03(#[from] crate::nuts::nut03::Error),
/// NUT04 error
#[error(transparent)]
NUT04(#[from] crate::nuts::nut04::Error),
/// NUT05 error
#[error(transparent)]
NUT05(#[from] crate::nuts::nut05::Error),
Expand Down Expand Up @@ -329,7 +329,7 @@ impl From<Error> for ErrorResponse {
detail: None,
},
Error::UnsupportedUnit => ErrorResponse {
code: ErrorCode::UnitUnsupported,
code: ErrorCode::UnsupportedUnit,
error: Some(err.to_string()),
detail: None,
},
Expand Down Expand Up @@ -412,7 +412,7 @@ impl From<ErrorResponse> for Error {
ErrorCode::KeysetNotFound => Self::UnknownKeySet,
ErrorCode::KeysetInactive => Self::InactiveKeyset,
ErrorCode::BlindedMessageAlreadySigned => Self::BlindedMessageAlreadySigned,
ErrorCode::UnitUnsupported => Self::UnitUnsupported,
ErrorCode::UnsupportedUnit => Self::UnsupportedUnit,
ErrorCode::TransactionUnbalanced => Self::TransactionUnbalanced(0, 0, 0),
ErrorCode::MintingDisabled => Self::MintingDisabled,
ErrorCode::InvoiceAlreadyPaid => Self::RequestAlreadyPaid,
Expand Down Expand Up @@ -449,7 +449,7 @@ pub enum ErrorCode {
/// Blinded Message Already signed
BlindedMessageAlreadySigned,
/// Unsupported unit
UnitUnsupported,
UnsupportedUnit,
/// Token already issed for quote
TokensAlreadyIssued,
/// Minting Disabled
Expand Down Expand Up @@ -478,7 +478,7 @@ impl ErrorCode {
10003 => Self::TokenNotVerified,
11001 => Self::TokenAlreadySpent,
11002 => Self::TransactionUnbalanced,
11005 => Self::UnitUnsupported,
11005 => Self::UnsupportedUnit,
11006 => Self::AmountOutofLimitRange,
11007 => Self::TokenPending,
12001 => Self::KeysetNotFound,
Expand All @@ -502,7 +502,7 @@ impl ErrorCode {
Self::TokenNotVerified => 10003,
Self::TokenAlreadySpent => 11001,
Self::TransactionUnbalanced => 11002,
Self::UnitUnsupported => 11005,
Self::UnsupportedUnit => 11005,
Self::AmountOutofLimitRange => 11006,
Self::TokenPending => 11007,
Self::KeysetNotFound => 12001,
Expand Down
7 changes: 4 additions & 3 deletions crates/cdk-fake-wallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use async_trait::async_trait;
use bitcoin::hashes::{sha256, Hash};
use bitcoin::secp256k1::rand::{thread_rng, Rng};
use bitcoin::secp256k1::{Secp256k1, SecretKey};
use cdk::amount::{to_unit, Amount, MSAT_IN_SAT};
use cdk::amount::{Amount, MSAT_IN_SAT};
use cdk::cdk_lightning::{
self, CreateInvoiceResponse, MintLightning, PayInvoiceResponse, PaymentQuoteResponse, Settings,
};
Expand Down Expand Up @@ -199,14 +199,15 @@ impl MintLightning for FakeWallet {
async fn create_invoice(
&self,
amount: Amount,
unit: &CurrencyUnit,
_unit: &CurrencyUnit,
description: String,
unix_expiry: u64,
) -> Result<CreateInvoiceResponse, Self::Err> {
let time_now = unix_time();
assert!(unix_expiry > time_now);

let amount_msat = to_unit(amount, unit, &CurrencyUnit::Msat)?;
// Since this is fake we just use the amount no matter the unit to create an invoice
let amount_msat = amount;

let invoice = create_fake_invoice(amount_msat.into(), description);

Expand Down
16 changes: 15 additions & 1 deletion crates/cdk-integration-tests/src/init_fake_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where

let fee_reserve = FeeReserve {
min_fee_reserve: 1.into(),
percent_fee_reserve: 1.0,
percent_fee_reserve: 0.0,
};

let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);
Expand All @@ -46,6 +46,20 @@ where
Arc::new(fake_wallet),
);

let fee_reserve = FeeReserve {
min_fee_reserve: 1.into(),
percent_fee_reserve: 0.0,
};

let fake_wallet = FakeWallet::new(fee_reserve, HashMap::default(), HashSet::default(), 0);

mint_builder = mint_builder.add_ln_backend(
CurrencyUnit::Usd,
PaymentMethod::Bolt11,
MintMeltLimits::new(1, 5_000),
Arc::new(fake_wallet),
);

let mnemonic = Mnemonic::generate(12)?;

mint_builder = mint_builder
Expand Down
Loading

0 comments on commit 3a267d5

Please sign in to comment.