@@ -45,6 +45,10 @@ const (
4545
4646 maxTraceConcurrency = int64 (16 ) // nolint:gomnd
4747 semaphoreTraceWeight = int64 (1 ) // nolint:gomnd
48+
49+ // eip1559TxType is the EthTypes.Transaction.Type() value that indicates this transaction
50+ // follows EIP-1559.
51+ eip1559TxType = 2
4852)
4953
5054// Client allows for querying a set of specific Ethereum endpoints in an
@@ -367,12 +371,19 @@ func (ec *Client) getBlock(
367371 for i , tx := range body .Transactions {
368372 txs [i ] = tx .tx
369373 receipt := receipts [i ]
370- gasUsedBig := new (big.Int ).SetUint64 (receipt .GasUsed )
371- feeAmount := gasUsedBig .Mul (gasUsedBig , txs [i ].GasPrice ())
372-
374+ gasUsed := new (big.Int ).SetUint64 (receipt .GasUsed )
375+ gasPrice , err := effectiveGasPrice (txs [i ], head .BaseFee )
376+ if err != nil {
377+ return nil , nil , fmt .Errorf ("%w: failure getting effective gas price" , err )
378+ }
373379 loadedTxs [i ] = tx .LoadedTransaction ()
374380 loadedTxs [i ].Transaction = txs [i ]
375- loadedTxs [i ].FeeAmount = feeAmount
381+ loadedTxs [i ].FeeAmount = new (big.Int ).Mul (gasUsed , gasPrice )
382+ if head .BaseFee != nil { // EIP-1559
383+ loadedTxs [i ].FeeBurned = new (big.Int ).Mul (gasUsed , head .BaseFee )
384+ } else {
385+ loadedTxs [i ].FeeBurned = nil
386+ }
376387 loadedTxs [i ].Miner = MustChecksum (head .Coinbase .Hex ())
377388 loadedTxs [i ].Receipt = receipt
378389
@@ -388,6 +399,21 @@ func (ec *Client) getBlock(
388399 return types .NewBlockWithHeader (& head ).WithBody (txs , uncles ), loadedTxs , nil
389400}
390401
402+ // effectiveGasPrice returns the price of gas charged to this transaction to be included in the
403+ // block.
404+ func effectiveGasPrice (tx * EthTypes.Transaction , baseFee * big.Int ) (* big.Int , error ) {
405+ if tx .Type () != eip1559TxType {
406+ return tx .GasPrice (), nil
407+ }
408+ // For EIP-1559 the gas price is determined by the base fee & miner tip instead
409+ // of the tx-specified gas price.
410+ tip , err := tx .EffectiveGasTip (baseFee )
411+ if err != nil {
412+ return nil , err
413+ }
414+ return new (big.Int ).Add (tip , baseFee ), nil
415+ }
416+
391417func (ec * Client ) getBlockTraces (
392418 ctx context.Context ,
393419 blockHash common.Hash ,
@@ -754,6 +780,7 @@ type loadedTransaction struct {
754780 BlockNumber * string
755781 BlockHash * common.Hash
756782 FeeAmount * big.Int
783+ FeeBurned * big.Int // nil if no fees were burned
757784 Miner string
758785 Status bool
759786
@@ -763,7 +790,13 @@ type loadedTransaction struct {
763790}
764791
765792func feeOps (tx * loadedTransaction ) []* RosettaTypes.Operation {
766- return []* RosettaTypes.Operation {
793+ var minerEarnedAmount * big.Int
794+ if tx .FeeBurned == nil {
795+ minerEarnedAmount = tx .FeeAmount
796+ } else {
797+ minerEarnedAmount = new (big.Int ).Sub (tx .FeeAmount , tx .FeeBurned )
798+ }
799+ ops := []* RosettaTypes.Operation {
767800 {
768801 OperationIdentifier : & RosettaTypes.OperationIdentifier {
769802 Index : 0 ,
@@ -774,7 +807,7 @@ func feeOps(tx *loadedTransaction) []*RosettaTypes.Operation {
774807 Address : MustChecksum (tx .From .String ()),
775808 },
776809 Amount : & RosettaTypes.Amount {
777- Value : new (big.Int ).Neg (tx . FeeAmount ).String (),
810+ Value : new (big.Int ).Neg (minerEarnedAmount ).String (),
778811 Currency : Currency ,
779812 },
780813 },
@@ -794,11 +827,29 @@ func feeOps(tx *loadedTransaction) []*RosettaTypes.Operation {
794827 Address : MustChecksum (tx .Miner ),
795828 },
796829 Amount : & RosettaTypes.Amount {
797- Value : tx . FeeAmount .String (),
830+ Value : minerEarnedAmount .String (),
798831 Currency : Currency ,
799832 },
800833 },
801834 }
835+ if tx .FeeBurned == nil {
836+ return ops
837+ }
838+ burntOp := & RosettaTypes.Operation {
839+ OperationIdentifier : & RosettaTypes.OperationIdentifier {
840+ Index : 2 ,
841+ },
842+ Type : FeeOpType ,
843+ Status : RosettaTypes .String (SuccessStatus ),
844+ Account : & RosettaTypes.AccountIdentifier {
845+ Address : MustChecksum (tx .From .String ()),
846+ },
847+ Amount : & RosettaTypes.Amount {
848+ Value : new (big.Int ).Neg (tx .FeeBurned ).String (),
849+ Currency : Currency ,
850+ },
851+ }
852+ return append (ops , burntOp )
802853}
803854
804855// transactionReceipt returns the receipt of a transaction by transaction hash.
0 commit comments