aboutsummaryrefslogtreecommitdiffstats
path: root/internal/ethapi/api.go
diff options
context:
space:
mode:
authorjohnliu-dexon <42129254+johnliu-dexon@users.noreply.github.com>2018-11-27 17:13:22 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commitdc18d07437b43de381ee47d7f8191ed956869ef8 (patch)
treeeb98bf23c11d0214eeff865a7e9b92a2e60e5262 /internal/ethapi/api.go
parent342a17ca87dbf2b2e6f746204efe46df371a4540 (diff)
downloaddexon-dc18d07437b43de381ee47d7f8191ed956869ef8.tar
dexon-dc18d07437b43de381ee47d7f8191ed956869ef8.tar.gz
dexon-dc18d07437b43de381ee47d7f8191ed956869ef8.tar.bz2
dexon-dc18d07437b43de381ee47d7f8191ed956869ef8.tar.lz
dexon-dc18d07437b43de381ee47d7f8191ed956869ef8.tar.xz
dexon-dc18d07437b43de381ee47d7f8191ed956869ef8.tar.zst
dexon-dc18d07437b43de381ee47d7f8191ed956869ef8.zip
internal/ethapi: add getBlockReceiptsByHash (#56)
* dex: add getBlockReceiptsByHash add rpc method for performance acceleration * Update internal/ethapi/api.go Co-Authored-By: johnliu-dexon <42129254+johnliu-dexon@users.noreply.github.com>
Diffstat (limited to 'internal/ethapi/api.go')
-rw-r--r--internal/ethapi/api.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index 43553bece..a06e5e0e8 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -673,6 +673,41 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A
return res[:], state.Error()
}
+// GetBlockReceiptsByNumber returns the requested block receipts.
+func (s *PublicBlockChainAPI) GetBlockReceiptsByHash(ctx context.Context, blockHash common.Hash) ([]map[string]interface{}, error) {
+ receipts, err := s.b.GetReceipts(ctx, blockHash)
+ if err != nil {
+ return nil, err
+ }
+
+ resp := make([]map[string]interface{}, 0, len(receipts))
+ for _, receipt := range receipts {
+ fields := map[string]interface{}{
+ "gasUsed": hexutil.Uint64(receipt.GasUsed),
+ "cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed),
+ "contractAddress": nil,
+ "logs": receipt.Logs,
+ "logsBloom": receipt.Bloom,
+ }
+
+ // Assign receipt status or post state.
+ if len(receipt.PostState) > 0 {
+ fields["root"] = hexutil.Bytes(receipt.PostState)
+ } else {
+ fields["status"] = hexutil.Uint(receipt.Status)
+ }
+ if receipt.Logs == nil {
+ fields["logs"] = [][]*types.Log{}
+ }
+ // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
+ if receipt.ContractAddress != (common.Address{}) {
+ fields["contractAddress"] = receipt.ContractAddress
+ }
+ resp = append(resp, fields)
+ }
+ return resp, nil
+}
+
// CallArgs represents the arguments for a call.
type CallArgs struct {
From common.Address `json:"from"`