From 218f96c1f50a05818be193635a7fe0e9db421079 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Tue, 10 Aug 2021 13:43:47 +0530 Subject: [PATCH 1/8] implemented the ethcall --- ethclient/ethclient.go | 10 ++++++ internal/ethapi/api.go | 61 +++++++++++++++++++++++++++++++++++++ internal/jsre/deps/web3.js | 7 +++++ internal/web3ext/web3ext.go | 5 +++ 4 files changed, 83 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index a17696356c..cab25f88c8 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -70,6 +70,16 @@ func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) { return (*big.Int)(&result), err } +// TransactionInBlock returns a single transaction at index in the given block. +func (ec *Client) TransactionRecipientsInBlock(ctx context.Context, number *big.Int) ([]*types.Receipt, error) { + var rs []*types.Receipt + err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlockNumber", toBlockNumArg(number)) + 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 diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 73b22852a8..5e4913f7f6 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -531,6 +531,67 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI { return &PublicBlockChainAPI{b} } +// GetTransactionReceipt returns the transaction receipt for the given transaction hash. +func (s *PublicTransactionPoolAPI) GetTransactionReceiptsByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) ([]map[string]interface{}, error) { + blockNumber := uint64(blockNr.Int64()) + blockHash := rawdb.ReadCanonicalHash(s.b.ChainDb(), blockNumber) + + receipts, err := s.b.GetReceipts(ctx, blockHash) + if err != nil { + return nil, err + } + block, err := s.b.BlockByHash(ctx, blockHash) + 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": blockHash, + "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, + } + + // 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 + } + + txReceipts = append(txReceipts, fields) + } + + return txReceipts, nil +} + // ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config. func (api *PublicBlockChainAPI) ChainId() (*hexutil.Big, error) { // if current block is at or past the EIP-155 replay-protection fork block, return chainID from config diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index f1fe15d48d..bd3e54067c 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -5393,6 +5393,13 @@ var methods = function () { inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] }); + var getTransactionReceiptsByBlockNumber = new Method({ + name: 'getTransactionReceiptsByBlockNumber', + call: 'eth_getTransactionReceiptsByBlockNumber', + params: 1, + outputFormatter: formatters.outputTransactionReceiptFormatter + }); + var estimateGas = new Method({ name: 'estimateGas', call: 'eth_estimateGas', diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index a24de36b22..7776c20b9d 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -494,6 +494,11 @@ const EthJs = ` web3._extend({ property: 'eth', methods: [ + new web3._extend.Method({ + name: 'getTransactionReceiptsByBlockNumber', + call: 'eth_getTransactionReceiptsByBlockNumber', + params: 1, + }), new web3._extend.Method({ name: 'chainId', call: 'eth_chainId', From 9d085ef65eff9cccf8b3eb655bbef86c270243aa Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 11 Aug 2021 14:00:52 +0530 Subject: [PATCH 2/8] 2 function calls --- ethclient/ethclient.go | 12 ++++++++++-- internal/jsre/deps/web3.js | 13 +++++++++---- internal/web3ext/web3ext.go | 6 ++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index cab25f88c8..73c00de86e 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -70,8 +70,7 @@ func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) { return (*big.Int)(&result), err } -// TransactionInBlock returns a single transaction at index in the given block. -func (ec *Client) TransactionRecipientsInBlock(ctx context.Context, number *big.Int) ([]*types.Receipt, error) { +func (ec *Client) TransactionReceiptsInBlockByBlockNumber(ctx context.Context, number *big.Int) ([]*types.Receipt, error) { var rs []*types.Receipt err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlockNumber", toBlockNumArg(number)) if err != nil { @@ -80,6 +79,15 @@ func (ec *Client) TransactionRecipientsInBlock(ctx context.Context, number *big. 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 diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index bd3e54067c..ed1d16f608 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -5214,6 +5214,10 @@ var transactionFromBlockCall = function (args) { 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) { return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; }; @@ -5393,9 +5397,9 @@ var methods = function () { inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] }); - var getTransactionReceiptsByBlockNumber = new Method({ - name: 'getTransactionReceiptsByBlockNumber', - call: 'eth_getTransactionReceiptsByBlockNumber', + var transactionReceiptsByBlock = new Method({ + name: 'getTransactionReceiptsByBlock', + call: transactionReceiptsFromBlockCall, params: 1, outputFormatter: formatters.outputTransactionReceiptFormatter }); @@ -5461,7 +5465,8 @@ var methods = function () { compileLLL, compileSerpent, submitWork, - getWork + getWork, + transactionReceiptsByBlock ]; }; diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 7776c20b9d..10ee49c81e 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -495,8 +495,10 @@ web3._extend({ property: 'eth', methods: [ new web3._extend.Method({ - name: 'getTransactionReceiptsByBlockNumber', - call: 'eth_getTransactionReceiptsByBlockNumber', + name: 'getTransactionReceiptsByBlock', + call: function(args) { + return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionReceiptsByBlockHash' : 'eth_getTransactionReceiptsByBlockNumber'; + }, params: 1, }), new web3._extend.Method({ From 8d77ab3551e965ab6af6dd306d48318a08f12669 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 11 Aug 2021 14:07:32 +0530 Subject: [PATCH 3/8] add by hash --- internal/ethapi/api.go | 64 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 5e4913f7f6..fd64652b4f 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -532,7 +532,7 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI { } // 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()) blockHash := rawdb.ReadCanonicalHash(s.b.ChainDb(), blockNumber) @@ -570,6 +570,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceiptsByBlockNumber(ctx conte "contractAddress": nil, "logs": receipt.Logs, "logsBloom": receipt.Bloom, + "transactions": []interface{}{tx}, } // Assign receipt status or post state. @@ -585,6 +586,67 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceiptsByBlockNumber(ctx conte 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()), + "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) } From 42a6c5e6ff1eb19a55f9edf58ee07ec0fc3185cf Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 11 Aug 2021 14:12:19 +0530 Subject: [PATCH 4/8] add input formatter --- internal/web3ext/web3ext.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 10ee49c81e..454134e1b8 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -500,6 +500,7 @@ web3._extend({ return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionReceiptsByBlockHash' : 'eth_getTransactionReceiptsByBlockNumber'; }, params: 1, + inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] }), new web3._extend.Method({ name: 'chainId', From 01c967146c3a2de06cb38fec7ea68a3c393e8795 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 11 Aug 2021 18:51:10 +0530 Subject: [PATCH 5/8] fix review comments --- ethclient/ethclient.go | 21 +--------- internal/ethapi/api.go | 79 +++++-------------------------------- internal/jsre/deps/web3.js | 13 ++---- internal/web3ext/web3ext.go | 2 +- 4 files changed, 16 insertions(+), 99 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 73c00de86e..daba37b666 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -70,32 +70,15 @@ func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) { 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 - err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlockNumber", toBlockNumArg(number)) + err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlock", blockNrOrHash) if err != nil { return nil, 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 // latest known block is returned. // diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index fd64652b4f..c759b307dc 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -531,19 +531,18 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI { return &PublicBlockChainAPI{b} } -// GetTransactionReceipt returns the transaction receipt for the given transaction hash. -func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlockNumber(ctx context.Context, blockNr rpc.BlockNumber) ([]map[string]interface{}, error) { - blockNumber := uint64(blockNr.Int64()) - blockHash := rawdb.ReadCanonicalHash(s.b.ChainDb(), blockNumber) +// GetTransactionReceiptsByBlock returns the transaction receipts for the given block number or hash. +func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]map[string]interface{}, error) { + block, err := s.b.BlockByNumberOrHash(ctx, blockNrOrHash) + if err != nil { + return nil, err + } - receipts, err := s.b.GetReceipts(ctx, blockHash) - if err != nil { - return nil, err - } - block, err := s.b.BlockByHash(ctx, blockHash) + receipts, err := s.b.GetReceipts(ctx, block.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") @@ -559,67 +558,7 @@ func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlockNumber(ctx context.Co from, _ := types.Sender(signer, tx) fields := map[string]interface{}{ - "blockHash": blockHash, - "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, + "blockHash": block.Hash(), "blockNumber": hexutil.Uint64(block.NumberU64()), "transactionHash": tx.Hash(), "transactionIndex": hexutil.Uint64(idx), diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index ed1d16f608..9b52740a59 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -5214,10 +5214,6 @@ var transactionFromBlockCall = function (args) { 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) { 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] }); - var transactionReceiptsByBlock = new Method({ + var getTransactionReceiptsByBlock = new Method({ name: 'getTransactionReceiptsByBlock', - call: transactionReceiptsFromBlockCall, - params: 1, - outputFormatter: formatters.outputTransactionReceiptFormatter + call: 'eth_getTransactionReceiptsByBlock', + params: 1 }); var estimateGas = new Method({ @@ -5466,7 +5461,7 @@ var methods = function () { compileSerpent, submitWork, getWork, - transactionReceiptsByBlock + getTransactionReceiptsByBlock ]; }; diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 454134e1b8..fa74f7a19d 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -500,7 +500,7 @@ web3._extend({ return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionReceiptsByBlockHash' : 'eth_getTransactionReceiptsByBlockNumber'; }, params: 1, - inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter, web3._extend.utils.toHex] + inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter] }), new web3._extend.Method({ name: 'chainId', From 8efd908e5875ddca0f3ad939c1e75c009a2a4f1f Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Wed, 11 Aug 2021 18:53:31 +0530 Subject: [PATCH 6/8] add removed code --- ethclient/ethclient.go | 8 ++++++++ internal/web3ext/web3ext.go | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index daba37b666..0f9bb295c2 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -70,6 +70,14 @@ func (ec *Client) ChainID(ctx context.Context) (*big.Int, error) { return (*big.Int)(&result), 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) +} + func (ec *Client) TransactionReceiptsInBlockByBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error) { var rs []*types.Receipt err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlock", blockNrOrHash) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index fa74f7a19d..f610aa3192 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -496,11 +496,8 @@ web3._extend({ methods: [ new web3._extend.Method({ name: 'getTransactionReceiptsByBlock', - call: function(args) { - return (web3._extend.utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionReceiptsByBlockHash' : 'eth_getTransactionReceiptsByBlockNumber'; - }, - params: 1, - inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter] + call: 'eth_getTransactionReceiptsByBlock', + params: 1 }), new web3._extend.Method({ name: 'chainId', From 5ab59960ed07a4228e20569a1a252c9fc372191d Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 12 Aug 2021 14:17:33 +0530 Subject: [PATCH 7/8] add bor receipts --- ethclient/ethclient.go | 4 ++-- internal/ethapi/api.go | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 0f9bb295c2..40d66b6f72 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -78,8 +78,8 @@ func (ec *Client) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo return ec.getBlock(ctx, "eth_getBlockByHash", hash, true) } -func (ec *Client) TransactionReceiptsInBlockByBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.Receipt, error) { - var rs []*types.Receipt +func (ec *Client) TransactionReceiptsInBlock(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]map[string]interface{}, error) { + var rs []map[string]interface{} err := ec.c.CallContext(ctx, &rs, "eth_getTransactionReceiptsByBlock", blockNrOrHash) if err != nil { return nil, err diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c759b307dc..a3e7b648fe 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -544,8 +544,21 @@ func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, } txs := block.Transactions() + + var txHash common.Hash + + borReceipt := rawdb.ReadBorReceipt(s.b.ChainDb(), block.Hash(), block.NumberU64()) + if borReceipt != nil { + receipts = append(receipts, borReceipt) + txHash = types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash())) + if txHash != (common.Hash{}) { + borTx, _, _, _, _ := s.b.GetBorBlockTransactionWithBlockHash(ctx, txHash, block.Hash()) + txs = append(txs, borTx) + } + } + 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", len(txs), len(receipts)) } txReceipts := make([]map[string]interface{}, 0, len(txs)) @@ -581,11 +594,13 @@ func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, if receipt.Logs == nil { fields["logs"] = [][]*types.Log{} } + if borReceipt != nil { + fields["transactionHash"] = txHash + } // 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) } From f77d924e193f72f83b913cf95de919e066111324 Mon Sep 17 00:00:00 2001 From: Arpit Temani Date: Thu, 12 Aug 2021 14:20:25 +0530 Subject: [PATCH 8/8] remove field --- internal/ethapi/api.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a3e7b648fe..7f708bf436 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -582,7 +582,6 @@ func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, "contractAddress": nil, "logs": receipt.Logs, "logsBloom": receipt.Bloom, - "transactions": []interface{}{tx}, } // Assign receipt status or post state.