@@ -30,29 +30,29 @@ const (
30
30
31
31
// EonKeyPublisher is a service that publishes eon keys via a eon key publisher contract.
32
32
type EonKeyPublisher struct {
33
- dbpool * pgxpool.Pool
34
- client * ethclient.Client
35
- contract * bindings.EonKeyPublish
36
- privateKey * ecdsa.PrivateKey
33
+ dbpool * pgxpool.Pool
34
+ client * ethclient.Client
35
+ keyperSetManager * bindings.KeyperSetManager
36
+ privateKey * ecdsa.PrivateKey
37
37
38
38
keys chan keyper.EonPublicKey
39
39
}
40
40
41
41
func NewEonKeyPublisher (
42
42
dbpool * pgxpool.Pool ,
43
43
client * ethclient.Client ,
44
- eonKeyPublishAddress common.Address ,
44
+ keyperSetManagerAddress common.Address ,
45
45
privateKey * ecdsa.PrivateKey ,
46
46
) (* EonKeyPublisher , error ) {
47
- contract , err := bindings .NewEonKeyPublish ( eonKeyPublishAddress , client )
47
+ keyperSetManager , err := bindings .NewKeyperSetManager ( keyperSetManagerAddress , client )
48
48
if err != nil {
49
- return nil , errors .Wrap (err , "failed to instantiate eon key publisher contract" )
49
+ return nil , errors .Wrapf (err , "failed to instantiate keyper set manager contract at address %s" , keyperSetManagerAddress . Hex () )
50
50
}
51
51
return & EonKeyPublisher {
52
- dbpool : dbpool ,
53
- client : client ,
54
- contract : contract ,
55
- privateKey : privateKey ,
52
+ dbpool : dbpool ,
53
+ client : client ,
54
+ keyperSetManager : keyperSetManager ,
55
+ privateKey : privateKey ,
56
56
57
57
keys : make (chan keyper.EonPublicKey , eonKeyChannelSize ),
58
58
}, nil
@@ -155,8 +155,12 @@ func (p *EonKeyPublisher) publish(ctx context.Context, key []byte, keyperSetInde
155
155
}
156
156
157
157
func (p * EonKeyPublisher ) tryPublish (ctx context.Context , key []byte , keyperSetIndex uint64 , keyperIndex uint64 ) error {
158
+ contract , err := p .getEonKeyPublisherContract (keyperSetIndex )
159
+ if err != nil {
160
+ return err
161
+ }
158
162
keyperAddress := ethcrypto .PubkeyToAddress (p .privateKey .PublicKey )
159
- hasAlreadyVoted , err := p . contract .HasKeyperVoted (& bind.CallOpts {}, keyperAddress )
163
+ hasAlreadyVoted , err := contract .HasKeyperVoted (& bind.CallOpts {}, keyperAddress )
160
164
if err != nil {
161
165
return errors .Wrap (err , "failed to query eon key publisher contract if keyper has already voted" )
162
166
}
@@ -168,7 +172,7 @@ func (p *EonKeyPublisher) tryPublish(ctx context.Context, key []byte, keyperSetI
168
172
Msg ("not publishing eon key as keyper has already voted" )
169
173
return nil
170
174
}
171
- isAlreadyConfirmed , err := p . contract .EonKeyConfirmed (& bind.CallOpts {}, key )
175
+ isAlreadyConfirmed , err := contract .EonKeyConfirmed (& bind.CallOpts {}, key )
172
176
if err != nil {
173
177
return errors .Wrap (err , "failed to query eon key publisher contract if eon key is confirmed" )
174
178
}
@@ -188,7 +192,7 @@ func (p *EonKeyPublisher) tryPublish(ctx context.Context, key []byte, keyperSetI
188
192
if err != nil {
189
193
return errors .Wrap (err , "failed to construct tx opts" )
190
194
}
191
- tx , err := p . contract .PublishEonKey (opts , key , keyperIndex )
195
+ tx , err := contract .PublishEonKey (opts , key , keyperIndex )
192
196
if err != nil {
193
197
return errors .Wrap (err , "failed to send publish eon key tx" )
194
198
}
@@ -216,3 +220,24 @@ func (p *EonKeyPublisher) tryPublish(ctx context.Context, key []byte, keyperSetI
216
220
Msg ("successfully published eon key" )
217
221
return nil
218
222
}
223
+
224
+ func (p * EonKeyPublisher ) getEonKeyPublisherContract (keyperSetIndex uint64 ) (* bindings.EonKeyPublish , error ) {
225
+ opts := & bind.CallOpts {}
226
+ keyperSetAddress , err := p .keyperSetManager .GetKeyperSetAddress (opts , keyperSetIndex )
227
+ if err != nil {
228
+ return nil , errors .Wrapf (err , "failed to get keyper set address from manager for index %d" , keyperSetIndex )
229
+ }
230
+ keyperSet , err := bindings .NewKeyperSet (keyperSetAddress , p .client )
231
+ if err != nil {
232
+ return nil , errors .Wrapf (err , "failed to instantiate keyper set contract at address %s" , keyperSetAddress .Hex ())
233
+ }
234
+ eonKeyPublisherAddress , err := keyperSet .GetPublisher (opts )
235
+ if err != nil {
236
+ return nil , errors .Wrapf (err , "failed to get eon key publisher contract from keyper set at address %s" , keyperSetAddress .Hex ())
237
+ }
238
+ eonKeyPublisher , err := bindings .NewEonKeyPublish (eonKeyPublisherAddress , p .client )
239
+ if err != nil {
240
+ return nil , errors .Wrapf (err , "failed to instantiate eon key publisher contract at address %s" , eonKeyPublisherAddress .Hex ())
241
+ }
242
+ return eonKeyPublisher , nil
243
+ }
0 commit comments