Skip to content

Commit a700935

Browse files
tchardingsanket1729
authored andcommitted
update to bitcoin 0.30.0
1 parent 560e7b8 commit a700935

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

+837
-656
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+
internals = { package = "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+
internals = { package = "bitcoin-private", version = "0.1.0", default_features = false }

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 internals::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: 22 additions & 12 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::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;
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.
@@ -109,7 +115,7 @@ pub fn test_from_cpp_ms(cl: &Client, testdata: &TestData) {
109115
let mut psbt = Psbt {
110116
unsigned_tx: Transaction {
111117
version: 2,
112-
lock_time: LockTime::from_time(1_603_866_330)
118+
lock_time: absolute::LockTime::from_time(1_603_866_330)
113119
.expect("valid timestamp")
114120
.into(), // 10/28/2020 @ 6:25am (UTC)
115121
input: vec![],
@@ -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 & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ 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::Psbt;
14+
use bitcoin::sighash::SighashCache;
15+
use bitcoin::taproot::{LeafVersion, TapLeafHash};
1716
use bitcoin::{
18-
secp256k1, Amount, LockTime, OutPoint, SchnorrSig, Script, Sequence, Transaction, TxIn, TxOut,
19-
Txid,
17+
absolute, psbt, secp256k1, sighash, Amount, OutPoint, Sequence, Transaction, TxIn, TxOut, Txid,
2018
};
2119
use bitcoind::bitcoincore_rpc::{json, Client, RpcApi};
20+
use miniscript::bitcoin::{self, ecdsa, taproot, ScriptBuf};
2221
use miniscript::psbt::{PsbtExt, PsbtInputExt};
23-
use miniscript::{bitcoin, Descriptor, Miniscript, ScriptContext, ToPublicKey};
22+
use miniscript::{Descriptor, Miniscript, ScriptContext, ToPublicKey};
2423
mod setup;
2524

2625
use rand::RngCore;
@@ -31,7 +30,7 @@ fn btc<F: Into<f64>>(btc: F) -> Amount {
3130
}
3231

3332
// Find the Outpoint by spk
34-
fn get_vout(cl: &Client, txid: Txid, value: u64, spk: Script) -> (OutPoint, TxOut) {
33+
fn get_vout(cl: &Client, txid: Txid, value: u64, spk: ScriptBuf) -> (OutPoint, TxOut) {
3534
let tx = cl
3635
.get_transaction(&txid, None)
3736
.unwrap()
@@ -79,7 +78,7 @@ pub fn test_desc_satisfy(
7978
let x_only_pks = &testdata.pubdata.x_only_pks;
8079
// Generate some blocks
8180
let blocks = cl
82-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap())
81+
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
8382
.unwrap();
8483
assert_eq!(blocks.len(), 1);
8584

@@ -98,15 +97,15 @@ pub fn test_desc_satisfy(
9897
.unwrap();
9998
// Wait for the funds to mature.
10099
let blocks = cl
101-
.generate_to_address(2, &cl.get_new_address(None, None).unwrap())
100+
.generate_to_address(2, &cl.get_new_address(None, None).unwrap().assume_checked())
102101
.unwrap();
103102
assert_eq!(blocks.len(), 2);
104103
// Create a PSBT for each transaction.
105104
// Spend one input and spend one output for simplicity.
106105
let mut psbt = Psbt {
107106
unsigned_tx: Transaction {
108107
version: 2,
109-
lock_time: LockTime::from_time(1_603_866_330)
108+
lock_time: absolute::LockTime::from_time(1_603_866_330)
110109
.expect("valid timestamp")
111110
.into(), // 10/28/2020 @ 6:25am (UTC)
112111
input: vec![],
@@ -134,7 +133,8 @@ pub fn test_desc_satisfy(
134133
// and we can check it by gettransaction RPC.
135134
let addr = cl
136135
.get_new_address(None, Some(json::AddressType::Bech32))
137-
.unwrap();
136+
.unwrap()
137+
.assume_checked();
138138
// Had to decrease 'value', so that fees can be increased
139139
// (Was getting insufficient fees error, for deep script trees)
140140
psbt.unsigned_tx.output.push(TxOut {
@@ -158,7 +158,7 @@ pub fn test_desc_satisfy(
158158
match derived_desc {
159159
Descriptor::Tr(ref tr) => {
160160
// Fixme: take a parameter
161-
let hash_ty = sighash::SchnorrSighashType::Default;
161+
let hash_ty = sighash::TapSighashType::Default;
162162

163163
let internal_key_present = x_only_pks
164164
.iter()
@@ -180,7 +180,7 @@ pub fn test_desc_satisfy(
180180
rand::thread_rng().fill_bytes(&mut aux_rand);
181181
let schnorr_sig =
182182
secp.sign_schnorr_with_aux_rand(&msg, &internal_keypair, &aux_rand);
183-
psbt.inputs[0].tap_key_sig = Some(SchnorrSig {
183+
psbt.inputs[0].tap_key_sig = Some(taproot::Signature {
184184
sig: schnorr_sig,
185185
hash_ty: hash_ty,
186186
});
@@ -212,7 +212,7 @@ pub fn test_desc_satisfy(
212212
let (x_only_pk, _parity) = secp256k1::XOnlyPublicKey::from_keypair(&keypair);
213213
psbt.inputs[0].tap_script_sigs.insert(
214214
(x_only_pk, leaf_hash),
215-
bitcoin::SchnorrSig {
215+
taproot::Signature {
216216
sig,
217217
hash_ty: hash_ty,
218218
},
@@ -258,7 +258,7 @@ pub fn test_desc_satisfy(
258258
.to_secp_msg();
259259

260260
// Fixme: Take a parameter
261-
let hash_ty = bitcoin::EcdsaSighashType::All;
261+
let hash_ty = sighash::EcdsaSighashType::All;
262262

263263
// Finally construct the signature and add to psbt
264264
for sk in sks_reqd {
@@ -267,7 +267,7 @@ pub fn test_desc_satisfy(
267267
assert!(secp.verify_ecdsa(&msg, &sig, &pk.inner).is_ok());
268268
psbt.inputs[0].partial_sigs.insert(
269269
pk,
270-
bitcoin::EcdsaSig {
270+
ecdsa::Signature {
271271
sig,
272272
hash_ty: hash_ty,
273273
},
@@ -281,7 +281,7 @@ pub fn test_desc_satisfy(
281281
testdata.secretdata.sha256_pre.to_vec(),
282282
);
283283
psbt.inputs[0].hash256_preimages.insert(
284-
sha256d::Hash::from_inner(testdata.pubdata.hash256.into_inner()),
284+
sha256d::Hash::from_byte_array(testdata.pubdata.hash256.to_byte_array()),
285285
testdata.secretdata.hash256_pre.to_vec(),
286286
);
287287
psbt.inputs[0].hash160_preimages.insert(
@@ -309,7 +309,7 @@ pub fn test_desc_satisfy(
309309

310310
// Finally mine the blocks and await confirmations
311311
let _blocks = cl
312-
.generate_to_address(1, &cl.get_new_address(None, None).unwrap())
312+
.generate_to_address(1, &cl.get_new_address(None, None).unwrap().assume_checked())
313313
.unwrap();
314314
// Get the required transactions from the node mined in the blocks.
315315
// Check whether the transaction is mined in blocks

0 commit comments

Comments
 (0)