/
lighthouse_model_aggregation.go
50 lines (41 loc) · 1.43 KB
/
lighthouse_model_aggregation.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
package lighthouse
import (
"encoding/hex"
"strconv"
"github.com/pkg/errors"
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
)
type aggregateModel struct {
Data attestationModel `json:"data"`
}
func (m *aggregateModel) toProto() (*ethpb.AggregateAttestationAndProof, error) {
data, err := m.Data.toProto()
if err != nil {
return nil, errors.Wrap(err, "failed to parse aggregation data")
}
return ðpb.AggregateAttestationAndProof{
Aggregate: data,
}, nil
}
type signedAggregateMessageModel struct {
AggregatorIndex string `json:"aggregator_index"`
SelectionProof string `json:"selection_proof"`
Aggregate attestationModel `json:"aggregate"`
}
func toSignedAggregateMessageModel(message *ethpb.AggregateAttestationAndProof) signedAggregateMessageModel {
return signedAggregateMessageModel{
AggregatorIndex: strconv.Itoa(int(message.GetAggregatorIndex())),
SelectionProof: "0x" + hex.EncodeToString(message.GetSelectionProof()),
Aggregate: toAttestationModel(message.GetAggregate()),
}
}
type signedAggregateModel struct {
Message signedAggregateMessageModel `json:"message"`
Signature string `json:"signature"`
}
func toSignedAggregateModel(sig []byte, message *ethpb.AggregateAttestationAndProof) signedAggregateModel {
return signedAggregateModel{
Message: toSignedAggregateMessageModel(message),
Signature: "0x" + hex.EncodeToString(sig),
}
}