Skip to content

Commit 7ad00c2

Browse files
committed
Fix validator API request
Deserializing the pubkey does not work out of the box. For simplicity, we parse it as a string and then add a getter that performs deserialization.
1 parent ca187b3 commit 7ad00c2

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

rolling-shutter/medley/beaconapiclient/getvalidator.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package beaconapiclient
22

33
import (
44
"context"
5+
"encoding/hex"
56
"encoding/json"
67
"fmt"
78
"io"
@@ -25,14 +26,14 @@ type ValidatorData struct {
2526
}
2627

2728
type Validator struct {
28-
Pubkey blst.P1Affine `json:"pubkey"`
29-
WithdrawalCredentials string `json:"withdrawal_credentials,string"`
30-
EffectiveBalance uint64 `json:"effective_balance,string"`
31-
Slashed bool `json:"slashed"`
32-
ActivationEligibilityEpoch uint64 `json:"activation_eligibility_epoch,string"`
33-
ActivationEpoch uint64 `json:"activation_epoch,string"`
34-
ExitEpoch uint64 `json:"exit_epoch,string"`
35-
WithdrawalEpoch uint64 `json:"withdrawal_epoch,string"`
29+
PubkeyHex string `json:"pubkey"`
30+
WithdrawalCredentials string `json:"withdrawal_credentials"`
31+
EffectiveBalance uint64 `json:"effective_balance,string"`
32+
Slashed bool `json:"slashed"`
33+
ActivationEligibilityEpoch uint64 `json:"activation_eligibility_epoch,string"`
34+
ActivationEpoch uint64 `json:"activation_epoch,string"`
35+
ExitEpoch uint64 `json:"exit_epoch,string"`
36+
WithdrawalEpoch uint64 `json:"withdrawal_epoch,string"`
3637
}
3738

3839
func (c *Client) GetValidatorByIndex(
@@ -71,3 +72,23 @@ func (c *Client) GetValidatorByIndex(
7172

7273
return response, nil
7374
}
75+
76+
func (v *Validator) GetPubkey() (*blst.P1Affine, error) {
77+
pubkeyHex := v.PubkeyHex
78+
if pubkeyHex[:2] == "0x" {
79+
pubkeyHex = pubkeyHex[2:]
80+
}
81+
82+
pubkeyBytes, err := hex.DecodeString(pubkeyHex)
83+
if err != nil {
84+
return nil, errors.Wrap(err, "failed to hex decode validator pubkey")
85+
}
86+
87+
pubkey := new(blst.P1Affine)
88+
pubkey = pubkey.Uncompress(pubkeyBytes)
89+
if pubkey == nil {
90+
return nil, errors.New("failed to deserialize pubkey")
91+
}
92+
93+
return pubkey, nil
94+
}

0 commit comments

Comments
 (0)