mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 23:13:45 +00:00
fix review comments
This commit is contained in:
parent
42a6c5e6ff
commit
01c967146c
4 changed files with 16 additions and 99 deletions
|
|
@ -70,32 +70,15 @@ func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) {
|
||||||
return (*big.Int)(&result), err
|
return (*big.Int)(&result), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *Client) TransactionReceiptsInBlockByBlockNumber(ctx context.Context, number *big.Int) ([]*types.Receipt, error) {
|
func (ec *Client) TransactionReceiptsInBlockByBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error) {
|
||||||
var rs []*types.Receipt
|
var rs []*types.Receipt
|
||||||
err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlockNumber", toBlockNumArg(number))
|
err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlock", blockNrOrHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return rs, err
|
return rs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *Client) TransactionReceiptsInBlockByBlockHash(ctx context.Context, hash common.Hash) ([]*types.Receipt, error) {
|
|
||||||
var rs []*types.Receipt
|
|
||||||
err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlockHash", hash)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return rs, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockByHash returns the given full block.
|
|
||||||
//
|
|
||||||
// Note that loading full blocks requires two requests. Use HeaderByHash
|
|
||||||
// if you don't need all transactions or uncle headers.
|
|
||||||
func (ec *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) {
|
|
||||||
return ec.getBlock(ctx, "eth_getBlockByHash", hash, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BlockByNumber returns a block from the current canonical chain. If number is nil, the
|
// BlockByNumber returns a block from the current canonical chain. If number is nil, the
|
||||||
// latest known block is returned.
|
// latest known block is returned.
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -531,19 +531,18 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI {
|
||||||
return &PublicBlockChainAPI{b}
|
return &PublicBlockChainAPI{b}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
|
// GetTransactionReceiptsByBlock returns the transaction receipts for the given block number or hash.
|
||||||
func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) ([]map[string]interface{}, error) {
|
func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]map[string]interface{}, error) {
|
||||||
blockNumber := uint64(blockNr.Int64())
|
block, err := s.b.BlockByNumberOrHash(ctx, blockNrOrHash)
|
||||||
blockHash := rawdb.ReadCanonicalHash(s.b.ChainDb(), blockNumber)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
receipts, err := s.b.GetReceipts(ctx, blockHash)
|
receipts, err := s.b.GetReceipts(ctx, block.Hash())
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
block, err := s.b.BlockByHash(ctx, blockHash)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
txs := block.Transactions()
|
txs := block.Transactions()
|
||||||
if len(txs) != len(receipts) {
|
if len(txs) != len(receipts) {
|
||||||
return nil, fmt.Errorf("txs length doesn't equal to receipts' length")
|
return nil, fmt.Errorf("txs length doesn't equal to receipts' length")
|
||||||
|
|
@ -559,67 +558,7 @@ func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlockNumber(ctx context.Co
|
||||||
from, _ := types.Sender(signer, tx)
|
from, _ := types.Sender(signer, tx)
|
||||||
|
|
||||||
fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
"blockHash": blockHash,
|
"blockHash": block.Hash(),
|
||||||
"blockNumber": hexutil.Uint64(blockNumber),
|
|
||||||
"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)
|
|
||||||
}
|
|
||||||
|
|
||||||
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()),
|
"blockNumber": hexutil.Uint64(block.NumberU64()),
|
||||||
"transactionHash": tx.Hash(),
|
"transactionHash": tx.Hash(),
|
||||||
"transactionIndex": hexutil.Uint64(idx),
|
"transactionIndex": hexutil.Uint64(idx),
|
||||||
|
|
|
||||||
|
|
@ -5214,10 +5214,6 @@ var transactionFromBlockCall = function (args) {
|
||||||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
|
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
|
||||||
};
|
};
|
||||||
|
|
||||||
var transactionReceiptsFromBlockCall = function (args) {
|
|
||||||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionReceiptsByBlockHash' : 'eth_getTransactionReceiptsByBlockNumber';
|
|
||||||
};
|
|
||||||
|
|
||||||
var uncleCall = function (args) {
|
var uncleCall = function (args) {
|
||||||
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
|
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
|
||||||
};
|
};
|
||||||
|
|
@ -5397,11 +5393,10 @@ var methods = function () {
|
||||||
inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter]
|
inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter]
|
||||||
});
|
});
|
||||||
|
|
||||||
var transactionReceiptsByBlock = new Method({
|
var getTransactionReceiptsByBlock = new Method({
|
||||||
name: 'getTransactionReceiptsByBlock',
|
name: 'getTransactionReceiptsByBlock',
|
||||||
call: transactionReceiptsFromBlockCall,
|
call: 'eth_getTransactionReceiptsByBlock',
|
||||||
params: 1,
|
params: 1
|
||||||
outputFormatter: formatters.outputTransactionReceiptFormatter
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var estimateGas = new Method({
|
var estimateGas = new Method({
|
||||||
|
|
@ -5466,7 +5461,7 @@ var methods = function () {
|
||||||
compileSerpent,
|
compileSerpent,
|
||||||
submitWork,
|
submitWork,
|
||||||
getWork,
|
getWork,
|
||||||
transactionReceiptsByBlock
|
getTransactionReceiptsByBlock
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -500,7 +500,7 @@ web3._extend({
|
||||||
return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionReceiptsByBlockHash' : 'eth_getTransactionReceiptsByBlockNumber';
|
return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionReceiptsByBlockHash' : 'eth_getTransactionReceiptsByBlockNumber';
|
||||||
},
|
},
|
||||||
params: 1,
|
params: 1,
|
||||||
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex]
|
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
|
||||||
}),
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'chainId',
|
name: 'chainId',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue