Skip to content

Commit d1365eb

Browse files
committed
Merge rust-bitcoin#4219: Rename then new Timestamp type
c707b95 Rename timestamp module to time (Tobin C. Harding) e2dee49 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 c707b95; successfully ran local tests Tree-SHA512: de3855b38445a58b6767a6081919eecb81c6c12aee3f6699f3bfa10efaf5770b54fb412da23991a9ee734e14dfb642af670f0218d1886cdc8c8d3f393ef65d7e
2 parents 1798679 + c707b95 commit d1365eb

File tree

10 files changed

+46
-46
lines changed

10 files changed

+46
-46
lines changed

bitcoin/src/bip152.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ mod test {
413413
use crate::merkle_tree::TxMerkleNode;
414414
use crate::transaction::OutPointExt;
415415
use crate::{
416-
transaction, Amount, BlockChecked, CompactTarget, OutPoint, ScriptBuf, Sequence, Timestamp,
416+
transaction, Amount, BlockChecked, CompactTarget, OutPoint, ScriptBuf, Sequence, BlockTime,
417417
TxIn, TxOut, Txid, Witness,
418418
};
419419

@@ -437,7 +437,7 @@ mod test {
437437
version: block::Version::ONE,
438438
prev_blockhash: BlockHash::from_byte_array([0x99; 32]),
439439
merkle_root: TxMerkleNode::from_byte_array([0x77; 32]),
440-
time: Timestamp::from_u32(2),
440+
time: BlockTime::from_u32(2),
441441
bits: CompactTarget::from_consensus(3),
442442
nonce: 4,
443443
};

bitcoin/src/blockdata/block.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use core::fmt;
1313
use hashes::{sha256d, HashEngine};
1414
use internals::{compact_size, ToU64};
1515
use io::{BufRead, Write};
16-
use units::Timestamp;
16+
use units::BlockTime;
1717

1818
use super::Weight;
1919
use crate::consensus::encode::WriteExt as _;
@@ -86,15 +86,15 @@ impl Decodable for Version {
8686
}
8787
}
8888

89-
impl Encodable for Timestamp {
89+
impl Encodable for BlockTime {
9090
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
9191
self.to_u32().consensus_encode(w)
9292
}
9393
}
9494

