Skip to content
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

Re-factor/re-name blockdata #1296

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions bitcoin/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ use bech32;
use bitcoin_internals::write_err;
use secp256k1::{Secp256k1, Verification, XOnlyPublicKey};

use crate::blockdata::constants::{
MAX_SCRIPT_ELEMENT_SIZE, PUBKEY_ADDRESS_PREFIX_MAIN, PUBKEY_ADDRESS_PREFIX_TEST,
SCRIPT_ADDRESS_PREFIX_MAIN, SCRIPT_ADDRESS_PREFIX_TEST,
};
use crate::blockdata::script::Instruction;
use crate::blockdata::{opcodes, script};
use crate::error::ParseIntError;
use crate::hash_types::{PubkeyHash, ScriptHash};
use crate::hashes::{sha256, Hash, HashEngine};
use crate::internal_macros::serde_string_impl;
use crate::network::constants::Network;
use crate::prelude::*;
use crate::primitives::{
MAX_SCRIPT_ELEMENT_SIZE, PUBKEY_ADDRESS_PREFIX_MAIN, PUBKEY_ADDRESS_PREFIX_TEST,
SCRIPT_ADDRESS_PREFIX_MAIN, SCRIPT_ADDRESS_PREFIX_TEST,
};
use crate::script::{self, opcodes, Instruction};
use crate::util::base58;
use crate::util::key::PublicKey;
use crate::util::schnorr::{TapTweak, TweakedPublicKey, UntweakedPublicKey};
Expand Down
6 changes: 3 additions & 3 deletions bitcoin/src/bip158.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ use core::fmt::{self, Display, Formatter};

use bitcoin_internals::write_err;

use crate::blockdata::block::Block;
use crate::blockdata::script::Script;
use crate::blockdata::transaction::OutPoint;
use crate::consensus::encode::VarInt;
use crate::consensus::{Decodable, Encodable};
use crate::hash_types::{BlockHash, FilterHash, FilterHeader};
use crate::hashes::{siphash24, Hash};
use crate::io;
use crate::prelude::*;
use crate::primitives::block::Block;
use crate::primitives::transaction::OutPoint;
use crate::script::Script;
use crate::util::endian;

/// Golomb encoding parameter as in BIP-158, see also https://gist.github.com/sipa/576d5f09c3b86c3b1b75598d799fc845
Expand Down
16 changes: 0 additions & 16 deletions bitcoin/src/blockdata/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion bitcoin/src/consensus/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::util::bip152::{ShortId, PrefilledTransaction};
use crate::util::taproot::TapLeafHash;
use crate::hashes::hex::ToHex;

use crate::blockdata::transaction::{TxOut, Transaction, TxIn};
use crate::primitives::transaction::{TxOut, Transaction, TxIn};
#[cfg(feature = "std")]
use crate::network::{message_blockdata::Inventory, address::{Address, AddrV2Message}};

Expand Down
14 changes: 7 additions & 7 deletions bitcoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ pub mod network;
pub mod address;
pub mod bip158;
pub mod bip32;
pub mod blockdata;
pub mod consensus;
pub mod error;
pub mod hash_types;
pub mod policy;
pub mod primitives;
pub mod script;
pub mod sign_message;
pub mod util;

Expand All @@ -97,15 +98,14 @@ use std::io;
use core2::io;

pub use crate::address::{Address, AddressType};
pub use crate::blockdata::block::{self, Block, BlockHeader, BlockVersion};
pub use crate::blockdata::locktime::{self, absolute, relative};
pub use crate::blockdata::script::{self, Script};
pub use crate::blockdata::transaction::{self, OutPoint, Sequence, Transaction, TxIn, TxOut};
pub use crate::blockdata::witness::{self, Witness};
pub use crate::blockdata::{constants, opcodes};
pub use crate::consensus::encode::VarInt;
pub use crate::hash_types::*;
pub use crate::network::constants::Network;
pub use crate::primitives::block::{self, Block, BlockHeader, BlockVersion};
pub use crate::primitives::locktime::{self, absolute, relative};
pub use crate::primitives::transaction::{self, OutPoint, Sequence, Transaction, TxIn, TxOut};
pub use crate::primitives::witness::{self, Witness};
pub use crate::script::{opcodes, Script};
pub use crate::util::amount::{Amount, Denomination, SignedAmount};
pub use crate::util::ecdsa::{self, EcdsaSig, EcdsaSigError};
pub use crate::util::key::{KeyPair, PrivateKey, PublicKey, XOnlyPublicKey};
Expand Down
10 changes: 5 additions & 5 deletions bitcoin/src/network/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use core::convert::TryFrom;

