@@ -19,13 +19,13 @@ package rawdb
19
19
import (
20
20
"bytes"
21
21
"encoding/hex"
22
- "errors"
23
22
"fmt"
24
23
"math/big"
25
24
"math/rand"
26
25
"os"
27
26
"reflect"
28
27
"testing"
28
+ "time"
29
29
30
30
"github.com/ethereum/go-ethereum/common"
31
31
"github.com/ethereum/go-ethereum/core/types"
@@ -768,27 +768,6 @@ func TestReadLogs(t *testing.T) {
768
768
}
769
769
}
770
770
771
- // deriveLogFields fills the logs in receiptLogs with information such as block number, txhash, etc.
772
- func deriveLogFields (receipts []* receiptLogs , hash common.Hash , number uint64 , txs types.Transactions ) error {
773
- logIndex := uint (0 )
774
- if len (txs ) != len (receipts ) {
775
- return errors .New ("transaction and receipt count mismatch" )
776
- }
777
- for i := 0 ; i < len (receipts ); i ++ {
778
- txHash := txs [i ].Hash ()
779
- // The derived log fields can simply be set from the block and transaction
780
- for j := 0 ; j < len (receipts [i ].Logs ); j ++ {
781
- receipts [i ].Logs [j ].BlockNumber = number
782
- receipts [i ].Logs [j ].BlockHash = hash
783
- receipts [i ].Logs [j ].TxHash = txHash
784
- receipts [i ].Logs [j ].TxIndex = uint (i )
785
- receipts [i ].Logs [j ].Index = logIndex
786
- logIndex ++
787
- }
788
- }
789
- return nil
790
- }
791
-
792
771
func TestDeriveLogFields (t * testing.T ) {
793
772
// Create a few transactions to have receipts for
794
773
to2 := common .HexToAddress ("0x2" )
@@ -816,7 +795,7 @@ func TestDeriveLogFields(t *testing.T) {
816
795
}),
817
796
}
818
797
// Create the corresponding receipts
819
- receipts := []* receiptLogs {
798
+ receipts := []* types. Receipt {
820
799
{
821
800
Logs : []* types.Log {
822
801
{Address : common .BytesToAddress ([]byte {0x11 })},
@@ -840,9 +819,7 @@ func TestDeriveLogFields(t *testing.T) {
840
819
// Derive log metadata fields
841
820
number := big .NewInt (1 )
842
821
hash := common .BytesToHash ([]byte {0x03 , 0x14 })
843
- if err := deriveLogFields (receipts , hash , number .Uint64 (), txs ); err != nil {
844
- t .Fatal (err )
845
- }
822
+ types .Receipts (receipts ).DeriveFields (params .TestChainConfig , hash , number .Uint64 (), uint64 (time .Now ().Unix ()), big .NewInt (0 ), big .NewInt (0 ), txs )
846
823
847
824
// Iterate over all the computed fields and check that they're correct
848
825
logIndex := uint (0 )
0 commit comments