MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / ToProto

Method ToProto

state/state.go:134–175  ·  view source on GitHub ↗

ToProto takes the local state type and returns the equivalent proto type

()

Source from the content-addressed store, hash-verified

132
133// ToProto takes the local state type and returns the equivalent proto type
134func (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
178func FromProto(pb *tmstate.State) (*State, error) { //nolint:golint

Callers 13

BytesMethod · 0.95
TestValidateBlockCommitFunction · 0.45
execBlockOnProxyAppFunction · 0.45
PruneStatesMethod · 0.45
LoadValidatorsMethod · 0.45
saveValidatorsInfoMethod · 0.45
TestStateProtoFunction · 0.45
SaveBlockMethod · 0.45
saveBlockPartMethod · 0.45
SaveSeenCommitMethod · 0.45
TestLoadBlockPartFunction · 0.45
TestLoadBlockMetaFunction · 0.45

Calls

no outgoing calls

Tested by 5

TestValidateBlockCommitFunction · 0.36
TestStateProtoFunction · 0.36
TestLoadBlockPartFunction · 0.36
TestLoadBlockMetaFunction · 0.36
TestBlockFetchAtHeightFunction · 0.36