Skip to content

Commit e2dee49

Browse files
committed
Re-name Timestamp to BlockTime
We just added a `Timestamp` type without knowing that there was a push by OpenTimestamps to also create a timestamp and that our new type may lead to confusion. Our timestamp is explicitly for the `time` field in a block so we can call it `BlockTime`. This name change makes the module name stale but we will change that in a following patch to ease review.
1 parent 1a18ff5 commit e2dee49

File tree

10 files changed

+43
-43
lines changed

10 files changed

+43
-43
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;
@@ -132,7 +132,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
132132
version: block::Version::ONE,
133133
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
134134
merkle_root,
135-
time: Timestamp::from_u32(1231006505),
135+
time: BlockTime::from_u32(1231006505),
136136
bits: CompactTarget::from_consensus(0x1d00ffff),
137137
nonce: 2083236893,
138138
},
@@ -144,7 +144,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
144144
version: block::Version::ONE,
145145
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
146146
merkle_root,
147-
time: Timestamp::from_u32(1296688602),
147+
time: BlockTime::from_u32(1296688602),
148148
bits: CompactTarget::from_consensus(0x1d00ffff),
149149
nonce: 414098458,
150150
},
@@ -156,7 +156,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
156156
version: block::Version::ONE,
157157
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
158158
merkle_root,
159-
time: Timestamp::from_u32(1714777860),
159+
time: BlockTime::from_u32(1714777860),
160160
bits: CompactTarget::from_consensus(0x1d00ffff),
161161
nonce: 393743547,
162162
},
@@ -168,7 +168,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
168168
version: block::Version::ONE,
169169
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
170170
merkle_root,
171-
time: Timestamp::from_u32(1598918400),
171+
time: BlockTime::from_u32(1598918400),
172172
bits: CompactTarget::from_consensus(0x1e0377ae),
173173
nonce: 52613770,
174174
},
@@ -180,7 +180,7 @@ pub fn genesis_block(params: impl AsRef<Params>) -> Block<Checked> {
180180
version: block::Version::ONE,
181181
prev_blockhash: BlockHash::GENESIS_PREVIOUS_BLOCK_HASH,
182182
merkle_root,
183-
time: Timestamp::from_u32(1296688602),
183+
time: BlockTime::from_u32(1296688602),
184184
bits: CompactTarget::from_consensus(0x207fffff),
185185
nonce: 2,
186186
},
@@ -320,7 +320,7 @@ mod test {
320320
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
321321
);
322322

323-
assert_eq!(gen.header().time, Timestamp::from_u32(1231006505));
323+
assert_eq!(gen.header().time, BlockTime::from_u32(1231006505));
324324
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1d00ffff));
325325
assert_eq!(gen.header().nonce, 2083236893);
326326
assert_eq!(
@@ -338,7 +338,7 @@ mod test {
338338
gen.header().merkle_root.to_string(),
339339
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
340340
);
341-
assert_eq!(gen.header().time, Timestamp::from_u32(1296688602));
341+
assert_eq!(gen.header().time, BlockTime::from_u32(1296688602));
342342
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1d00ffff));
343343
assert_eq!(gen.header().nonce, 414098458);
344344
assert_eq!(
@@ -356,7 +356,7 @@ mod test {
356356
gen.header().merkle_root.to_string(),
357357
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
358358
);
359-
assert_eq!(gen.header().time, Timestamp::from_u32(1598918400));
359+
assert_eq!(gen.header().time, BlockTime::from_u32(1598918400));
360360
assert_eq!(gen.header().bits, CompactTarget::from_consensus(0x1e0377ae));
361361
assert_eq!(gen.header().nonce, 52613770);
362362
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+
timestamp::{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.
@@ -402,7 +402,7 @@ mod tests {
402402
version: Version::ONE,
403403
prev_blockhash: BlockHash::from_byte_array([0x99; 32]),
404404
merkle_root: TxMerkleNode::from_byte_array([0x77; 32]),
405-
time: Timestamp::from(2),
405+
time: BlockTime::from(2),
406406
bits: CompactTarget::from_consensus(3),
407407
nonce: 4,
408408
};

primitives/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub use units::{
5858
amount::{self, Amount, SignedAmount},
5959
block::{BlockHeight, BlockInterval},
6060
fee_rate::{self, FeeRate},
61-
timestamp::{self, Timestamp},
61+
timestamp::{self, BlockTime},
6262
weight::{self, Weight},
6363
};
6464

units/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ pub use self::{
4343
amount::{Amount, SignedAmount},
4444
block::{BlockHeight, BlockInterval},
4545
fee_rate::FeeRate,
46-
timestamp::Timestamp,
46+
timestamp::BlockTime,
4747
weight::Weight
4848
};

units/src/timestamp.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

+7-7
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`.
@@ -147,7 +147,7 @@ fn api_can_use_modules_from_crate_root() {
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

@@ -190,7 +190,7 @@ fn api_can_use_all_types_from_module_parse() {
190190

191191
#[test]
192192
fn api_can_use_all_types_from_module_timestamp() {
193-
use bitcoin_units::timestamp::Timestamp;
193+
use bitcoin_units::timestamp::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)