use crate::io;
use io::Read as _;
use crate::blockdata::block;
use crate::blockdata::transaction;
use crate::primitives::block;
use crate::primitives::transaction;
use crate::network::address::{Address, AddrV2Message};
use crate::network::{message_network, message_bloom};
use crate::network::message_blockdata;
Expand Down Expand Up @@ -479,10 +479,10 @@ mod test {
use crate::network::address::{Address, AddrV2, AddrV2Message};
use super::message_network::{Reject, RejectReason, VersionMessage};
use crate::network::message_blockdata::{Inventory, GetBlocksMessage, GetHeadersMessage};
use crate::blockdata::block::{Block, BlockHeader};
use crate::primitives::block::{Block, BlockHeader};
use crate::network::message_filter::{GetCFilters, CFilter, GetCFHeaders, CFHeaders, GetCFCheckpt, CFCheckpt};
use crate::blockdata::transaction::Transaction;
use crate::blockdata::script::Script;
use crate::primitives::transaction::Transaction;
use crate::script::Script;
use crate::network::message_bloom::{FilterAdd, FilterLoad, BloomFlags};
use crate::MerkleBlock;
use crate::network::message_compact_blocks::{GetBlockTxn, SendCmpct};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use core::cmp;

use super::blockdata::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};
use super::primitives::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};

