ToProto takes the local state type and returns the equivalent proto type
()
| 132 | |
| 133 | // ToProto takes the local state type and returns the equivalent proto type |
| 134 | func (state *State) ToProto() (*tmstate.State, error) { |
| 135 | if state == nil { |
| 136 | return nil, errors.New("state is nil") |
| 137 | } |
| 138 | |
| 139 | sm := new(tmstate.State) |
| 140 | |
| 141 | sm.Version = state.Version |
| 142 | sm.ChainID = state.ChainID |
| 143 | sm.InitialHeight = state.InitialHeight |
| 144 | sm.LastBlockHeight = state.LastBlockHeight |
| 145 | |
| 146 | sm.LastBlockID = state.LastBlockID.ToProto() |
| 147 | sm.LastBlockTime = state.LastBlockTime |
| 148 | vals, err := state.Validators.ToProto() |
| 149 | if err != nil { |
| 150 | return nil, err |
| 151 | } |
| 152 | sm.Validators = vals |
| 153 | |
| 154 | nVals, err := state.NextValidators.ToProto() |
| 155 | if err != nil { |
| 156 | return nil, err |
| 157 | } |
| 158 | sm.NextValidators = nVals |
| 159 | |
| 160 | if state.LastBlockHeight >= 1 { // At Block 1 LastValidators is nil |
| 161 | lVals, err := state.LastValidators.ToProto() |
| 162 | if err != nil { |
| 163 | return nil, err |
| 164 | } |
| 165 | sm.LastValidators = lVals |
| 166 | } |
| 167 | |
| 168 | sm.LastHeightValidatorsChanged = state.LastHeightValidatorsChanged |
| 169 | sm.ConsensusParams = state.ConsensusParams |
| 170 | sm.LastHeightConsensusParamsChanged = state.LastHeightConsensusParamsChanged |
| 171 | sm.LastResultsHash = state.LastResultsHash |
| 172 | sm.AppHash = state.AppHash |
| 173 | |
| 174 | return sm, nil |
| 175 | } |
| 176 | |
| 177 | // FromProto takes a state proto message & returns the local state type |
| 178 | func FromProto(pb *tmstate.State) (*State, error) { //nolint:golint |
no outgoing calls