From 6239a0ac980384d6b520271e916f154154603e55 Mon Sep 17 00:00:00 2001 From: Wade Date: Thu, 27 Oct 2022 11:58:54 +0900 Subject: [PATCH 1/6] =?UTF-8?q?Feat=20:=20getReceipts()=20API=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/ethapi/api.go | 42 +++++++++++++++++++++++++++++++++++++ internal/web3ext/web3ext.go | 12 +++++++++++ 2 files changed, 54 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f26eb3e16d931..4fae4a68b1052 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -643,6 +643,48 @@ func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 { return hexutil.Uint64(header.Number.Uint64()) } +// GetBlockReceipts returns all the transaction receipts for the given block hash. +func (s *PublicBlockChainAPI) GetReceipts(ctx context.Context, blockHash common.Hash) ([]map[string]interface{}, error) { + receipts, err1 := s.b.GetReceipts(ctx, blockHash) + if err1 != nil { + return nil, err1 + } + block, err2 := s.b.BlockByHash(ctx, blockHash) + if err2 != nil { + return nil, err2 + } + + txs := block.Transactions() + if receipts.Len() != txs.Len() { + return nil, fmt.Errorf("the size of transactions and receipts is different in the block (%s)", blockHash.String()) + } + fieldsList := make([]map[string]interface{}, 0, len(receipts)) + + for index, receipt := range receipts { + + bigblock := new(big.Int).SetUint64(block.NumberU64()) + signer := types.MakeSigner(s.b.ChainConfig(), bigblock) + from, _ := types.Sender(signer, txs[index]) + + fields := map[string]interface{}{ + "blockHash": blockHash, + "blockNumber": bigblock, + "transactionHash": receipt.TxHash, + "transactionIndex": hexutil.Uint64(index), + "from": from, + "to": txs[index].To(), + "gasUsed": hexutil.Uint64(receipt.GasUsed), + "cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed), + "contractAddress": nil, + "logs": receipt.Logs, + "logsBloom": receipt.Bloom, + "type": hexutil.Uint(txs[index].Type()), + } + fieldsList = append(fieldsList, fields) + } + return fieldsList, nil +} + // GetBalance returns the amount of wei for the given address in the state of the // given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta // block numbers are also allowed. diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index bc8fa570cce91..e769dd312ef7c 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -611,6 +611,18 @@ web3._extend({ params: 1, inputFormatter: [web3._extend.formatters.inputTransactionFormatter] }), + new web3._extend.Method({ + name: 'getReceipts', + call: 'wemix_getReceipts', + params: 1, + outputFormatter: function(receipts) { + var formatted = []; + for (var i = 0; i < receipts.length; i++) { + formatted.push(web3._extend.formatters.outputTransactionReceiptFormatter(receipts[i])); + } + return formatted; + } + }), new web3._extend.Method({ name: 'getHeaderByNumber', call: 'eth_getHeaderByNumber', From d48039f9c65a1891c49c8f8481eacd1e7160ad13 Mon Sep 17 00:00:00 2001 From: Wade Date: Thu, 27 Oct 2022 18:30:51 +0900 Subject: [PATCH 2/6] Fix : fix namespace error --- internal/web3ext/web3ext.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index e769dd312ef7c..16b76c7312e30 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -613,7 +613,7 @@ web3._extend({ }), new web3._extend.Method({ name: 'getReceipts', - call: 'wemix_getReceipts', + call: 'eth_getReceipts', params: 1, outputFormatter: function(receipts) { var formatted = []; From d4b4cbadbcaeea11e73333fab62d39f509d205a2 Mon Sep 17 00:00:00 2001 From: Wade Date: Thu, 27 Oct 2022 20:01:37 +0900 Subject: [PATCH 3/6] Fix : fix go mod module error --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 8d9fa00c92f83..582b0f48d5a32 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/ethereum/go-ethereum +module github.com/wemixarchive/go-wemix go 1.19 From 175eda2b0bf6f2db8bd46fb16f1a8a132bdd740c Mon Sep 17 00:00:00 2001 From: Wade Date: Fri, 28 Oct 2022 11:46:52 +0900 Subject: [PATCH 4/6] =?UTF-8?q?Fix=20:=20go=20module=20=EB=A1=A4=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 582b0f48d5a32..8d9fa00c92f83 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/wemixarchive/go-wemix +module github.com/ethereum/go-ethereum go 1.19 From f644cc12dd93dd7c25fdd283f5f7d8423f0821d0 Mon Sep 17 00:00:00 2001 From: Wade-wemade <113892329+Wade-wemade@users.noreply.github.com> Date: Thu, 3 Nov 2022 11:54:58 +0900 Subject: [PATCH 5/6] Chore : Change API Name for clarify --- internal/web3ext/web3ext.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 16b76c7312e30..df590c3c4030c 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -612,8 +612,8 @@ web3._extend({ inputFormatter: [web3._extend.formatters.inputTransactionFormatter] }), new web3._extend.Method({ - name: 'getReceipts', - call: 'eth_getReceipts', + name: 'getReceiptsByHash', + call: 'eth_getReceiptsByHash', params: 1, outputFormatter: function(receipts) { var formatted = []; From c3765432747221fa5e7a04b27455347abcb59843 Mon Sep 17 00:00:00 2001 From: Wade Date: Thu, 3 Nov 2022 11:56:49 +0900 Subject: [PATCH 6/6] Chore : Change function name for clarify --- internal/ethapi/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 4fae4a68b1052..20a7c6e313adb 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -644,7 +644,7 @@ func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 { } // GetBlockReceipts returns all the transaction receipts for the given block hash. -func (s *PublicBlockChainAPI) GetReceipts(ctx context.Context, blockHash common.Hash) ([]map[string]interface{}, error) { +func (s *PublicBlockChainAPI) GetReceiptsByHash(ctx context.Context, blockHash common.Hash) ([]map[string]interface{}, error) { receipts, err1 := s.b.GetReceipts(ctx, blockHash) if err1 != nil { return nil, err1