Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Jan 16, 2025
1 parent eb1e87f commit 0d7dc20
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
49 changes: 48 additions & 1 deletion shared/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::bond::BondAddresses;
use crate::checksums::Checksums;
use crate::header::BlockHeader;
use crate::id::Id;
use crate::masp::MaspEntry;
use crate::proposal::{GovernanceProposal, GovernanceProposalKind};
use crate::public_key::PublicKey;
use crate::token::{IbcToken, Token};
Expand Down Expand Up @@ -153,7 +154,7 @@ impl Block {
proposer_address_namada: proposer_address_namada
.as_ref()
.map(Id::to_string),
timestamp: block_response.block.header.time.to_string(),
timestamp: block_response.block.header.time.unix_timestamp(),
app_hash: Id::from(&block_response.block.header.app_hash),
},
transactions,
Expand Down Expand Up @@ -543,6 +544,52 @@ impl Block {
.collect::<HashSet<_>>()
}

pub fn masp(&self) -> Vec<MaspEntry> {
self
.transactions
.iter()
.flat_map(|(_, txs)| txs)
.filter(|tx| tx.data.is_some() && tx.was_successful())
.map(|tx| match &tx.kind {
TransactionKind::ShieldingTransfer(Some(transfer_data)) => {
transfer_data.targets.0.iter().map(|(account, amount)| MaspEntry {
token_address: account.token.to_string(),
timestamp: self.header.timestamp,
raw_amount: amount.amount().into(),
inner_tx_id: tx.tx_id,
}).collect()
},
TransactionKind::UnshieldingTransfer(Some(transfer_data)) => {
transfer_data.sources.0.iter().map(|(account, amount)| MaspEntry {
token_address: account.token.to_string(),
timestamp: self.header.timestamp,
raw_amount: amount.amount().into(),
inner_tx_id: tx.tx_id,
}).collect()
},
TransactionKind::IbcMsgTransfer(Some(ibc_message)) => {
match ibc_message.0 {
IbcMessage::Transfer(transfer) => {
if let Some(transfer_data) = transfer.transfer {

} else {
vec![]

Check failure on line 576 in shared/src/block.rs

View workflow job for this annotation

GitHub Actions / Clippy

`if` and `else` have incompatible types

Check failure on line 576 in shared/src/block.rs

View workflow job for this annotation

GitHub Actions / Tests

`if` and `else` have incompatible types
}
},
IbcMessage::NftTransfer(transfer) => {
if let Some(transfer_data) = transfer.transfer {

} else {
vec![]

Check failure on line 583 in shared/src/block.rs

View workflow job for this annotation

GitHub Actions / Clippy

`if` and `else` have incompatible types

Check failure on line 583 in shared/src/block.rs

View workflow job for this annotation

GitHub Actions / Tests

`if` and `else` have incompatible types
}
},
_ => vec![]
}
},
_ => vec![]
}).flatten()
}

pub fn governance_proposal(
&self,
mut next_proposal_id: u64,
Expand Down
2 changes: 1 addition & 1 deletion shared/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ pub struct BlockHeader {
pub height: BlockHeight,
pub proposer_address_tm: String,
pub proposer_address_namada: Option<String>,
pub timestamp: String,
pub timestamp: i64,
pub app_hash: Id,
}
1 change: 1 addition & 0 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ pub mod unbond;
pub mod utils;
pub mod validator;
pub mod vote;
pub mod masp;
9 changes: 9 additions & 0 deletions shared/src/masp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::{balance::Amount, id::Id};

#[derive(Debug, Clone)]
pub struct MaspEntry {
pub token_address: String,
pub timestamp: i64,
pub raw_amount: Amount,
pub inner_tx_id: Id,
}

0 comments on commit 0d7dc20

Please sign in to comment.