95-
impl Decodable for Timestamp {
95+
impl Decodable for BlockTime {
9696
fn consensus_decode<R: BufRead + ?Sized>(r: &mut R) -> Result<Self, encode::Error> {
97-
Decodable::consensus_decode(r).map(Timestamp::from_u32)
97+
Decodable::consensus_decode(r).map(BlockTime::from_u32)
9898
}
9999
}
100100

@@ -609,7 +609,7 @@ mod tests {
609609
block::compute_merkle_root(&transactions).unwrap()
610610
);
611611
assert_eq!(serialize(&real_decode.header().merkle_root), merkle);
612-
assert_eq!(real_decode.header().time, Timestamp::from_u32(1231965655));
612+
assert_eq!(real_decode.header().time, BlockTime::from_u32(1231965655));
613613
assert_eq!(real_decode.header().bits, CompactTarget::from_consensus(486604799));
614614
assert_eq!(real_decode.header().nonce, 2067413810);
615615
assert_eq!(real_decode.header().work(), work);
@@ -660,7 +660,7 @@ mod tests {
660660
real_decode.header().merkle_root,
661661
block::compute_merkle_root(&transactions).unwrap()
662662
);
663-
assert_eq!(real_decode.header().time, Timestamp::from_u32(1472004949));
663+
assert_eq!(real_decode.header().time, BlockTime::from_u32(1472004949));
664664
assert_eq!(real_decode.header().bits, CompactTarget::from_consensus(0x1a06d450));
665665
assert_eq!(real_decode.header().nonce, 1879759182);
666666
assert_eq!(real_decode.header().work(), work);

bitcoin/src/blockdata/constants.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::opcodes::all::*;
1616
use crate::pow::CompactTarget;
1717
use crate::transaction::{self, OutPoint, Transaction, TxIn, TxOut};
1818
use crate::witness::Witness;
19-
use crate::{script, Amount, BlockHash, Sequence, TestnetVersion, Timestamp};
19+
use crate::{script, Amount, BlockHash, Sequence, TestnetVersion, BlockTime};
2020

2121
/// How many seconds between blocks we expect on average.
2222
pub const TARGET_BLOCK_SPACING: u32 = 600;
@@ -134,7 +134,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
134134
version: block::Version::ONE,
135135
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
136136
merkle_root,
137-
time: Timestamp::from_u32(1231006505),
137+
time: BlockTime::from_u32(1231006505),
138138
bits: CompactTarget::from_consensus(0x1d00ffff),
139139
nonce: 2083236893,
140140
},
@@ -146,7 +146,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
146146
version: block::Version::ONE,
147147
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
148148
merkle_root,
149-
time: Timestamp::from_u32(1296688602),
149+
time: BlockTime::from_u32(1296688602),
150150
bits: CompactTarget::from_consensus(0x1d00ffff),
151151
nonce: 414098458,
152152
},
@@ -158,7 +158,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
158158
version: block::Version::ONE,
159159
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
160160
merkle_root,
161-
time: Timestamp::from_u32(1714777860),
161+
time: BlockTime::from_u32(1714777860),
162162
bits: CompactTarget::from_consensus(0x1d00ffff),
163163
nonce: 393743547,
164164
},
@@ -170,7 +170,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
170170
version: block::Version::ONE,
171171
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
172172
merkle_root,
173-
time: Timestamp::from_u32(1598918400),
173+
time: BlockTime::from_u32(1598918400),
174174
bits: CompactTarget::from_consensus(0x1e0377ae),
175175
nonce: 52613770,
176176
},
@@ -182,7 +182,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
182182
version: block::Version::ONE,
183183
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
184184
merkle_root,
185-
time: Timestamp::from_u32(1296688602),
185+
time: BlockTime::from_u32(1296688602),
186186
bits: CompactTarget::from_consensus(0x207fffff),
187187
nonce: 2,
188188
},
@@ -322,7 +322,7 @@ mod test {
322322
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
323323
);
324324

