Skip to content

Commit

Permalink
Merge #36: upgrading to match bdk v29
Browse files Browse the repository at this point in the history
3295228 upgrading to match bdk v29 CI fix for MSRV 1.63 (Richard Ulrich)

Pull request description:

ACKs for top commit:
  notmandatory:
    ACK 3295228

Tree-SHA512: ea3999530691ec823e100a395db40cd4ab2b40480a609b7a9d4c6c8d2dcd955a7f0efa234d2864b33933cec4a4dcf8c8a5e48b4adff19a1cae433f56b65cdbd4
  • Loading branch information
notmandatory committed Aug 24, 2024
2 parents 170d0de + 3295228 commit 62ddcb1
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
if: matrix.rust == '1.63.0'
run: |
cargo update -p home:0.5.9 --precise 0.5.5
cargo update -p tokio:1.39.3 --precise 1.38.1
cargo update -p cc --precise 1.0.105
- name: Build
run: cargo build
- name: Clippy
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bdk-reserves"
version = "0.28.1"
version = "0.29.0"
authors = ["Richard Ulrich <[email protected]>"]
edition = "2018"
description = "Proof of reserves for bitcoin dev kit"
Expand All @@ -10,12 +10,12 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/bitcoindevkit/bdk-reserves"

[dependencies]
bdk = { version = "0.28", default-features = false }
bdk = { version = "0.29", default-features = false, features = ["std"] }
bitcoinconsensus = "0.19.0-3"
log = "^0.4"

[dev-dependencies]
rstest = "^0.11"
bdk-testutils = "^0.4"
bdk = { version = "0.28", default-features = true }
electrsd = { version = "0.23", features = ["bitcoind_22_0", "electrs_0_9_1"] }
bdk = { version = "0.29", default-features = true }
electrsd = { version = "0.24", features = ["bitcoind_22_0", "electrs_0_9_1"] }
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ test_63: builder_63
rm -f Cargo.lock
$(DOCKER_RUN) ${TAG_63} cargo test || true
$(DOCKER_RUN) ${TAG_63} cargo update -p home:0.5.9 --precise 0.5.5 || true
$(DOCKER_RUN) ${TAG_63} cargo update -p tokio:1.39.3 --precise 1.38.1 || true
$(DOCKER_RUN) ${TAG_63} cargo update -p cc --precise 1.0.105 || true
$(DOCKER_RUN) ${TAG_63} cargo test

run: builder
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ To build with the MSRV you will need to pin the below dependencies:

```shell
cargo update -p home:0.5.9 --precise 0.5.5
cargo update -p tokio:1.39.3 --precise 1.38.1
cargo update -p cc --precise 1.0.105
```

## Contribution
Expand Down
25 changes: 13 additions & 12 deletions src/reserves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
//! https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
use bdk::bitcoin::blockdata::opcodes;
use bdk::bitcoin::blockdata::script::{Builder, Script};
use bdk::bitcoin::blockdata::transaction::{EcdsaSighashType, OutPoint, TxIn, TxOut};
use bdk::bitcoin::blockdata::script::{Builder, Script, ScriptBuf};
use bdk::bitcoin::blockdata::transaction::{OutPoint, TxIn, TxOut};
use bdk::bitcoin::consensus::encode::serialize;
use bdk::bitcoin::hash_types::{PubkeyHash, Txid};
use bdk::bitcoin::hashes::{hash160, sha256d, Hash};
use bdk::bitcoin::util::psbt::{Input, PartiallySignedTransaction as PSBT};
use bdk::bitcoin::psbt::{Input, PartiallySignedTransaction as PSBT};
use bdk::bitcoin::sighash::EcdsaSighashType;
use bdk::bitcoin::{Network, Sequence};
use bdk::database::BatchDatabase;
use bdk::wallet::tx_builder::TxOrdering;
Expand Down Expand Up @@ -113,12 +114,12 @@ where
value: 0,
script_pubkey: Builder::new().push_opcode(opcodes::OP_TRUE).into_script(),
}),
final_script_sig: Some(Script::default()), /* "finalize" the input with an empty scriptSig */
final_script_sig: Some(Script::empty().into()), /* "finalize" the input with an empty scriptSig */
..Default::default()
};

let pkh = PubkeyHash::from_hash(hash160::Hash::hash(&[0]));
let out_script_unspendable = Script::new_p2pkh(&pkh);
let pkh = PubkeyHash::from_raw_hash(hash160::Hash::hash(&[0]));
let out_script_unspendable = ScriptBuf::new_p2pkh(&pkh);

let mut builder = self.build_tx();
builder
Expand Down Expand Up @@ -252,8 +253,8 @@ pub fn verify_proof(
}

// verify the unspendable output
let pkh = PubkeyHash::from_hash(hash160::Hash::hash(&[0]));
let out_script_unspendable = Script::new_p2pkh(&pkh);
let pkh = PubkeyHash::from_raw_hash(hash160::Hash::hash(&[0]));
let out_script_unspendable = ScriptBuf::new_p2pkh(&pkh);

