@@ -21,6 +21,8 @@ import (
21
21
"github.com/ledgerwatch/erigon/eth/ethutils"
22
22
23
23
"github.com/ledgerwatch/erigon/consensus"
24
+ "github.com/ledgerwatch/erigon/consensus/ethash"
25
+ "github.com/ledgerwatch/erigon/consensus/misc"
24
26
"github.com/ledgerwatch/erigon/core"
25
27
"github.com/ledgerwatch/erigon/core/rawdb"
26
28
"github.com/ledgerwatch/erigon/core/state"
@@ -803,11 +805,15 @@ func (api *APIImpl) GetERCBlockReceipts(ctx context.Context, to rpc.BlockNumber,
803
805
804
806
blocks := make ([]map [string ]interface {}, 0 )
805
807
for ; start <= end ; start ++ {
806
- blockNum , _ , _ , err := rpchelper .GetBlockNumber (rpc .BlockNumberOrHashWithNumber (rpc .BlockNumber (start )), tx , api .filters )
808
+ var (
809
+ totalFees uint64
810
+ )
811
+
812
+ blockNum , hash , _ , err := rpchelper .GetBlockNumber (rpc .BlockNumberOrHashWithNumber (rpc .BlockNumber (start )), tx , api .filters )
807
813
if err != nil {
808
814
return nil , err
809
815
}
810
- block , err := api .blockByNumberWithSenders (ctx , tx , blockNum )
816
+ block , err := api .blockWithSenders (ctx , tx , hash , blockNum )
811
817
if err != nil {
812
818
return nil , err
813
819
}
@@ -831,6 +837,18 @@ func (api *APIImpl) GetERCBlockReceipts(ctx context.Context, to rpc.BlockNumber,
831
837
for _ , receipt := range receipts {
832
838
marhaledReciept := queryERCTransaction (engine , ctx , chainConfig , signer , rules , blockCtx , ibs , receipt , block )
833
839
result = append (result , marhaledReciept )
840
+
841
+ // Gas Fee Calculation
842
+ txn := block .Transactions ()[receipt .TransactionIndex ]
843
+ effectiveGasPrice := uint64 (0 )
844
+ if ! chainConfig .IsLondon (block .NumberU64 ()) {
845
+ effectiveGasPrice = txn .GetPrice ().Uint64 ()
846
+ } else {
847
+ baseFee , _ := uint256 .FromBig (block .BaseFee ())
848
+ gasPrice := new (big.Int ).Add (block .BaseFee (), txn .GetEffectiveGasTip (baseFee ).ToBig ())
849
+ effectiveGasPrice = gasPrice .Uint64 ()
850
+ }
851
+ totalFees += effectiveGasPrice * receipt .GasUsed
834
852
}
835
853
836
854
if chainConfig .Bor != nil {
@@ -846,17 +864,52 @@ func (api *APIImpl) GetERCBlockReceipts(ctx context.Context, to rpc.BlockNumber,
846
864
}
847
865
}
848
866
867
+ issuance , _ := api .delegateIssuance (tx , block , chainConfig )
868
+
849
869
blocks = append (blocks , map [string ]interface {}{
850
870
"number" : block .Number ().Int64 (),
851
871
"timestamp" : block .Time (),
852
872
"baseFeePerGas" : (* hexutil .Big )(block .BaseFee ()),
873
+ "gasUsed" : hexutil .Uint64 (block .GasUsed ()),
874
+ "miner" : block .Coinbase (),
875
+ "issuance" : issuance .Issuance ,
876
+ "totalFees" : hexutil .Uint64 (totalFees ),
853
877
"transactions" : result ,
854
878
})
855
879
}
856
880
857
881
return blocks , nil
858
882
}
859
883
884
+ func (api * APIImpl ) delegateIssuance (tx kv.Tx , block * types.Block , chainConfig * chain.Config ) (internalIssuance , error ) {
885
+ if chainConfig .Ethash == nil {
886
+ // Clique for example has no issuance
887
+ return internalIssuance {}, nil
888
+ }
889
+
890
+ if chainConfig .TerminalTotalDifficulty != nil {
891
+ isPos := block .HeaderNoCopy ().Difficulty .Cmp (common .Big0 ) == 0 || block .HeaderNoCopy ().Difficulty .Cmp (chainConfig .TerminalTotalDifficulty ) >= 0
892
+ if isPos {
893
+ // No execution layer issuance in PoS
894
+ return internalIssuance {}, nil
895
+ }
896
+ }
897
+
898
+ minerReward , uncleRewards := ethash .AccumulateRewards (chainConfig , block .Header (), block .Uncles ())
899
+ issuance := minerReward
900
+ for _ , r := range uncleRewards {
901
+ p := r // avoids warning?
902
+ issuance .Add (& issuance , & p )
903
+ }
904
+
905
+ var ret internalIssuance
906
+ ret .BlockReward = hexutil .EncodeBig (minerReward .ToBig ())
907
+ ret .Issuance = hexutil .EncodeBig (issuance .ToBig ())
908
+ issuance .Sub (& issuance , & minerReward )
909
+ ret .UncleReward = hexutil .EncodeBig (issuance .ToBig ())
910
+ return ret , nil
911
+ }
912
+
860
913
func (api * APIImpl ) GetERCTransactionReceipt (ctx context.Context , txnHash common.Hash ) (map [string ]any , error ) {
861
914
tx , err := api .db .BeginRo (ctx )
862
915
if err != nil {
0 commit comments