-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
132 lines (106 loc) · 3.3 KB
/
interfaces.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package catapult_sync
import (
"context"
"io"
"time"
"github.com/pkg/errors"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk"
"github.com/proximax-storage/go-xpx-chain-sdk/sdk/websocket"
"github.com/proximax-storage/go-xpx-utils/logger"
)
// Change those values if needed depending on the catapult version and used consensus
var (
TransactionResultsTimeout = time.Minute * 8
TransactionCosigningTimeout = time.Second * 15 * 5
)
var (
ErrCatapultTimeout = errors.New("catapult is not responding for too long")
ErrCoSignTimeout = errors.New("no aggregate transaction is requested to cosign")
ErrCannotGetAggTransaction = errors.New("cannot get aggregate transaction to cosig")
ErrTxnDeadlineExceeded = errors.New("transaction deadline exceeded")
ErrNilHashPassed = errors.New("nil hash passed")
)
type TransactionSyncer interface {
io.Closer
transactionAnnouncer
transactionCache
Context() context.Context
}
type transactionAnnouncer interface {
Sync(time.Time, *sdk.Hash) <-chan Result
Announce(ctx context.Context, tx sdk.Transaction) (*sdk.SignedTransaction, error)
AnnounceSync(ctx context.Context, tx sdk.Transaction, opts ...AnnounceOption) <-chan Result
CoSign(ctx context.Context, hash *sdk.Hash, force bool) error
}
type transactionCache interface {
Unconfirmed() []*sdk.Hash
UnCosignedTransaction(hash *sdk.Hash) <-chan *AggregatedAddedResult
UnCosignedTransactions() []*sdk.AggregateTransaction
}
// Result interface is a result of transaction manipulation.
// If Err equals to nil then any kind of manipulation on transaction is successful.
// TODO Change name to appropriate one
type Result interface {
Hash() *sdk.Hash
Err() error
}
// Option types
type SyncerOption func(*syncerConfig)
type AnnounceOption func(*announceConfig)
// Syncer configuration
type syncerConfig struct {
wsClient websocket.CatapultClient
client *sdk.Client
connectionTimeout time.Duration
gcTimeout time.Duration
logger *logger.Logger
}
func WithLogger(l *logger.Logger) SyncerOption {
return func(config *syncerConfig) {
config.logger = l
}
}
func WithWsClient(client websocket.CatapultClient) SyncerOption {
return func(config *syncerConfig) {
config.wsClient = client
}
}
// WithHttpClient option configures Catapult SDK client to work with passed one
func WithClient(client *sdk.Client) SyncerOption {
return func(config *syncerConfig) {
config.client = client
}
}
// WSTimeout option specifies websocket connection timeout on start-up
func WSTimeout(timeout time.Duration) SyncerOption {
return func(config *syncerConfig) {
config.connectionTimeout = timeout
}
}
// WSTimeout option specifies
func GCTimeout(timeout time.Duration) SyncerOption {
return func(config *syncerConfig) {
config.gcTimeout = timeout
}
}
// Transaction Announcing configuration
type announceConfig struct {
lockDuration int64
lockDeadline time.Duration
lockAmount uint64
}
func LockDuration(duration int64) AnnounceOption {
return func(config *announceConfig) {
config.lockDuration = duration
}
}
func LockDeadline(deadline time.Duration) AnnounceOption {
return func(config *announceConfig) {
config.lockDeadline = deadline
}
}
func LockAmount(amount uint64) AnnounceOption {
return func(config *announceConfig) {
config.lockAmount = amount
}
}