chore: code formatting
This commit is contained in:
@@ -13,7 +13,6 @@ pub fn json_serialize_value<T: serde::Serialize + Debug>(v: T) -> Vec<u8> {
|
|||||||
.to_vec()
|
.to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Encodes a list of addresses (in byte representation) into json.
|
/// Encodes a list of addresses (in byte representation) into json.
|
||||||
///
|
///
|
||||||
/// Converts each address to a 0x prefixed hex string and then serializes
|
/// 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.
|
/// Encodes a list of BigInt values into json.
|
||||||
///
|
///
|
||||||
/// Converts each integer to a 0x prefixed hex string and then serializes
|
/// Converts each integer to a 0x prefixed hex string and then serializes
|
||||||
|
|||||||
@@ -10,13 +10,14 @@
|
|||||||
/// more [here](https://streamingfastio.medium.com/new-block-model-to-accelerate-chain-integration-9f65126e5425)
|
/// more [here](https://streamingfastio.medium.com/new-block-model-to-accelerate-chain-integration-9f65126e5425)
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
models::{InterimContractChange, TransactionChanges},
|
||||||
|
prelude::TransactionChangesBuilder,
|
||||||
|
};
|
||||||
use substreams_ethereum::pb::{
|
use substreams_ethereum::pb::{
|
||||||
eth,
|
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.
|
/// Extracts and aggregates contract changes from a block.
|
||||||
///
|
///
|
||||||
@@ -49,46 +50,40 @@ pub fn extract_contract_changes<F: Fn(&[u8]) -> bool>(
|
|||||||
inclusion_predicate: F,
|
inclusion_predicate: F,
|
||||||
transaction_changes: &mut HashMap<u64, TransactionChanges>,
|
transaction_changes: &mut HashMap<u64, TransactionChanges>,
|
||||||
) {
|
) {
|
||||||
extract_contract_changes_generic(
|
extract_contract_changes_generic(block, inclusion_predicate, |tx, changed_contracts| {
|
||||||
block,
|
transaction_changes
|
||||||
inclusion_predicate,
|
.entry(tx.index.into())
|
||||||
|tx, changed_contracts| {
|
.or_insert_with(|| TransactionChanges::new(&(tx.into())))
|
||||||
transaction_changes
|
.contract_changes
|
||||||
.entry(tx.index.into())
|
.extend(
|
||||||
.or_insert_with(|| TransactionChanges::new(&(tx.into())))
|
changed_contracts
|
||||||
.contract_changes
|
.clone()
|
||||||
.extend(
|
.into_values()
|
||||||
changed_contracts
|
.map(|change| change.into()),
|
||||||
.clone()
|
);
|
||||||
.into_values()
|
})
|
||||||
.map(|change| change.into()),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn extract_contract_changes_builder<F: Fn(&[u8]) -> bool>(
|
pub fn extract_contract_changes_builder<F: Fn(&[u8]) -> bool>(
|
||||||
block: ð::v2::Block,
|
block: ð::v2::Block,
|
||||||
inclusion_predicate: F,
|
inclusion_predicate: F,
|
||||||
transaction_changes: &mut HashMap<u64, TransactionChangesBuilder>,
|
transaction_changes: &mut HashMap<u64, TransactionChangesBuilder>,
|
||||||
) {
|
) {
|
||||||
extract_contract_changes_generic(
|
extract_contract_changes_generic(block, inclusion_predicate, |tx, changed_contracts| {
|
||||||
block,
|
let builder = transaction_changes
|
||||||
inclusion_predicate,
|
.entry(tx.index.into())
|
||||||
|tx, changed_contracts| {
|
.or_insert_with(|| TransactionChangesBuilder::new(&(tx.into())));
|
||||||
let builder = transaction_changes
|
changed_contracts
|
||||||
.entry(tx.index.into())
|
.clone()
|
||||||
.or_insert_with(|| TransactionChangesBuilder::new(&(tx.into())));
|
.into_iter()
|
||||||
changed_contracts
|
.for_each(|(_, change)| builder.add_contract_changes(&change));
|
||||||
.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: ð::v2::Block,
|
block: ð::v2::Block,
|
||||||
inclusion_predicate: F,
|
inclusion_predicate: F,
|
||||||
mut store_changes: G,
|
mut store_changes: G,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
mod abi;
|
mod abi;
|
||||||
|
pub mod attributes;
|
||||||
pub mod balances;
|
pub mod balances;
|
||||||
pub mod contract;
|
pub mod contract;
|
||||||
mod mock_store;
|
mod mock_store;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
mod pb;
|
mod pb;
|
||||||
pub mod attributes;
|
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use super::models::*;
|
pub use super::models::*;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ impl TransactionChangesBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Unique contract/account addresses that have been changed so far.
|
/// 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
|
self.contract_changes
|
||||||
.keys()
|
.keys()
|
||||||
.map(|k| k.as_slice())
|
.map(|k| k.as_slice())
|
||||||
|
|||||||
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
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,11 @@
|
|||||||
#![allow(clippy::all)]
|
#![allow(clippy::all)]
|
||||||
pub mod yearn_linear_pool_factory;
|
|
||||||
pub mod composable_stable_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 erc_linear_pool_factory;
|
||||||
|
pub mod euler_linear_pool_factory;
|
||||||
pub mod gearbox_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
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
@@ -176,14 +176,17 @@ pub fn map_protocol_changes(
|
|||||||
.or_insert_with(|| TransactionChangesBuilder::new(tx));
|
.or_insert_with(|| TransactionChangesBuilder::new(tx));
|
||||||
|
|
||||||
// iterate over individual components created within this tx
|
// iterate over individual components created within this tx
|
||||||
tx_component.components.iter().for_each(|component| {
|
tx_component
|
||||||
builder.add_protocol_component(component);
|
.components
|
||||||
let entity_change = EntityChanges {
|
.iter()
|
||||||
component_id: component.id.clone(),
|
.for_each(|component| {
|
||||||
attributes: default_attributes.clone(),
|
builder.add_protocol_component(component);
|
||||||
};
|
let entity_change = EntityChanges {
|
||||||
builder.add_entity_change(&entity_change)
|
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
|
// Balance changes are gathered by the `StoreDelta` based on `PoolBalanceChanged` creating
|
||||||
@@ -196,7 +199,9 @@ pub fn map_protocol_changes(
|
|||||||
let builder = transaction_changes
|
let builder = transaction_changes
|
||||||
.entry(tx.index)
|
.entry(tx.index)
|
||||||
.or_insert_with(|| TransactionChangesBuilder::new(&tx));
|
.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.
|
// 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,
|
&mut transaction_changes,
|
||||||
);
|
);
|
||||||
|
|
||||||
transaction_changes.iter_mut().for_each(|(_, change)| {
|
transaction_changes
|
||||||
// this indirection is necessary due to borrowing rules.
|
.iter_mut()
|
||||||
let addresses = change.changed_contracts().map(|e| e.to_vec()).collect::<Vec<_>>();
|
.for_each(|(_, change)| {
|
||||||
addresses.into_iter().for_each(|address| {
|
// this indirection is necessary due to borrowing rules.
|
||||||
if address != VAULT_ADDRESS {
|
let addresses = change
|
||||||
// We reconstruct the component_id from the address here
|
.changed_contracts()
|
||||||
change.mark_component_as_updated(&format!("0x{}", hex::encode(address)))
|
.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`,
|
// Process all `transaction_changes` for final output in the `BlockChanges`,
|
||||||
// sorted by transaction index (the key).
|
// sorted by transaction index (the key).
|
||||||
@@ -229,9 +241,7 @@ pub fn map_protocol_changes(
|
|||||||
changes: transaction_changes
|
changes: transaction_changes
|
||||||
.drain()
|
.drain()
|
||||||
.sorted_unstable_by_key(|(index, _)| *index)
|
.sorted_unstable_by_key(|(index, _)| *index)
|
||||||
.filter_map(|(_, builder)| {
|
.filter_map(|(_, builder)| builder.build())
|
||||||
builder.build()
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -929,8 +929,8 @@ pub mod events {
|
|||||||
.topics
|
.topics
|
||||||
.get(0)
|
.get(0)
|
||||||
.expect("bounds already checked")
|
.expect("bounds already checked")
|
||||||
.as_ref() ==
|
.as_ref()
|
||||||
Self::TOPIC_ID;
|
== Self::TOPIC_ID;
|
||||||
}
|
}
|
||||||
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
|
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
|
||||||
let mut values =
|
let mut values =
|
||||||
@@ -1009,8 +1009,8 @@ pub mod events {
|
|||||||
.topics
|
.topics
|
||||||
.get(0)
|
.get(0)
|
||||||
.expect("bounds already checked")
|
.expect("bounds already checked")
|
||||||
.as_ref() ==
|
.as_ref()
|
||||||
Self::TOPIC_ID;
|
== Self::TOPIC_ID;
|
||||||
}
|
}
|
||||||
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
|
pub fn decode(log: &substreams_ethereum::pb::eth::v2::Log) -> Result<Self, String> {
|
||||||
let mut values =
|
let mut values =
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
|||||||
#![allow(clippy::all)]
|
#![allow(clippy::all)]
|
||||||
pub mod crypto_pool_factory;
|
pub mod crypto_pool_factory;
|
||||||
pub mod stableswap_factory;
|
|
||||||
pub mod crypto_swap_ng_factory;
|
pub mod crypto_swap_ng_factory;
|
||||||
pub mod meta_registry;
|
|
||||||
pub mod tricrypto_factory;
|
|
||||||
pub mod twocrypto_factory;
|
|
||||||
pub mod erc20;
|
pub mod erc20;
|
||||||
pub mod meta_pool_factory;
|
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
Reference in New Issue
Block a user