Run grouped by transaction
This commit is contained in:
parent
0b74331235
commit
f4bba7c885
@ -1,32 +1,34 @@
|
||||
from typing import Dict, List
|
||||
from typing import List
|
||||
|
||||
from mev_inspect.schemas.classified_traces import ClassifiedTrace
|
||||
from mev_inspect.schemas.miner_payments import MinerPayment
|
||||
from mev_inspect.traces import get_traces_by_transaction_hash
|
||||
from mev_inspect.transfers import (
|
||||
get_eth_transfers,
|
||||
filter_transfers,
|
||||
get_eth_transfers,
|
||||
)
|
||||
|
||||
|
||||
def get_miner_payments(
|
||||
miner_address: str, traces: List[ClassifiedTrace]
|
||||
) -> List[MinerPayment]:
|
||||
eth_transfers = get_eth_transfers(traces)
|
||||
miner_eth_transfers = filter_transfers(
|
||||
eth_transfers, to_address=miner_address.lower()
|
||||
)
|
||||
miner_payments = []
|
||||
|
||||
eth_by_transaction: Dict[str, int] = {}
|
||||
for transfer in miner_eth_transfers:
|
||||
existing_amount = eth_by_transaction.get(transfer.transaction_hash, 0)
|
||||
eth_by_transaction[transfer.transaction_hash] = (
|
||||
existing_amount + transfer.amount
|
||||
for transaction_hash, transaciton_traces in get_traces_by_transaction_hash(traces):
|
||||
eth_transfers = get_eth_transfers(list(transaciton_traces))
|
||||
miner_eth_transfers = filter_transfers(
|
||||
eth_transfers, to_address=miner_address.lower()
|
||||
)
|
||||
total_eth_transfer_payment = sum(
|
||||
transfer.amount for transfer in miner_eth_transfers
|
||||
)
|
||||
|
||||
return [
|
||||
MinerPayment(
|
||||
transaction_hash=transaction_hash,
|
||||
total_eth_transfer_payment=eth_amount,
|
||||
)
|
||||
for transaction_hash, eth_amount in eth_by_transaction.items()
|
||||
]
|
||||
if total_eth_transfer_payment > 0:
|
||||
miner_payments.append(
|
||||
MinerPayment(
|
||||
transaction_hash=transaction_hash,
|
||||
total_eth_transfer_payment=total_eth_transfer_payment,
|
||||
)
|
||||
)
|
||||
|
||||
return miner_payments
|
||||
|
@ -1,3 +1,4 @@
|
||||
from itertools import groupby
|
||||
from typing import List
|
||||
|
||||
from mev_inspect.schemas.classified_traces import ClassifiedTrace
|
||||
@ -31,3 +32,10 @@ def get_child_traces(
|
||||
child_traces.append(trace)
|
||||
|
||||
return child_traces
|
||||
|
||||
|
||||
def get_traces_by_transaction_hash(
|
||||
traces: List[ClassifiedTrace],
|
||||
) -> groupby[str, ClassifiedTrace]:
|
||||
get_transaction_hash = lambda trace: trace.transaction_hash
|
||||
return groupby(sorted(traces, key=get_transaction_hash), key=get_transaction_hash)
|
||||
|
Loading…
x
Reference in New Issue
Block a user