diff --git a/Cargo.lock b/Cargo.lock index 33f3845..f47145e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1002,7 +1002,7 @@ dependencies = [ [[package]] name = "fedimint-clientd" -version = "0.3.1" +version = "0.3.2" dependencies = [ "anyhow", "async-utility", @@ -1026,7 +1026,7 @@ dependencies = [ "lazy_static", "lightning-invoice", "lnurl-rs", - "multimint 0.3.0", + "multimint 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.12.3", "serde", "serde_json", @@ -2389,9 +2389,7 @@ dependencies = [ [[package]] name = "multimint" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a926e1ecf3b97aa2bf98d30de76032c7dcfa12b04ba957c985bd7a11c612f0be" +version = "0.3.2" dependencies = [ "anyhow", "fedimint-client", @@ -2411,7 +2409,9 @@ dependencies = [ [[package]] name = "multimint" -version = "0.3.1" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e09006ccf96f467878dd322f159a5597b53455e6693992b75b18fcedcf53913" dependencies = [ "anyhow", "fedimint-client", diff --git a/fedimint-clientd/Cargo.toml b/fedimint-clientd/Cargo.toml index f78e871..996be41 100644 --- a/fedimint-clientd/Cargo.toml +++ b/fedimint-clientd/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fedimint-clientd" -version = "0.3.1" +version = "0.3.2" edition = "2021" description = "A fedimint client daemon for server side applications to hold, use, and manage Bitcoin" repository = "https://github.com/fedimint/fedimint-clientd" @@ -31,13 +31,16 @@ tower-http = { version = "0.5.2", features = ["cors", "auth", "trace"] } bitcoin = "0.29.2" itertools = "0.12.0" lnurl-rs = { version = "0.5.0", features = ["async"], default-features = false } -reqwest = { version = "0.12.3", features = ["json", "rustls-tls"], default-features = false } +reqwest = { version = "0.12.3", features = [ + "json", + "rustls-tls", +], default-features = false } lightning-invoice = { version = "0.26.0", features = ["serde"] } bitcoin_hashes = "0.13.0" time = { version = "0.3.25", features = ["formatting"] } chrono = "0.4.31" futures-util = "0.3.30" clap = { version = "3", features = ["derive", "env"] } -multimint = { version = "0.3.0" } +multimint = { version = "0.3.2" } # multimint = { path = "../multimint" } axum-otel-metrics = "0.8.0" diff --git a/fedimint-clientd/src/state.rs b/fedimint-clientd/src/state.rs index 31a24aa..b9f91bb 100644 --- a/fedimint-clientd/src/state.rs +++ b/fedimint-clientd/src/state.rs @@ -16,6 +16,7 @@ pub struct AppState { impl AppState { pub async fn new(fm_db_path: PathBuf) -> Result { let clients = MultiMint::new(fm_db_path).await?; + clients.update_gateway_caches(true).await?; Ok(Self { multimint: clients, cashu_mint: None, diff --git a/multimint/Cargo.toml b/multimint/Cargo.toml index ff94234..4dc8120 100644 --- a/multimint/Cargo.toml +++ b/multimint/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "multimint" -version = "0.3.1" +version = "0.3.2" edition = "2021" description = "A library for managing fedimint clients across multiple federations" license = "MIT" diff --git a/multimint/src/lib.rs b/multimint/src/lib.rs index 832df4a..d61442b 100644 --- a/multimint/src/lib.rs +++ b/multimint/src/lib.rs @@ -72,6 +72,7 @@ use fedimint_core::api::InviteCode; use fedimint_core::config::{FederationId, FederationIdPrefix, JsonClientConfig}; use fedimint_core::db::Database; use fedimint_core::Amount; +use fedimint_ln_client::LightningClientModule; use fedimint_mint_client::MintClientModule; use fedimint_wallet_client::WalletClientModule; use tokio::sync::Mutex; @@ -362,4 +363,17 @@ impl MultiMint { Ok(info_map) } + + /// Update the gateway caches for all the lightning modules in the + /// multimint. + pub async fn update_gateway_caches(&self, apply_meta: bool) -> Result<()> { + let clients = self.clients.lock().await; + + for (_, client) in clients.iter() { + let lightning_client = client.get_first_module::(); + lightning_client.update_gateway_cache(apply_meta).await?; + } + + Ok(()) + } } diff --git a/wrappers/fedimint-ts/bun.lockb b/wrappers/fedimint-ts/bun.lockb new file mode 100755 index 0000000..a33ea38 Binary files /dev/null and b/wrappers/fedimint-ts/bun.lockb differ diff --git a/wrappers/fedimint-ts/src/FedimintClient.ts b/wrappers/fedimint-ts/src/FedimintClient.ts index ec82560..43ea1ec 100644 --- a/wrappers/fedimint-ts/src/FedimintClient.ts +++ b/wrappers/fedimint-ts/src/FedimintClient.ts @@ -392,18 +392,10 @@ export class FedimintClient { * Creates a lightning invoice to receive payment via gateway */ createInvoice: async ( - amountMsat: number, - description: string, - expiryTime?: number, + request: LightningInvoiceRequest, gatewayId?: string, federationId?: string ): Promise => { - const request: LightningInvoiceRequest = { - amountMsat, - description, - expiryTime, - }; - return await this.postWithGatewayIdAndFederationId( "/ln/invoice", request, @@ -425,22 +417,10 @@ export class FedimintClient { * @param federationId - The ID of the federation to use for the invoice, if not provided will use the active federation ID */ createInvoiceForPubkeyTweak: async ( - pubkey: string, - tweak: number, - amountMsat: number, - description: string, - expiryTime?: number, + request: LightningInvoiceExternalPubkeyTweakedRequest, gatewayId?: string, federationId?: string ): Promise => { - const request: LightningInvoiceExternalPubkeyTweakedRequest = { - externalPubkey: pubkey, - tweak, - amountMsat, - description, - expiryTime, - }; - return await this.postWithGatewayIdAndFederationId( "/ln/invoice-external-pubkey-tweaked", request, @@ -457,15 +437,9 @@ export class FedimintClient { * @param federationId - The ID of the federation to claim the contracts in. Contracts are on specific federations so this is required. */ claimPubkeyTweakReceives: async ( - privateKey: string, - tweaks: number[], + request: LightningClaimPubkeyTweakReceivesRequest, federationId: string ): Promise => { - const request: LightningClaimPubkeyTweakReceivesRequest = { - privateKey, - tweaks, - }; - return await this.postWithFederationId( "/ln/claim-external-receive-tweaked", request, @@ -495,18 +469,10 @@ export class FedimintClient { * Pays a lightning invoice or Lightningurl via a gateway */ pay: async ( - paymentInfo: string, - amountMsat?: number, - LightningurlComment?: string, + request: LightningPayRequest, gatewayId?: string, federationId?: string ): Promise => { - const request: LightningPayRequest = { - paymentInfo, - amountMsat, - LightningurlComment, - }; - return await this.postWithGatewayIdAndFederationId( "/ln/pay", request, @@ -529,9 +495,7 @@ export class FedimintClient { /** * Decodes hex encoded binary ecash notes to json */ - decodeNotes: async ( - notes: string - ): Promise => { + decodeNotes: async (notes: string): Promise => { const request: MintDecodeNotesRequest = { notes, }; @@ -587,19 +551,9 @@ export class FedimintClient { * @param federationId - The ID of the federation to spend the note in, if not provided will use the active federation ID */ spend: async ( - amountMsat: number, - allowOverpay: boolean, - timeout: number, - includeInvite: boolean, + request: MintSpendRequest, federationId?: string ): Promise => { - const request: MintSpendRequest = { - amountMsat, - allowOverpay, - timeout, - includeInvite, - }; - return await this.postWithFederationId( "/mint/spend", request, @@ -637,9 +591,7 @@ export class FedimintClient { * Combines ecash notes into a single note string. * @param notesVec - The notes to combine */ - combine: async ( - notesVec: string[] - ): Promise => { + combine: async (notesVec: string[]): Promise => { const request: MintCombineRequest = { notesVec }; return await this.post("/mint/combine", request); diff --git a/wrappers/fedimint-ts/tests/test.ts b/wrappers/fedimint-ts/tests/test.ts index 26a5e5a..7754253 100644 --- a/wrappers/fedimint-ts/tests/test.ts +++ b/wrappers/fedimint-ts/tests/test.ts @@ -1,7 +1,14 @@ import dotenv from "dotenv"; import { randomBytes } from "crypto"; import * as secp256k1 from "secp256k1"; -import { FedimintClientBuilder } from "../src"; +import { + FedimintClientBuilder, + LightningClaimPubkeyReceiveTweakedRequest, + LightningInvoiceExternalPubkeyTweakedRequest, + LightningInvoiceRequest, + LightningPayRequest, + MintSpendRequest, +} from "../src"; dotenv.config(); @@ -98,9 +105,13 @@ async function main() { logInputAndOutput({}, data); // `/v2/ln/invoice` logMethod("/v2/ln/invoice"); + let lightningInvoiceRequest: LightningInvoiceRequest = { + amountMsat: 10000, + description: "test", + expiryTime: 3600, + }; let { operationId, invoice } = await fedimintClient.lightning.createInvoice( - 10000, - "test" + lightningInvoiceRequest ); logInputAndOutput( { amountMsat: 10000, description: "test" }, @@ -108,7 +119,10 @@ async function main() { ); // `/v2/ln/pay` logMethod("/v2/ln/pay"); - let payResponse = await fedimintClient.lightning.pay(invoice); + let lightningPayRequest: LightningPayRequest = { + paymentInfo: invoice, + }; + let payResponse = await fedimintClient.lightning.pay(lightningPayRequest); logInputAndOutput({ paymentInfo: invoice }, payResponse); // `/v2/ln/await-invoice` logMethod("/v2/ln/await-invoice"); @@ -116,11 +130,16 @@ async function main() { logInputAndOutput({ operationId }, data); // `/v1/ln/invoice-external-pubkey-tweaked` logMethod("/v1/ln/invoice-external-pubkey-tweaked"); + let lightningInvoiceExternalPubkeyTweakedRequest: LightningInvoiceExternalPubkeyTweakedRequest = + { + externalPubkey: keyPair.publicKey, + tweak: 1, + amountMsat: 1000, + description: "test", + expiryTime: 3600, + }; data = await fedimintClient.lightning.createInvoiceForPubkeyTweak( - keyPair.publicKey, - 1, - 1000, - "test" + lightningInvoiceExternalPubkeyTweakedRequest ); logInputAndOutput( { @@ -132,12 +151,19 @@ async function main() { data ); // pay the invoice - payResponse = await fedimintClient.lightning.pay(data.invoice); + let payRequest: LightningPayRequest = { + paymentInfo: data.invoice, + }; + payResponse = await fedimintClient.lightning.pay(payRequest); // `/v1/ln/claim-external-pubkey-tweaked` logMethod("/v1/ln/claim-external-pubkey-tweaked"); + let lightningClaimPubkeyTweakedRequest: LightningClaimPubkeyReceiveTweakedRequest = + { + privateKey: keyPair.privateKey, + tweaks: [1], + }; data = await fedimintClient.lightning.claimPubkeyTweakReceives( - keyPair.privateKey, - [1], + lightningClaimPubkeyTweakedRequest, fedimintClient.getActiveFederationId() ); logInputAndOutput({ privateKey: keyPair.privateKey, tweaks: [1] }, data); @@ -145,7 +171,13 @@ async function main() { // MINT METHODS // `/v2/mint/spend` logMethod("/v2/mint/spend"); - let mintData = await fedimintClient.mint.spend(3000, true, 1000, false); + let spendRequest: MintSpendRequest = { + amountMsat: 3000, + allowOverpay: true, + timeout: 1000, + includeInvite: true, + }; + let mintData = await fedimintClient.mint.spend(spendRequest); logInputAndOutput( { amountMsat: 3000, allowOverpay: true, timeout: 1000 }, data