mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-16 08:53:46 +00:00
add by hash
This commit is contained in:
parent
9d085ef65e
commit
8d77ab3551
1 changed files with 63 additions and 1 deletions
|
|
@ -532,7 +532,7 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
|
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
|
||||||
func (s *PublicTransactionPoolAPI) GetTransactionReceiptsByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) ([]map[string]interface{}, error) {
|
func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) ([]map[string]interface{}, error) {
|
||||||
blockNumber := uint64(blockNr.Int64())
|
blockNumber := uint64(blockNr.Int64())
|
||||||
blockHash := rawdb.ReadCanonicalHash(s.b.ChainDb(), blockNumber)
|
blockHash := rawdb.ReadCanonicalHash(s.b.ChainDb(), blockNumber)
|
||||||
|
|
||||||
|
|
@ -570,6 +570,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceiptsByBlockNumber(ctx conte
|
||||||
"contractAddress": nil,
|
"contractAddress": nil,
|
||||||
"logs": receipt.Logs,
|
"logs": receipt.Logs,
|
||||||
"logsBloom": receipt.Bloom,
|
"logsBloom": receipt.Bloom,
|
||||||
|
"transactions": []interface{}{tx},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign receipt status or post state.
|
// Assign receipt status or post state.
|
||||||
|
|
@ -585,6 +586,67 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceiptsByBlockNumber(ctx conte
|
||||||
if receipt.ContractAddress != (common.Address{}) {
|
if receipt.ContractAddress != (common.Address{}) {
|
||||||
fields["contractAddress"] = receipt.ContractAddress
|
fields["contractAddress"] = receipt.ContractAddress
|
||||||
}
|
}
|
||||||
|
fields = s.appendRPCMarshalBorTransaction(ctx, block, fields, true)
|
||||||
|
|
||||||
|
txReceipts = append(txReceipts, fields)
|
||||||
|
}
|
||||||
|
|
||||||
|
return txReceipts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
|
||||||
|
func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlockHash(ctx context.Context, hash common.Hash) ([]map[string]interface{}, error) {
|
||||||
|
receipts, err := s.b.GetReceipts(ctx, hash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
block, err := s.b.BlockByHash(ctx, hash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
txs := block.Transactions()
|
||||||
|
if len(txs) != len(receipts) {
|
||||||
|
return nil, fmt.Errorf("txs length doesn't equal to receipts' length")
|
||||||
|
}
|
||||||
|
|
||||||
|
txReceipts := make([]map[string]interface{}, 0, len(txs))
|
||||||
|
for idx, receipt := range receipts {
|
||||||
|
tx := txs[idx]
|
||||||
|
var signer types.Signer = types.FrontierSigner{}
|
||||||
|
if tx.Protected() {
|
||||||
|
signer = types.NewEIP155Signer(tx.ChainId())
|
||||||
|
}
|
||||||
|
from, _ := types.Sender(signer, tx)
|
||||||
|
|
||||||
|
fields := map[string]interface{}{
|
||||||
|
"blockHash": hash,
|
||||||
|
"blockNumber": hexutil.Uint64(block.NumberU64()),
|
||||||
|
"transactionHash": tx.Hash(),
|
||||||
|
"transactionIndex": hexutil.Uint64(idx),
|
||||||
|
"from": from,
|
||||||
|
"to": tx.To(),
|
||||||
|
"gasUsed": hexutil.Uint64(receipt.GasUsed),
|
||||||
|
"cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed),
|
||||||
|
"contractAddress": nil,
|
||||||
|
"logs": receipt.Logs,
|
||||||
|
"logsBloom": receipt.Bloom,
|
||||||
|
"transactions": []interface{}{tx},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
fields = s.appendRPCMarshalBorTransaction(ctx, block, fields, true)
|
||||||
|
|
||||||
txReceipts = append(txReceipts, fields)
|
txReceipts = append(txReceipts, fields)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue