Merge rust-bitcoin/rust-bitcoin#4219: Rename then new `Timestamp` type
c707b959b7
Rename timestamp module to time (Tobin C. Harding)e2dee4900f
Re-name Timestamp to BlockTime (Tobin C. Harding) Pull request description: Done in two patches so we can bikeshed the name of the type and separately the name of the module. - Rename type: `Timestamp` to `BlockTime` - Rename module: `timestamp` to `time` ACKs for top commit: apoelstra: ACK c707b959b72dd89ca6df581a6102f32daedb8368; successfully ran local tests Tree-SHA512: de3855b38445a58b6767a6081919eecb81c6c12aee3f6699f3bfa10efaf5770b54fb412da23991a9ee734e14dfb642af670f0218d1886cdc8c8d3f393ef65d7e
This commit is contained in:
commit
d1365eb376
|
@ -413,7 +413,7 @@ mod test {
|
|||
use crate::merkle_tree::TxMerkleNode;
|
||||
use crate::transaction::OutPointExt;
|
||||
use crate::{
|
||||
transaction, Amount, BlockChecked, CompactTarget, OutPoint, ScriptBuf, Sequence, Timestamp,
|
||||
transaction, Amount, BlockChecked, CompactTarget, OutPoint, ScriptBuf, Sequence, BlockTime,
|
||||
TxIn, TxOut, Txid, Witness,
|
||||
};
|
||||
|
||||
|
@ -437,7 +437,7 @@ mod test {
|
|||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::from_byte_array([0x99; 32]),
|
||||
merkle_root: TxMerkleNode::from_byte_array([0x77; 32]),
|
||||
time: Timestamp::from_u32(2),
|
||||
time: BlockTime::from_u32(2),
|
||||
bits: CompactTarget::from_consensus(3),
|
||||
nonce: 4,
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ use core::fmt;
|
|||
use hashes::{sha256d, HashEngine};
|
||||
use internals::{compact_size, ToU64};
|
||||
use io::{BufRead, Write};
|
||||
use units::Timestamp;
|
||||
use units::BlockTime;
|
||||
|
||||
use super::Weight;
|
||||
use crate::consensus::encode::WriteExt as _;
|
||||
|
@ -86,15 +86,15 @@ impl Decodable for Version {
|
|||
}
|
||||
}
|
||||
|
||||
impl Encodable for Timestamp {
|
||||
impl Encodable for BlockTime {
|
||||
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
|
||||
self.to_u32().consensus_encode(w)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for Timestamp {
|
||||
impl Decodable for BlockTime {
|
||||
fn consensus_decode<R: BufRead + ?Sized>(r: &mut R) -> Result<Self, encode::Error> {
|
||||
Decodable::consensus_decode(r).map(Timestamp::from_u32)
|
||||
Decodable::consensus_decode(r).map(BlockTime::from_u32)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -609,7 +609,7 @@ mod tests {
|
|||
block::compute_merkle_root(&transactions).unwrap()
|
||||
);
|
||||
assert_eq!(serialize(&real_decode.header().merkle_root), merkle);
|
||||
assert_eq!(real_decode.header().time, Timestamp::from_u32(1231965655));
|
||||
assert_eq!(real_decode.header().time, BlockTime::from_u32(1231965655));
|
||||
assert_eq!(real_decode.header().bits, CompactTarget::from_consensus(486604799));
|
||||
assert_eq!(real_decode.header().nonce, 2067413810);
|
||||
assert_eq!(real_decode.header().work(), work);
|
||||
|
@ -660,7 +660,7 @@ mod tests {
|
|||
real_decode.header().merkle_root,
|
||||
block::compute_merkle_root(&transactions).unwrap()
|
||||
);
|
||||
assert_eq!(real_decode.header().time, Timestamp::from_u32(1472004949));
|
||||
assert_eq!(real_decode.header().time, BlockTime::from_u32(1472004949));
|
||||
assert_eq!(real_decode.header().bits, CompactTarget::from_consensus(0x1a06d450));
|
||||
assert_eq!(real_decode.header().nonce, 1879759182);
|
||||
assert_eq!(real_decode.header().work(), work);
|
||||
|
|
|
@ -16,7 +16,7 @@ use crate::opcodes::all::*;
|
|||
use crate::pow::CompactTarget;
|
||||
use crate::transaction::{self, OutPoint, Transaction, TxIn, TxOut};
|
||||
use crate::witness::Witness;
|
||||
use crate::{script, Amount, BlockHash, Sequence, TestnetVersion, Timestamp};
|
||||
use crate::{script, Amount, BlockHash, Sequence, TestnetVersion, BlockTime};
|
||||
|
||||
/// How many seconds between blocks we expect on average.
|
||||
pub const TARGET_BLOCK_SPACING: u32 = 600;
|
||||
|
@ -134,7 +134,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
|
|||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: Timestamp::from_u32(1231006505),
|
||||
time: BlockTime::from_u32(1231006505),
|
||||
bits: CompactTarget::from_consensus(0x1d00ffff),
|
||||
nonce: 2083236893,
|
||||
},
|
||||
|
@ -146,7 +146,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
|
|||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: Timestamp::from_u32(1296688602),
|
||||
time: BlockTime::from_u32(1296688602),
|
||||
bits: CompactTarget::from_consensus(0x1d00ffff),
|
||||
nonce: 414098458,
|
||||
},
|
||||
|
@ -158,7 +158,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
|
|||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: Timestamp::from_u32(1714777860),
|
||||
time: BlockTime::from_u32(1714777860),
|
||||
bits: CompactTarget::from_consensus(0x1d00ffff),
|
||||
nonce: 393743547,
|
||||
},
|
||||
|
@ -170,7 +170,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
|
|||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: Timestamp::from_u32(1598918400),
|
||||
time: BlockTime::from_u32(1598918400),
|
||||
bits: CompactTarget::from_consensus(0x1e0377ae),
|
||||
nonce: 52613770,
|
||||
},
|
||||
|
@ -182,7 +182,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
|
|||
version: block::Version::ONE,
|
||||
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
|
||||
merkle_root,
|
||||
time: Timestamp::from_u32(1296688602),
|
||||
time: BlockTime::from_u32(1296688602),
|
||||
bits: CompactTarget::from_consensus(0x207fffff),
|
||||
nonce: 2,
|
||||
},
|
||||
|
@ -322,7 +322,7 @@ mod test {
|
|||
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
|
||||
);
|
||||
|
||||
assert_eq!(gen.header().time, Timestamp::from_u32(1231006505));
|
||||
assert_eq!(gen.header().time, BlockTime::from_u32(1231006505));
|
||||
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1d00ffff));
|
||||
assert_eq!(gen.header().nonce, 2083236893);
|
||||
assert_eq!(
|
||||
|
@ -340,7 +340,7 @@ mod test {
|
|||
gen.header().merkle_root.to_string(),
|
||||
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
|
||||
);
|
||||
assert_eq!(gen.header().time, Timestamp::from_u32(1296688602));
|
||||
assert_eq!(gen.header().time, BlockTime::from_u32(1296688602));
|
||||
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1d00ffff));
|
||||
assert_eq!(gen.header().nonce, 414098458);
|
||||
assert_eq!(
|
||||
|
@ -358,7 +358,7 @@ mod test {
|
|||
gen.header().merkle_root.to_string(),
|
||||
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
|
||||
);
|
||||
assert_eq!(gen.header().time, Timestamp::from_u32(1598918400));
|
||||
assert_eq!(gen.header().time, BlockTime::from_u32(1598918400));
|
||||
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1e0377ae));
|
||||
assert_eq!(gen.header().nonce, 52613770);
|
||||
assert_eq!(
|
||||
|
|
|
@ -135,7 +135,7 @@ pub use units::{
|
|||
amount::{Amount, Denomination, SignedAmount},
|
||||
block::{BlockHeight, BlockInterval},
|
||||
fee_rate::FeeRate,
|
||||
timestamp::{self, Timestamp},
|
||||
time::{self, BlockTime},
|
||||
weight::Weight,
|
||||
};
|
||||
|
||||
|
|
|
@ -1078,7 +1078,7 @@ pub mod test_utils {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::pow::test_utils::{u128_to_work, u32_to_target, u64_to_target};
|
||||
use crate::Timestamp;
|
||||
use crate::BlockTime;
|
||||
|
||||
impl U256 {
|
||||
fn bit_at(&self, index: usize) -> bool {
|
||||
|
@ -1763,7 +1763,7 @@ mod tests {
|
|||
version: Version::ONE,
|
||||
prev_blockhash: BlockHash::from_byte_array([0; 32]),
|
||||
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
|
||||
time: Timestamp::from_u32(1599332177),
|
||||
time: BlockTime::from_u32(1599332177),
|
||||
bits: epoch_start.bits,
|
||||
nonce: epoch_start.nonce,
|
||||
};
|
||||
|
@ -1785,7 +1785,7 @@ mod tests {
|
|||
version: Version::ONE,
|
||||
prev_blockhash: BlockHash::from_byte_array([0; 32]),
|
||||
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
|
||||
time: Timestamp::from_u32(1599332844),
|
||||
time: BlockTime::from_u32(1599332844),
|
||||
bits: starting_bits,
|
||||
nonce: 0,
|
||||
};
|
||||
|
@ -1795,7 +1795,7 @@ mod tests {
|
|||
version: Version::ONE,
|
||||
prev_blockhash: BlockHash::from_byte_array([0; 32]),
|
||||
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
|
||||
time: Timestamp::from_u32(1600591200),
|
||||
time: BlockTime::from_u32(1600591200),
|
||||
bits: starting_bits,
|
||||
nonce: 0,
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ use core::marker::PhantomData;
|
|||
#[cfg(feature = "arbitrary")]
|
||||
use arbitrary::{Arbitrary, Unstructured};
|
||||
use hashes::{sha256d, HashEngine as _};
|
||||
use units::Timestamp;
|
||||
use units::BlockTime;
|
||||
|
||||
use crate::merkle_tree::TxMerkleNode;
|
||||
#[cfg(feature = "alloc")]
|
||||
|
@ -180,7 +180,7 @@ pub struct Header {
|
|||
/// The root hash of the Merkle tree of transactions in the block.
|
||||
pub merkle_root: TxMerkleNode,
|
||||
/// The timestamp of the block, as claimed by the miner.
|
||||
pub time: Timestamp,
|
||||
pub time: BlockTime,
|
||||
/// The target value below which the blockhash must lie.
|
||||
pub bits: CompactTarget,
|
||||
/// The nonce, selected to obtain a low enough blockhash.
|
||||
|
@ -366,7 +366,7 @@ mod tests {
|
|||
version: Version::ONE,
|
||||
prev_blockhash: BlockHash::from_byte_array([0x99; 32]),
|
||||
merkle_root: TxMerkleNode::from_byte_array([0x77; 32]),
|
||||
time: Timestamp::from(2),
|
||||
time: BlockTime::from(2),
|
||||
bits: CompactTarget::from_consensus(3),
|
||||
nonce: 4,
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ pub use units::{
|
|||
amount::{self, Amount, SignedAmount},
|
||||
block::{BlockHeight, BlockInterval},
|
||||
fee_rate::{self, FeeRate},
|
||||
timestamp::{self, Timestamp},
|
||||
time::{self, BlockTime},
|
||||
weight::{self, Weight},
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ pub mod block;
|
|||
pub mod fee_rate;
|
||||
pub mod locktime;
|
||||
pub mod parse;
|
||||
pub mod timestamp;
|
||||
pub mod time;
|
||||
pub mod weight;
|
||||
|
||||
#[doc(inline)]
|
||||
|
@ -43,6 +43,6 @@ pub use self::{
|
|||
amount::{Amount, SignedAmount},
|
||||
block::{BlockHeight, BlockInterval},
|
||||
fee_rate::FeeRate,
|
||||
timestamp::Timestamp,
|
||||
time::BlockTime,
|
||||
weight::Weight
|
||||
};
|
||||
|
|
|
@ -26,33 +26,33 @@ use serde::{Deserialize, Serialize};
|
|||
/// ref: <https://en.bitcoin.it/wiki/Block_timestamp>
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct Timestamp(u32);
|
||||
pub struct BlockTime(u32);
|
||||
|
||||
impl Timestamp {
|
||||
/// Constructs a new [`Timestamp`] from an unsigned 32 bit integer value.
|
||||
impl BlockTime {
|
||||
/// Constructs a new [`BlockTime`] from an unsigned 32 bit integer value.
|
||||
#[inline]
|
||||
pub const fn from_u32(t: u32) -> Self { Timestamp(t) }
|
||||
pub const fn from_u32(t: u32) -> Self { BlockTime(t) }
|
||||
|
||||
/// Returns the inner `u32` value.
|
||||
#[inline]
|
||||
pub const fn to_u32(self) -> u32 { self.0 }
|
||||
}
|
||||
|
||||
impl From<u32> for Timestamp {
|
||||
impl From<u32> for BlockTime {
|
||||
#[inline]
|
||||
fn from(t: u32) -> Self { Self::from_u32(t) }
|
||||
}
|
||||
|
||||
impl From<Timestamp> for u32 {
|
||||
impl From<BlockTime> for u32 {
|
||||
#[inline]
|
||||
fn from(t: Timestamp) -> Self { t.to_u32() }
|
||||
fn from(t: BlockTime) -> Self { t.to_u32() }
|
||||
}
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
impl<'a> Arbitrary<'a> for Timestamp {
|
||||
impl<'a> Arbitrary<'a> for BlockTime {
|
||||
#[inline]
|
||||
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
|
||||
let t: u32 = u.arbitrary()?;
|
||||
Ok(Timestamp::from(t))
|
||||
Ok(BlockTime::from(t))
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ use arbitrary::{Arbitrary, Unstructured};
|
|||
use bitcoin_units::locktime::{absolute, relative}; // Typical usage is `absolute::Height`.
|
||||
use bitcoin_units::{
|
||||
amount, block, fee_rate, locktime, parse, weight, Amount, BlockHeight, BlockInterval, FeeRate,
|
||||
SignedAmount, Timestamp, Weight,
|
||||
SignedAmount, BlockTime, Weight,
|
||||
};
|
||||
|
||||
/// A struct that includes all public non-error enums.
|
||||
|
@ -42,7 +42,7 @@ struct Structs {
|
|||
i: relative::Height,
|
||||
j: relative::Time,
|
||||
k: Weight,
|
||||
l: Timestamp,
|
||||
l: BlockTime,
|
||||
}
|
||||
|
||||
impl Structs {
|
||||
|
@ -59,7 +59,7 @@ impl Structs {
|
|||
i: relative::Height::MAX,
|
||||
j: relative::Time::MAX,
|
||||
k: Weight::MAX,
|
||||
l: Timestamp::from_u32(u32::MAX),
|
||||
l: BlockTime::from_u32(u32::MAX),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ struct CommonTraits {
|
|||
i: relative::Height,
|
||||
j: relative::Time,
|
||||
k: Weight,
|
||||
l: Timestamp,
|
||||
l: BlockTime,
|
||||
}
|
||||
|
||||
/// A struct that includes all types that implement `Default`.
|
||||
|
@ -141,13 +141,13 @@ struct Errors {
|
|||
|
||||
#[test]
|
||||
fn api_can_use_modules_from_crate_root() {
|
||||
use bitcoin_units::{amount, block, fee_rate, locktime, parse, timestamp, weight};
|
||||
use bitcoin_units::{amount, block, fee_rate, locktime, parse, time, weight};
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn api_can_use_types_from_crate_root() {
|
||||
use bitcoin_units::{
|
||||
Amount, BlockHeight, BlockInterval, FeeRate, SignedAmount, Timestamp, Weight,
|
||||
Amount, BlockHeight, BlockInterval, FeeRate, SignedAmount, BlockTime, Weight,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -189,8 +189,8 @@ fn api_can_use_all_types_from_module_parse() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn api_can_use_all_types_from_module_timestamp() {
|
||||
use bitcoin_units::timestamp::Timestamp;
|
||||
fn api_can_use_all_types_from_module_time() {
|
||||
use bitcoin_units::time::BlockTime;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -295,7 +295,7 @@ impl<'a> Arbitrary<'a> for Structs {
|
|||
i: relative::Height::arbitrary(u)?,
|
||||
j: relative::Time::arbitrary(u)?,
|
||||
k: Weight::arbitrary(u)?,
|
||||
l: Timestamp::arbitrary(u)?,
|
||||
l: BlockTime::arbitrary(u)?,
|
||||
};
|
||||
Ok(a)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue