1
- package sync
1
+ package chainsync
2
2
3
3
import (
4
4
"context"
5
5
"crypto/ecdsa"
6
- "io"
7
6
"math/big"
8
7
9
8
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -12,25 +11,19 @@ import (
12
11
"github.com/pkg/errors"
13
12
"github.com/shutter-network/shop-contracts/bindings"
14
13
15
- "github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync /client"
16
- "github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync /event"
17
- "github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync /syncer"
14
+ "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync /client"
15
+ "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync /event"
16
+ "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync /syncer"
18
17
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/number"
19
18
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/logger"
20
19
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
21
20
)
22
21
23
22
var noopLogger = & logger.NoopLogger {}
24
23
25
- var ErrServiceNotInstantiated = errors .New ("service is not instantiated, pass a handler function option. " )
24
+ var ErrServiceNotInstantiated = errors .New ("service is not instantiated, pass a handler function option" )
26
25
27
- type ShutterSync interface {
28
- io.Closer
29
- // Start starts an additional worker syncing job
30
- Start () error
31
- }
32
-
33
- type ShutterL2Client struct {
26
+ type Client struct {
34
27
client.Client
35
28
log log.Logger
36
29
@@ -49,7 +42,7 @@ type ShutterL2Client struct {
49
42
services []service.Service
50
43
}
51
44
52
- func NewShutterL2Client (ctx context.Context , options ... Option ) (* ShutterL2Client , error ) {
45
+ func NewClient (ctx context.Context , options ... Option ) (* Client , error ) {
53
46
opts := defaultOptions ()
54
47
for _ , option := range options {
55
48
err := option (opts )
@@ -63,7 +56,7 @@ func NewShutterL2Client(ctx context.Context, options ...Option) (*ShutterL2Clien
63
56
return nil , err
64
57
}
65
58
66
- c := & ShutterL2Client {
59
+ c := & Client {
67
60
log : noopLogger ,
68
61
services : []service.Service {},
69
62
}
@@ -75,11 +68,11 @@ func NewShutterL2Client(ctx context.Context, options ...Option) (*ShutterL2Clien
75
68
return c , nil
76
69
}
77
70
78
- func (s * ShutterL2Client ) getServices () []service.Service {
71
+ func (s * Client ) getServices () []service.Service {
79
72
return s .services
80
73
}
81
74
82
- func (s * ShutterL2Client ) GetShutterState (ctx context.Context ) (* event.ShutterState , error ) {
75
+ func (s * Client ) GetShutterState (ctx context.Context ) (* event.ShutterState , error ) {
83
76
if s .sssync == nil {
84
77
return nil , errors .Wrap (ErrServiceNotInstantiated , "ShutterStateSyncer service not instantiated" )
85
78
}
@@ -89,7 +82,7 @@ func (s *ShutterL2Client) GetShutterState(ctx context.Context) (*event.ShutterSt
89
82
return s .sssync .GetShutterState (ctx , opts )
90
83
}
91
84
92
- func (s * ShutterL2Client ) GetKeyperSetByIndex (ctx context.Context , index uint64 ) (* event.KeyperSet , error ) {
85
+ func (s * Client ) GetKeyperSetByIndex (ctx context.Context , index uint64 ) (* event.KeyperSet , error ) {
93
86
if s .kssync == nil {
94
87
return nil , errors .Wrap (ErrServiceNotInstantiated , "KeyperSetSyncer service not instantiated" )
95
88
}
@@ -99,7 +92,7 @@ func (s *ShutterL2Client) GetKeyperSetByIndex(ctx context.Context, index uint64)
99
92
return s .kssync .GetKeyperSetByIndex (ctx , opts , index )
100
93
}
101
94
102
- func (s * ShutterL2Client ) GetKeyperSetForBlock (ctx context.Context , b * number.BlockNumber ) (* event.KeyperSet , error ) {
95
+ func (s * Client ) GetKeyperSetForBlock (ctx context.Context , b * number.BlockNumber ) (* event.KeyperSet , error ) {
103
96
if s .kssync == nil {
104
97
return nil , errors .Wrap (ErrServiceNotInstantiated , "KeyperSetSyncer service not instantiated" )
105
98
}
@@ -109,7 +102,7 @@ func (s *ShutterL2Client) GetKeyperSetForBlock(ctx context.Context, b *number.Bl
109
102
return s .kssync .GetKeyperSetForBlock (ctx , opts , b )
110
103
}
111
104
112
- func (s * ShutterL2Client ) GetEonPubKeyForEon (ctx context.Context , eon uint64 ) (* event.EonPublicKey , error ) {
105
+ func (s * Client ) GetEonPubKeyForEon (ctx context.Context , eon uint64 ) (* event.EonPublicKey , error ) {
113
106
if s .sssync == nil {
114
107
return nil , errors .Wrap (ErrServiceNotInstantiated , "ShutterStateSyncer service not instantiated" )
115
108
}
@@ -119,8 +112,9 @@ func (s *ShutterL2Client) GetEonPubKeyForEon(ctx context.Context, eon uint64) (*
119
112
return s .epksync .GetEonPubKeyForEon (ctx , opts , eon )
120
113
}
121
114
122
- func (s * ShutterL2Client ) BroadcastEonKey (ctx context.Context , eon uint64 , eonPubKey []byte ) (* types.Transaction , error ) {
123
- // TODO: first do a getEonKey. If we already have something (ideally the same)
115
+ func (s * Client ) BroadcastEonKey (ctx context.Context , eon uint64 , eonPubKey []byte ) (* types.Transaction , error ) {
116
+ // TODO: first do a getEonKey. If we already have this key, do nothing,
117
+ // if we have a different key, error
124
118
// don't do a transaction
125
119
// s.KeyBroadcast.GetEonKey(eon)
126
120
if s .privKey == nil {
@@ -140,7 +134,7 @@ func (s *ShutterL2Client) BroadcastEonKey(ctx context.Context, eon uint64, eonPu
140
134
141
135
// ChainID returns the chainid of the underlying L2 chain.
142
136
// This value is cached, since it is not expected to change.
143
- func (s * ShutterL2Client ) ChainID (ctx context.Context ) (* big.Int , error ) {
137
+ func (s * Client ) ChainID (ctx context.Context ) (* big.Int , error ) {
144
138
if s .chainID == nil {
145
139
cid , err := s .Client .ChainID (ctx )
146
140
if err != nil {
@@ -151,6 +145,6 @@ func (s *ShutterL2Client) ChainID(ctx context.Context) (*big.Int, error) {
151
145
return s .chainID , nil
152
146
}
153
147
154
- func (s * ShutterL2Client ) Start (_ context.Context , runner service.Runner ) error {
148
+ func (s * Client ) Start (_ context.Context , runner service.Runner ) error {
155
149
return runner .StartService (s .getServices ()... )
156
150
}
0 commit comments