/// Maximum weight of a transaction for it to be relayed by most nodes on the network
pub const MAX_STANDARD_TX_WEIGHT: u32 = 400_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ use crate::hash_types::{Wtxid, BlockHash, TxMerkleNode, WitnessMerkleNode, Witne
use crate::util::uint::Uint256;
use crate::consensus::{encode, Encodable, Decodable};
use crate::network::constants::Network;
use crate::blockdata::transaction::Transaction;
use crate::blockdata::constants::{max_target, WITNESS_SCALE_FACTOR};
use crate::blockdata::script;
use crate::primitives::transaction::Transaction;
use crate::primitives::{max_target, WITNESS_SCALE_FACTOR};
use crate::script;
use crate::VarInt;
use crate::internal_macros::impl_consensus_encoding;
use crate::io;
Expand Down Expand Up @@ -453,7 +453,7 @@ impl From<&Block> for BlockHash {
mod tests {
use crate::hashes::hex::FromHex;

use crate::blockdata::block::{Block, BlockHeader, BlockVersion};
use crate::primitives::block::{Block, BlockHeader, BlockVersion};
use crate::consensus::encode::{deserialize, serialize};
use crate::util::uint::Uint256;
use crate::util::Error::{BlockBadTarget, BlockBadProofOfWork};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// Written in 2014 by Andrew Poelstra <apoelstra@wpsoftware.net>
// SPDX-License-Identifier: CC0-1.0

//! Blockdata constants.
//! Bitcoin block data.
//!
//! This module provides various constants relating to the blockchain and
//! consensus code. In particular, it defines the genesis block and its
//! single transaction.
//! This module defines structures and functions for storing the blocks and
//! transactions which make up the Bitcoin system.
//!

pub mod locktime;
pub mod transaction;
pub mod block;
pub mod witness;
use crate::prelude::*;

use core::default::Default;

use crate::hashes::hex::{self, HexIterator};
use crate::hashes::{Hash, sha256d};
use crate::blockdata::opcodes;
use crate::blockdata::script;
use crate::blockdata::locktime::absolute;
use crate::blockdata::transaction::{OutPoint, Transaction, TxOut, TxIn, Sequence};
use crate::blockdata::block::{Block, BlockHeader, BlockVersion};
use crate::blockdata::witness::Witness;
use crate::script::{self, opcodes};
use crate::primitives::locktime::absolute;
use crate::primitives::transaction::{OutPoint, Transaction, TxOut, TxIn, Sequence};
use crate::primitives::block::{Block, BlockHeader, BlockVersion};
use crate::primitives::witness::Witness;
use crate::network::constants::Network;
use crate::util::uint::Uint256;
use crate::internal_macros::{impl_array_newtype, impl_bytes_newtype};
Expand Down Expand Up @@ -200,7 +202,7 @@ mod test {
use crate::hashes::hex::{ToHex, FromHex};
use crate::network::constants::Network;
use crate::consensus::encode::serialize;
use crate::blockdata::locktime::absolute;
use crate::primitives::locktime::absolute;

#[test]
fn bitcoin_genesis_first_transaction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ use bitcoin_internals::write_err;
use crate::hashes::{self, Hash, sha256d};
use crate::hashes::hex::FromHex;

use crate::blockdata::constants::WITNESS_SCALE_FACTOR;
#[cfg(feature="bitcoinconsensus")] use crate::blockdata::script;
use crate::blockdata::script::Script;
use crate::blockdata::witness::Witness;
use crate::blockdata::locktime::absolute::{self, Height, Time};
use crate::blockdata::locktime::relative;
use crate::primitives::WITNESS_SCALE_FACTOR;
#[cfg(feature="bitcoinconsensus")] use crate::script;
use crate::script::Script;
use crate::primitives::witness::Witness;
use crate::primitives::locktime::absolute::{self, Height, Time};
use crate::primitives::locktime::relative;
use crate::consensus::{encode, Decodable, Encodable};
use crate::hash_types::{Sighash, Txid, Wtxid};
use crate::VarInt;
Expand Down Expand Up @@ -75,7 +75,7 @@ impl OutPoint {
/// # Examples
///
/// ```rust
/// use bitcoin::constants::genesis_block;
/// use bitcoin::primitives::genesis_block;
/// use bitcoin::network::constants::Network;
///
/// let block = genesis_block(Network::Bitcoin);
Expand Down Expand Up @@ -1020,9 +1020,9 @@ mod tests {

use core::str::FromStr;

use crate::blockdata::constants::WITNESS_SCALE_FACTOR;
use crate::blockdata::script::Script;
use crate::blockdata::locktime::absolute;
use crate::primitives::WITNESS_SCALE_FACTOR;
use crate::script::Script;
use crate::primitives::locktime::absolute;
use crate::consensus::encode::serialize;
use crate::consensus::encode::deserialize;
use crate::sighash::EcdsaSighashType;
Expand Down Expand Up @@ -1096,9 +1096,9 @@ mod tests {
#[test]
fn test_is_coinbase () {
use crate::network::constants::Network;
use crate::blockdata::constants;
use crate::primitives;

let genesis = constants::genesis_block(Network::Bitcoin);
let genesis = primitives::genesis_block(Network::Bitcoin);
assert! (genesis.txdata[0].is_coin_base());
let tx_bytes = Vec::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
let tx: Transaction = deserialize(&tx_bytes).unwrap();
Expand Down Expand Up @@ -1337,8 +1337,8 @@ mod tests {
fn test_transaction_verify () {
use std::collections::HashMap;
use crate::hashes::hex::FromHex;
use crate::blockdata::script;
use crate::blockdata::witness::Witness;
use crate::script;
use crate::primitives::witness::Witness;

// a random recent segwit transaction from blockchain using both old and segwit inputs
let mut spending: Transaction = deserialize(Vec::from_hex("020000000001031cfbc8f54fbfa4a33a30068841371f80dbfe166211242213188428f437445c91000000006a47304402206fbcec8d2d2e740d824d3d36cc345b37d9f65d665a99f5bd5c9e8d42270a03a8022013959632492332200c2908459547bf8dbf97c65ab1a28dec377d6f1d41d3d63e012103d7279dfb90ce17fe139ba60a7c41ddf605b25e1c07a4ddcb9dfef4e7d6710f48feffffff476222484f5e35b3f0e43f65fc76e21d8be7818dd6a989c160b1e5039b7835fc00000000171600140914414d3c94af70ac7e25407b0689e0baa10c77feffffffa83d954a62568bbc99cc644c62eb7383d7c2a2563041a0aeb891a6a4055895570000000017160014795d04cc2d4f31480d9a3710993fbd80d04301dffeffffff06fef72f000000000017a91476fd7035cd26f1a32a5ab979e056713aac25796887a5000f00000000001976a914b8332d502a529571c6af4be66399cd33379071c588ac3fda0500000000001976a914fc1d692f8de10ae33295f090bea5fe49527d975c88ac522e1b00000000001976a914808406b54d1044c429ac54c0e189b0d8061667e088ac6eb68501000000001976a914dfab6085f3a8fb3e6710206a5a959313c5618f4d88acbba20000000000001976a914eb3026552d7e3f3073457d0bee5d4757de48160d88ac0002483045022100bee24b63212939d33d513e767bc79300051f7a0d433c3fcf1e0e3bf03b9eb1d70220588dc45a9ce3a939103b4459ce47500b64e23ab118dfc03c9caa7d6bfc32b9c601210354fd80328da0f9ae6eef2b3a81f74f9a6f66761fadf96f1d1d22b1fd6845876402483045022100e29c7e3a5efc10da6269e5fc20b6a1cb8beb92130cc52c67e46ef40aaa5cac5f0220644dd1b049727d991aece98a105563416e10a5ac4221abac7d16931842d5c322012103960b87412d6e169f30e12106bdf70122aabb9eb61f455518322a18b920a4dfa887d30700")
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions bitcoin/src/blockdata/script.rs → bitcoin/src/script/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//! This module provides the structures and functions needed to support scripts.
//!

pub mod opcodes;

use crate::prelude::*;

use crate::io;
Expand All @@ -25,7 +27,6 @@ use bitcoin_internals::write_err;
#[cfg(feature = "serde")] use serde;

use crate::hash_types::{PubkeyHash, WPubkeyHash, ScriptHash, WScriptHash};
use crate::blockdata::opcodes;
use crate::consensus::{encode, Decodable, Encodable};
use crate::hashes::{Hash, hex};
use crate::policy::DUST_RELAY_TX_FEE;
Expand Down Expand Up @@ -580,7 +581,7 @@ impl Script {

/// Checks whether a script can be proven to have no satisfying input.
pub fn is_provably_unspendable(&self) -> bool {
use crate::blockdata::opcodes::Class::{ReturnOp, IllegalOp};
use crate::opcodes::Class::{ReturnOp, IllegalOp};

match self.0.first() {
Some(b) => {
Expand Down Expand Up @@ -1128,7 +1129,7 @@ mod test {

use crate::hashes::hex::{FromHex, ToHex};
use crate::consensus::encode::{deserialize, serialize};
use crate::blockdata::opcodes;
use crate::script::opcodes;
use crate::util::key::PublicKey;
use crate::util::psbt::serialize::Serialize;
use crate::internal_macros::hex_script;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bitcoin/src/util/bip152.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl BlockTransactions {
#[cfg(test)]
mod test {
use super::*;
use crate::blockdata::locktime::absolute;
use crate::primitives::locktime::absolute;
use crate::consensus::encode::{deserialize, serialize};
use crate::hashes::hex::FromHex;
use crate::{
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/util/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ mod tests {
use crate::consensus::encode::deserialize;
use crate::hashes::sha256d;

use crate::blockdata::block::Block;
use crate::primitives::block::Block;
use super::*;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/util/merkleblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ use crate::io;
use crate::hashes::Hash;
use crate::hash_types::{Txid, TxMerkleNode};

use crate::blockdata::transaction::Transaction;
use crate::blockdata::constants::{MAX_BLOCK_WEIGHT, MIN_TRANSACTION_WEIGHT};
use crate::primitives::transaction::Transaction;
use crate::primitives::{MAX_BLOCK_WEIGHT, MIN_TRANSACTION_WEIGHT};
use crate::consensus::encode::{self, Decodable, Encodable};
use crate::util::merkleblock::MerkleBlockError::*;
use crate::{Block, BlockHeader};
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub mod misc {
// For why we deprecated see: https://github.com/rust-bitcoin/rust-bitcoin/pull/1259#discussion_r968613736
#[deprecated(since = "0.30.0", note = "No longer supported")]
pub fn script_find_and_remove(haystack: &mut Vec<u8>, needle: &[u8]) -> usize {
use crate::blockdata::opcodes;
use crate::script::opcodes;

if needle.len() > haystack.len() {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/util/psbt/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::fmt;

use bitcoin_internals::write_err;

use crate::blockdata::transaction::Transaction;
use crate::primitives::transaction::Transaction;
use crate::consensus::encode;
use crate::util::psbt::raw;

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/util/psbt/map/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::prelude::*;

use crate::io::{self, Cursor, Read};

use crate::blockdata::transaction::Transaction;
use crate::primitives::transaction::Transaction;
use crate::consensus::{encode, Encodable, Decodable};
use crate::consensus::encode::MAX_VEC_SIZE;
use crate::util::psbt::map::Map;
Expand Down
6 changes: 3 additions & 3 deletions bitcoin/src/util/psbt/map/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use core::convert::TryFrom;

use secp256k1::XOnlyPublicKey;

use crate::blockdata::script::Script;
use crate::blockdata::witness::Witness;
use crate::blockdata::transaction::{Transaction, TxOut};
use crate::script::Script;
use crate::primitives::witness::Witness;
use crate::primitives::transaction::{Transaction, TxOut};
use crate::consensus::encode;
use crate::hashes::{self, hash160, ripemd160, sha256, sha256d};
use crate::util::bip32::KeySource;
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/util/psbt/map/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::convert::TryFrom;

use crate::io;

use crate::blockdata::script::Script;
use crate::script::Script;
use crate::consensus::encode;
use secp256k1::XOnlyPublicKey;
use crate::util::bip32::KeySource;
Expand Down