Skip to content

Commit

Permalink
Update to Bitcoin 32
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyhodl committed Sep 9, 2024
1 parent d8afc96 commit 42f951f
Show file tree
Hide file tree
Showing 43 changed files with 477 additions and 585 deletions.
8 changes: 4 additions & 4 deletions bitcoin-rpc-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ name = "bitcoin-rpc-provider"
version = "0.1.0"

[dependencies]
bitcoin = {version = "0.30.2"}
bitcoincore-rpc = {version = "0.17.0"}
bitcoincore-rpc-json = {version = "0.17.0"}
bitcoin = {version = "0.32.2"}
bitcoincore-rpc = {version = "0.19.0"}
bitcoincore-rpc-json = {version = "0.19.0"}
dlc-manager = {path = "../dlc-manager"}
hex = { package = "hex-conservative", version = "0.1" }
lightning = { version = "0.0.121" }
lightning = { version = "0.0.124" }
log = "0.4.14"
rust-bitcoin-coin-selection = { version = "0.1.0", git = "https://github.com/p2pderivatives/rust-bitcoin-coin-selection", rev = "405451929568422f7df809e35d6ad8f36fccce90", features = ["rand"] }
simple-wallet = {path = "../simple-wallet"}
54 changes: 16 additions & 38 deletions bitcoin-rpc-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ use std::time::Duration;
use bitcoin::address::NetworkUnchecked;
use bitcoin::consensus::encode::Error as EncodeError;
use bitcoin::hashes::serde;
use bitcoin::psbt::PartiallySignedTransaction;
use bitcoin::psbt::Psbt;
use bitcoin::secp256k1::rand::thread_rng;
use bitcoin::secp256k1::{PublicKey, SecretKey};
use bitcoin::{
consensus::Decodable, network::constants::Network, Amount, PrivateKey, Transaction, Txid,
};
use bitcoin::{Address, OutPoint, ScriptBuf, TxOut};
use bitcoin::secp256k1::SecretKey;
use bitcoin::{consensus::Decodable, Network, PrivateKey, Transaction, Txid};
use bitcoin::{secp256k1::PublicKey, Address, OutPoint, ScriptBuf, TxOut};
use bitcoincore_rpc::jsonrpc::serde_json;
use bitcoincore_rpc::jsonrpc::serde_json::Value;
use bitcoincore_rpc::{json, Auth, Client, RpcApi};
Expand Down Expand Up @@ -106,7 +104,7 @@ impl BitcoinCoreProvider {
pub fn new_from_rpc_client(rpc_client: Client) -> Self {
let client = Arc::new(Mutex::new(rpc_client));
let mut fees: HashMap<ConfirmationTarget, AtomicU32> = HashMap::with_capacity(7);
fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000));
fees.insert(ConfirmationTarget::UrgentOnChainSweep, AtomicU32::new(5000));
fees.insert(
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
AtomicU32::new(MIN_FEERATE),
Expand Down Expand Up @@ -155,7 +153,7 @@ struct UtxoWrap(Utxo);

impl rust_bitcoin_coin_selection::Utxo for UtxoWrap {
fn get_value(&self) -> u64 {
self.0.tx_out.value
self.0.tx_out.value.to_sat()
}
}

Expand Down Expand Up @@ -206,7 +204,7 @@ impl ContractSignerProvider for BitcoinCoreProvider {
.import_private_key(
&PrivateKey {
compressed: true,
network,
network: network.into(),
inner: sk,
},
Some(&keys_id.to_lower_hex_string()),
Expand All @@ -219,12 +217,8 @@ impl ContractSignerProvider for BitcoinCoreProvider {
}

fn get_secret_key_for_pubkey(&self, pubkey: &PublicKey) -> Result<SecretKey, ManagerError> {
let b_pubkey = bitcoin::PublicKey {
compressed: true,
inner: *pubkey,
};
let address =
Address::p2wpkh(&b_pubkey, self.get_network()?).or(Err(Error::BitcoinError))?;
let b_pubkey = bitcoin::CompressedPublicKey(pubkey.to_owned());
let address = Address::p2wpkh(&b_pubkey, self.get_network()?);

let pk = self
.client
Expand All @@ -244,7 +238,7 @@ impl ContractSignerProvider for BitcoinCoreProvider {
.import_private_key(
&PrivateKey {
compressed: true,
network,
network: network.into(),
inner: sk,
},
None,
Expand Down Expand Up @@ -296,7 +290,7 @@ impl Wallet for BitcoinCoreProvider {
.map(|x| {
Ok(UtxoWrap(Utxo {
tx_out: TxOut {
value: x.amount.to_sat(),
value: x.amount,
script_pubkey: x.script_pub_key.clone(),
},
outpoint: OutPoint {
Expand Down Expand Up @@ -338,11 +332,7 @@ impl Wallet for BitcoinCoreProvider {
.map_err(rpc_err_to_manager_err)
}

fn sign_psbt_input(
&self,
psbt: &mut PartiallySignedTransaction,
input_index: usize,
) -> Result<(), ManagerError> {
fn sign_psbt_input(&self, psbt: &mut Psbt, input_index: usize) -> Result<(), ManagerError> {
let outpoint = &psbt.unsigned_tx.input[input_index].previous_output;
let tx_out = if let Some(input) = psbt.inputs.get(input_index) {
if let Some(wit_utxo) = &input.witness_utxo {
Expand Down Expand Up @@ -370,7 +360,7 @@ impl Wallet for BitcoinCoreProvider {
vout: outpoint.vout,
script_pub_key: tx_out.script_pubkey.clone(),
redeem_script,
amount: Some(Amount::from_sat(tx_out.value)),
amount: Some(tx_out.value),
};

let sign_result = self
Expand Down Expand Up @@ -417,25 +407,13 @@ impl Blockchain for BitcoinCoreProvider {
}

fn get_network(&self) -> Result<Network, ManagerError> {
let network = match self
let network = self
.client
.lock()
.unwrap()
.get_blockchain_info()
.map_err(rpc_err_to_manager_err)?
.chain
.as_ref()
{
"main" => Network::Bitcoin,
"test" => Network::Testnet,
"regtest" => Network::Regtest,
"signet" => Network::Signet,
_ => {
return Err(ManagerError::BlockchainError(
"Unknown Bitcoin network".to_string(),
))
}
};
.chain;

Ok(network)
}
Expand Down Expand Up @@ -547,7 +525,7 @@ fn poll_for_fee_estimates(
};
match query_fee_estimate(&client, 6, EstimateMode::Conservative) {
Ok(fee_rate) => {
fees.get(&ConfirmationTarget::OnChainSweep)
fees.get(&ConfirmationTarget::UrgentOnChainSweep)
.unwrap()
.store(fee_rate, Ordering::Release);
}
Expand Down
6 changes: 3 additions & 3 deletions bitcoin-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ name = "bitcoin-test-utils"
version = "0.1.0"

[dependencies]
bitcoin = { version = "0.30.2", default-features = false }
bitcoincore-rpc = {version = "0.17"}
bitcoincore-rpc-json = {version = "0.17"}
bitcoin = { version = "0.32.2", default-features = false }
bitcoincore-rpc = {version = "0.19"}
bitcoincore-rpc-json = {version = "0.19"}
20 changes: 10 additions & 10 deletions dlc-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://github.com/p2pderivatives/rust-dlc"
license-file = "../LICENSE"
name = "dlc-manager"
repository = "https://github.com/p2pderivatives/rust-dlc/tree/master/dlc-manager"
version = "0.5.0"
version = "0.6.0"

[features]
default = ["std"]
Expand All @@ -17,29 +17,29 @@ use-serde = ["serde", "dlc/use-serde", "dlc-messages/use-serde", "dlc-trie/use-s

[dependencies]
async-trait = "0.1.50"
bitcoin = { version = "0.30.2", default-features = false }
dlc = { version = "0.5.0", default-features = false, path = "../dlc" }
dlc-messages = { version = "0.5.0", default-features = false, path = "../dlc-messages" }
dlc-trie = { version = "0.5.0", default-features = false, path = "../dlc-trie" }
bitcoin = { version = "0.32.2", default-features = false }
dlc = { version = "0.6.0", default-features = false, path = "../dlc" }
dlc-messages = { version = "0.6.0", default-features = false, path = "../dlc-messages" }
dlc-trie = { version = "0.6.0", default-features = false, path = "../dlc-trie" }
hex = { package = "hex-conservative", version = "0.1" }
lightning = { version = "0.0.121", default-features = false, features = ["grind_signatures"] }
lightning = { version = "0.0.124", default-features = false, features = ["grind_signatures"] }
log = "0.4.14"
rand_chacha = {version = "0.3.1", optional = true}
secp256k1-zkp = {version = "0.9.2"}
secp256k1-zkp = {version = "0.11.0"}
serde = {version = "1.0", optional = true}

[dev-dependencies]
bitcoin-rpc-provider = {path = "../bitcoin-rpc-provider"}
bitcoin-test-utils = {path = "../bitcoin-test-utils"}
bitcoincore-rpc = {version = "0.17"}
bitcoincore-rpc-json = {version = "0.17"}
bitcoincore-rpc = {version = "0.19"}
bitcoincore-rpc-json = {version = "0.19"}
criterion = "0.4.0"
dlc-manager = { path = ".", default-features = false, features = ["use-serde"] }
dlc-messages = { path = "../dlc-messages", default-features = false, features = ["serde"] }
electrs-blockchain-provider = {path = "../electrs-blockchain-provider"}
env_logger = "0.9.1"
mocks = {path = "../mocks"}
secp256k1-zkp = {version = "0.9.2", features = ["bitcoin_hashes", "rand", "rand-std", "global-context", "serde"]}
secp256k1-zkp = {version = "0.11.0", features = ["hashes", "rand", "rand-std", "global-context", "serde"]}
serde = "1.0"
serde_json = "1.0"
simple-wallet = {path = "../simple-wallet"}
Expand Down
6 changes: 3 additions & 3 deletions dlc-manager/src/chain_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl ChainMonitor {
assert_eq!(self.last_height + 1, height);

for tx in block.txdata.iter() {
if let Some(state) = self.watched_tx.get_mut(&tx.txid()) {
if let Some(state) = self.watched_tx.get_mut(&tx.compute_txid()) {
state.confirm(tx.clone());
}

Expand Down Expand Up @@ -190,7 +190,7 @@ impl WatchState {
WatchState::Registered { ref channel_info } => {
log::info!(
"Transaction {} confirmed: {channel_info:?}",
transaction.txid()
transaction.compute_txid()
);

*self = WatchState::Confirmed {
Expand All @@ -204,7 +204,7 @@ impl WatchState {
} => {
log::error!(
"Transaction {} already confirmed: {channel_info:?}",
transaction.txid()
transaction.compute_txid()
);
}
}
Expand Down
Loading

0 comments on commit 42f951f

Please sign in to comment.