func StateFromProto(s *pb.State) (*State, error) {
	validatorRegistry := make([]Validator, len(s.ValidatorRegistry))
	shardAndCommitteeForSlots := make([][]ShardAndCommittee, len(s.ShardCommittees))
	latestCrosslinks := make([]Crosslink, len(s.LatestCrosslinks))
	previousCrosslinks := make([]Crosslink, len(s.PreviousCrosslinks))
	latestBlockHashes := make([]chainhash.Hash, len(s.LatestBlockHashes))
	currentAttestations := make([]PendingAttestation, len(s.CurrentEpochAttestations))
	previousAttestations := make([]PendingAttestation, len(s.PreviousEpochAttestations))
	batchedBlockRoots := make([]chainhash.Hash, len(s.BatchedBlockRoots))
	pendingVotes := make([]AggregatedVote, len(s.PendingVotes))
	proposals := make([]ActiveProposal, len(s.Proposals))
	shardRegistry := make([]chainhash.Hash, len(s.ShardRegistry))

	fd, err := ForkDataFromProto(s.ForkData)
	if err != nil {
		return nil, err
	}

	for i := range validatorRegistry {
		v, err := ValidatorFromProto(s.ValidatorRegistry[i])
		if err != nil {
			return nil, err
		}
		validatorRegistry[i] = *v
	}

	for i := range shardAndCommitteeForSlots {
		shardAndCommitteeForSlots[i] = make([]ShardAndCommittee, len(s.ShardCommittees[i].Committees))
		for j := range shardAndCommitteeForSlots[i] {
			sc, err := ShardAndCommitteeFromProto(s.ShardCommittees[i].Committees[j])
			if err != nil {
				return nil, err
			}
			shardAndCommitteeForSlots[i][j] = *sc
		}
	}

	for i := range latestCrosslinks {
		c, err := CrosslinkFromProto(s.LatestCrosslinks[i])
		if err != nil {
			return nil, err
		}
		latestCrosslinks[i] = *c
	}

	for i := range previousCrosslinks {
		c, err := CrosslinkFromProto(s.PreviousCrosslinks[i])
		if err != nil {
			return nil, err
		}
		previousCrosslinks[i] = *c
	}

	for i := range latestBlockHashes {
		err := latestBlockHashes[i].SetBytes(s.LatestBlockHashes[i])
		if err != nil {
			return nil, err
		}
	}

	for i := range previousAttestations {
		a, err := PendingAttestationFromProto(s.PreviousEpochAttestations[i])
		if err != nil {
			return nil, err
		}
		previousAttestations[i] = *a
	}

	for i := range proposals {
		a, err := ActiveProposalFromProto(s.Proposals[i])
		if err != nil {
			return nil, err
		}
		proposals[i] = *a
	}

	for i := range pendingVotes {
		a, err := AggregatedVoteFromProto(s.PendingVotes[i])
		if err != nil {
			return nil, err
		}
		pendingVotes[i] = *a
	}

	for i := range currentAttestations {
		a, err := PendingAttestationFromProto(s.CurrentEpochAttestations[i])
		if err != nil {
			return nil, err
		}
		currentAttestations[i] = *a
	}

	for i := range batchedBlockRoots {
		err := batchedBlockRoots[i].SetBytes(s.BatchedBlockRoots[i])
		if err != nil {
			return nil, err
		}
	}

	for i := range shardRegistry {
		err := shardRegistry[i].SetBytes(s.ShardRegistry[i])
		if err != nil {
			return nil, err
		}
	}

	newState := &State{
		Slot:                               s.Slot,
		GenesisTime:                        s.GenesisTime,
		EpochIndex:                         s.EpochIndex,
		ForkData:                           *fd,
		ValidatorRegistry:                  validatorRegistry,
		ValidatorRegistryLatestChangeEpoch: s.ValidatorRegistryLatestChangeEpoch,
		ValidatorRegistryExitCount:         s.ValidatorRegistryExitCount,
		ShardAndCommitteeForSlots:          shardAndCommitteeForSlots,
		PreviousJustifiedEpoch:             s.PreviousJustifiedEpoch,
		JustifiedEpoch:                     s.JustifiedEpoch,
		JustificationBitfield:              s.JustificationBitField,
		FinalizedEpoch:                     s.FinalizedEpoch,
		LatestCrosslinks:                   latestCrosslinks,
		PreviousCrosslinks:                 previousCrosslinks,
		LatestBlockHashes:                  latestBlockHashes,
		CurrentEpochAttestations:           currentAttestations,
		PreviousEpochAttestations:          previousAttestations,
		BatchedBlockRoots:                  batchedBlockRoots,
		ShardRegistry:                      shardRegistry,
		PendingVotes:                       pendingVotes,
		Proposals:                          proposals,
	}

	err = newState.ValidatorRegistryDeltaChainTip.SetBytes(s.ValidatorRegistryDeltaChainTip)
	if err != nil {
		return nil, err
	}

	err = newState.RandaoMix.SetBytes(s.RandaoMix)
	if err != nil {
		return nil, err
	}

	err = newState.NextRandaoMix.SetBytes(s.NextRandaoMix)
	if err != nil {
		return nil, err
	}

	newState.ValidatorBalances = append([]uint64{}, s.ValidatorBalances...)

	return newState, nil
}
// StateFromProto gets the state fromo the protobuf representation.
StateFromProto gets the state fromo the protobuf representation.
// StateFromProto gets the state fromo the protobuf representation .
func StateFromProto(s *pb.State) (*State, error) {
	validatorRegistry := make([]Validator, len(s.ValidatorRegistry))
	shardAndCommitteeForSlots := make([][]ShardAndCommittee, len(s.ShardCommittees))
	latestCrosslinks := make([]Crosslink, len(s.LatestCrosslinks))
	previousCrosslinks := make([]Crosslink, len(s.PreviousCrosslinks))
	latestBlockHashes := make([]chainhash.Hash, len(s.LatestBlockHashes))
	currentAttestations := make([]PendingAttestation, len(s.CurrentEpochAttestations))
	previousAttestations := make([]PendingAttestation, len(s.PreviousEpochAttestations))
	batchedBlockRoots := make([]chainhash.Hash, len(s.BatchedBlockRoots))
	pendingVotes := make([]AggregatedVote, len(s.PendingVotes))
	proposals := make([]ActiveProposal, len(s.Proposals))
	shardRegistry := make([]chainhash.Hash, len(s.ShardRegistry))
	fd, err := ForkDataFromProto(s.ForkData)
	if err != nil {
		return nil, err
	}
	for i := range validatorRegistry {
		v, err := ValidatorFromProto(s.ValidatorRegistry[i])
		if err != nil {
			return nil, err
		}
		validatorRegistry[i] = *v
	}
	for i := range shardAndCommitteeForSlots {
		shardAndCommitteeForSlots[i] = make([]ShardAndCommittee, len(s.ShardCommittees[i].Committees))
		for j := range shardAndCommitteeForSlots[i] {
			sc, err := ShardAndCommitteeFromProto(s.ShardCommittees[i].Committees[j])
			if err != nil {
				return nil, err
			}
			shardAndCommitteeForSlots[i][j] = *sc
		}
	}
	for i := range latestCrosslinks {
		c, err := CrosslinkFromProto(s.LatestCrosslinks[i])
		if err != nil {
			return nil, err
		}
		latestCrosslinks[i] = *c
	}
	for i := range previousCrosslinks {
		c, err := CrosslinkFromProto(s.PreviousCrosslinks[i])
		if err != nil {
			return nil, err
		}
		previousCrosslinks[i] = *c
	}
	for i := range latestBlockHashes {
		err := latestBlockHashes[i].SetBytes(s.LatestBlockHashes[i])
		if err != nil {
			return nil, err
		}
	}
	for i := range previousAttestations {
		a, err := PendingAttestationFromProto(s.PreviousEpochAttestations[i])
		if err != nil {
			return nil, err
		}
		previousAttestations[i] = *a
	}
	for i := range proposals {
		a, err := ActiveProposalFromProto(s.Proposals[i])
		if err != nil {
			return nil, err
		}
		proposals[i] = *a
	}
	for i := range pendingVotes {
		a, err := AggregatedVoteFromProto(s.PendingVotes[i])
		if err != nil {
			return nil, err
		}
		pendingVotes[i] = *a
	}
	for i := range currentAttestations {
		a, err := PendingAttestationFromProto(s.CurrentEpochAttestations[i])
		if err != nil {
			return nil, err
		}
		currentAttestations[i] = *a
	}
	for i := range batchedBlockRoots {
		err := batchedBlockRoots[i].SetBytes(s.BatchedBlockRoots[i])
		if err != nil {
			return nil, err
		}
	}
	for i := range shardRegistry {
		err := shardRegistry[i].SetBytes(s.ShardRegistry[i])
		if err != nil {
			return nil, err
		}
	}
	newState := &State{
		Slot:                               s.Slot,
		GenesisTime:                        s.GenesisTime,
		EpochIndex:                         s.EpochIndex,
		ForkData:                           *fd,
		ValidatorRegistry:                  validatorRegistry,
		ValidatorRegistryLatestChangeEpoch: s.ValidatorRegistryLatestChangeEpoch,
		ValidatorRegistryExitCount:         s.ValidatorRegistryExitCount,
		ShardAndCommitteeForSlots:          shardAndCommitteeForSlots,
		PreviousJustifiedEpoch:             s.PreviousJustifiedEpoch,
		JustifiedEpoch:                     s.JustifiedEpoch,
		JustificationBitfield:              s.JustificationBitField,
		FinalizedEpoch:                     s.FinalizedEpoch,
		LatestCrosslinks:                   latestCrosslinks,
		PreviousCrosslinks:                 previousCrosslinks,
		LatestBlockHashes:                  latestBlockHashes,
		CurrentEpochAttestations:           currentAttestations,
		PreviousEpochAttestations:          previousAttestations,
		BatchedBlockRoots:                  batchedBlockRoots,
		ShardRegistry:                      shardRegistry,
		PendingVotes:                       pendingVotes,
		Proposals:                          proposals,
	}
	err = newState.ValidatorRegistryDeltaChainTip.SetBytes(s.ValidatorRegistryDeltaChainTip)
	if err != nil {
		return nil, err
	}
	err = newState.RandaoMix.SetBytes(s.RandaoMix)
	if err != nil {
		return nil, err
	}
	err = newState.NextRandaoMix.SetBytes(s.NextRandaoMix)
	if err != nil {
		return nil, err
	}
	newState.ValidatorBalances = append([]uint64{}, s.ValidatorBalances...)
	return newState, nil
}
func StateFromProto ( s * pb . State ) ( * State , error ) { validatorRegistry := make ( [ ] Validator , len ( s . ValidatorRegistry ) ) shardAndCommitteeForSlots := make ( [ ] [ ] ShardAndCommittee , len ( s . ShardCommittees ) ) latestCrosslinks := make ( [ ] Crosslink , len ( s . LatestCrosslinks ) ) previousCrosslinks := make ( [ ] Crosslink , len ( s . PreviousCrosslinks ) ) latestBlockHashes := make ( [ ] chainhash . Hash , len ( s . LatestBlockHashes ) ) currentAttestations := make ( [ ] PendingAttestation , len ( s . CurrentEpochAttestations ) ) previousAttestations := make ( [ ] PendingAttestation , len ( s . PreviousEpochAttestations ) ) batchedBlockRoots := make ( [ ] chainhash . Hash , len ( s . BatchedBlockRoots ) ) pendingVotes := make ( [ ] AggregatedVote , len ( s . PendingVotes ) ) proposals := make ( [ ] ActiveProposal , len ( s . Proposals ) ) shardRegistry := make ( [ ] chainhash . Hash , len ( s . ShardRegistry ) ) fd , err := ForkDataFromProto ( s . ForkData ) if err != nil { return nil , err } for i := range validatorRegistry { v , err := ValidatorFromProto ( s . ValidatorRegistry [ i ] ) if err != nil { return nil , err } validatorRegistry [ i ] = * v } for i := range shardAndCommitteeForSlots { shardAndCommitteeForSlots [ i ] = make ( [ ] ShardAndCommittee , len ( s . ShardCommittees [ i ] . Committees ) ) for j := range shardAndCommitteeForSlots [ i ] { sc , err := ShardAndCommitteeFromProto ( s . ShardCommittees [ i ] . Committees [ j ] ) if err != nil { return nil , err } shardAndCommitteeForSlots [ i ] [ j ] = * sc } } for i := range latestCrosslinks { c , err := CrosslinkFromProto ( s . LatestCrosslinks [ i ] ) if err != nil { return nil , err } latestCrosslinks [ i ] = * c } for i := range previousCrosslinks { c , err := CrosslinkFromProto ( s . PreviousCrosslinks [ i ] ) if err != nil { return nil , err } previousCrosslinks [ i ] = * c } for i := range latestBlockHashes { err := latestBlockHashes [ i ] . SetBytes ( s . LatestBlockHashes [ i ] ) if err != nil { return nil , err } } for i := range previousAttestations { a , err := PendingAttestationFromProto ( s . PreviousEpochAttestations [ i ] ) if err != nil { return nil , err } previousAttestations [ i ] = * a } for i := range proposals { a , err := ActiveProposalFromProto ( s . Proposals [ i ] ) if err != nil { return nil , err } proposals [ i ] = * a } for i := range pendingVotes { a , err := AggregatedVoteFromProto ( s . PendingVotes [ i ] ) if err != nil { return nil , err } pendingVotes [ i ] = * a } for i := range currentAttestations { a , err := PendingAttestationFromProto ( s . CurrentEpochAttestations [ i ] ) if err != nil { return nil , err } currentAttestations [ i ] = * a } for i := range batchedBlockRoots { err := batchedBlockRoots [ i ] . SetBytes ( s . BatchedBlockRoots [ i ] ) if err != nil { return nil , err } } for i := range shardRegistry { err := shardRegistry [ i ] . SetBytes ( s . ShardRegistry [ i ] ) if err != nil { return nil , err } } newState := & State { Slot : s . Slot , GenesisTime : s . GenesisTime , EpochIndex : s . EpochIndex , ForkData : * fd , ValidatorRegistry : validatorRegistry , ValidatorRegistryLatestChangeEpoch : s . ValidatorRegistryLatestChangeEpoch , ValidatorRegistryExitCount : s . ValidatorRegistryExitCount , ShardAndCommitteeForSlots : shardAndCommitteeForSlots , PreviousJustifiedEpoch : s . PreviousJustifiedEpoch , JustifiedEpoch : s . JustifiedEpoch , JustificationBitfield : s . JustificationBitField , FinalizedEpoch : s . FinalizedEpoch , LatestCrosslinks : latestCrosslinks , PreviousCrosslinks : previousCrosslinks , LatestBlockHashes : latestBlockHashes , CurrentEpochAttestations : currentAttestations , PreviousEpochAttestations : previousAttestations , BatchedBlockRoots : batchedBlockRoots , ShardRegistry : shardRegistry , PendingVotes : pendingVotes , Proposals : proposals , } err = newState . ValidatorRegistryDeltaChainTip . SetBytes ( s . ValidatorRegistryDeltaChainTip ) if err != nil { return nil , err } err = newState . RandaoMix . SetBytes ( s . RandaoMix ) if err != nil { return nil , err } err = newState . NextRandaoMix . SetBytes ( s . NextRandaoMix ) if err != nil { return nil , err } newState . ValidatorBalances = append ( [ ] uint64 { } , s . ValidatorBalances ... ) return newState , nil }
StateFromProto gets the state fromo the protobuf representation.
StateFromProto gets the state fromo the protobuf representation .