Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 28d7532

Browse files
committed
add eth_getBlockReceipts
1 parent 30c6db7 commit 28d7532

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

internal/ethapi/api.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,56 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A
840840
return res[:], state.Error()
841841
}
842842

843+
// gets all receipts in block
844+
// Note, this method doesnt return the entire transaction receipt to save resources
845+
func (s *PublicBlockChainAPI) GetBlockReceipts(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
846+
receipts, err := s.b.GetReceipts(ctx, hash)
847+
if err != nil {
848+
return nil, err
849+
}
850+
resultFields := map[string]interface{}{
851+
"blockHash": hash,
852+
"receipts": []map[string]interface{}{},
853+
}
854+
855+
// add all receipts to the result
856+
for _, receipt := range receipts {
857+
fields := map[string]interface{}{
858+
"transactionHash": receipt.TxHash,
859+
"transactionIndex": receipt.TransactionIndex,
860+
"gasUsed": hexutil.Uint64(receipt.GasUsed),
861+
"cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed),
862+
"contractAddress": nil,
863+
"logs": receipt.Logs,
864+
"type": hexutil.Uint(receipt.Type),
865+
}
866+
// we dont need to return gas price atm
867+
// // Assign the effective gas price paid
868+
// if isLondon {
869+
// fields["effectiveGasPrice"] = hexutil.Uint64(tx.GasPrice().Uint64())
870+
// } else {
871+
// gasPrice := new(big.Int).Add(header.BaseFee, tx.EffectiveGasTipValue(header.BaseFee))
872+
// fields["effectiveGasPrice"] = hexutil.Uint64(gasPrice.Uint64())
873+
// }
874+
// Assign receipt status or post state.
875+
if len(receipt.PostState) > 0 {
876+
fields["root"] = hexutil.Bytes(receipt.PostState)
877+
} else {
878+
fields["status"] = hexutil.Uint(receipt.Status)
879+
}
880+
if receipt.Logs == nil {
881+
fields["logs"] = []*types.Log{}
882+
}
883+
// If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
884+
if receipt.ContractAddress != (common.Address{}) {
885+
fields["contractAddress"] = receipt.ContractAddress
886+
}
887+
resultFields["receipts"] = append(resultFields["receipts"].([]map[string]interface{}), fields)
888+
}
889+
890+
return resultFields, nil
891+
}
892+
843893
// OverrideAccount indicates the overriding fields of account during the execution
844894
// of a message call.
845895
// Note, state and stateDiff can't be specified at the same time. If state is

internal/web3ext/web3ext.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,12 @@ web3._extend({
551551
params: 2,
552552
inputFormatter: [null, function (val) { return !!val; }]
553553
}),
554+
new web3._extend.Method({
555+
name: 'getBlockReceipts',
556+
call: 'eth_getBlockReceipts',
557+
params: 1,
558+
inputFormatter: [null]
559+
}),
554560
new web3._extend.Method({
555561
name: 'getRawTransaction',
556562
call: 'eth_getRawTransactionByHash',

0 commit comments

Comments
 (0)