8000 Move `merkleblock` into `merkle_tree` by tcharding · Pull Request #1374 · rust-bitcoin/rust-bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move merkleblock into merkle_tree #1374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub use crate::pow::{CompactTarget, Target, Work};
pub use crate::amount::{Amount, Denomination, SignedAmount};
pub use crate::util::ecdsa::{self, EcdsaSig, EcdsaSigError};
pub use crate::util::key::{KeyPair, PrivateKey, PublicKey, XOnlyPublicKey};
pub use crate::util::merkleblock::MerkleBlock;
pub use crate::merkle_tree::MerkleBlock;
pub use crate::util::schnorr::{self, SchnorrSig, SchnorrSigError};
pub use crate::util::{psbt, Error};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::blockdata::block::{self, Block};
use crate::blockdata::transaction::Transaction;
use crate::blockdata::constants::{MAX_BLOCK_WEIGHT, MIN_TRANSACTION_WEIGHT};
use crate::consensus::encode::{self, Decodable, Encodable};
use crate::util::merkleblock::MerkleBlockError::*;
use crate::merkle_tree::MerkleBlockError::*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WTF, this should've been self.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah! the number of times I changed this to self in the last few weeks. Eventually I tried to make the diff as unsurprising with minimal changes as possible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My rule of thumb is to never use absolute path that starts with the equivalent of self. If this was self from the beginning this diff line wouldn't be here now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll make that my own policy as well, cheers.


/// An error when verifying the merkle block.
#[derive(Clone, PartialEq, Eq, Debug)]
Expand Down Expand Up @@ -164,7 +164,7 @@ impl PartialMerkleTree {
/// ```rust
/// use bitcoin::hash_types::Txid;
/// use bitcoin::hashes::hex::FromHex;
/// use bitcoin::util::merkleblock::PartialMerkleTree;
/// use bitcoin::merkle_tree::{MerkleBlock, PartialMerkleTree};
///
/// // Block 80000
/// let txids: Vec<Txid> = [
Expand Down Expand Up @@ -520,6 +520,8 @@ impl Decodable for MerkleBlock {

#[cfg(test)]
mod tests {
use super::*;

use core::cmp::min;

use crate::hashes::Hash;
Expand All @@ -528,7 +530,6 @@ mod tests {
use secp256k1::rand::prelude::*;

use crate::consensus::encode::{deserialize, serialize};
use crate::util::merkleblock::{MerkleBlock, PartialMerkleTree};
use crate::{merkle_tree, Block};

/// accepts `pmt_test_$num`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//! let root = merkle_tree::calculate_root(tx_hashes.into_iter());
//! ```

mod block;

use core::iter;

use crate::prelude::*;
Expand All @@ -24,6 +26,8 @@ use core::cmp::min;
use crate::hashes::Hash;
use crate::consensus::encode::Encodable;

pub use block::{MerkleBlock, PartialMerkleTree, MerkleBlockError};

/// Calculates the merkle root of a list of *hashes*, inline (in place) in `hashes`.
///
/// In most cases, you'll want to use [`calculate_root`] instead. Please note, calling this function
Expand Down Expand Up @@ -117,7 +121,7 @@ mod tests {
#[test]
fn both_merkle_root_functions_return_the_same_result() {
// testnet block 000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b
let segwit_block = include_bytes!("../tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw");
let segwit_block = include_bytes!("../../tests/data/testnet_block_000000000000045e0b1660b6445b5e5c5ab63c9a4f956be7e1e69be04fa4497b.raw");
let block: Block = deserialize(&segwit_block[..]).expect("Failed to deserialize block");
assert!(block.check_merkle_root()); // Sanity check.

Expand Down
5 changes: 3 additions & 2 deletions bitcoin/src/network/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::network::message_compact_blocks;
use crate::network::constants::Magic;
use crate::consensus::encode::{CheckedData, Decodable, Encodable, VarInt};
use crate::consensus::{encode, serialize};
use crate::util::merkleblock::MerkleBlock;
use crate::merkle_tree::MerkleBlock;

/// The maximum number of [super::message_blockdata::Inventory] items in an `inv` message.
///
Expand Down Expand Up @@ -469,6 +469,8 @@ impl Decodable for RawNetworkMessage {

#[cfg(test)]
mod test {
use super::*;

use std::net::Ipv4Addr;
use super::{RawNetworkMessage, NetworkMessage, CommandString};
use crate::network::constants::{ServiceFlags, Magic, Network};
Expand All @@ -484,7 +486,6 @@ mod test {
use crate::blockdata::transaction::Transaction;
use crate::blockdata::script::Script;
use crate::network::message_bloom::{FilterAdd, FilterLoad, BloomFlags};
use crate::MerkleBlock;
use crate::network::message_compact_blocks::{GetBlockTxn, SendCmpct};
use crate::bip152::BlockTransactionsRequest;

Expand Down
1 change: 0 additions & 1 deletion bitcoin/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod key;
pub mod ecdsa;
pub mod schnorr;
pub mod base58;
pub mod merkleblock;
pub mod psbt;
pub mod taproot;

Expand Down
0