-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
94 lines (81 loc) · 2.68 KB
/
client.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
package aggregator
import (
"context"
"math/big"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/types"
"github.com/automata-network/multi-prover-avs/contracts/bindings"
"github.com/chzyer/logex"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rpc"
)
type Client struct {
client *rpc.Client
}
func NewClient(endpoint string) (*Client, error) {
logex.Infof("connecting to aggregator: %v", endpoint)
client, err := rpc.Dial(endpoint)
if err != nil {
return nil, logex.Trace(err)
}
return &Client{
client: client,
}, nil
}
type Metadata struct {
BatchId uint64 `json:"batch_id,omitempty"`
StartBlock uint64 `json:"start_block"`
EndBlock uint64 `json:"end_block"`
}
type TaskRequest struct {
Task *StateHeader
Signature *bls.Signature
OperatorId types.OperatorId
ProverSignature hexutil.Bytes
}
type StateHeader struct {
Identifier *hexutil.Big `json:"identifier"`
Metadata hexutil.Bytes `json:"metadata"`
State hexutil.Bytes `json:"state"`
QuorumNumbers hexutil.Bytes `json:"quorum_numbers"`
QuorumThresholdPercentages hexutil.Bytes `json:"quorum_threshold_percentages"`
ReferenceBlockNumber uint32 `json:"reference_blocknumber"`
}
func (s *StateHeader) ToAbi() *bindings.StateHeader {
return &bindings.StateHeader{
CommitteeId: new(big.Int).Set((*big.Int)(s.Identifier)),
Metadata: []byte(s.Metadata),
State: []byte(s.State),
QuorumNumbers: []byte(s.QuorumNumbers),
QuorumThresholdPercentages: []byte(s.QuorumThresholdPercentages),
ReferenceBlockNumber: s.ReferenceBlockNumber,
}
}
func (s *StateHeader) Digest() (types.TaskResponseDigest, error) {
digest, err := bindings.DigestStateHeader(s.ToAbi())
if err != nil {
return types.TaskResponseDigest{}, logex.Trace(err)
}
return digest, nil
}
func (c *Client) SubmitTask(ctx context.Context, task *TaskRequest) error {
var result bool
if err := c.client.CallContext(ctx, &result, "aggregator_submitTask", task); err != nil {
return logex.Trace(err)
}
return nil
}
func (c *Client) FetchTask(ctx context.Context, task *FetchTaskReq) (*FetchTaskResp, error) {
var result *FetchTaskResp
if err := c.client.CallContext(ctx, &result, "aggregator_fetchTask", task); err != nil {
return nil, logex.Trace(err)
}
return result, nil
}
func (c *Client) SubmitMetrics(ctx context.Context, req *SubmitMetricsReq) error {
var result interface{}
if err := c.client.CallContext(ctx, &result, "aggregator_submitMetrics", req); err != nil {
return logex.Trace(err)
}
return nil
}