Skip to content

Commit e252e90

Browse files
committed
refactor: move tx input related types in a new module
1 parent 50daa9b commit e252e90

File tree

4 files changed

+77
-75
lines changed

4 files changed

+77
-75
lines changed

crates/asm/common/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ mod msg;
66
mod spec;
77
mod state;
88
mod subprotocol;
9+
mod tx;
910

1011
pub use error::AsmError;
1112
pub use msg::{InterprotoMsg, Log, NullMsg};
1213
pub use spec::{AsmSpec, Stage};
1314
pub use state::{AnchorState, ChainViewState, SectionState};
14-
pub use subprotocol::{MsgRelayer, Sps50TagPayload, Subprotocol, SubprotocolId, TxInput};
15+
pub use subprotocol::{MsgRelayer, Subprotocol, SubprotocolId};
16+
pub use tx::{TagPayload, TxInput};

crates/asm/common/src/subprotocol.rs

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
77
use std::any::Any;
88

9-
use bitcoin::Transaction;
109
use borsh::{BorshDeserialize, BorshSerialize};
1110

12-
use crate::{Log, msg::InterprotoMsg};
11+
use crate::{Log, TxInput, msg::InterprotoMsg};
1312

1413
/// Identifier for a subprotocol.
1514
pub type SubprotocolId = u8;
@@ -58,72 +57,3 @@ pub trait MsgRelayer: Any {
5857
/// Gets this msg relayer as a `&dyn Any`.
5958
fn as_mut_any(&mut self) -> &mut dyn Any;
6059
}
61-
62-
/// A wrapper containing a reference to a Bitcoin `Transaction` together with its
63-
/// parsed SPS-50 payload.
64-
///
65-
/// This struct bundles:
66-
/// 1. `tx`: the original Bitcoin transaction containing the SPS-50 tag in its first output, and
67-
/// 2. `sps_50_payload`: the extracted `Sps50TagPayload`, representing the subprotocol’s transaction
68-
/// type and any auxiliary data.
69-
#[derive(Debug)]
70-
pub struct TxInput<'t> {
71-
tx: &'t Transaction,
72-
sps_50_payload: Sps50TagPayload<'t>,
73-
}
74-
75-
/// A parsed SPS-50 tag payload (excluding the “ALPN” magic and subprotocol ID),
76-
/// containing the subprotocol-specific transaction type and any auxiliary data.
77-
///
78-
/// This struct represents everything in the OP_RETURN after the first 6 bytes:
79-
/// 1. Byte 0: subprotocol-defined transaction type
80-
/// 2. Bytes 1…: auxiliary payload (type-specific)
81-
#[derive(Debug)]
82-
pub struct Sps50TagPayload<'p> {
83-
/// The transaction type as defined by the SPS-50 subprotocol.
84-
tx_type: u8,
85-
86-
/// The remaining, type-specific payload for this transaction.
87-
auxiliary_data: &'p [u8],
88-
}
89-
90-
impl<'p> Sps50TagPayload<'p> {
91-
/// Constructs a new `Sps50TagPayload`.
92-
pub fn new(tx_type: u8, auxiliary_data: &'p [u8]) -> Self {
93-
Self {
94-
tx_type,
95-
auxiliary_data,
96-
}
97-
}
98-
99-
/// Returns the subprotocol-defined transaction type.
100-
pub fn tx_type(&self) -> u8 {
101-
self.tx_type
102-
}
103-
104-
/// Returns the auxiliary data slice associated with this tag.
105-
pub fn aux_data(&self) -> &[u8] {
106-
self.auxiliary_data
107-
}
108-
}
109-
110-
impl<'t> TxInput<'t> {
111-
/// Create a new `TxInput` referencing the given `Transaction`.
112-
pub fn new(tx: &'t Transaction, sps_50_info: Sps50TagPayload<'t>) -> Self {
113-
TxInput {
114-
tx,
115-
sps_50_payload: sps_50_info,
116-
}
117-
}
118-
119-
/// Gets the inner transaction.
120-
pub fn tx(&self) -> &Transaction {
121-
self.tx
122-
}
123-
124-
/// Returns a reference to the parsed SPS-50 payload for this transaction,
125-
/// which contains the subprotocol-specific transaction type and auxiliary data.
126-
pub fn sps50_payload(&self) -> &Sps50TagPayload<'t> {
127-
&self.sps_50_payload
128-
}
129-
}

