Skip to content

Commit 0a02d26

Browse files
evanlinjinLagginTimes
authored andcommitted
feat(chain): Add convenience conversions for CanonicalTx
* `From<CanonicalTx> for Txid` * `From<CanonicalTx> for Arc<Transaction>` Also added a convenience method `ChainPosition::is_unconfirmed`. These are intended to simplify the calls needed to populate the `expected_mempool_txids` field of `Emitter::new`.
1 parent d11f6ef commit 0a02d26

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

crates/chain/src/chain_data.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ impl<A> ChainPosition<A> {
4040
pub fn is_confirmed(&self) -> bool {
4141
matches!(self, Self::Confirmed { .. })
4242
}
43+
44+
/// Returns whether [`ChainPosition`] is unconfirmed or not.
45+
pub fn is_unconfirmed(&self) -> bool {
46+
matches!(self, Self::Unconfirmed { .. })
47+
}
4348
}
4449

4550
impl<A: Clone> ChainPosition<&A> {

crates/chain/src/tx_graph.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,18 @@ pub struct CanonicalTx<'a, T, A> {
251251
pub tx_node: TxNode<'a, T, A>,
252252
}
253253

254+
impl<'a, T, A> From<CanonicalTx<'a, T, A>> for Txid {
255+
fn from(tx: CanonicalTx<'a, T, A>) -> Self {
256+
tx.tx_node.txid
257+
}
258+
}
259+
260+
impl<'a, A> From<CanonicalTx<'a, Arc<Transaction>, A>> for Arc<Transaction> {
261+
fn from(tx: CanonicalTx<'a, Arc<Transaction>, A>) -> Self {
262+
tx.tx_node.tx
263+
}
264+
}
265+
254266
/// Errors returned by `TxGraph::calculate_fee`.
255267
#[derive(Debug, PartialEq, Eq)]
256268
pub enum CalculateFeeError {

0 commit comments

Comments
 (0)