325-
assert_eq!(gen.header().time, Timestamp::from_u32(1231006505));
325+
assert_eq!(gen.header().time, BlockTime::from_u32(1231006505));
326326
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1d00ffff));
327327
assert_eq!(gen.header().nonce, 2083236893);
328328
assert_eq!(
@@ -340,7 +340,7 @@ mod test {
340340
gen.header().merkle_root.to_string(),
341341
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
342342
);
343-
assert_eq!(gen.header().time, Timestamp::from_u32(1296688602));
343+
assert_eq!(gen.header().time, BlockTime::from_u32(1296688602));
344344
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1d00ffff));
345345
assert_eq!(gen.header().nonce, 414098458);
346346
assert_eq!(
@@ -358,7 +358,7 @@ mod test {
358358
gen.header().merkle_root.to_string(),
359359
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
360360
);
361-
assert_eq!(gen.header().time, Timestamp::from_u32(1598918400));
361+
assert_eq!(gen.header().time, BlockTime::from_u32(1598918400));
362362
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1e0377ae));
363363
assert_eq!(gen.header().nonce, 52613770);
364364
assert_eq!(

bitcoin/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub use units::{
135135
amount::{Amount, Denomination, SignedAmount},
136136
block::{BlockHeight, BlockInterval},
137137
fee_rate::FeeRate,
138-
timestamp::{self, Timestamp},
138+
time::{self, BlockTime},
139139
weight::Weight,
140140
};
141141

bitcoin/src/pow.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ pub mod test_utils {
10781078
mod tests {
10791079
use super::*;
10801080
use crate::pow::test_utils::{u128_to_work, u32_to_target, u64_to_target};
1081-
use crate::Timestamp;
1081+
use crate::BlockTime;
10821082

10831083
impl U256 {
10841084
fn bit_at(&self, index: usize) -> bool {
@@ -1763,7 +1763,7 @@ mod tests {
17631763
version: Version::ONE,
17641764
prev_blockhash: BlockHash::from_byte_array([0; 32]),
17651765
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
1766-
time: Timestamp::from_u32(1599332177),
1766+
time: BlockTime::from_u32(1599332177),
17671767
bits: epoch_start.bits,
17681768
nonce: epoch_start.nonce,
17691769
};
@@ -1785,7 +1785,7 @@ mod tests {
17851785
version: Version::ONE,
17861786
prev_blockhash: BlockHash::from_byte_array([0; 32]),
17871787
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
1788-
time: Timestamp::from_u32(1599332844),
1788+
time: BlockTime::from_u32(1599332844),
17891789
bits: starting_bits,
17901790
nonce: 0,
17911791
};
@@ -1795,7 +1795,7 @@ mod tests {
17951795
version: Version::ONE,
17961796
prev_blockhash: BlockHash::from_byte_array([0; 32]),
17971797
merkle_root: TxMerkleNode::from_byte_array([0; 32]),
1798-
time: Timestamp::from_u32(1600591200),
1798+
time: BlockTime::from_u32(1600591200),
17991799
bits: starting_bits,
18001800
nonce: 0,
18011801
};

primitives/src/block.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::marker::PhantomData;
1414
#[cfg(feature = "arbitrary")]
1515
use arbitrary::{Arbitrary, Unstructured};
1616
use hashes::{sha256d, HashEngine as _};
17-
use units::Timestamp;
17+
use units::BlockTime;
1818

1919
use crate::merkle_tree::TxMerkleNode;
2020
#[cfg(feature = "alloc")]
@@ -180,7 +180,7 @@ pub struct Header {
180180
/// The root hash of the Merkle tree of transactions in the block.
181181
pub merkle_root: TxMerkleNode,
182182
/// The timestamp of the block, as claimed by the miner.
183-
pub time: Timestamp,
183+
pub time: BlockTime,
184184
/// The target value below which the blockhash must lie.
185185
pub bits: CompactTarget,
186186
/// The nonce, selected to obtain a low enough blockhash.
@@ -366,7 +366,7 @@ mod tests {
366366
version: Version::ONE,
367367
prev_blockhash: BlockHash::from_byte_array([0x99; 32]),
368368
merkle_root: TxMerkleNode::from_byte_array([0x77; 32]),
369-
time: Timestamp::from(2),
369+
time: BlockTime::from(2),
370370
bits: CompactTarget::from_consensus(3),
371371
nonce: 4,
372372
}

primitives/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub use units::{
5252
amount::{self, Amount, SignedAmount},
5353
block::{BlockHeight, BlockInterval},
5454
fee_rate::{self, FeeRate},
55-
timestamp::{self, Timestamp},
55+
time::{self, BlockTime},
5656
weight::{self, Weight},
5757
};
5858

units/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub mod block;
3434
pub mod fee_rate;
3535
pub mod locktime;
3636
pub mod parse;
37-
pub mod timestamp;
37+
pub mod time;
3838
pub mod weight;
3939

4040
#[doc(inline)]
@@ -43,6 +43,6 @@ pub use self::{
4343
amount::{Amount, SignedAmount},
4444
block::{BlockHeight, BlockInterval},
4545
fee_rate::FeeRate,
46-
timestamp::Timestamp,
46+
time::BlockTime,
4747
weight::Weight
4848
};

units/src/timestamp.rs units/src/time.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@ use serde::{Deserialize, Serialize};
2626
/// ref: <https://en.bitcoin.it/wiki/Block_timestamp>
2727
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
2828
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
29-
pub struct Timestamp(u32);
29+
pub struct BlockTime(u32);
3030

31-
impl Timestamp {
32-
/// Constructs a new [`Timestamp`] from an unsigned 32 bit integer value.
31+
impl BlockTime {
32+
/// Constructs a new [`BlockTime`] from an unsigned 32 bit integer value.
3333
#[inline]
34-
pub const fn from_u32(t: u32) -> Self { Timestamp(t) }
34+
pub const fn from_u32(t: u32) -> Self { BlockTime(t) }
3535

3636
/// Returns the inner `u32` value.
3737
#[inline]
3838
pub const fn to_u32(self) -> u32 { self.0 }
3939
}
4040

41-
impl From<u32> for Timestamp {
41+
impl From<u32> for BlockTime {
4242
#[inline]
4343
fn from(t: u32) -> Self { Self::from_u32(t) }
4444
}
4545

46-
impl From<Timestamp> for u32 {
46+
impl From<BlockTime> for u32 {
4747
#[inline]
48-
fn from(t: Timestamp) -> Self { t.to_u32() }
48+
fn from(t: BlockTime) -> Self { t.to_u32() }
4949
}
5050

5151
#[cfg(feature = "arbitrary")]
52-
impl<'a> Arbitrary<'a> for Timestamp {
52+
impl<'a> Arbitrary<'a> for BlockTime {
5353
#[inline]
5454
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
5555
let t: u32 = u.arbitrary()?;
56-
Ok(Timestamp::from(t))
56+
Ok(BlockTime::from(t))
5757
}
5858
}

units/tests/api.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use arbitrary::{Arbitrary, Unstructured};
1515
use bitcoin_units::locktime::{absolute, relative}; // Typical usage is `absolute::Height`.
1616
use bitcoin_units::{
1717
amount, block, fee_rate, locktime, parse, weight, Amount, BlockHeight, BlockInterval, FeeRate,
18-
SignedAmount, Timestamp, Weight,
18+
SignedAmount, BlockTime, Weight,
1919
};
2020

2121
/// A struct that includes all public non-error enums.
@@ -42,7 +42,7 @@ struct Structs {
4242
i: relative::Height,
4343
j: relative::Time,
4444
k: Weight,
45-
l: Timestamp,
45+
l: BlockTime,
4646
}
4747

4848
impl Structs {
@@ -59,7 +59,7 @@ impl Structs {
5959
i: relative::Height::MAX,
6060
j: relative::Time::MAX,
6161
k: Weight::MAX,
62-
l: Timestamp::from_u32(u32::MAX),
62+
l: BlockTime::from_u32(u32::MAX),
6363
}
6464
}
6565
}
@@ -89,7 +89,7 @@ struct CommonTraits {
8989
i: relative::Height,
9090
j: relative::Time,
9191
k: Weight,
92-
l: Timestamp,
92+
l: BlockTime,
9393
}
9494

9595
/// A struct that includes all types that implement `Default`.
@@ -141,13 +141,13 @@ struct Errors {
141141

142142
#[test]
143143
fn api_can_use_modules_from_crate_root() {
144-
use bitcoin_units::{amount, block, fee_rate, locktime, parse, timestamp, weight};
144+
use bitcoin_units::{amount, block, fee_rate, locktime, parse, time, weight};
145145
}
146146

147147
#[test]
148148
fn api_can_use_types_from_crate_root() {
149149
use bitcoin_units::{
150-
Amount, BlockHeight, BlockInterval, FeeRate, SignedAmount, Timestamp, Weight,
150+
Amount, BlockHeight, BlockInterval, FeeRate, SignedAmount, BlockTime, Weight,
151151
};
152152
}
153153

@@ -189,8 +189,8 @@ fn api_can_use_all_types_from_module_parse() {
189189
}
190190

191191
#[test]
192-
fn api_can_use_all_types_from_module_timestamp() {
193-
use bitcoin_units::timestamp::Timestamp;
192+
fn api_can_use_all_types_from_module_time() {
193+
use bitcoin_units::time::BlockTime;
194194
}
195195

196196
#[test]
@@ -295,7 +295,7 @@ impl<'a> Arbitrary<'a> for Structs {
295295
i: relative::Height::arbitrary(u)?,
296296
j: relative::Time::arbitrary(u)?,
297297
k: Weight::arbitrary(u)?,
298-
l: Timestamp::arbitrary(u)?,
298+
l: BlockTime::arbitrary(u)?,
299299
};
300300
Ok(a)
301301
}

0 commit comments

Comments
 (0)