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)
}
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
#![allow(clippy::all)]
pub mod yearn_linear_pool_factory;
pub mod composable_stable_pool_factory;
pub mod vault;
pub mod weighted_pool_tokens_factory;
pub mod silo_linear_pool_factory;
pub mod euler_linear_pool_factory;
pub mod weighted_pool_factory;
pub mod managed_pool_factory;
pub mod erc_linear_pool_factory;
pub mod euler_linear_pool_factory;
pub mod gearbox_linear_pool_factory;
pub mod managed_pool_factory;
pub mod silo_linear_pool_factory;
pub mod vault;
pub mod weighted_pool_factory;
pub mod weighted_pool_tokens_factory;
pub mod yearn_linear_pool_factory;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -176,14 +176,17 @@ pub fn map_protocol_changes(
.or_insert_with(|| TransactionChangesBuilder::new(tx));
// iterate over individual components created within this tx
tx_component.components.iter().for_each(|component| {
builder.add_protocol_component(component);
let entity_change = EntityChanges {
component_id: component.id.clone(),
attributes: default_attributes.clone(),
};
builder.add_entity_change(&entity_change)
});
tx_component
.components
.iter()
.for_each(|component| {
builder.add_protocol_component(component);
let entity_change = EntityChanges {
component_id: component.id.clone(),
attributes: default_attributes.clone(),
};
builder.add_entity_change(&entity_change)
});
});
// Balance changes are gathered by the `StoreDelta` based on `PoolBalanceChanged` creating
@@ -196,7 +199,9 @@ pub fn map_protocol_changes(
let builder = transaction_changes
.entry(tx.index)
.or_insert_with(|| TransactionChangesBuilder::new(&tx));
balances.values().for_each(|bc| builder.add_balance_change(bc));
balances
.values()
.for_each(|bc| builder.add_balance_change(bc));
});
// Extract and insert any storage changes that happened for any of the components.
@@ -211,16 +216,23 @@ pub fn map_protocol_changes(
&mut transaction_changes,
);
transaction_changes.iter_mut().for_each(|(_, change)| {
// this indirection is necessary due to borrowing rules.
let addresses = change.changed_contracts().map(|e| e.to_vec()).collect::<Vec<_>>();
addresses.into_iter().for_each(|address| {
if address != VAULT_ADDRESS {
// We reconstruct the component_id from the address here
change.mark_component_as_updated(&format!("0x{}", hex::encode(address)))
}
})
});
transaction_changes
.iter_mut()
.for_each(|(_, change)| {
// this indirection is necessary due to borrowing rules.
let addresses = change
.changed_contracts()
.map(|e| e.to_vec())
.collect::<Vec<_>>();
addresses
.into_iter()
.for_each(|address| {
if address != VAULT_ADDRESS {
// We reconstruct the component_id from the address here
change.mark_component_as_updated(&format!("0x{}", hex::encode(address)))
}
})
});
// Process all `transaction_changes` for final output in the `BlockChanges`,
// sorted by transaction index (the key).
@@ -229,9 +241,7 @@ pub fn map_protocol_changes(
changes: transaction_changes
.drain()
.sorted_unstable_by_key(|(index, _)| *index)
.filter_map(|(_, builder)| {
builder.build()
})
.filter_map(|(_, builder)| builder.build())
.collect::<Vec<_>>(),
})
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -929,8 +929,8 @@ pub mod events {
.topics
.get(0)
.expect("bounds already checked")
.as_ref() ==
Self::TOPIC_ID;
.as_ref()
== Self::TOPIC_ID;
}
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
let mut values =
@@ -1009,8 +1009,8 @@ pub mod events {
.topics
.get(0)
.expect("bounds already checked")
.as_ref() ==
Self::TOPIC_ID;
.as_ref()
== Self::TOPIC_ID;
}
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
let mut values =

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
#![allow(clippy::all)]
pub mod crypto_pool_factory;
pub mod stableswap_factory;
pub mod crypto_swap_ng_factory;
pub mod meta_registry;
pub mod tricrypto_factory;
pub mod twocrypto_factory;
pub mod erc20;
pub mod meta_pool_factory;
pub mod meta_registry;
pub mod stableswap_factory;
pub mod tricrypto_factory;
pub mod twocrypto_factory;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff