chore: code formatting

This commit is contained in:
kayibal
2024-07-22 23:06:05 +01:00
parent 148fac276c
commit f5b4c54a99
26 changed files with 49427 additions and 56933 deletions

View File

@@ -13,7 +13,6 @@ pub fn json_serialize_value<T: serde::Serialize + Debug>(v: T) -> Vec<u8> {
.to_vec()
}
/// Encodes a list of addresses (in byte representation) into json.
///
/// Converts each address to a 0x prefixed hex string and then serializes
@@ -30,7 +29,6 @@ pub fn json_serialize_address_list(addresses: &[Vec<u8>]) -> Vec<u8> {
)
}
/// Encodes a list of BigInt values into json.
///
/// Converts each integer to a 0x prefixed hex string and then serializes

View File

@@ -10,13 +10,14 @@
/// more [here](https://streamingfastio.medium.com/new-block-model-to-accelerate-chain-integration-9f65126e5425)
use std::collections::HashMap;
use crate::{
models::{InterimContractChange, TransactionChanges},
prelude::TransactionChangesBuilder,
};
use substreams_ethereum::pb::{
eth,
eth::v2::block::DetailLevel, eth::v2::CallType
eth::v2::{block::DetailLevel, TransactionTrace, CallType},
};
use substreams_ethereum::pb::eth::v2::TransactionTrace;
use crate::models::{InterimContractChange, TransactionChanges};
use crate::prelude::TransactionChangesBuilder;
/// Extracts and aggregates contract changes from a block.
///
@@ -49,46 +50,40 @@ pub fn extract_contract_changes<F: Fn(&[u8]) -> bool>(
inclusion_predicate: F,
transaction_changes: &mut HashMap<u64, TransactionChanges>,
) {
extract_contract_changes_generic(
block,
inclusion_predicate,
|tx, changed_contracts| {
transaction_changes
.entry(tx.index.into())
.or_insert_with(|| TransactionChanges::new(&(tx.into())))
.contract_changes
.extend(
changed_contracts
.clone()
.into_values()
.map(|change| change.into()),
);
},
)
extract_contract_changes_generic(block, inclusion_predicate, |tx, changed_contracts| {
transaction_changes
.entry(tx.index.into())
.or_insert_with(|| TransactionChanges::new(&(tx.into())))
.contract_changes
.extend(
changed_contracts
.clone()
.into_values()
.map(|change| change.into()),
);
})
}
pub fn extract_contract_changes_builder<F: Fn(&[u8]) -> bool>(
block: &eth::v2::Block,
inclusion_predicate: F,
transaction_changes: &mut HashMap<u64, TransactionChangesBuilder>,
) {
extract_contract_changes_generic(
block,
inclusion_predicate,
|tx, changed_contracts| {
let builder = transaction_changes
.entry(tx.index.into())
.or_insert_with(|| TransactionChangesBuilder::new(&(tx.into())));
changed_contracts
.clone()
.into_iter()
.for_each(|(_, change)| builder.add_contract_changes(&change));
},
)
extract_contract_changes_generic(block, inclusion_predicate, |tx, changed_contracts| {
let builder = transaction_changes
.entry(tx.index.into())
.or_insert_with(|| TransactionChangesBuilder::new(&(tx.into())));
changed_contracts
.clone()
.into_iter()
.for_each(|(_, change)| builder.add_contract_changes(&change));
})
}
fn extract_contract_changes_generic<F: Fn(&[u8]) -> bool, G: FnMut(&TransactionTrace, &HashMap<Vec<u8>, InterimContractChange>)>(
fn extract_contract_changes_generic<
F: Fn(&[u8]) -> bool,
G: FnMut(&TransactionTrace, &HashMap<Vec<u8>, InterimContractChange>),
>(
block: &eth::v2::Block,
inclusion_predicate: F,
mut store_changes: G,

View File

@@ -1,10 +1,10 @@
mod abi;
pub mod attributes;
pub mod balances;
pub mod contract;
mod mock_store;
pub mod models;
mod pb;
pub mod attributes;
pub mod prelude {
pub use super::models::*;

View File

@@ -66,7 +66,7 @@ impl TransactionChangesBuilder {
}
/// Unique contract/account addresses that have been changed so far.
pub fn changed_contracts(&self) -> impl Iterator<Item=&[u8]> {
pub fn changed_contracts(&self) -> impl Iterator<Item = &[u8]> {
self.contract_changes
.keys()
.map(|k| k.as_slice())

View File

@@ -7,4 +7,4 @@ pub mod tycho {
// @@protoc_insertion_point(tycho.evm.v1)
}
}
}
}