if tx.output[0].script_pubkey != out_script_unspendable {
return Err(ProofError::InvalidOutput);
Expand Down Expand Up @@ -303,7 +304,7 @@ fn challenge_txin(message: &str) -> TxIn {
let message = "Proof-of-Reserves: ".to_string() + message;
let message = sha256d::Hash::hash(message.as_bytes());
TxIn {
previous_output: OutPoint::new(Txid::from_hash(message), 0),
previous_output: OutPoint::new(Txid::from_raw_hash(message), 0),
sequence: Sequence(0xFFFFFFFF),
..Default::default()
}
Expand All @@ -313,7 +314,7 @@ fn challenge_txin(message: &str) -> TxIn {
mod test {
use super::*;
use bdk::bitcoin::secp256k1::ecdsa::{SerializedSignature, Signature};
use bdk::bitcoin::{EcdsaSighashType, Network, Witness};
use bdk::bitcoin::{Network, Witness};
use bdk::wallet::get_funded_wallet;
use std::str::FromStr;

Expand Down Expand Up @@ -506,8 +507,8 @@ mod test {
let message = "This belongs to me.";
let mut psbt = get_signed_proof();

let pkh = PubkeyHash::from_hash(hash160::Hash::hash(&[0, 1, 2, 3]));
let out_script_unspendable = Script::new_p2pkh(&pkh);
let pkh = PubkeyHash::from_raw_hash(hash160::Hash::hash(&[0, 1, 2, 3]));
let out_script_unspendable = ScriptBuf::new_p2pkh(&pkh);
psbt.unsigned_tx.output[0].script_pubkey = out_script_unspendable;

wallet.verify_proof(&psbt, message, None).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion tests/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ fn unconfirmed() -> Result<(), ProofError> {

let spendable = wallet.verify_proof(&psbt, message, None)?;
dbg!(&new_balance);
assert_eq!(
assert!(
spendable <= new_balance.untrusted_pending + new_balance.confirmed,
"spendable ({}) <= new_balance.untrusted_pending + new_balance.confirmed ({})",
spendable,
new_balance.untrusted_pending + new_balance.confirmed
);
Expand Down
15 changes: 10 additions & 5 deletions tests/multi_sig.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod regtestenv;
use bdk::bitcoin::key::{PrivateKey, PublicKey};
use bdk::bitcoin::psbt::PartiallySignedTransaction as PSBT;
use bdk::bitcoin::secp256k1::Secp256k1;
use bdk::bitcoin::util::key::{PrivateKey, PublicKey};
use bdk::bitcoin::util::psbt::PartiallySignedTransaction as PSBT;
use bdk::bitcoin::Network;
use bdk::database::memory::MemoryDatabase;
use bdk::wallet::{AddressIndex, Wallet};
Expand Down Expand Up @@ -98,8 +98,8 @@ fn test_proof_multisig(
wallets.iter().enumerate().for_each(|(i, wallet)| {
let balance = wallet.get_balance().unwrap();
assert!(
(4_999_999_256..=4_999_999_596).contains(&balance.confirmed),
"balance of wallet {} is {} but should be between 4'999'999'256 and 4'999'999'596",
(49_999_999_256..=49_999_999_596).contains(&balance.confirmed),
"balance of wallet {} is {} but should be between 49_999_999_256 and 49_999_999_596",
i,
balance
);
Expand Down Expand Up @@ -158,7 +158,12 @@ fn test_proof_multisig(

let spendable = wallets[0].verify_proof(&psbt, message, None)?;
let balance = wallets[0].get_balance()?;
assert_eq!(spendable, balance.confirmed);
assert!(
spendable <= balance.confirmed,
"spendable ({}) <= balance.confirmed ({})",
spendable,
balance.confirmed,
);

Ok(())
}
16 changes: 11 additions & 5 deletions tests/regtestenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use bdk::database::memory::MemoryDatabase;
use bdk::electrum_client::Client;
use bdk::wallet::{AddressIndex, SyncOptions, Wallet};
use bdk::SignOptions;
use electrsd::bitcoind::bitcoincore_rpc::{bitcoin::Address, RpcApi};
use electrsd::bitcoind::bitcoincore_rpc::{
bitcoin::{network::constants::Network, Address},
RpcApi,
};
use electrsd::bitcoind::BitcoinD;
use electrsd::electrum_client::ElectrumApi;
use electrsd::ElectrsD;
Expand Down Expand Up @@ -47,7 +50,10 @@ impl RegTestEnv {
let addr2 = wallets[0].get_address(AddressIndex::Peek(1)).unwrap();
let addr1 = wallets[0].get_address(AddressIndex::Peek(0)).unwrap();
const MY_FOREIGN_ADDR: &str = "mpSFfNURcFTz2yJxBzRY9NhnozxeJ2AUC8";
let foreign_addr = Address::from_str(MY_FOREIGN_ADDR).unwrap();
let foreign_addr = Address::from_str(MY_FOREIGN_ADDR)
.unwrap()
.require_network(Network::Testnet)
.unwrap();

// generate to the first receiving address of the test wallet
self.generate_to_address(10, &addr2.address);
Expand All @@ -60,16 +66,16 @@ impl RegTestEnv {
wallet.sync(&blockchain, SyncOptions::default()).unwrap();
let balance = wallet.get_balance().unwrap();
assert!(
balance.confirmed == 5_000_000_000,
"balance of wallet {} is {} but should be 5'000'000'000",
balance.confirmed == 50_000_000_000,
"balance of wallet {} is {} but should be 50_000_000_000",
i,
balance
);
});

let mut builder = wallets[0].build_tx();
builder
.add_recipient(addr1.script_pubkey(), 1_000_000)
.add_recipient(addr1.address.script_pubkey(), 1_000_000)
.fee_rate(bdk::FeeRate::from_sat_per_vb(2.0));
let (mut psbt, _) = builder.finish().unwrap();
let signopts = SignOptions {
Expand Down
2 changes: 1 addition & 1 deletion tests/tampering.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bdk::bitcoin::blockdata::transaction::EcdsaSighashType;
use bdk::bitcoin::sighash::EcdsaSighashType;
use bdk::wallet::get_funded_wallet;
use bdk::SignOptions;
use bdk_reserves::reserves::*;
Expand Down

0 comments on commit 62ddcb1

Please sign in to comment.