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