|
2 | 2 |
|
3 | 3 | use std::{fmt::Debug, sync::Arc}; |
4 | 4 |
|
5 | | -use cardano_blockchain_types::Network; |
| 5 | +use cardano_blockchain_types::{Network, TransactionAuxData}; |
6 | 6 | use cip36::Cip36; |
7 | 7 | use cip509::Cip509; |
8 | 8 | use dashmap::DashMap; |
9 | | -use pallas::ledger::traverse::{MultiEraBlock, MultiEraTx}; |
10 | | -use raw_aux_data::RawAuxData; |
11 | | -use tracing::error; |
12 | | - |
13 | | -use crate::utils::usize_from_saturating; |
| 9 | +use pallas::ledger::traverse::MultiEraTx; |
14 | 10 |
|
15 | 11 | pub mod cip36; |
16 | 12 | pub mod cip509; |
17 | | -mod raw_aux_data; |
18 | 13 |
|
19 | 14 | /// List of all validation errors (as strings) Metadata is considered Valid if this list |
20 | 15 | /// is empty. |
@@ -50,7 +45,7 @@ pub(crate) struct DecodedMetadata(DashMap<u64, Arc<DecodedMetadataItem>>); |
50 | 45 |
|
51 | 46 | impl DecodedMetadata { |
52 | 47 | /// Create new decoded metadata for a transaction. |
53 | | - fn new(chain: Network, slot: u64, txn: &MultiEraTx, raw_aux_data: &RawAuxData) -> Self { |
| 48 | + fn new(chain: Network, slot: u64, txn: &MultiEraTx, raw_aux_data: &TransactionAuxData) -> Self { |
54 | 49 | let decoded_metadata = Self(DashMap::new()); |
55 | 50 |
|
56 | 51 | // Process each known type of metadata here, and record the decoded result. |
@@ -82,100 +77,3 @@ impl Debug for DecodedMetadata { |
82 | 77 | f.write_str("}") |
83 | 78 | } |
84 | 79 | } |
85 | | - |
86 | | -/// Decoded Metadata for a all transactions in a block. |
87 | | -/// The Key for both entries is the Transaction offset in the block. |
88 | | -#[derive(Debug)] |
89 | | -pub struct DecodedTransaction { |
90 | | - /// The Raw Auxiliary Data for each transaction in the block. |
91 | | - raw: DashMap<usize, RawAuxData>, |
92 | | - /// The Decoded Metadata for each transaction in the block. |
93 | | - decoded: DashMap<usize, DecodedMetadata>, |
94 | | -} |
95 | | - |
96 | | -impl DecodedTransaction { |
97 | | - /// Insert another transaction worth of data into the Decoded Aux Data |
98 | | - fn insert( |
99 | | - &mut self, chain: Network, slot: u64, txn_idx: u32, cbor_data: &[u8], |
100 | | - transactions: &[MultiEraTx], |
101 | | - ) { |
102 | | - let txn_idx = usize_from_saturating(txn_idx); |
103 | | - |
104 | | - let Some(txn) = transactions.get(txn_idx) else { |
105 | | - error!("No transaction at index {txn_idx} trying to decode metadata."); |
106 | | - return; |
107 | | - }; |
108 | | - |
109 | | - let txn_raw_aux_data = RawAuxData::new(cbor_data); |
110 | | - let txn_metadata = DecodedMetadata::new(chain, slot, txn, &txn_raw_aux_data); |
111 | | - |
112 | | - self.raw.insert(txn_idx, txn_raw_aux_data); |
113 | | - self.decoded.insert(txn_idx, txn_metadata); |
114 | | - } |
115 | | - |
116 | | - /// Create a new `DecodedTransaction`. |
117 | | - pub(crate) fn new(chain: Network, block: &MultiEraBlock) -> Self { |
118 | | - let mut decoded_aux_data = DecodedTransaction { |
119 | | - raw: DashMap::new(), |
120 | | - decoded: DashMap::new(), |
121 | | - }; |
122 | | - |
123 | | - if block.has_aux_data() { |
124 | | - let transactions = block.txs(); |
125 | | - let slot = block.slot(); |
126 | | - |
127 | | - if let Some(_metadata) = block.as_byron() { |
128 | | - // Nothing to do here. |
129 | | - } else if let Some(alonzo_block) = block.as_alonzo() { |
130 | | - for (txn_idx, metadata) in alonzo_block.auxiliary_data_set.iter() { |
131 | | - decoded_aux_data.insert( |
132 | | - chain, |
133 | | - slot, |
134 | | - *txn_idx, |
135 | | - metadata.raw_cbor(), |
136 | | - &transactions, |
137 | | - ); |
138 | | - } |
139 | | - } else if let Some(babbage_block) = block.as_babbage() { |
140 | | - for (txn_idx, metadata) in babbage_block.auxiliary_data_set.iter() { |
141 | | - decoded_aux_data.insert( |
142 | | - chain, |
143 | | - slot, |
144 | | - *txn_idx, |
145 | | - metadata.raw_cbor(), |
146 | | - &transactions, |
147 | | - ); |
148 | | - } |
149 | | - } else if let Some(conway_block) = block.as_conway() { |
150 | | - for (txn_idx, metadata) in conway_block.auxiliary_data_set.iter() { |
151 | | - decoded_aux_data.insert( |
152 | | - chain, |
153 | | - slot, |
154 | | - *txn_idx, |
155 | | - metadata.raw_cbor(), |
156 | | - &transactions, |
157 | | - ); |
158 | | - } |
159 | | - } else { |
160 | | - error!("Undecodable metadata, unknown Era"); |
161 | | - }; |
162 | | - } |
163 | | - decoded_aux_data |
164 | | - } |
165 | | - |
166 | | - /// Get metadata for a given label in a transaction if it exists. |
167 | | - #[must_use] |
168 | | - pub fn get_metadata(&self, txn_idx: usize, label: u64) -> Option<Arc<DecodedMetadataItem>> { |
169 | | - let txn_metadata = self.decoded.get(&txn_idx)?; |
170 | | - let txn_metadata = txn_metadata.value(); |
171 | | - txn_metadata.get(label) |
172 | | - } |
173 | | - |
174 | | - /// Get raw metadata for a given label in a transaction if it exists. |
175 | | - #[must_use] |
176 | | - pub fn get_raw_metadata(&self, txn_idx: usize, label: u64) -> Option<Arc<Vec<u8>>> { |
177 | | - let txn_metadata = self.raw.get(&txn_idx)?; |
178 | | - let txn_metadata = txn_metadata.value(); |
179 | | - txn_metadata.get_metadata(label) |
180 | | - } |
181 | | -} |
0 commit comments