forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtransaction_data.go
34 lines (29 loc) · 1.07 KB
/
transaction_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
package arbutil
import (
"context"
"fmt"
"github.com/ethereum/go-ethereum/core/types"
)
func GetLogTransaction(ctx context.Context, client L1Interface, log types.Log) (*types.Transaction, error) {
tx, err := client.TransactionInBlock(ctx, log.BlockHash, log.TxIndex)
if err != nil {
return nil, err
}
if tx.Hash() != log.TxHash {
return nil, fmt.Errorf("L1 client returned unexpected transaction hash %v when looking up block %v transaction %v with expected hash %v", tx.Hash(), log.BlockHash, log.TxIndex, log.TxHash)
}
return tx, nil
}
// GetLogEmitterTxData requires that the tx's data is at least 4 bytes long
func GetLogEmitterTxData(ctx context.Context, client L1Interface, log types.Log) ([]byte, error) {
tx, err := GetLogTransaction(ctx, client, log)
if err != nil {
return nil, err
}
if len(tx.Data()) < 4 {
return nil, fmt.Errorf("log emitting transaction %v unexpectedly does not have enough data", tx.Hash())
}
return tx.Data(), nil
}