2018-10-15 13:17:07 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2018-12-23 20:34:59 +00:00
|
|
|
"github.com/gogo/protobuf/jsonpb"
|
2018-10-15 13:17:07 +00:00
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
|
|
)
|
|
|
|
|
2018-12-04 03:05:22 +00:00
|
|
|
// InitialValidatorRegistryFromJSON retrieves the validator set that is stored in
|
2018-10-15 13:17:07 +00:00
|
|
|
// genesis.json.
|
2018-12-04 03:05:22 +00:00
|
|
|
func InitialValidatorRegistryFromJSON(genesisJSONPath string) ([]*pb.ValidatorRecord, error) {
|
2018-10-15 13:17:07 +00:00
|
|
|
// genesisJSONPath is a user input for the path of genesis.json.
|
|
|
|
// Ex: /path/to/my/genesis.json.
|
2018-12-05 23:44:07 +00:00
|
|
|
f, err := os.Open(genesisJSONPath) // #nosec
|
2018-10-15 13:17:07 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2018-12-01 22:09:12 +00:00
|
|
|
beaconState := &pb.BeaconState{}
|
|
|
|
if err := jsonpb.Unmarshal(f, beaconState); err != nil {
|
2018-10-15 13:17:07 +00:00
|
|
|
return nil, fmt.Errorf("error converting JSON to proto: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-12-04 03:05:22 +00:00
|
|
|
return beaconState.ValidatorRegistry, nil
|
2018-10-15 13:17:07 +00:00
|
|
|
}
|