Skip to content

Commit

Permalink
hide util module and re-export its contents
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Dec 3, 2020
1 parent 2f4d915 commit 6f71797
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 27 deletions.
11 changes: 5 additions & 6 deletions examples/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use std::{env, process};
use std::str::FromStr;

use bitcoin::secp256k1::Secp256k1;
use bitcoin::util::key::PrivateKey;
use bitcoin::util::bip32::ExtendedPrivKey;
use bitcoin::util::bip32::ExtendedPubKey;
use bitcoin::util::bip32::DerivationPath;
use bitcoin::util::bip32::ChildNumber;
use bitcoin::util::address::Address;
use bitcoin::bip32::ExtendedPrivKey;
use bitcoin::bip32::ExtendedPubKey;
use bitcoin::bip32::DerivationPath;
use bitcoin::bip32::ChildNumber;
use bitcoin::{Address, PrivateKey};

fn main() {
// This example derives root xprv
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/deserialize_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate bitcoin;
use std::str::FromStr;
fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data);
let addr = match bitcoin::util::address::Address::from_str(&data_str) {
let addr = match bitcoin::address::Address::from_str(&data_str) {
Ok(addr) => addr,
Err(_) => return,
};
Expand Down
8 changes: 4 additions & 4 deletions fuzz/fuzz_targets/deserialize_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data);

