|
1 |
| -use bitcoin::{hashes::Hash, BlockHash, OutPoint, TxOut, Txid}; |
| 1 | +use crate::ConfirmationBlockTime; |
| 2 | +use bitcoin::{OutPoint, TxOut, Txid}; |
2 | 3 |
|
3 |
| -use crate::{Anchor, AnchorFromBlockPosition, COINBASE_MATURITY}; |
| 4 | +use crate::{Anchor, COINBASE_MATURITY}; |
4 | 5 |
|
5 | 6 | /// Represents the observed position of some chain data.
|
6 | 7 | ///
|
@@ -82,92 +83,6 @@ impl From<ChainPosition<ConfirmationBlockTime>> for ConfirmationTime {
|
82 | 83 | }
|
83 | 84 | }
|
84 | 85 |
|
85 |
| -/// A reference to a block in the canonical chain. |
86 |
| -/// |
87 |
| -/// `BlockId` implements [`Anchor`]. When a transaction is anchored to `BlockId`, the confirmation |
88 |
| -/// block and anchor block are the same block. |
89 |
| -#[derive(Debug, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)] |
90 |
| -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
91 |
| -pub struct BlockId { |
92 |
| - /// The height of the block. |
93 |
| - pub height: u32, |
94 |
| - /// The hash of the block. |
95 |
| - pub hash: BlockHash, |
96 |
| -} |
97 |
| - |
98 |
| -impl Anchor for BlockId { |
99 |
| - fn anchor_block(&self) -> Self { |
100 |
| - *self |
101 |
| - } |
102 |
| -} |
103 |
| - |
104 |
| -impl AnchorFromBlockPosition for BlockId { |
105 |
| - fn from_block_position(_block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self { |
106 |
| - block_id |
107 |
| - } |
108 |
| -} |
109 |
| - |
110 |
| -impl Default for BlockId { |
111 |
| - fn default() -> Self { |
112 |
| - Self { |
113 |
| - height: Default::default(), |
114 |
| - hash: BlockHash::all_zeros(), |
115 |
| - } |
116 |
| - } |
117 |
| -} |
118 |
| - |
119 |
| -impl From<(u32, BlockHash)> for BlockId { |
120 |
| - fn from((height, hash): (u32, BlockHash)) -> Self { |
121 |
| - Self { height, hash } |
122 |
| - } |
123 |
| -} |
124 |
| - |
125 |
| -impl From<BlockId> for (u32, BlockHash) { |
126 |
| - fn from(block_id: BlockId) -> Self { |
127 |
| - (block_id.height, block_id.hash) |
128 |
| - } |
129 |
| -} |
130 |
| - |
131 |
| -impl From<(&u32, &BlockHash)> for BlockId { |
132 |
| - fn from((height, hash): (&u32, &BlockHash)) -> Self { |
133 |
| - Self { |
134 |
| - height: *height, |
135 |
| - hash: *hash, |
136 |
| - } |
137 |
| - } |
138 |
| -} |
139 |
| - |
140 |
| -/// An [`Anchor`] implementation that also records the exact confirmation time of the transaction. |
141 |
| -/// |
142 |
| -/// Refer to [`Anchor`] for more details. |
143 |
| -#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)] |
144 |
| -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
145 |
| -pub struct ConfirmationBlockTime { |
146 |
| - /// The anchor block. |
147 |
| - pub block_id: BlockId, |
148 |
| - /// The confirmation time of the transaction being anchored. |
149 |
| - pub confirmation_time: u64, |
150 |
| -} |
151 |
| - |
152 |
| -impl Anchor for ConfirmationBlockTime { |
153 |
| - fn anchor_block(&self) -> BlockId { |
154 |
| - self.block_id |
155 |
| - } |
156 |
| - |
157 |
| - fn confirmation_height_upper_bound(&self) -> u32 { |
158 |
| - self.block_id.height |
159 |
| - } |
160 |
| -} |
161 |
| - |
162 |
| -impl AnchorFromBlockPosition for ConfirmationBlockTime { |
163 |
| - fn from_block_position(block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self { |
164 |
| - Self { |
165 |
| - block_id, |
166 |
| - confirmation_time: block.header.time as _, |
167 |
| - } |
168 |
| - } |
169 |
| -} |
170 |
| - |
171 | 86 | /// A `TxOut` with as much data as we can retrieve about it
|
172 | 87 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
173 | 88 | pub struct FullTxOut<A> {
|
@@ -244,6 +159,8 @@ impl<A: Anchor> FullTxOut<A> {
|
244 | 159 |
|
245 | 160 | #[cfg(test)]
|
246 | 161 | mod test {
|
| 162 | + use crate::BlockId; |
| 163 | + |
247 | 164 | use super::*;
|
248 | 165 |
|
249 | 166 | #[test]
|
|
0 commit comments