crates/asm/common/src/tx.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
use bitcoin::Transaction;
2+
3+
/// A parsed SPS-50 tag payload (excluding the “ALPN” magic and subprotocol ID),
4+
/// containing the subprotocol-specific transaction type and any auxiliary data.
5+
///
6+
/// This struct represents everything in the OP_RETURN after the first 6 bytes:
7+
/// 1. Byte 0: subprotocol-defined transaction type
8+
/// 2. Bytes 1…: auxiliary payload (type-specific)
9+
#[derive(Debug)]
10+
pub struct TagPayload<'p> {
11+
/// The transaction type as defined by the SPS-50 subprotocol.
12+
tx_type: u8,
13+
14+
/// The remaining, type-specific payload for this transaction.
15+
auxiliary_data: &'p [u8],
16+
}
17+
18+
impl<'p> TagPayload<'p> {
19+
/// Constructs a new `Sps50TagPayload`.
20+
pub fn new(tx_type: u8, auxiliary_data: &'p [u8]) -> Self {
21+
Self {
22+
tx_type,
23+
auxiliary_data,
24+
}
25+
}
26+
27+
/// Returns the subprotocol-defined transaction type.
28+
pub fn tx_type(&self) -> u8 {
29+
self.tx_type
30+
}
31+
32+
/// Returns the auxiliary data slice associated with this tag.
33+
pub fn aux_data(&self) -> &[u8] {
34+
self.auxiliary_data
35+
}
36+
}
37+
38+
/// A wrapper containing a reference to a Bitcoin `Transaction` together with its
39+
/// parsed SPS-50 payload.
40+
///
41+
/// This struct bundles:
42+
/// 1. `tx`: the original Bitcoin transaction containing the SPS-50 tag in its first output, and
43+
/// 2. `tag`: the extracted `TagPayload`, representing the subprotocol’s transaction type and any
44+
/// auxiliary data.
45+
#[derive(Debug)]
46+
pub struct TxInput<'t> {
47+
tx: &'t Transaction,
48+
tag: TagPayload<'t>,
49+
}
50+
51+
impl<'t> TxInput<'t> {
52+
/// Create a new `TxInput` referencing the given `Transaction`.
53+
pub fn new(tx: &'t Transaction, sps_50_info: TagPayload<'t>) -> Self {
54+
TxInput {
55+
tx,
56+
tag: sps_50_info,
57+
}
58+
}
59+
60+
/// Gets the inner transaction.
61+
pub fn tx(&self) -> &Transaction {
62+
self.tx
63+
}
64+
65+
/// Returns a reference to the parsed SPS-50 tag payload for this transaction,
66+
/// which contains the subprotocol-specific transaction type and auxiliary data.
67+
pub fn tag(&self) -> &TagPayload<'t> {
68+
&self.tag
69+
}
70+
}

crates/asm/stf/src/tx_filter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::collections::BTreeMap;
33

44
use bitcoin::{Transaction, opcodes::all::OP_RETURN, script::Instruction};
5-
use strata_asm_common::{Sps50TagPayload, SubprotocolId, TxInput};
5+
use strata_asm_common::{SubprotocolId, TagPayload, TxInput};
66

77
/// Attempt to parse the SPS-50 L1 transaction header from the first output of a Bitcoin
88
/// `Transaction`.
@@ -14,7 +14,7 @@ use strata_asm_common::{Sps50TagPayload, SubprotocolId, TxInput};
1414
/// [5] tx type (u8)
1515
/// [6..] auxiliary data (ignored here)
1616
/// ```
17-
fn parse_sps50_header(tx: &Transaction) -> Option<(SubprotocolId, Sps50TagPayload<'_>)> {
17+
fn parse_sps50_header(tx: &Transaction) -> Option<(SubprotocolId, TagPayload<'_>)> {
1818
// 1) Ensure there's an output 0
1919
let first_out = tx.output.first()?;
2020
let script = &first_out.script_pubkey;
@@ -40,7 +40,7 @@ fn parse_sps50_header(tx: &Transaction) -> Option<(SubprotocolId, Sps50TagPayloa
4040
// 4) Extract subprotocol and tx type
4141
let subprotocol = data[4];
4242

43-
let sps_50_payload = Sps50TagPayload::new(data[5], data[5..].as_bytes());
43+
let sps_50_payload = TagPayload::new(data[5], data[5..].as_bytes());
4444
Some((subprotocol, sps_50_payload))
4545
}
4646

0 commit comments

Comments
 (0)