// signed
let samt = match bitcoin::util::amount::SignedAmount::from_str(&data_str) {
let samt = match bitcoin::amount::SignedAmount::from_str(&data_str) {
Ok(amt) => amt,
Err(_) => return,
};
let samt_roundtrip = match bitcoin::util::amount::SignedAmount::from_str(&samt.to_string()) {
let samt_roundtrip = match bitcoin::amount::SignedAmount::from_str(&samt.to_string()) {
Ok(amt) => amt,
Err(_) => return,
};
assert_eq!(samt, samt_roundtrip);

// unsigned
let amt = match bitcoin::util::amount::Amount::from_str(&data_str) {
let amt = match bitcoin::amount::Amount::from_str(&data_str) {
Ok(amt) => amt,
Err(_) => return,
};
let amt_roundtrip = match bitcoin::util::amount::Amount::from_str(&amt.to_string()) {
let amt_roundtrip = match bitcoin::amount::Amount::from_str(&amt.to_string()) {
Ok(amt) => amt,
Err(_) => return,
};
Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/deserialize_psbt.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate bitcoin;

fn do_test(data: &[u8]) {
let psbt: Result<bitcoin::util::psbt::PartiallySignedTransaction, _> = bitcoin::consensus::encode::deserialize(data);
let psbt: Result<bitcoin::psbt::PartiallySignedTransaction, _> = bitcoin::consensus::encode::deserialize(data);
match psbt {
Err(_) => {},
Ok(psbt) => {
let ser = bitcoin::consensus::encode::serialize(&psbt);
let deser: bitcoin::util::psbt::PartiallySignedTransaction = bitcoin::consensus::encode::deserialize(&ser).unwrap();
let deser: bitcoin::psbt::PartiallySignedTransaction = bitcoin::consensus::encode::deserialize(&ser).unwrap();
// Since the fuzz data could order psbt fields differently, we compare to our deser/ser instead of data
assert_eq!(ser, bitcoin::consensus::encode::serialize(&deser));
}
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/uint128_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ fn do_test(data: &[u8]) {
native |= (*c) as u128;
}
// Note BE:
let uint128 = bitcoin::util::uint::Uint128::from(&[native as u64, (native >> 8*8) as u64][..]);
let uint128 = bitcoin::uint::Uint128::from(&[native as u64, (native >> 8*8) as u64][..]);

// Checking two conversion methods against each other
let mut slice = [0u8; 16];
slice.copy_from_slice(&data[$start..$start + 16]);
assert_eq!(uint128, bitcoin::util::uint::Uint128::from_be_bytes(slice));
assert_eq!(uint128, bitcoin::uint::Uint128::from_be_bytes(slice));

(native, uint128)
} }
Expand All @@ -36,7 +36,7 @@ fn do_test(data: &[u8]) {
assert_eq!(a_native as u64, a.low_u64());
assert_eq!(a_native as u32, a.low_u32());
assert_eq!(128 - a_native.leading_zeros() as usize, a.bits());
assert_eq!(a_native as u64, bitcoin::util::uint::Uint128::from_u64(a_native as u64).unwrap().low_u64());
assert_eq!(a_native as u64, bitcoin::uint::Uint128::from_u64(a_native as u64).unwrap().low_u64());

// Checks with two numbers:
let (b_native, b) = read_ints!(16);
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ mod internal_macros;
#[macro_use]
pub mod network;
pub mod primitives;
mod util;
pub mod script;
pub mod util;
pub mod consensus;
pub mod hash_types;
mod hash_types;

pub use hash_types::*;
pub use primitives::block::Block;
Expand All @@ -88,6 +88,10 @@ pub use util::key::PrivateKey;
pub use util::key::PublicKey;
pub use util::merkleblock::MerkleBlock;

pub use util::{address, amount, base58, bip32, bip143, hash, key, merkleblock, misc, psbt, uint, bip158};
#[allow(deprecated)]
pub use util::contracthash;

#[cfg(all(test, feature = "unstable"))] use tests::EmptyWrite;

#[cfg(all(test, feature = "unstable"))]
Expand Down
2 changes: 1 addition & 1 deletion src/util/bip143.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<R: DerefMut<Target=Transaction>> SigHashCache<R> {
/// This allows in-line signing such as
/// ```
/// use bitcoin::primitives::transaction::{Transaction, SigHashType};
/// use bitcoin::util::bip143::SigHashCache;
/// use bitcoin::bip143::SigHashCache;
/// use bitcoin::Script;
///
/// let mut tx_to_sign = Transaction { version: 2, lock_time: 0, input: Vec::new(), output: Vec::new() };
Expand Down
2 changes: 1 addition & 1 deletion src/util/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl DerivationPath {
/// Concatenate `self` with `path` and return the resulting new path.
///
/// ```
/// use bitcoin::util::bip32::{DerivationPath, ChildNumber};
/// use bitcoin::bip32::{DerivationPath, ChildNumber};
/// use std::str::FromStr;
///
/// let base = DerivationPath::from_str("m/42").unwrap();
Expand Down
10 changes: 4 additions & 6 deletions src/util/merkleblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
//! # Examples
//!
//! ```rust
//! use bitcoin::hash_types::Txid;
//! use bitcoin::hashes::hex::FromHex;
//! use bitcoin::{Block, MerkleBlock};
//! use bitcoin::{Block, MerkleBlock, Txid};
//!
//! // Get the proof from a bitcoind by running in the terminal:
//! // $ TXID="5a4ebf66822b0b2d56bd9dc64ece0bc38ee7844a23ff1d7320a88c5fdb2ad3e2"
Expand Down Expand Up @@ -129,9 +128,9 @@ impl PartialMerkleTree {
/// # Examples
///
/// ```rust
/// use bitcoin::hash_types::Txid;
/// use bitcoin::Txid;
/// use bitcoin::hashes::hex::FromHex;
/// use bitcoin::util::merkleblock::PartialMerkleTree;
/// use bitcoin::merkleblock::PartialMerkleTree;
///
/// // Block 80000
/// let txids: Vec<Txid> = [
Expand Down Expand Up @@ -400,9 +399,8 @@ impl MerkleBlock {
/// # Examples
///
/// ```rust
/// use bitcoin::hash_types::Txid;
/// use bitcoin::hashes::hex::FromHex;
/// use bitcoin::{Block, MerkleBlock};
/// use bitcoin::{Block, MerkleBlock, Txid};
///
/// // Block 80000
/// let block_bytes = Vec::from_hex("01000000ba8b9cda965dd8e536670f9ddec10e53aab14b20bacad2\
Expand Down
2 changes: 1 addition & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod psbt;
pub mod uint;
pub mod bip158;

pub(crate) mod endian;
pub mod endian;

/// A trait which allows numbers to act as fixed-size bit arrays
pub trait BitArray {
Expand Down

0 comments on commit 6f71797

Please sign in to comment.