@@ -53,25 +53,29 @@ func ReadTxLookupEntry(db ethdb.Reader, hash common.Hash) *uint64 {
5353 return & entry .BlockIndex
5454}
5555
56- // WriteTxLookupEntries stores a positional metadata for every transaction from
57- // a block, enabling hash based transaction and receipt lookups.
58- func WriteTxLookupEntries (db ethdb.KeyValueWriter , block * types.Block ) {
59- number := block .Number ().Bytes ()
60- for _ , tx := range block .Transactions () {
61- if err := db .Put (txLookupKey (tx .Hash ()), number ); err != nil {
62- log .Crit ("Failed to store transaction lookup entry" , "err" , err )
63- }
56+ // writeTxLookupEntry stores a positional metadata for a transaction,
57+ // enabling hash based transaction and receipt lookups.
58+ func writeTxLookupEntry (db ethdb.KeyValueWriter , hash common.Hash , numberBytes []byte ) {
59+ if err := db .Put (txLookupKey (hash ), numberBytes ); err != nil {
60+ log .Crit ("Failed to store transaction lookup entry" , "err" , err )
6461 }
6562}
6663
67- // WriteTxLookupEntriesByHash is identical to WriteTxLookupEntries , but does not
68- // require a full types.Block as input.
69- func WriteTxLookupEntriesByHash (db ethdb.KeyValueWriter , number uint64 , hashes []common.Hash ) {
64+ // WriteTxLookupEntries is identical to WriteTxLookupEntry , but it works on
65+ // a list of hashes
66+ func WriteTxLookupEntries (db ethdb.KeyValueWriter , number uint64 , hashes []common.Hash ) {
7067 numberBytes := new (big.Int ).SetUint64 (number ).Bytes ()
7168 for _ , hash := range hashes {
72- if err := db .Put (txLookupKey (hash ), numberBytes ); err != nil {
73- log .Crit ("Failed to store transaction lookup entry" , "err" , err )
74- }
69+ writeTxLookupEntry (db , hash , numberBytes )
70+ }
71+ }
72+
73+ // WriteTxLookupEntriesByBlock stores a positional metadata for every transaction from
74+ // a block, enabling hash based transaction and receipt lookups.
75+ func WriteTxLookupEntriesByBlock (db ethdb.KeyValueWriter , block * types.Block ) {
76+ numberBytes := block .Number ().Bytes ()
77+ for _ , tx := range block .Transactions () {
78+ writeTxLookupEntry (db , tx .Hash (), numberBytes )
7579 }
7680}
7781
@@ -83,11 +87,9 @@ func DeleteTxLookupEntry(db ethdb.KeyValueWriter, hash common.Hash) {
8387}
8488
8589// DeleteTxLookupEntries removes all transaction lookups for a given block.
86- func DeleteTxLookupEntriesByHash (db ethdb.KeyValueWriter , hashes []common.Hash ) {
90+ func DeleteTxLookupEntries (db ethdb.KeyValueWriter , hashes []common.Hash ) {
8791 for _ , hash := range hashes {
88- if err := db .Delete (txLookupKey (hash )); err != nil {
89- log .Crit ("Failed to delete transaction lookup entry" , "err" , err )
90- }
92+ DeleteTxLookupEntry (db , hash )
9193 }
9294}
9395
0 commit comments