Skip to content

Commit ca305c8

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

Some content is hidden

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

41 files changed

+827
-648
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: 25 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,41 @@ 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(
311+
"sha256(H!)",
312+
&format!("sha256({})", rand_hash32.to_lower_hex_string()),
313+
);
314+
let ms = ms.replace(
315+
"hash256(H!)",
316+
&format!("hash256({})", rand_hash32.to_lower_hex_string()),
317+
);
311318
let ms = ms.replace(
312319
"ripemd160(H!)",
313-
&format!("ripemd160({})", rand_hash20.to_hex()),
320+
&format!("ripemd160({})", rand_hash20.to_lower_hex_string()),
321+
);
322+
let ms = ms.replace(
323+
"hash160(H!)",
324+
&format!("hash160({})", rand_hash20.to_lower_hex_string()),
314325
);
315-
let ms = ms.replace("hash160(H!)", &format!("hash160({})", rand_hash20.to_hex()));
316326
ms
317327
}

bitcoind-tests/tests/test_cpp.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use std::io::{self, BufRead};
1010
use std::path::Path;
1111

1212
use bitcoin::hashes::{sha256d, Hash};
13+
use bitcoin::psbt::PartiallySignedTransaction as Psbt;
1314
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};
15+
use bitcoin::{psbt, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid};
1716
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
17+
use miniscript::bitcoin::absolute::LockTime;
1818
use miniscript::psbt::PsbtExt;
1919
use miniscript::{bitcoin, Descriptor};
2020

@@ -76,7 +76,10 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
7676
let pks = &testdata.pubdata.pks;
7777
// Generate some blocks
7878
let blocks = cl
79-
.generate_to_address(500, &cl.get_new_address(None, None).unwrap())
79+
.generate_to_address(
80+
500,
81+
&cl.get_new_address(None, None).unwrap().assume_checked(),
82+
)
8083
.unwrap();
8184
assert_eq!(blocks.len(), 500);
8285

