cfx_execute_helper/
tx_outcome.rs1use cfx_executor::{
2 executive::ExecutionOutcome, internal_contract::make_staking_events,
3};
4use cfx_types::{H256, U256};
5use cfx_vm_types::Spec;
6use pow_types::StakingEvent;
7use primitives::Receipt;
8
9use alloy_rpc_types_trace::geth::GethTrace;
10use geth_tracer::GethTraceKey;
11
12use super::{
13 observer::exec_tracer::{ExecTrace, ExecTraceKey},
14 phantom_tx::{recover_phantom, PhantomTransaction},
15};
16
17pub struct ProcessTxOutcome {
18 pub receipt: Receipt,
19 pub phantom_txs: Vec<PhantomTransaction>,
20 pub tx_traces: Vec<ExecTrace>,
21 pub tx_staking_events: Vec<StakingEvent>,
22 pub tx_exec_error_msg: String,
23 pub consider_repacked: bool,
24 pub geth_trace: Option<GethTrace>,
25}
26
27fn parity_traces(outcome: &ExecutionOutcome) -> Vec<ExecTrace> {
28 outcome
29 .try_as_executed()
30 .and_then(|executed| executed.ext_result.get::<ExecTraceKey>().cloned())
31 .unwrap_or_default()
32}
33
34fn geth_traces(outcome: &ExecutionOutcome) -> Option<GethTrace> {
35 outcome
36 .try_as_executed()
37 .and_then(|executed| executed.ext_result.get::<GethTraceKey>().cloned())
38}
39
40pub fn make_process_tx_outcome(
41 outcome: ExecutionOutcome, accumulated_gas_used: &mut U256, tx_hash: H256,
42 spec: &Spec,
43) -> ProcessTxOutcome {
44 let tx_traces = parity_traces(&outcome);
45 let geth_trace = geth_traces(&outcome);
46 let tx_exec_error_msg = outcome.error_message();
47 let consider_repacked = outcome.consider_repacked();
48 let receipt = outcome.make_receipt(accumulated_gas_used, spec);
49
50 let tx_staking_events = make_staking_events(receipt.logs());
51
52 let phantom_txs = recover_phantom(&receipt.logs(), tx_hash);
53
54 ProcessTxOutcome {
55 receipt,
56 phantom_txs,
57 tx_traces,
58 tx_staking_events,
59 tx_exec_error_msg,
60 consider_repacked,
61 geth_trace,
62 }
63}