Skip to content

Commit 956d332

Browse files
tchardingsanket1729
authored andcommitted
update to bitcoin 10.0
1 parent 560e7b8 commit 956d332

40 files changed

+796
-633
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ rand = ["bitcoin/rand"]
2323
base64 = ["bitcoin/base64"]
2424

2525
[dependencies]
26-
bitcoin = { version = "0.29.1", default-features = false }
26+
bitcoin = { version = "0.30.0", default-features = false }
2727
hashbrown = { version = "0.11", optional = true }
28+
bitcoin-private = { version = "0.1.0", default-features = false }
2829

2930
# Do NOT use this as a feature! Use the `serde` feature instead.
3031
actual-serde = { package = "serde", version = "1.0.103", optional = true }
3132

3233
[dev-dependencies]
3334
serde_test = "1.0.147"
34-
bitcoin = { version = "0.29.2", features = ["base64"] }
35-
secp256k1 = {version = "0.24.0", features = ["rand-std"]}
35+
bitcoin = { version = "0.30.0", features = ["base64"] }
36+
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
3637
actual-base64 = { package = "base64", version = "0.13.0" }
3738

3839
[[example]]

bitcoind-tests/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ publish = false
99

1010
[dependencies]
1111
miniscript = {path = "../"}
12-
bitcoind = { version = "0.29.3" }
12+
bitcoind = { version = "0.30.0" }
1313
actual-rand = { package = "rand", version = "0.8.4"}
1414
secp256k1 = {version = "0.27.0", features = ["rand-std"]}
15+
bitcoin-private = {version = "0.1.0"}

