From 6f593002d4b38d809fe5848dd35d0bb9d7446867 Mon Sep 17 00:00:00 2001 From: Dat Luong Date: Tue, 12 Mar 2024 14:47:06 +0700 Subject: [PATCH 1/2] feat: add common type for pending tx usage --- pkg/types/pendingtx.go | 89 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 pkg/types/pendingtx.go diff --git a/pkg/types/pendingtx.go b/pkg/types/pendingtx.go new file mode 100644 index 0000000..efb59cb --- /dev/null +++ b/pkg/types/pendingtx.go @@ -0,0 +1,89 @@ +package types + +import ( + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" +) + +type PendingTxSource string + +const ( + PendingTxBloxroute PendingTxSource = "bloxroute" + PendingTxFlashbots PendingTxSource = "flashbots" + PendingTxBeaverBuild PendingTxSource = "beaverbuild" + PendingTxRsyncBuilder PendingTxSource = "rsync-builder" + PendingTxTitan PendingTxSource = "titan" + PendingTxPublicRPC PendingTxSource = "public-rpc" +) + +type Message struct { + PendingBlockNumber uint64 `json:"pending_block_number"` + TxHash string `json:"tx_hash"` + SimDebugInfo SimDebugInfo `json:"sim_debug_info"` + InternalTx *CallFrame `json:"internal_txs"` + BaseFee *big.Int `json:"base_fee"` + CurrentBlockTime uint64 `json:"current_block_time"` + GasFeeCap *big.Int `json:"gas_fee_cap"` + GasPrice *big.Int `json:"gas_price"` + GasTip *big.Int `json:"gas_tip"` + Gas uint64 `json:"gas"` + GasUsed uint64 `json:"gas_used"` + From string `json:"from"` + Nonce uint64 `json:"nonce"` +} + +type SimDebugInfo struct { + E2EMs int64 `json:"e2e_ms"` + DetectTimeMs int64 `json:"detect_time_ms"` + StartTraceTimeMs int64 `json:"start_trace_time_ms"` + EndTraceTimeMs int64 `json:"end_trace_time_ms"` + StartSimulationTimeMs int64 `json:"start_simulation_time_ms"` + EndSimulationTimeMs int64 `json:"end_simulation_time_ms"` +} + +type CallFrame struct { + Type vm.OpCode `json:"-"` + From common.Address `json:"from"` + Gas uint64 `json:"gas"` + GasUsed uint64 `json:"gasUsed"` + To *common.Address `json:"to,omitempty" ` + Input []byte `json:"input"` + Output []byte `json:"output,omitempty"` + Error string `json:"error,omitempty"` + RevertReason string `json:"revertReason,omitempty"` + Calls []*CallFrame `json:"calls,omitempty"` + Logs []*types.Log `json:"logs,omitempty"` + // Placed at end on purpose. The RLP will be decoded to 0 instead of + // nil if there are non-empty elements after in the struct. + Value *big.Int `json:"value,omitempty"` + + // contract call fields + ContractCall *ContractCall `json:"contract_call,omitempty"` +} + +type ContractCallParam struct { + Name string `json:"name"` + Value interface{} `json:"value"` + Type string `json:"type"` +} + +type ContractCall struct { + ContractType string `json:"contract_type,omitempty"` + Name string `json:"name"` + Params []ContractCallParam `json:"params"` +} + +type Transaction struct { + From common.Address `json:"from"` + Nonce uint64 `json:"nonce"` +} + +type MinedBlock struct { + BlockNumber int64 `json:"block_number"` + BlockHash string `json:"block_hash"` + BlockTime int64 `json:"block_time"` + Transactions []Transaction `json:"transactions"` +} From d9f1d3fa6c9e14f2a214bc8356a6b45c78a82bd2 Mon Sep 17 00:00:00 2001 From: Dat Luong Date: Tue, 12 Mar 2024 14:54:23 +0700 Subject: [PATCH 2/2] chore: fix lint --- pkg/types/pendingtx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/types/pendingtx.go b/pkg/types/pendingtx.go index efb59cb..348e04a 100644 --- a/pkg/types/pendingtx.go +++ b/pkg/types/pendingtx.go @@ -49,7 +49,7 @@ type CallFrame struct { From common.Address `json:"from"` Gas uint64 `json:"gas"` GasUsed uint64 `json:"gasUsed"` - To *common.Address `json:"to,omitempty" ` + To *common.Address `json:"to,omitempty"` Input []byte `json:"input"` Output []byte `json:"output,omitempty"` Error string `json:"error,omitempty"`