-
Notifications
You must be signed in to change notification settings - Fork 697
/
transaction.go
61 lines (52 loc) · 1.5 KB
/
transaction.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
package pool
import (
"time"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
const (
// TxStatusPending represents a tx that has not been processed
TxStatusPending TxStatus = "pending"
// TxStatusInvalid represents an invalid tx
TxStatusInvalid TxStatus = "invalid"
// TxStatusSelected represents a tx that has been selected
TxStatusSelected TxStatus = "selected"
// TxStatusFailed represents a tx that has been failed after processing
TxStatusFailed TxStatus = "failed"
)
// TxStatus represents the state of a tx
type TxStatus string
// String returns a representation of the tx state in a string format
func (s TxStatus) String() string {
return string(s)
}
// TxStatusUpdateInfo represents the information needed to update the status of a tx
type TxStatusUpdateInfo struct {
Hash common.Hash
NewStatus TxStatus
IsWIP bool
FailedReason *string
}
// Transaction represents a pool tx
type Transaction struct {
types.Transaction
Status TxStatus
state.ZKCounters
ReceivedAt time.Time
PreprocessedStateRoot common.Hash
IsWIP bool
IP string
FailedReason *string
}
// NewTransaction creates a new transaction
func NewTransaction(tx types.Transaction, ip string, isWIP bool) *Transaction {
poolTx := Transaction{
Transaction: tx,
Status: TxStatusPending,
ReceivedAt: time.Now(),
IsWIP: isWIP,
IP: ip,
}
return &poolTx
}