Skip to content

Commit f0aec42

Browse files
committed
Update to Bitcoin 32
1 parent d8afc96 commit f0aec42

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+490
-588
lines changed

bitcoin-rpc-provider/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ name = "bitcoin-rpc-provider"
55
version = "0.1.0"
66

77
[dependencies]
8-
bitcoin = {version = "0.30.2"}
9-
bitcoincore-rpc = {version = "0.17.0"}
10-
bitcoincore-rpc-json = {version = "0.17.0"}
8+
bitcoin = {version = "0.32.2"}
9+
bitcoincore-rpc = {version = "0.19.0"}
10+
bitcoincore-rpc-json = {version = "0.19.0"}
1111
dlc-manager = {path = "../dlc-manager"}
1212
hex = { package = "hex-conservative", version = "0.1" }
13-
lightning = { version = "0.0.121" }
13+
lightning = { version = "0.0.124" }
1414
log = "0.4.14"
1515
rust-bitcoin-coin-selection = { version = "0.1.0", git = "https://github.com/p2pderivatives/rust-bitcoin-coin-selection", rev = "405451929568422f7df809e35d6ad8f36fccce90", features = ["rand"] }
1616
simple-wallet = {path = "../simple-wallet"}

bitcoin-rpc-provider/src/lib.rs

