-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from anoma/grarco/single-masp-event-attribute
Single masp event attribute
- Loading branch information
Showing
4 changed files
with
59 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |