mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 03:01:19 +00:00
29 lines
729 B
Go
29 lines
729 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/golang/protobuf/jsonpb"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
)
|
|
|
|
// InitialValidatorRegistryFromJSON retrieves the validator set that is stored in
|
|
// genesis.json.
|
|
func InitialValidatorRegistryFromJSON(genesisJSONPath string) ([]*pb.ValidatorRecord, error) {
|
|
// #nosec G304
|
|
// genesisJSONPath is a user input for the path of genesis.json.
|
|
// Ex: /path/to/my/genesis.json.
|
|
f, err := os.Open(genesisJSONPath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
beaconState := &pb.BeaconState{}
|
|
if err := jsonpb.Unmarshal(f, beaconState); err != nil {
|
|
return nil, fmt.Errorf("error converting JSON to proto: %v", err)
|
|
}
|
|
|
|
return beaconState.ValidatorRegistry, nil
|
|
}
|