node/watched_accounts/
mod.rs

1mod watched_accounts_state;
2pub use watched_accounts_state::*;
3
4mod watched_accounts_actions;
5pub use watched_accounts_actions::*;
6
7mod watched_accounts_reducer;
8
9use mina_p2p_messages::{
10    bigint::InvalidBigInt,
11    v2::{
12        NonZeroCurvePoint, NonZeroCurvePointUncompressedStableV1, StagedLedgerDiffDiffDiffStableV2,
13        StagedLedgerDiffDiffPreDiffWithAtMostTwoCoinbaseStableV2B,
14    },
15};
16
17pub fn is_transaction_affecting_account(
18    pub_key: &NonZeroCurvePoint,
19    tx: &StagedLedgerDiffDiffPreDiffWithAtMostTwoCoinbaseStableV2B,
20) -> Result<bool, InvalidBigInt> {
21    use ledger::scan_state::transaction_logic::UserCommand;
22    Ok(UserCommand::try_from(&tx.data)?
23        .accounts_referenced()
24        .iter()
25        .map(|v| {
26            NonZeroCurvePoint::from(NonZeroCurvePointUncompressedStableV1 {
27                x: v.public_key.x.into(),
28                is_odd: v.public_key.is_odd,
29            })
30        })
31        .any(|referenced_pub_key| &referenced_pub_key == pub_key))
32}
33
34pub fn account_relevant_transactions_in_diff_iter<'a>(
35    pub_key: &'a NonZeroCurvePoint,
36    diff: &'a StagedLedgerDiffDiffDiffStableV2,
37) -> impl 'a + Iterator<Item = Transaction> {
38    let iter_0 = diff.0.commands.iter();
39    let iter_1: Box<
40        dyn Iterator<Item = &StagedLedgerDiffDiffPreDiffWithAtMostTwoCoinbaseStableV2B>,
41    > = match &diff.1 {
42        Some(v) => Box::new(v.commands.iter()),
43        None => Box::new(std::iter::empty()),
44    };
45    iter_0
46        .chain(iter_1)
47        .filter(|tx| is_transaction_affecting_account(pub_key, tx).unwrap_or(false))
48        .map(|tx| Transaction {
49            hash: tx.data.hash().ok(),
50            data: tx.data.clone(),
51            status: tx.status.clone(),
52        })
53}