Skip to content

Commit

Permalink
chore: bump gateway/cli to bitcoin v0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
tvolk131 committed Oct 27, 2024
1 parent 49b0531 commit a34b51f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

7 changes: 7 additions & 0 deletions fedimint-core/src/bitcoin_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion gateway/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
13 changes: 8 additions & 5 deletions gateway/cli/src/general_commands.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -115,7 +118,7 @@ pub enum GeneralCommands {
routing_fees: Option<FederationRoutingFees>,

#[clap(long)]
network: Option<bitcoin30::Network>,
network: Option<bitcoin::Network>,

/// Format federation id,base msat,proportional to millionths part. Any
/// other federations not given here will keep their current fees.
Expand Down Expand Up @@ -202,7 +205,7 @@ impl GeneralCommands {
.withdraw(WithdrawPayload {
federation_id,
amount,
address,
address: bitcoin32_to_bitcoin30_unchecked_address(&address),
})
.await?;

Expand Down Expand Up @@ -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?;
Expand Down
17 changes: 13 additions & 4 deletions gateway/cli/src/lightning_commands.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -67,7 +70,7 @@ pub enum LightningCommands {
WithdrawOnchain {
/// The address to withdraw funds to.
#[clap(long)]
address: bitcoin30::Address<NetworkUnchecked>,
address: bitcoin::Address<NetworkUnchecked>,

/// The amount to withdraw.
/// Can be "all" to withdraw all funds, an amount + unit (e.g. "1000
Expand Down Expand Up @@ -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,
Expand All @@ -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?;
Expand All @@ -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,
Expand Down

0 comments on commit a34b51f

Please sign in to comment.