-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
models.go
112 lines (100 loc) · 3.26 KB
/
models.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package bulletprooftxmanager
import (
"bytes"
"fmt"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
"github.com/smartcontractkit/chainlink/core/assets"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/utils"
"gopkg.in/guregu/null.v4"
"gorm.io/datatypes"
)
type EthTxState string
type EthTxAttemptState string
const (
EthTxUnstarted = EthTxState("unstarted")
EthTxInProgress = EthTxState("in_progress")
EthTxFatalError = EthTxState("fatal_error")
EthTxUnconfirmed = EthTxState("unconfirmed")
EthTxConfirmed = EthTxState("confirmed")
EthTxConfirmedMissingReceipt = EthTxState("confirmed_missing_receipt")
EthTxAttemptInProgress = EthTxAttemptState("in_progress")
EthTxAttemptInsufficientEth = EthTxAttemptState("insufficient_eth")
EthTxAttemptBroadcast = EthTxAttemptState("broadcast")
)
type EthTaskRunTx struct {
TaskRunID uuid.UUID
EthTxID int64
EthTx EthTx
}
type EthTx struct {
ID int64
Nonce *int64
FromAddress common.Address
ToAddress common.Address
EncodedPayload []byte
Value assets.Eth
// GasLimit on the EthTx is always the conceptual gas limit, which is not
// necessarily the same as the on-chain encoded value (i.e. Optimism)
GasLimit uint64
Error null.String
// BroadcastAt is updated every time an attempt for this eth_tx is re-sent
// In almost all cases it will be within a second or so of the actual send time.
BroadcastAt *time.Time
CreatedAt time.Time
State EthTxState
EthTxAttempts []EthTxAttempt `gorm:"->"`
// Marshalled EthTxMeta
// Used for additional context around transactions which you want to log
// at send time.
Meta datatypes.JSON
Subject uuid.NullUUID
}
func (e EthTx) GetError() error {
if e.Error.Valid {
return errors.New(e.Error.String)
}
return nil
}
// GetID allows EthTx to be used as jsonapi.MarshalIdentifier
func (e EthTx) GetID() string {
return fmt.Sprintf("%d", e.ID)
}
type EthTxAttempt struct {
ID int64
EthTxID int64
EthTx EthTx `gorm:"foreignkey:EthTxID;->"`
GasPrice utils.Big
// ChainSpecificGasLimit on the EthTxAttempt is always the same as the on-chain encoded value for gas limit
ChainSpecificGasLimit uint64
SignedRawTx []byte
Hash common.Hash
CreatedAt time.Time
BroadcastBeforeBlockNum *int64
State EthTxAttemptState
EthReceipts []EthReceipt `gorm:"foreignKey:TxHash;references:Hash;association_foreignkey:Hash;->"`
}
// GetSignedTx decodes the SignedRawTx into a types.Transaction struct
func (a EthTxAttempt) GetSignedTx() (*types.Transaction, error) {
s := rlp.NewStream(bytes.NewReader(a.SignedRawTx), 0)
signedTx := new(types.Transaction)
if err := signedTx.DecodeRLP(s); err != nil {
logger.Error("could not decode RLP")
return nil, err
}
return signedTx, nil
}
type EthReceipt struct {
ID int64
TxHash common.Hash
BlockHash common.Hash
BlockNumber int64
TransactionIndex uint
Receipt []byte
CreatedAt time.Time
}