Run rustfmt
This commit is contained in:
@@ -3,21 +3,21 @@
|
||||
//!
|
||||
//! To aggregate relative balances changes to absolute balances the general approach is:
|
||||
//!
|
||||
//! 1. Use a map function that will extract a `BlockBalanceDeltas` message. BalanceDeltas
|
||||
//! within this message are required to have increasing ordinals so that
|
||||
//! the order of relative balance changes is unambiguous.
|
||||
//! 2. Store the balances changes with a store handler. You can use the
|
||||
//! `store_balance_changes` library method directly for this.
|
||||
//! 3. In the output module, use aggregate_balance_changes to receive an
|
||||
//! aggregated map of absolute balances.
|
||||
//!
|
||||
//! 1. Use a map function that will extract a `BlockBalanceDeltas` message. BalanceDeltas within
|
||||
//! this message are required to have increasing ordinals so that the order of relative balance
|
||||
//! changes is unambiguous.
|
||||
//! 2. Store the balances changes with a store handler. You can use the `store_balance_changes`
|
||||
//! library method directly for this.
|
||||
//! 3. In the output module, use aggregate_balance_changes to receive an aggregated map of absolute
|
||||
//! balances.
|
||||
use crate::pb::tycho::evm::v1::{BalanceChange, BlockBalanceDeltas, Transaction};
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use substreams::key;
|
||||
use substreams::pb::substreams::StoreDeltas;
|
||||
use substreams::prelude::{BigInt, StoreAdd};
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use substreams::{
|
||||
key,
|
||||
pb::substreams::StoreDeltas,
|
||||
prelude::{BigInt, StoreAdd},
|
||||
};
|
||||
|
||||
/// Store relative balances changes in a additive manner.
|
||||
///
|
||||
@@ -25,9 +25,9 @@ use substreams::prelude::{BigInt, StoreAdd};
|
||||
///
|
||||
/// ## Arguments
|
||||
///
|
||||
/// * `deltas` - A `BlockBalanceDeltas` message containing the relative balances changes.
|
||||
/// Note: relative balance deltas must have strictly increasing ordinals per token
|
||||
/// address, will panic otherwise.
|
||||
/// * `deltas` - A `BlockBalanceDeltas` message containing the relative balances changes. Note:
|
||||
/// relative balance deltas must have strictly increasing ordinals per token address, will panic
|
||||
/// otherwise.
|
||||
/// * `store` - An AddStore that will add relative balance changes.
|
||||
///
|
||||
/// This method is meant to be used in combination with `aggregate_balances_changes`
|
||||
@@ -68,8 +68,7 @@ type TxAggregatedBalances = HashMap<Vec<u8>, (Transaction, HashMap<Vec<u8>, Bala
|
||||
/// Aggregates absolute balances per transaction and token.
|
||||
///
|
||||
/// ## Arguments
|
||||
/// * `balance_store` - A `StoreDeltas` with all changes that occured in the source
|
||||
/// store module.
|
||||
/// * `balance_store` - A `StoreDeltas` with all changes that occured in the source store module.
|
||||
/// * `deltas` - A `BlockBalanceDeltas` message containing the relative balances changes.
|
||||
///
|
||||
/// Reads absolute balance values from the additive store (see `store_balance_changes`
|
||||
@@ -127,10 +126,14 @@ pub fn aggregate_balances_changes(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::mock_store::MockStore;
|
||||
use crate::pb::tycho::evm::v1::{BalanceDelta, Transaction};
|
||||
use substreams::pb::substreams::StoreDelta;
|
||||
use substreams::prelude::{StoreGet, StoreNew};
|
||||
use crate::{
|
||||
mock_store::MockStore,
|
||||
pb::tycho::evm::v1::{BalanceDelta, Transaction},
|
||||
};
|
||||
use substreams::{
|
||||
pb::substreams::StoreDelta,
|
||||
prelude::{StoreGet, StoreNew},
|
||||
};
|
||||
|
||||
fn block_balance_deltas() -> BlockBalanceDeltas {
|
||||
let comp_id = "0x42c0ffee"
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
/// more [here](https://streamingfastio.medium.com/new-block-model-to-accelerate-chain-integration-9f65126e5425)
|
||||
use std::collections::HashMap;
|
||||
|
||||
use substreams_ethereum::pb::eth;
|
||||
use substreams_ethereum::pb::eth::v2::block::DetailLevel;
|
||||
use substreams_ethereum::pb::eth::v2::StorageChange;
|
||||
use substreams_ethereum::pb::{
|
||||
eth,
|
||||
eth::v2::{block::DetailLevel, StorageChange},
|
||||
};
|
||||
|
||||
use crate::pb::tycho::evm::v1::{self as tycho};
|
||||
|
||||
@@ -78,7 +79,8 @@ impl From<InterimContractChange> for tycho::ContractChange {
|
||||
/// ## Arguments
|
||||
///
|
||||
/// * `block` - The block to extract changes from. Must be the extended block model.
|
||||
/// * `inclusion_predicate` - A predicate function that determines if a contract address is relevant.
|
||||
/// * `inclusion_predicate` - A predicate function that determines if a contract address is
|
||||
/// relevant.
|
||||
/// * `transaction_contract_changes` - A mutable map to store the contract changes in.
|
||||
///
|
||||
/// ## Panics
|
||||
@@ -189,9 +191,9 @@ pub fn extract_contract_changes<F: Fn(&[u8]) -> bool>(
|
||||
.extend_from_slice(&code_change.new_code);
|
||||
});
|
||||
|
||||
if !storage_changes.is_empty()
|
||||
|| !balance_changes.is_empty()
|
||||
|| !code_changes.is_empty()
|
||||
if !storage_changes.is_empty() ||
|
||||
!balance_changes.is_empty() ||
|
||||
!code_changes.is_empty()
|
||||
{
|
||||
transaction_contract_changes
|
||||
.entry(block_tx.index.into())
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//! Contains a mock store for internal testing.
|
||||
//!
|
||||
//! Might make this public alter to users can test their store handlers.
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use substreams::prelude::{BigInt, StoreDelete, StoreGet, StoreNew};
|
||||
use substreams::store::StoreAdd;
|
||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||
use substreams::{
|
||||
prelude::{BigInt, StoreDelete, StoreGet, StoreNew},
|
||||
store::StoreAdd,
|
||||
};
|
||||
|
||||
type BigIntStore = HashMap<String, Vec<(u64, BigInt)>>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user