Skip to content

Commit 9f48bd0

Browse files
committed
fix(cardano-chain-follower): remove decoded_transaction
Signed-off-by: bkioshn <[email protected]>
1 parent 1ce3a20 commit 9f48bd0

File tree

1 file changed

+3
-105
lines changed
  • rust/cardano-chain-follower/src/metadata

1 file changed

+3
-105
lines changed

rust/cardano-chain-follower/src/metadata/mod.rs

Lines changed: 3 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@
22
33
use std::{fmt::Debug, sync::Arc};
44

5-
use cardano_blockchain_types::Network;
5+
use cardano_blockchain_types::{Network, TransactionAuxData};
66
use cip36::Cip36;
77
use cip509::Cip509;
88
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;
1410

1511
pub mod cip36;
1612
pub mod cip509;
17-
mod raw_aux_data;
1813

1914
/// List of all validation errors (as strings) Metadata is considered Valid if this list
2015
/// is empty.
@@ -50,7 +45,7 @@ pub(crate) struct DecodedMetadata(DashMap<u64, Arc<DecodedMetadataItem>>);
5045

5146
impl DecodedMetadata {
5247
/// 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 {
5449
let decoded_metadata = Self(DashMap::new());
5550

5651
// Process each known type of metadata here, and record the decoded result.
@@ -82,100 +77,3 @@ impl Debug for DecodedMetadata {
8277
f.write_str("}")
8378
}
8479
}
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

Comments
 (0)