diff options
author | johnliu-dexon <42129254+johnliu-dexon@users.noreply.github.com> | 2018-11-27 17:13:22 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | bc28384d725f57c5d71ea3d81dde0f7251ab868e (patch) | |
tree | 7db55ebdb79b449584d36958f1b7c2ceed6bf63d /internal/ethapi | |
parent | bc796b1e2f9c0a3bc7c6b9eeb6b262987f9d037a (diff) | |
download | dexon-bc28384d725f57c5d71ea3d81dde0f7251ab868e.tar dexon-bc28384d725f57c5d71ea3d81dde0f7251ab868e.tar.gz dexon-bc28384d725f57c5d71ea3d81dde0f7251ab868e.tar.bz2 dexon-bc28384d725f57c5d71ea3d81dde0f7251ab868e.tar.lz dexon-bc28384d725f57c5d71ea3d81dde0f7251ab868e.tar.xz dexon-bc28384d725f57c5d71ea3d81dde0f7251ab868e.tar.zst dexon-bc28384d725f57c5d71ea3d81dde0f7251ab868e.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')
-rw-r--r-- | internal/ethapi/api.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 45a0a3e10..d295aaf58 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"` |