-
Notifications
You must be signed in to change notification settings - Fork 651
/
transaction.go
52 lines (44 loc) · 1.31 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
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, but can be processed in the future
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)
}
// Transaction represents a pool tx
type Transaction struct {
types.Transaction
Status TxStatus
state.ZKCounters
ReceivedAt time.Time
PreprocessedStateRoot common.Hash
IsWIP bool
IP string
}
// NewTransaction creates a new transaction
func NewTransaction(tx types.Transaction, ip string, isWIP bool, p *Pool) *Transaction {
poolTx := Transaction{
Transaction: tx,
Status: TxStatusPending,
ReceivedAt: time.Now(),
IsWIP: isWIP,
IP: ip,
}
return &poolTx
}