+16-38
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ use std::time::Duration;
88
use bitcoin::address::NetworkUnchecked;
99
use bitcoin::consensus::encode::Error as EncodeError;
1010
use bitcoin::hashes::serde;
11-
use bitcoin::psbt::PartiallySignedTransaction;
11+
use bitcoin::psbt::Psbt;
1212
use bitcoin::secp256k1::rand::thread_rng;
13-
use bitcoin::secp256k1::{PublicKey, SecretKey};
14-
use bitcoin::{
15-
consensus::Decodable, network::constants::Network, Amount, PrivateKey, Transaction, Txid,
16-
};
17-
use bitcoin::{Address, OutPoint, ScriptBuf, TxOut};
13+
use bitcoin::secp256k1::SecretKey;
14+
use bitcoin::{consensus::Decodable, Network, PrivateKey, Transaction, Txid};
15+
use bitcoin::{secp256k1::PublicKey, Address, OutPoint, ScriptBuf, TxOut};
1816
use bitcoincore_rpc::jsonrpc::serde_json;
1917
use bitcoincore_rpc::jsonrpc::serde_json::Value;
2018
use bitcoincore_rpc::{json, Auth, Client, RpcApi};
@@ -106,7 +104,7 @@ impl BitcoinCoreProvider {
106104
pub fn new_from_rpc_client(rpc_client: Client) -> Self {
107105
let client = Arc::new(Mutex::new(rpc_client));
108106
let mut fees: HashMap<ConfirmationTarget, AtomicU32> = HashMap::with_capacity(7);
109-
fees.insert(ConfirmationTarget::OnChainSweep, AtomicU32::new(5000));
107+
fees.insert(ConfirmationTarget::UrgentOnChainSweep, AtomicU32::new(5000));
110108
fees.insert(
111109
ConfirmationTarget::MinAllowedAnchorChannelRemoteFee,
112110
AtomicU32::new(MIN_FEERATE),
@@ -155,7 +153,7 @@ struct UtxoWrap(Utxo);
155153

156154
impl rust_bitcoin_coin_selection::Utxo for UtxoWrap {
157155
fn get_value(&self) -> u64 {
158-
self.0.tx_out.value
156+
self.0.tx_out.value.to_sat()
159157
}
160158
}
161159

@@ -206,7 +204,7 @@ impl ContractSignerProvider for BitcoinCoreProvider {
206204
.import_private_key(
207205
&PrivateKey {
208206
compressed: true,
209-
network,
207+
network: network.into(),
210208
inner: sk,
211209
},
212210
Some(&keys_id.to_lower_hex_string()),
@@ -219,12 +217,8 @@ impl ContractSignerProvider for BitcoinCoreProvider {
219217
}
220218

221219
fn get_secret_key_for_pubkey(&self, pubkey: &PublicKey) -> Result<SecretKey, ManagerError> {
222-
let b_pubkey = bitcoin::PublicKey {
223-
compressed: true,
224-
inner: *pubkey,
225-
};
226-
let address =
227-
Address::p2wpkh(&b_pubkey, self.get_network()?).or(Err(Error::BitcoinError))?;
220+
let b_pubkey = bitcoin::CompressedPublicKey(*pubkey);
221+
let address = Address::p2wpkh(&b_pubkey, self.get_network()?);
228222

229223
let pk = self
230224
.client
@@ -244,7 +238,7 @@ impl ContractSignerProvider for BitcoinCoreProvider {
244238
.import_private_key(
245239
&PrivateKey {
246240
compressed: true,
247-
network,
241+
network: network.into(),
248242
inner: sk,
249243
},
250244
None,
@@ -296,7 +290,7 @@ impl Wallet for BitcoinCoreProvider {
296290
.map(|x| {
297291
Ok(UtxoWrap(Utxo {
298292
tx_out: TxOut {
299-
value: x.amount.to_sat(),
293+
value: x.amount,
300294
script_pubkey: x.script_pub_key.clone(),
301295
},
302296
outpoint: OutPoint {
@@ -338,11 +332,7 @@ impl Wallet for BitcoinCoreProvider {
338332
.map_err(rpc_err_to_manager_err)
339333
}
340334

341-
fn sign_psbt_input(
342-
&self,
343-
psbt: &mut PartiallySignedTransaction,
344-
input_index: usize,
345-
) -> Result<(), ManagerError> {
335+
fn sign_psbt_input(&self, psbt: &mut Psbt, input_index: usize) -> Result<(), ManagerError> {
346336
let outpoint = &psbt.unsigned_tx.input[input_index].previous_output;
347337
let tx_out = if let Some(input) = psbt.inputs.get(input_index) {
348338
if let Some(wit_utxo) = &input.witness_utxo {
@@ -370,7 +360,7 @@ impl Wallet for BitcoinCoreProvider {
370360
vout: outpoint.vout,
371361
script_pub_key: tx_out.script_pubkey.clone(),
372362
redeem_script,
373-
amount: Some(Amount::from_sat(tx_out.value)),
363+
amount: Some(tx_out.value),
374364
};
375365

376366
let sign_result = self
@@ -417,25 +407,13 @@ impl Blockchain for BitcoinCoreProvider {
417407
}
418408

419409
fn get_network(&self) -> Result<Network, ManagerError> {
420-
let network = match self
410+
let network = self
421411
.client
422412
.lock()
423413
.unwrap()
424414
.get_blockchain_info()
425415
.map_err(rpc_err_to_manager_err)?
426-
.chain
427-
.as_ref()
428-
{
429-
"main" => Network::Bitcoin,
430-
"test" => Network::Testnet,
431-
"regtest" => Network::Regtest,
432-
"signet" => Network::Signet,
433-
_ => {
434-
return Err(ManagerError::BlockchainError(
435-
"Unknown Bitcoin network".to_string(),
436-
))
437-
}
438-
};
416+
.chain;
439417

440418
Ok(network)
441419
}
@@ -547,7 +525,7 @@ fn poll_for_fee_estimates(
547525
};
548526
match query_fee_estimate(&client, 6, EstimateMode::Conservative) {
549527
Ok(fee_rate) => {
550-
fees.get(&ConfirmationTarget::OnChainSweep)
528+
fees.get(&ConfirmationTarget::UrgentOnChainSweep)
551529
.unwrap()
552530
.store(fee_rate, Ordering::Release);
553531
}

bitcoin-test-utils/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ name = "bitcoin-test-utils"
44
version = "0.1.0"
55

66
[dependencies]
7-
bitcoin = { version = "0.30.2", default-features = false }
8-
bitcoincore-rpc = {version = "0.17"}
9-
bitcoincore-rpc-json = {version = "0.17"}
7+
bitcoin = { version = "0.32.2", default-features = false }
8+
bitcoincore-rpc = {version = "0.19"}
9+
bitcoincore-rpc-json = {version = "0.19"}

dlc-manager/Cargo.toml

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ homepage = "https://github.com/p2pderivatives/rust-dlc"
66
license-file = "../LICENSE"
77
name = "dlc-manager"
88
repository = "https://github.com/p2pderivatives/rust-dlc/tree/master/dlc-manager"
9-
version = "0.5.0"
9+
version = "0.6.0"
1010

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

1818
[dependencies]
1919
async-trait = "0.1.50"
20-
bitcoin = { version = "0.30.2", default-features = false }
21-
dlc = { version = "0.5.0", default-features = false, path = "../dlc" }
22-
dlc-messages = { version = "0.5.0", default-features = false, path = "../dlc-messages" }
23-
dlc-trie = { version = "0.5.0", default-features = false, path = "../dlc-trie" }
20+
bitcoin = { version = "0.32.2", default-features = false }
21+
dlc = { version = "0.6.0", default-features = false, path = "../dlc" }
22+
dlc-messages = { version = "0.6.0", default-features = false, path = "../dlc-messages" }
23+
dlc-trie = { version = "0.6.0", default-features = false, path = "../dlc-trie" }
2424
hex = { package = "hex-conservative", version = "0.1" }
25-
lightning = { version = "0.0.121", default-features = false, features = ["grind_signatures"] }
25+
lightning = { version = "0.0.124", default-features = false, features = ["grind_signatures"] }
2626
log = "0.4.14"
2727
rand_chacha = {version = "0.3.1", optional = true}
28-
secp256k1-zkp = {version = "0.9.2"}
28+
secp256k1-zkp = {version = "0.11.0"}
2929
serde = {version = "1.0", optional = true}
3030

3131
[dev-dependencies]
3232
bitcoin-rpc-provider = {path = "../bitcoin-rpc-provider"}
3333
bitcoin-test-utils = {path = "../bitcoin-test-utils"}
34-
bitcoincore-rpc = {version = "0.17"}
35-
bitcoincore-rpc-json = {version = "0.17"}
34+
bitcoincore-rpc = {version = "0.19"}
35+
bitcoincore-rpc-json = {version = "0.19"}
3636
criterion = "0.4.0"
3737
dlc-manager = { path = ".", default-features = false, features = ["use-serde"] }
3838
dlc-messages = { path = "../dlc-messages", default-features = false, features = ["serde"] }
3939
electrs-blockchain-provider = {path = "../electrs-blockchain-provider"}
4040
env_logger = "0.9.1"
4141
mocks = {path = "../mocks"}
42-
secp256k1-zkp = {version = "0.9.2", features = ["bitcoin_hashes", "rand", "rand-std", "global-context", "serde"]}
42+
secp256k1-zkp = {version = "0.11.0", features = ["hashes", "rand", "rand-std", "global-context", "serde"]}
4343
serde = "1.0"
4444
serde_json = "1.0"
4545
simple-wallet = {path = "../simple-wallet"}

dlc-manager/src/chain_monitor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl ChainMonitor {
132132
assert_eq!(self.last_height + 1, height);
133133

134134
for tx in block.txdata.iter() {
135-
if let Some(state) = self.watched_tx.get_mut(&tx.txid()) {
135+
if let Some(state) = self.watched_tx.get_mut(&tx.compute_txid()) {
136136
state.confirm(tx.clone());
137137
}
138138

@@ -190,7 +190,7 @@ impl WatchState {
190190
WatchState::Registered { ref channel_info } => {
191191
log::info!(
192192
"Transaction {} confirmed: {channel_info:?}",
193-
transaction.txid()
193+
transaction.compute_txid()
194194
);
195195

196196
*self = WatchState::Confirmed {
@@ -204,7 +204,7 @@ impl WatchState {
204204
} => {
205205
log::error!(
206206
"Transaction {} already confirmed: {channel_info:?}",
207-
transaction.txid()
207+
transaction.compute_txid()
208208
);
209209
}
210210
}

0 commit comments

Comments
 (0)