pub struct TransferInspector {
pub transfers: Vec<TokenTransfer>,
pub logs: Vec<Log>,
}Expand description
Inspector that captures ERC20 Transfer events during EVM execution.
Attach to a simulation and the Inspector::log hook records every emitted
log; logs matching the ERC20 Transfer layout are additionally decoded into
TokenTransfers. Reconstruct net balance changes afterward with
balance_deltas or
balance_deltas_for_tokens, and reuse the
inspector across calls via clear.
Fields§
§transfers: Vec<TokenTransfer>Token transfers decoded from captured logs.
logs: Vec<Log>Every log emitted during execution, retained for debugging/analysis.
Implementations§
Source§impl TransferInspector
impl TransferInspector
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty inspector with no captured transfers or logs.
use evm_fork_cache::inspector::TransferInspector;
let inspector = TransferInspector::new();
assert!(inspector.transfers.is_empty());
assert!(inspector.logs.is_empty());Sourcepub fn balance_deltas(&self, owner: Address) -> HashMap<Address, I256>
pub fn balance_deltas(&self, owner: Address) -> HashMap<Address, I256>
Compute balance deltas for a specific owner from captured transfers
Returns a map of token address -> signed balance change Positive values indicate tokens received, negative indicates tokens sent
Sourcepub fn balance_deltas_for_tokens(
&self,
owner: Address,
tokens: impl IntoIterator<Item = Address>,
) -> HashMap<Address, I256>
pub fn balance_deltas_for_tokens( &self, owner: Address, tokens: impl IntoIterator<Item = Address>, ) -> HashMap<Address, I256>
Like balance_deltas, but restricted to the
given set of token addresses.
Tokens in tokens with no transfers touching owner are simply absent
from the result; tokens not in tokens are excluded even if owner
transacted in them.
let mut inspector = TransferInspector::new();
let token_a = Address::repeat_byte(0xAA);
let token_b = Address::repeat_byte(0xBB);
let owner = Address::repeat_byte(0x11);
let other = Address::repeat_byte(0x22);
inspector.transfers.push(TokenTransfer { token: token_a, from: owner, to: other, value: U256::from(100u64) });
inspector.transfers.push(TokenTransfer { token: token_b, from: other, to: owner, value: U256::from(50u64) });
let deltas = inspector.balance_deltas_for_tokens(owner, [token_a]);
assert_eq!(deltas.len(), 1);
assert_eq!(deltas.get(&token_a), Some(&(-I256::from_raw(U256::from(100u64)))));
assert!(!deltas.contains_key(&token_b));Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drop all captured transfers and logs so the inspector can be reused across simulations.
Sourcepub fn parse_transfer(log: &Log) -> Option<TokenTransfer>
pub fn parse_transfer(log: &Log) -> Option<TokenTransfer>
Parse a Transfer event from log topics and data
Trait Implementations§
Source§impl Clone for TransferInspector
impl Clone for TransferInspector
Source§fn clone(&self) -> TransferInspector
fn clone(&self) -> TransferInspector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TransferInspector
impl Debug for TransferInspector
Source§impl Default for TransferInspector
impl Default for TransferInspector
Source§fn default() -> TransferInspector
fn default() -> TransferInspector
Source§impl<CTX, INTR> Inspector<CTX, INTR> for TransferInspectorwhere
INTR: InterpreterTypes,
Captures every emitted log via the Inspector::log hook.
impl<CTX, INTR> Inspector<CTX, INTR> for TransferInspectorwhere
INTR: InterpreterTypes,
Captures every emitted log via the Inspector::log hook.
Each log is pushed to logs; logs whose first
topic matches the ERC20 Transfer signature and that carry the standard ERC20
layout are additionally decoded into transfers.
Logs that do not match (wrong signature, fewer than three topics, or fewer
than 32 data bytes) are retained in logs but produce no transfer.
Source§fn log(&mut self, _context: &mut CTX, log: Log)
fn log(&mut self, _context: &mut CTX, log: Log)
Records log and, if it parses as an ERC20 Transfer, the decoded transfer.
Source§fn initialize_interp(
&mut self,
interp: &mut Interpreter<INTR>,
context: &mut CTX,
)
fn initialize_interp( &mut self, interp: &mut Interpreter<INTR>, context: &mut CTX, )
Source§fn step(&mut self, interp: &mut Interpreter<INTR>, context: &mut CTX)
fn step(&mut self, interp: &mut Interpreter<INTR>, context: &mut CTX)
Source§fn step_end(&mut self, interp: &mut Interpreter<INTR>, context: &mut CTX)
fn step_end(&mut self, interp: &mut Interpreter<INTR>, context: &mut CTX)
step when the instruction has been executed. Read moreSource§fn log_full(
&mut self,
interpreter: &mut Interpreter<INTR>,
context: &mut CTX,
log: Log,
)
fn log_full( &mut self, interpreter: &mut Interpreter<INTR>, context: &mut CTX, log: Log, )
Source§fn call(
&mut self,
context: &mut CTX,
inputs: &mut CallInputs,
) -> Option<CallOutcome>
fn call( &mut self, context: &mut CTX, inputs: &mut CallInputs, ) -> Option<CallOutcome>
Source§fn call_end(
&mut self,
context: &mut CTX,
inputs: &CallInputs,
outcome: &mut CallOutcome,
)
fn call_end( &mut self, context: &mut CTX, inputs: &CallInputs, outcome: &mut CallOutcome, )
Source§fn create(
&mut self,
context: &mut CTX,
inputs: &mut CreateInputs,
) -> Option<CreateOutcome>
fn create( &mut self, context: &mut CTX, inputs: &mut CreateInputs, ) -> Option<CreateOutcome>
Source§fn create_end(
&mut self,
context: &mut CTX,
inputs: &CreateInputs,
outcome: &mut CreateOutcome,
)
fn create_end( &mut self, context: &mut CTX, inputs: &CreateInputs, outcome: &mut CreateOutcome, )
Auto Trait Implementations§
impl Freeze for TransferInspector
impl RefUnwindSafe for TransferInspector
impl Send for TransferInspector
impl Sync for TransferInspector
impl Unpin for TransferInspector
impl UnsafeUnpin for TransferInspector
impl UnwindSafe for TransferInspector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.