@@ -99,7 +102,10 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
99102
}
100103
// Wait for the funds to mature.
101104
let blocks = cl
102-
.generate_to_address(50, &cl.get_new_address(None, None).unwrap())
105+
.generate_to_address(
106+
50,
107+
&cl.get_new_address(None, None).unwrap().assume_checked(),
108+
)
103109
.unwrap();
104110
assert_eq!(blocks.len(), 50);
105111
// Create a PSBT for each transaction.
@@ -136,7 +142,8 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
136142
// and we can check it by gettransaction RPC.
137143
let addr = cl
138144
.get_new_address(None, Some(json::AddressType::Bech32))
139-
.unwrap();
145+
.unwrap()
146+
.assume_checked();
140147
psbt.unsigned_tx.output.push(TxOut {
141148
value: 99_999_000,
142149
script_pubkey: addr.script_pubkey(),
@@ -168,8 +175,8 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
168175
.collect();
169176
// Get the required sighash message
170177
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;
178+
let mut sighash_cache = bitcoin::sighash::SighashCache::new(&psbts[i].unsigned_tx);
179+
let sighash_ty = bitcoin::sighash::EcdsaSighashType::All;
173180
let sighash = sighash_cache
174181
.segwit_signature_hash(0, &ms.encode(), amt, sighash_ty)
175182
.unwrap();
@@ -184,7 +191,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
184191
let pk = pks[sks.iter().position(|&x| x == sk).unwrap()];
185192
psbts[i].inputs[0].partial_sigs.insert(
186193
pk,
187-
bitcoin::EcdsaSig {
194+
bitcoin::ecdsa::Signature {
188195
sig,
189196
hash_ty: sighash_ty,
190197
},
@@ -196,7 +203,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
196203
testdata.secretdata.sha256_pre.to_vec(),
197204
);
198205
psbts[i].inputs[0].hash256_preimages.insert(
199-
sha256d::Hash::from_inner(testdata.pubdata.hash256.into_inner()),
206+
sha256d::Hash::from_byte_array(testdata.pubdata.hash256.to_byte_array()),
200207
testdata.secretdata.hash256_pre.to_vec(),
201208
);
202209
println!("{}", ms);
@@ -227,7 +234,10 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
227234
}
228235
// Finally mine the blocks and await confirmations
229236
let _blocks = cl
230-
.generate_to_address(10, &cl.get_new_address(None, None).unwrap())
237+
.generate_to_address(
238+
10,
239+
&cl.get_new_address(None, None).unwrap().assume_checked(),
240+
)
231241
.unwrap();
232242
// Get the required transactions from the node mined in the blocks.
233243
for txid in spend_txids {

bitcoind-tests/tests/test_desc.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ use std::collections::BTreeMap;
88
use std::{error, fmt};
99

1010
use actual_rand as rand;
11+
use bitcoin::absolute::LockTime;
1112
use bitcoin::blockdata::witness::Witness;
1213
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};
14+
use bitcoin::psbt::PartiallySignedTransaction as Psbt;
15+
use bitcoin::sighash::SighashCache;
16+
use bitcoin::taproot::{LeafVersion, TapLeafHash};
1717
use bitcoin::{
18-
secp256k1, Amount, LockTime, OutPoint, SchnorrSig, Script, Sequence, Transaction, TxIn, TxOut,
19-
Txid,
18+
psbt, secp256k1, sighash, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
2019
};
2120
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
21+
use miniscript::bitcoin::{self, ScriptBuf};
2222
use miniscript::psbt::{PsbtExt, PsbtInputExt};
23-
use miniscript::{bitcoin, Descriptor, Miniscript, ScriptContext, ToPublicKey};
23+
use miniscript::{Descriptor, Miniscript, ScriptContext, ToPublicKey};
2424
mod setup;
2525

2626
use rand::RngCore;
@@ -31,7 +31,7 @@ fn btc<F: Into<f64>>(btc: F) -> Amount {
3131
}
3232

3333
// Find the Outpoint by spk
34-
fn get_vout(cl: &Client, txid: Txid, value: u64, spk: Script) -> (OutPoint, TxOut) {
34+
fn get_vout(cl: &Client, txid: Txid, value: u64, spk: ScriptBuf) -> (OutPoint, TxOut) {
3535
let tx = cl
3636
.get_transaction(&txid, None)
3737
.unwrap()
@@ -79,7 +79,7 @@ pub fn test_desc_satisfy(
7979
let x_only_pks = &testdata.pubdata.x_only_pks;
8080
// Generate some blocks
8181
let blocks = cl
82-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap())
82+
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
8383
.unwrap();
8484
assert_eq!(blocks.len(), 1);
8585

@@ -98,7 +98,7 @@ pub fn test_desc_satisfy(
9898
.unwrap();
9999
// Wait for the funds to mature.
100100
let blocks = cl
101-
.generate_to_address(2, &cl.get_new_address(None, None).unwrap())
101+
.generate_to_address(2, &cl.get_new_address(None, None).unwrap().assume_checked())
102102
.unwrap();
103103
assert_eq!(blocks.len(), 2);
104104
// Create a PSBT for each transaction.
@@ -134,7 +134,8 @@ pub fn test_desc_satisfy(
134134
// and we can check it by gettransaction RPC.
135135
let addr = cl
136136
.get_new_address(None, Some(json::AddressType::Bech32))
137-
.unwrap();
137+
.unwrap()
138+
.assume_checked();
138139
// Had to decrease 'value', so that fees can be increased
139140
// (Was getting insufficient fees error, for deep script trees)
140141
psbt.unsigned_tx.output.push(TxOut {
@@ -158,7 +159,7 @@ pub fn test_desc_satisfy(
158159
match derived_desc {
159160
Descriptor::Tr(ref tr) => {
160161
// Fixme: take a parameter
161-
let hash_ty = sighash::SchnorrSighashType::Default;
162+
let hash_ty = sighash::TapSighashType::Default;
162163

163164
let internal_key_present = x_only_pks
164165
.iter()
@@ -180,7 +181,7 @@ pub fn test_desc_satisfy(
180181
rand::thread_rng().fill_bytes(&mut aux_rand);
181182
let schnorr_sig =
182183
secp.sign_schnorr_with_aux_rand(&msg, &internal_keypair, &aux_rand);
183-
psbt.inputs[0].tap_key_sig = Some(SchnorrSig {
184+
psbt.inputs[0].tap_key_sig = Some(bitcoin::taproot::Signature {
184185
sig: schnorr_sig,
185186
hash_ty: hash_ty,
186187
});
@@ -212,7 +213,7 @@ pub fn test_desc_satisfy(
212213
let (x_only_pk, _parity) = secp256k1::XOnlyPublicKey::from_keypair(&keypair);
213214
psbt.inputs[0].tap_script_sigs.insert(
214215
(x_only_pk, leaf_hash),
215-
bitcoin::SchnorrSig {
216+
bitcoin::taproot::Signature {
216217
sig,
217218
hash_ty: hash_ty,
218219
},
@@ -258,7 +259,7 @@ pub fn test_desc_satisfy(
258259
.to_secp_msg();
259260

260261
// Fixme: Take a parameter
261-
let hash_ty = bitcoin::EcdsaSighashType::All;
262+
let hash_ty = bitcoin::sighash::EcdsaSighashType::All;
262263

263264
// Finally construct the signature and add to psbt
264265
for sk in sks_reqd {
@@ -267,7 +268,7 @@ pub fn test_desc_satisfy(
267268
assert!(secp.verify_ecdsa(&msg, &sig, &pk.inner).is_ok());
268269
psbt.inputs[0].partial_sigs.insert(
269270
pk,
270-
bitcoin::EcdsaSig {
271+
bitcoin::ecdsa::Signature {
271272
sig,
272273
hash_ty: hash_ty,
273274
},
@@ -281,7 +282,7 @@ pub fn test_desc_satisfy(
281282
testdata.secretdata.sha256_pre.to_vec(),
282283
);
283284
psbt.inputs[0].hash256_preimages.insert(
284-
sha256d::Hash::from_inner(testdata.pubdata.hash256.into_inner()),
285+
sha256d::Hash::from_byte_array(testdata.pubdata.hash256.to_byte_array()),
285286
testdata.secretdata.hash256_pre.to_vec(),
286287
);
287288
psbt.inputs[0].hash160_preimages.insert(
@@ -309,7 +310,7 @@ pub fn test_desc_satisfy(
309310

310311
// Finally mine the blocks and await confirmations
311312
let _blocks = cl
312-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap())
313+
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
313314
.unwrap();
314315
// Get the required transactions from the node mined in the blocks.
315316
// Check whether the transaction is mined in blocks

0 commit comments

Comments
 (0)