Skip to content

Commit

Permalink
begin bitcoin upgrade
Browse files Browse the repository at this point in the history
This includes a lot of changed paths and method names.
We need to change all bdk::x imports to bdk_wallet::x,
::bitcoin::Address now comes with type states to account
for the network check,
Script now is a [u8], so we should probably use ScriptBuf,
etc.
  • Loading branch information
Einliterflasche committed Nov 19, 2024
1 parent cc760f0 commit 6e6eb9d
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 148 deletions.
75 changes: 48 additions & 27 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ asynchronous-codec = "0.7.0"
atty = "0.2"
backoff = { version = "0.4", features = [ "tokio" ] }
base64 = "0.22"
bdk = { version = "0.28" }
bdk = { version = "0.29" }
bdk_electrum = { version = "0.19", features = [ "use-rustls" ] }
bdk_wallet = { version = "1.0.0-beta.5", features = [ "rusqlite" ] }
big-bytes = "1"
bitcoin = { version = "0.29", features = [ "rand", "serde" ] }
bitcoin = { version = "0.32", features = [ "rand", "serde" ] }
bmrng = "0.5.2"
comfy-table = "7.1"
config = { version = "0.14", default-features = false, features = [ "toml" ] }
Expand Down
17 changes: 5 additions & 12 deletions swap/src/asb/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,14 @@ where
Ok(arguments)
}

fn bitcoin_address(address: Address, is_testnet: bool) -> Result<Address> {
fn bitcoin_address(address: Address<bitcoin::address::NetworkUnchecked>, is_testnet: bool) -> Result<Address<bitcoin::address::NetworkChecked>> {
let network = if is_testnet {
bitcoin::Network::Testnet
} else {
bitcoin::Network::Bitcoin
};

if address.network != network {
bail!(BitcoinAddressNetworkMismatch {
expected: network,
actual: address.network
});
}

Ok(address)
Ok(address.require_network(network)?)
}

fn config_path(config: Option<PathBuf>, is_testnet: bool) -> Result<PathBuf> {
Expand Down Expand Up @@ -306,7 +299,7 @@ pub enum RawCommand {
)]
amount: Option<Amount>,
#[structopt(long = "address", help = "The address to receive the Bitcoin.")]
address: Address,
address: Address<bitcoin::address::NetworkUnchecked>,
},
#[structopt(
about = "Prints the Bitcoin and Monero balance. Requires the monero-wallet-rpc to be running."
Expand Down Expand Up @@ -451,7 +444,7 @@ mod tests {
env_config: mainnet_env_config,
cmd: Command::WithdrawBtc {
amount: None,
address: Address::from_str(BITCOIN_MAINNET_ADDRESS).unwrap(),
address: bitcoin_address(Address::from_str(BITCOIN_MAINNET_ADDRESS).unwrap(), false).unwrap(),
},
};
let args = parse_args(raw_ars).unwrap();
Expand Down Expand Up @@ -628,7 +621,7 @@ mod tests {
env_config: testnet_env_config,
cmd: Command::WithdrawBtc {
amount: None,
address: Address::from_str(BITCOIN_TESTNET_ADDRESS).unwrap(),
address: bitcoin_address(Address::from_str(BITCOIN_TESTNET_ADDRESS).unwrap(), true).unwrap(),
},
};
let args = parse_args(raw_ars).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions swap/src/asb/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ pub struct TorConf {
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Maker {
#[serde(with = "::bitcoin::util::amount::serde::as_btc")]
#[serde(with = "::bitcoin::amount::serde::as_btc")]
pub min_buy_btc: bitcoin::Amount,
#[serde(with = "::bitcoin::util::amount::serde::as_btc")]
#[serde(with = "::bitcoin::amount::serde::as_btc")]
pub max_buy_btc: bitcoin::Amount,
pub ask_spread: Decimal,
pub price_ticker_ws_url: Url,
pub external_bitcoin_redeem_address: Option<bitcoin::Address>,
pub external_bitcoin_redeem_address: Option<bitcoin::Address<bitcoin::address::NetworkUnchecked>>,
}

impl Default for TorConf {
Expand Down
2 changes: 1 addition & 1 deletion swap/src/asb/recovery/punish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub async fn punish(
let txid = state3.punish_btc(&bitcoin_wallet).await?;

let state = AliceState::BtcPunished {
state3: state3.clone(),
state3: Box::new(state3.clone()),
};
db.insert_latest_state(swap_id, state.clone().into())
.await?;
Expand Down
Loading

0 comments on commit 6e6eb9d

Please sign in to comment.