From a34b51f91aa7924284e2975c889bb4dcfb58407e Mon Sep 17 00:00:00 2001 From: Tommy Volk Date: Wed, 23 Oct 2024 16:53:59 +0100 Subject: [PATCH] chore: bump gateway/cli to bitcoin v0.32 --- Cargo.lock | 2 +- fedimint-core/src/bitcoin_migration.rs | 7 +++++++ gateway/cli/Cargo.toml | 2 +- gateway/cli/src/general_commands.rs | 13 ++++++++----- gateway/cli/src/lightning_commands.rs | 17 +++++++++++++---- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 05db25490b2..609a9f14d5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2492,7 +2492,7 @@ name = "fedimint-gateway-cli" version = "0.5.0-alpha" dependencies = [ "anyhow", - "bitcoin 0.30.2", + "bitcoin 0.32.3", "clap", "clap_complete", "fedimint-build", diff --git a/fedimint-core/src/bitcoin_migration.rs b/fedimint-core/src/bitcoin_migration.rs index 4b0dd2b9939..425454e561b 100644 --- a/fedimint-core/src/bitcoin_migration.rs +++ b/fedimint-core/src/bitcoin_migration.rs @@ -150,6 +150,13 @@ pub fn bitcoin30_to_bitcoin32_network(network: &bitcoin30::Network) -> bitcoin:: .expect("Failed to convert bitcoin30 network to bitcoin32 network") } +pub fn bitcoin32_to_bitcoin30_network(network: &bitcoin::Network) -> bitcoin30::Network { + bincode::deserialize( + &bincode::serialize(network).expect("Failed to serialize bitcoin32 network"), + ) + .expect("Failed to convert bitcoin32 network to bitcoin30 network") +} + fn bitcoin30_to_bitcoin32_txid(txid: &bitcoin30::Txid) -> bitcoin::Txid { bitcoin::Txid::from_str(&txid.to_string()) .expect("Failed to convert bitcoin30 txid to bitcoin32 txid") diff --git a/gateway/cli/Cargo.toml b/gateway/cli/Cargo.toml index c121dd7acc3..9cf7d8963c3 100644 --- a/gateway/cli/Cargo.toml +++ b/gateway/cli/Cargo.toml @@ -20,7 +20,7 @@ path = "src/main.rs" [dependencies] anyhow = { workspace = true } -bitcoin30 = { workspace = true } +bitcoin = { workspace = true } clap = { workspace = true } clap_complete = "4.5.35" fedimint-core = { workspace = true } diff --git a/gateway/cli/src/general_commands.rs b/gateway/cli/src/general_commands.rs index 7f04fa349cb..074ec512272 100644 --- a/gateway/cli/src/general_commands.rs +++ b/gateway/cli/src/general_commands.rs @@ -1,7 +1,10 @@ use anyhow::bail; -use bitcoin30::address::NetworkUnchecked; -use bitcoin30::Address; +use bitcoin::address::NetworkUnchecked; +use bitcoin::Address; use clap::Subcommand; +use fedimint_core::bitcoin_migration::{ + bitcoin32_to_bitcoin30_network, bitcoin32_to_bitcoin30_unchecked_address, +}; use fedimint_core::config::FederationId; use fedimint_core::{fedimint_build_code_version_env, Amount, BitcoinAmountOrAll}; use fedimint_mint_client::OOBNotes; @@ -115,7 +118,7 @@ pub enum GeneralCommands { routing_fees: Option, #[clap(long)] - network: Option, + network: Option, /// Format federation id,base msat,proportional to millionths part. Any /// other federations not given here will keep their current fees. @@ -202,7 +205,7 @@ impl GeneralCommands { .withdraw(WithdrawPayload { federation_id, amount, - address, + address: bitcoin32_to_bitcoin30_unchecked_address(&address), }) .await?; @@ -250,7 +253,7 @@ impl GeneralCommands { password, num_route_hints, routing_fees, - network, + network: network.map(|network| bitcoin32_to_bitcoin30_network(&network)), per_federation_routing_fees, }) .await?; diff --git a/gateway/cli/src/lightning_commands.rs b/gateway/cli/src/lightning_commands.rs index 28263c28b17..3baad1554d8 100644 --- a/gateway/cli/src/lightning_commands.rs +++ b/gateway/cli/src/lightning_commands.rs @@ -1,7 +1,10 @@ use std::time::Duration; -use bitcoin30::address::NetworkUnchecked; +use bitcoin::address::NetworkUnchecked; use clap::Subcommand; +use fedimint_core::bitcoin_migration::{ + bitcoin32_to_bitcoin30_secp256k1_pubkey, bitcoin32_to_bitcoin30_unchecked_address, +}; use fedimint_core::util::{backoff_util, retry}; use fedimint_core::BitcoinAmountOrAll; use lightning_invoice::Bolt11Invoice; @@ -40,7 +43,7 @@ pub enum LightningCommands { OpenChannel { /// The public key of the node to open a channel with #[clap(long)] - pubkey: bitcoin30::secp256k1::PublicKey, + pubkey: bitcoin::secp256k1::PublicKey, #[clap(long)] host: String, @@ -58,7 +61,7 @@ pub enum LightningCommands { CloseChannelsWithPeer { // The public key of the node to close channels with #[clap(long)] - pubkey: bitcoin30::secp256k1::PublicKey, + pubkey: bitcoin::secp256k1::PublicKey, }, /// List active channels. ListActiveChannels, @@ -67,7 +70,7 @@ pub enum LightningCommands { WithdrawOnchain { /// The address to withdraw funds to. #[clap(long)] - address: bitcoin30::Address, + address: bitcoin::Address, /// The amount to withdraw. /// Can be "all" to withdraw all funds, an amount + unit (e.g. "1000 @@ -136,6 +139,8 @@ impl LightningCommands { channel_size_sats, push_amount_sats, } => { + let pubkey = bitcoin32_to_bitcoin30_secp256k1_pubkey(&pubkey); + let funding_txid = create_client() .open_channel(OpenChannelPayload { pubkey, @@ -147,6 +152,8 @@ impl LightningCommands { println!("{funding_txid}"); } Self::CloseChannelsWithPeer { pubkey } => { + let pubkey = bitcoin32_to_bitcoin30_secp256k1_pubkey(&pubkey); + let response = create_client() .close_channels_with_peer(CloseChannelsWithPeerPayload { pubkey }) .await?; @@ -161,6 +168,8 @@ impl LightningCommands { amount, fee_rate_sats_per_vbyte, } => { + let address = bitcoin32_to_bitcoin30_unchecked_address(&address); + let response = create_client() .withdraw_onchain(WithdrawOnchainPayload { address,