forked from ObolNetwork/charon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdutydefinition.go
90 lines (71 loc) · 2.81 KB
/
dutydefinition.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
// Copyright © 2022-2024 Obol Labs Inc. Licensed under the terms of a Business Source License 1.1
package core
import (
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/obolnetwork/charon/app/errors"
)
var (
_ DutyDefinition = AttesterDefinition{}
_ DutyDefinition = ProposerDefinition{}
_ DutyDefinition = SyncCommitteeDefinition{}
)
// NewAttesterDefinition is a convenience function that returns a new attester definition.
func NewAttesterDefinition(duty *eth2v1.AttesterDuty) AttesterDefinition {
return AttesterDefinition{AttesterDuty: *duty}
}
// AttesterDefinition defines an attester duty. It implements DutyDefinition.
// Note the slight rename from Duty to Definition to avoid overloading the term Duty.
type AttesterDefinition struct {
eth2v1.AttesterDuty
}
func (d AttesterDefinition) Clone() (DutyDefinition, error) {
duty := new(eth2v1.AttesterDuty)
err := cloneJSONMarshaler(&d.AttesterDuty, duty)
if err != nil {
return nil, errors.Wrap(err, "clone attester definition")
}
return NewAttesterDefinition(duty), nil
}
func (d AttesterDefinition) MarshalJSON() ([]byte, error) {
return d.AttesterDuty.MarshalJSON()
}
// NewProposerDefinition is a convenience function that returns a new proposer definition.
func NewProposerDefinition(duty *eth2v1.ProposerDuty) ProposerDefinition {
return ProposerDefinition{ProposerDuty: *duty}
}
// ProposerDefinition defines a block proposer duty. It implements DutyDefinition.
// Note the slight rename from Duty to Definition to avoid overloading the term Duty.
type ProposerDefinition struct {
eth2v1.ProposerDuty
}
func (d ProposerDefinition) Clone() (DutyDefinition, error) {
duty := new(eth2v1.ProposerDuty)
err := cloneJSONMarshaler(&d.ProposerDuty, duty)
if err != nil {
return nil, errors.Wrap(err, "clone proposer definition")
}
return NewProposerDefinition(duty), nil
}
func (d ProposerDefinition) MarshalJSON() ([]byte, error) {
return d.ProposerDuty.MarshalJSON()
}
// NewSyncCommitteeDefinition is a convenience function that returns a new SyncCommitteeDefinition.
func NewSyncCommitteeDefinition(duty *eth2v1.SyncCommitteeDuty) DutyDefinition {
return SyncCommitteeDefinition{SyncCommitteeDuty: *duty}
}
// SyncCommitteeDefinition defines a sync committee duty. It implements DutyDefinition.
// Note the slight rename from Duty to Definition to avoid overloading the term Duty.
type SyncCommitteeDefinition struct {
eth2v1.SyncCommitteeDuty
}
func (s SyncCommitteeDefinition) Clone() (DutyDefinition, error) {
duty := new(eth2v1.SyncCommitteeDuty)
err := cloneJSONMarshaler(&s.SyncCommitteeDuty, duty)
if err != nil {
return nil, errors.Wrap(err, "clone sync committee definition")
}
return NewSyncCommitteeDefinition(duty), nil
}
func (s SyncCommitteeDefinition) MarshalJSON() ([]byte, error) {
return s.SyncCommitteeDuty.MarshalJSON()
}