Skip to content

Commit

Permalink
Merge pull request #22 from anoma/grarco/single-masp-event-attribute
Browse files Browse the repository at this point in the history
Single masp event attribute
  • Loading branch information
grarco authored Sep 26, 2024
2 parents 05840ef + 7fd485f commit 967ba31
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 74 deletions.
54 changes: 27 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ diesel_migrations = { version = "2.2.0", default-features = false, features = [
futures = "0.3.30"
itertools = "0.13.0"
lazy_static = "1.4.0"
namada_core = { git = "https://github.com/anoma/namada", rev = "6c813dfc3cd3ba3757ee29923a78caa2124704e9" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "6c813dfc3cd3ba3757ee29923a78caa2124704e9" }
namada_tx = { git = "https://github.com/anoma/namada", rev = "6c813dfc3cd3ba3757ee29923a78caa2124704e9" }
namada_core = { git = "https://github.com/anoma/namada", rev = "297ee2638dcebe3566286a504249bc66ad8a5e94" }
namada_sdk = { git = "https://github.com/anoma/namada", rev = "297ee2638dcebe3566286a504249bc66ad8a5e94" }
namada_tx = { git = "https://github.com/anoma/namada", rev = "297ee2638dcebe3566286a504249bc66ad8a5e94" }
orm = { path = "orm" }
serde = { version = "1.0.138", features = [ "derive" ] }
serde_json = "1.0"
Expand Down
31 changes: 18 additions & 13 deletions shared/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fmt::Display;

use namada_sdk::events::extend::IndexedMaspData;
use tendermint_rpc::endpoint::{block, block_results};

use crate::block_results::locate_masp_txs;
Expand Down Expand Up @@ -27,21 +28,25 @@ impl Block {
transactions: Vec::with_capacity(raw_block.block.data.len()),
};

for (block_index, masp_tx_refs) in indexed_masp_txs.locations {
for IndexedMaspData {
tx_index,
masp_refs,
} in indexed_masp_txs
{
let block_index = tx_index.0 as usize;
let tx_bytes = &raw_block.block.data[block_index];

let tx =
match Transaction::from_namada_tx(tx_bytes, &masp_tx_refs.0) {
Some(tx) => tx,
None => {
tracing::warn!(
block_hash = %block.hash,
block_index,
"Invalid Namada transaction in block"
);
continue;
}
};
let tx = match Transaction::from_namada_tx(tx_bytes, &masp_refs.0) {
Some(tx) => tx,
None => {
tracing::warn!(
block_hash = %block.hash,
block_index,
"Invalid Namada transaction in block"
);
continue;
}
};

block.transactions.push((block_index, tx));
}
Expand Down
42 changes: 11 additions & 31 deletions shared/src/block_results.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
use std::collections::BTreeMap;

use namada_sdk::events::extend::{
MaspTxBatchRefs, MaspTxBlockIndex, MaspTxRefs, ReadFromEventAttributes,
IndexedMaspData, MaspDataRefs, ReadFromEventAttributes,
};
use tendermint_rpc::endpoint::block_results;

pub struct IndexedMaspTxs {
/// Mapping of block indexes to valid masp tx ids.
pub locations: BTreeMap<usize, MaspTxRefs>,
}

pub fn locate_masp_txs(
raw_block_results: &block_results::Response,
) -> IndexedMaspTxs {
IndexedMaspTxs {
locations: raw_block_results
.end_block_events
.as_ref()
.unwrap_or(&vec![])
.iter()
.filter_map(|event| {
let index = MaspTxBlockIndex::read_from_event_attributes(
&event.attributes,
)
.ok()?;

// Extract the references to the correct masp sections
let refs = MaspTxBatchRefs::read_from_event_attributes(
&event.attributes,
)
.unwrap_or_default();

Some((index.0 as usize, refs))
})
.collect(),
}
) -> Vec<IndexedMaspData> {
raw_block_results
.end_block_events
.as_ref()
.unwrap_or(&vec![])
.iter()
.filter_map(|event| {
MaspDataRefs::read_from_event_attributes(&event.attributes).ok()
})
.collect()
}

0 comments on commit 967ba31

Please sign in to comment.