Filter out failed transactions

this fixes #301
This commit is contained in:
zhangcan 2022-05-25 15:46:49 +08:00
parent 3c9fe3dca9
commit bda20447a1
3 changed files with 18 additions and 0 deletions

View File

@ -35,6 +35,19 @@ async def create_from_block_number(
_find_or_fetch_base_fee_per_gas(w3, block_number, trace_db_session), _find_or_fetch_base_fee_per_gas(w3, block_number, trace_db_session),
) )
# filter out failed transactions
failed_transactions = set(
receipt.transaction_hash for receipt in receipts if receipt.status == 0
)
receipts = [
receipt
for receipt in receipts
if receipt.transaction_hash not in failed_transactions
]
traces = [
trace for trace in traces if trace.transaction_hash not in failed_transactions
]
miner_address = _get_miner_address_from_traces(traces) miner_address = _get_miner_address_from_traces(traces)
return Block( return Block(

View File

@ -15,6 +15,7 @@ class Receipt(CamelModel):
effective_gas_price: int effective_gas_price: int
cumulative_gas_used: int cumulative_gas_used: int
to: Optional[str] to: Optional[str]
status: int
@validator( @validator(
"block_number", "block_number",
@ -22,6 +23,7 @@ class Receipt(CamelModel):
"gas_used", "gas_used",
"effective_gas_price", "effective_gas_price",
"cumulative_gas_used", "cumulative_gas_used",
"status",
pre=True, pre=True,
) )
def maybe_hex_to_int(v): def maybe_hex_to_int(v):

View File

@ -23,6 +23,9 @@ def load_test_block(block_number: int) -> Block:
with open(block_path, "r") as block_file: with open(block_path, "r") as block_file:
block_json = json.load(block_file) block_json = json.load(block_file)
for item in block_json["receipts"]:
if "status" not in item:
item["status"] = "0x1"
return Block( return Block(
**{ **{
**defaults, **defaults,