2020-10-18 19:44:28 +00:00
package commands
import (
"context"
"fmt"
2021-05-20 18:25:53 +00:00
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/types"
2020-10-18 19:44:28 +00:00
)
2021-05-26 10:35:39 +00:00
// GetLogsByHash implements erigon_getLogsByHash. Returns an array of arrays of logs generated by the transactions in the block given by the block's hash.
func ( api * ErigonImpl ) GetLogsByHash ( ctx context . Context , hash common . Hash ) ( [ ] [ ] * types . Log , error ) {
2021-04-03 06:26:00 +00:00
tx , err := api . db . BeginRo ( ctx )
2020-10-18 19:44:28 +00:00
if err != nil {
return nil , err
}
defer tx . Rollback ( )
2021-04-15 05:23:10 +00:00
number := rawdb . ReadHeaderNumber ( tx , hash )
2020-10-18 19:44:28 +00:00
if number == nil {
return nil , fmt . Errorf ( "block not found: %x" , hash )
}
2020-10-24 17:03:52 +00:00
2021-01-02 19:28:22 +00:00
chainConfig , err := api . chainConfig ( tx )
if err != nil {
return nil , err
}
receipts , err := getReceipts ( ctx , tx , chainConfig , * number , hash )
2020-10-18 19:44:28 +00:00
if err != nil {
return nil , fmt . Errorf ( "getReceipts error: %v" , err )
}
2020-10-24 17:03:52 +00:00
2020-10-18 19:44:28 +00:00
logs := make ( [ ] [ ] * types . Log , len ( receipts ) )
for i , receipt := range receipts {
logs [ i ] = receipt . Logs
}
return logs , nil
}
2020-10-24 17:03:52 +00:00
2021-05-26 10:35:39 +00:00
// GetLogsByNumber implements erigon_getLogsByHash. Returns all the logs that appear in a block given the block's hash.
// func (api *ErigonImpl) GetLogsByNumber(ctx context.Context, number rpc.BlockNumber) ([][]*types.Log, error) {
2021-02-10 17:04:22 +00:00
// tx, err := api.db.Begin(ctx, false)
2020-10-24 17:03:52 +00:00
// if err != nil {
// return nil, err
// }
// defer tx.Rollback()
// number := rawdb.ReadHeaderNumber(tx, hash)
// if number == nil {
// return nil, fmt.Errorf("block not found: %x", hash)
// }
// receipts, err := getReceipts(ctx, tx, *number, hash)
// if err != nil {
// return nil, fmt.Errorf("getReceipts error: %v", err)
// }
// logs := make([][]*types.Log, len(receipts))
// for i, receipt := range receipts {
// logs[i] = receipt.Logs
// }
// return logs, nil
// }