mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
d020e1b2d9
* Correctly display epoch participation in `GetStateV2` * fix file names * handle null case Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
33 lines
771 B
Go
33 lines
771 B
Go
package apimiddleware
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"strconv"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// EpochParticipation represents participation of validators in their duties.
|
|
type EpochParticipation []string
|
|
|
|
func (p *EpochParticipation) UnmarshalJSON(b []byte) error {
|
|
if string(b) == "null" {
|
|
return nil
|
|
}
|
|
if len(b) < 2 {
|
|
return errors.New("epoch participation length must be at least 2")
|
|
}
|
|
|
|
// Remove leading and trailing quotation marks.
|
|
decoded, err := base64.StdEncoding.DecodeString(string(b[1 : len(b)-1]))
|
|
if err != nil {
|
|
return errors.Wrapf(err, "could not decode epoch participation base64 value")
|
|
}
|
|
|
|
*p = make([]string, len(decoded))
|
|
for i, participation := range decoded {
|
|
(*p)[i] = strconv.FormatUint(uint64(participation), 10)
|
|
}
|
|
return nil
|
|
}
|