bitcoind-tests/tests/setup/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn setup() -> BitcoinD {
2929
let bitcoind = bitcoind::BitcoinD::new(exe_path).unwrap();
3030
let cl = &bitcoind.client;
3131
// generate to an address by the wallet. And wait for funds to mature
32-
let addr = cl.get_new_address(None, None).unwrap();
32+
let addr = cl.get_new_address(None, None).unwrap().assume_checked();
3333
let blks = cl.generate_to_address(101, &addr).unwrap();
3434
assert_eq!(blks.len(), 101);
3535

bitcoind-tests/tests/setup/test_util.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@
2020
use std::str::FromStr;
2121

2222
use actual_rand as rand;
23-
use bitcoin::hashes::hex::ToHex;
2423
use bitcoin::hashes::{hash160, ripemd160, sha256, Hash};
2524
use bitcoin::secp256k1;
25+
use bitcoin_private::hex::exts::DisplayHex;
2626
use miniscript::descriptor::{SinglePub, SinglePubKey};
2727
use miniscript::{
2828
bitcoin, hash256, Descriptor, DescriptorPublicKey, Error, Miniscript, ScriptContext,
2929
TranslatePk, Translator,
3030
};
3131
use rand::RngCore;
32+
use secp256k1::XOnlyPublicKey;
3233

3334
#[derive(Clone, Debug)]
3435
pub struct PubData {
3536
pub pks: Vec<bitcoin::PublicKey>,
36-
pub x_only_pks: Vec<bitcoin::XOnlyPublicKey>,
37+
pub x_only_pks: Vec<XOnlyPublicKey>,
3738
pub sha256: sha256::Hash,
3839
pub hash256: hash256::Hash,
3940
pub ripemd160: ripemd160::Hash,
@@ -43,7 +44,7 @@ pub struct PubData {
4344
#[derive(Debug, Clone)]
4445
pub struct SecretData {
4546
pub sks: Vec<bitcoin::secp256k1::SecretKey>,
46-
pub x_only_keypairs: Vec<bitcoin::KeyPair>,
47+
pub x_only_keypairs: Vec<bitcoin::secp256k1::KeyPair>,
4748
pub sha256_pre: [u8; 32],
4849
pub hash256_pre: [u8; 32],
4950
pub ripemd160_pre: [u8; 32],
@@ -61,8 +62,8 @@ fn setup_keys(
6162
) -> (
6263
Vec<bitcoin::secp256k1::SecretKey>,
6364
Vec<miniscript::bitcoin::PublicKey>,
64-
Vec<bitcoin::KeyPair>,
65-
Vec<bitcoin::XOnlyPublicKey>,
65+
Vec<bitcoin::secp256k1::KeyPair>,
66+
Vec<XOnlyPublicKey>,
6667
) {
6768
let secp_sign = secp256k1::Secp256k1::signing_only();
6869
let mut sk = [0; 32];
@@ -86,8 +87,8 @@ fn setup_keys(
8687
let mut x_only_pks = vec![];
8788

8889
for i in 0..n {
89-
let keypair = bitcoin::KeyPair::from_secret_key(&secp_sign, &sks[i]);
90-
let (xpk, _parity) = bitcoin::XOnlyPublicKey::from_keypair(&keypair);
90+
let keypair = bitcoin::secp256k1::KeyPair::from_secret_key(&secp_sign, &sks[i]);
91+
let (xpk, _parity) = XOnlyPublicKey::from_keypair(&keypair);
9192
x_only_keypairs.push(keypair);
9293
x_only_pks.push(xpk);
9394
}
@@ -286,32 +287,32 @@ pub fn parse_test_desc(
286287
fn subs_hash_frag(ms: &str, pubdata: &PubData) -> String {
287288
let ms = ms.replace(
288289
"sha256(H)",
289-
&format!("sha256({})", &pubdata.sha256.to_hex()),
290+
&format!("sha256({})", &pubdata.sha256.to_string()),
290291
);
291292
let ms = ms.replace(
292293
"hash256(H)",
293-
&format!("hash256({})", &pubdata.hash256.into_inner().to_hex()),
294+
&format!("hash256({})", &pubdata.hash256.to_string()),
294295
);
295296
let ms = ms.replace(
296297
"ripemd160(H)",
297-
&format!("ripemd160({})", &pubdata.ripemd160.to_hex()),
298+
&format!("ripemd160({})", &pubdata.ripemd160.to_string()),
298299
);
299300
let ms = ms.replace(
300301
"hash160(H)",
301-
&format!("hash160({})", &pubdata.hash160.to_hex()),
302+
&format!("hash160({})", &pubdata.hash160.to_string()),
302303
);
303304

304305
let mut rand_hash32 = [0u8; 32];
305306
rand::thread_rng().fill_bytes(&mut rand_hash32);
306307

307308
let mut rand_hash20 = [0u8; 20];
308309
rand::thread_rng().fill_bytes(&mut rand_hash20);
309-
let ms = ms.replace("sha256(H!)", &format!("sha256({})", rand_hash32.to_hex()));
310-
let ms = ms.replace("hash256(H!)", &format!("hash256({})", rand_hash32.to_hex()));
310+
let ms = ms.replace("sha256(H!)", &format!("sha256({})", rand_hash32.to_lower_hex_string()));
311+
let ms = ms.replace("hash256(H!)", &format!("hash256({})", rand_hash32.to_lower_hex_string()));
311312
let ms = ms.replace(
312313
"ripemd160(H!)",
313-
&format!("ripemd160({})", rand_hash20.to_hex()),
314+
&format!("ripemd160({})", rand_hash20.to_lower_hex_string()),
314315
);
315-
let ms = ms.replace("hash160(H!)", &format!("hash160({})", rand_hash20.to_hex()));
316+
let ms = ms.replace("hash160(H!)", &format!("hash160({})", rand_hash20.to_lower_hex_string()));
316317
ms
317318
}

bitcoind-tests/tests/test_cpp.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ use std::path::Path;
1111

1212
use bitcoin::hashes::{sha256d, Hash};
1313
use bitcoin::secp256k1::{self, Secp256k1};
14-
use bitcoin::util::psbt;
15-
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
16-
use bitcoin::{Amount, LockTime, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid};
14+
use bitcoin::psbt;
15+
use bitcoin::psbt::PartiallySignedTransaction as Psbt;
16+
use bitcoin::{Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid};
1717
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
18+
use miniscript::bitcoin::absolute::LockTime;
1819
use miniscript::psbt::PsbtExt;
1920
use miniscript::{bitcoin, Descriptor};
2021

@@ -76,7 +77,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
7677
let pks = &testdata.pubdata.pks;
7778
// Generate some blocks
7879
let blocks = cl
79-
.generate_to_address(500, &cl.get_new_address(None, None).unwrap())
80+
.generate_to_address(500, &cl.get_new_address(None, None).unwrap().assume_checked())
8081
.unwrap();
8182
assert_eq!(blocks.len(), 500);
8283

@@ -99,7 +100,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
99100
}
100101
// Wait for the funds to mature.
101102
let blocks = cl
102-
.generate_to_address(50, &cl.get_new_address(None, None).unwrap())
103+
.generate_to_address(50, &cl.get_new_address(None, None).unwrap().assume_checked())
103104
.unwrap();
104105
assert_eq!(blocks.len(), 50);
105106
// Create a PSBT for each transaction.
@@ -136,7 +137,8 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
136137
// and we can check it by gettransaction RPC.
137138
let addr = cl
138139
.get_new_address(None, Some(json::AddressType::Bech32))
139-
.unwrap();
140+
.unwrap()
141+
.assume_checked();
140142
psbt.unsigned_tx.output.push(TxOut {
141143
value: 99_999_000,
142144
script_pubkey: addr.script_pubkey(),
@@ -168,8 +170,8 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
168170
.collect();
169171
// Get the required sighash message
170172
let amt = btc(1).to_sat();
171-
let mut sighash_cache = bitcoin::util::sighash::SighashCache::new(&psbts[i].unsigned_tx);
172-
let sighash_ty = bitcoin::EcdsaSighashType::All;
173+
let mut sighash_cache = bitcoin::sighash::SighashCache::new(&psbts[i].unsigned_tx);
174+
let sighash_ty = bitcoin::sighash::EcdsaSighashType::All;
173175
let sighash = sighash_cache
174176
.segwit_signature_hash(0, &ms.encode(), amt, sighash_ty)
175177
.unwrap();
@@ -184,7 +186,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
184186
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
185187
psbts[i].inputs[0].partial_sigs.insert(
186188
pk,
187-
bitcoin::EcdsaSig {
189+
bitcoin::ecdsa::Signature {
188190
sig,
189191
hash_ty: sighash_ty,
190192
},
@@ -196,7 +198,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
196198
testdata.secretdata.sha256_pre.to_vec(),
197199
);
198200
psbts[i].inputs[0].hash256_preimages.insert(
199-
sha256d::Hash::from_inner(testdata.pubdata.hash256.into_inner()),
201+
sha256d::Hash::from_byte_array(testdata.pubdata.hash256.to_byte_array()),
200202
testdata.secretdata.hash256_pre.to_vec(),
201203
);
202204
println!("{}", ms);
@@ -227,7 +229,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
227229
}
228230
// Finally mine the blocks and await confirmations
229231
let _blocks = cl
230-
.generate_to_address(10, &cl.get_new_address(None, None).unwrap())
232+
.generate_to_address(10, &cl.get_new_address(None, None).unwrap().assume_checked())
231233
.unwrap();
232234
// Get the required transactions from the node mined in the blocks.
233235
for txid in spend_txids {

bitcoind-tests/tests/test_desc.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ use std::{error, fmt};
1010
use actual_rand as rand;
1111
use bitcoin::blockdata::witness::Witness;
1212
use bitcoin::hashes::{sha256d, Hash};
13-
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
14-
use bitcoin::util::sighash::SighashCache;
15-
use bitcoin::util::taproot::{LeafVersion, TapLeafHash};
16-
use bitcoin::util::{psbt, sighash};
13+
use bitcoin::psbt::PartiallySignedTransaction as Psbt;
14+
use bitcoin::sighash::SighashCache;
15+
use bitcoin::taproot::{LeafVersion, TapLeafHash};
16+
use bitcoin::{psbt, sighash};
1717
use bitcoin::{
18-
secp256k1, Amount, LockTime, OutPoint, SchnorrSig, Script, Sequence, Transaction, TxIn, TxOut,
18+
secp256k1, Amount, absolute::LockTime, OutPoint, Sequence, Transaction, TxIn, TxOut,
1919
Txid,
2020
};
2121
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
22+
use miniscript::bitcoin::{self, ScriptBuf};
2223
use miniscript::psbt::{PsbtExt, PsbtInputExt};
23-
use miniscript::{bitcoin, Descriptor, Miniscript, ScriptContext, ToPublicKey};
24+
use miniscript::{Descriptor, Miniscript, ScriptContext, ToPublicKey};
2425
mod setup;
2526

2627
use rand::RngCore;
@@ -31,7 +32,7 @@ fn btc<F: Into<f64>>(btc: F) -> Amount {
3132
}
3233

3334
// Find the Outpoint by spk
34-
fn get_vout(cl: &Client, txid: Txid, value: u64, spk: Script) -> (OutPoint, TxOut) {
35+
fn get_vout(cl: &Client, txid: Txid, value: u64, spk: ScriptBuf) -> (OutPoint, TxOut) {
3536
let tx = cl
3637
.get_transaction(&txid, None)
3738
.unwrap()
@@ -79,7 +80,7 @@ pub fn test_desc_satisfy(
7980
let x_only_pks = &testdata.pubdata.x_only_pks;
8081
// Generate some blocks
8182
let blocks = cl
82-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap())
83+
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
8384
.unwrap();
8485
assert_eq!(blocks.len(), 1);
8586

@@ -98,7 +99,7 @@ pub fn test_desc_satisfy(
9899
.unwrap();
99100
// Wait for the funds to mature.
100101
let blocks = cl
101-
.generate_to_address(2, &cl.get_new_address(None, None).unwrap())
102+
.generate_to_address(2, &cl.get_new_address(None, None).unwrap().assume_checked())
102103
.unwrap();
103104
assert_eq!(blocks.len(), 2);
104105
// Create a PSBT for each transaction.
@@ -134,7 +135,8 @@ pub fn test_desc_satisfy(
134135
// and we can check it by gettransaction RPC.
135136
let addr = cl
136137
.get_new_address(None, Some(json::AddressType::Bech32))
137-
.unwrap();
138+
.unwrap()
139+
.assume_checked();
138140
// Had to decrease 'value', so that fees can be increased
139141
// (Was getting insufficient fees error, for deep script trees)
140142
psbt.unsigned_tx.output.push(TxOut {
@@ -158,7 +160,7 @@ pub fn test_desc_satisfy(
158160
match derived_desc {
159161
Descriptor::Tr(ref tr) => {
160162
// Fixme: take a parameter
161-
let hash_ty = sighash::SchnorrSighashType::Default;
163+
let hash_ty = sighash::TapSighashType::Default;
162164

163165
let internal_key_present = x_only_pks
164166
.iter()
@@ -180,7 +182,7 @@ pub fn test_desc_satisfy(
180182
rand::thread_rng().fill_bytes(&mut aux_rand);
181183
let schnorr_sig =
182184
secp.sign_schnorr_with_aux_rand(&msg, &internal_keypair, &aux_rand);
183-
psbt.inputs[0].tap_key_sig = Some(SchnorrSig {
185+
psbt.inputs[0].tap_key_sig = Some(bitcoin::taproot::Signature {
184186
sig: schnorr_sig,
185187
hash_ty: hash_ty,
186188
});
@@ -212,7 +214,7 @@ pub fn test_desc_satisfy(
212214
let (x_only_pk, _parity) = secp256k1::XOnlyPublicKey::from_keypair(&keypair);
213215
psbt.inputs[0].tap_script_sigs.insert(
214216
(x_only_pk, leaf_hash),
215-
bitcoin::SchnorrSig {
217+
bitcoin::taproot::Signature {
216218
sig,
217219
hash_ty: hash_ty,
218220
},
@@ -258,7 +260,7 @@ pub fn test_desc_satisfy(
258260
.to_secp_msg();
259261

260262
// Fixme: Take a parameter
261-
let hash_ty = bitcoin::EcdsaSighashType::All;
263+
let hash_ty = bitcoin::sighash::EcdsaSighashType::All;
262264

263265
// Finally construct the signature and add to psbt
264266
for sk in sks_reqd {
@@ -267,7 +269,7 @@ pub fn test_desc_satisfy(
267269
assert!(secp.verify_ecdsa(&msg, &sig, &pk.inner).is_ok());
268270
psbt.inputs[0].partial_sigs.insert(
269271
pk,
270-
bitcoin::EcdsaSig {
272+
bitcoin::ecdsa::Signature {
271273
sig,
272274
hash_ty: hash_ty,
273275
},
@@ -281,7 +283,7 @@ pub fn test_desc_satisfy(
281283
testdata.secretdata.sha256_pre.to_vec(),
282284
);
283285
psbt.inputs[0].hash256_preimages.insert(
284-
sha256d::Hash::from_inner(testdata.pubdata.hash256.into_inner()),
286+
sha256d::Hash::from_byte_array(testdata.pubdata.hash256.to_byte_array()),
285287
testdata.secretdata.hash256_pre.to_vec(),
286288
);
287289
psbt.inputs[0].hash160_preimages.insert(
@@ -309,7 +311,7 @@ pub fn test_desc_satisfy(
309311

310312
// Finally mine the blocks and await confirmations
311313
let _blocks = cl
312-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap())
314+
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
313315
.unwrap();
314316
// Get the required transactions from the node mined in the blocks.
315317
// Check whether the transaction is mined in blocks

0 commit comments

Comments
 (0)