HandleMessagePause() is the proper handler for an `Pause` message
(msg *MessagePause)
| 231 | |
| 232 | // HandleMessagePause() is the proper handler for an `Pause` message |
| 233 | func (s *StateMachine) HandleMessagePause(msg *MessagePause) lib.ErrorI { |
| 234 | // extract the address object from the address bytes from the pause message |
| 235 | address := crypto.NewAddressFromBytes(msg.Address) |
| 236 | // get the validator from the state |
| 237 | validator, err := s.GetValidator(address) |
| 238 | if err != nil { |
| 239 | return err |
| 240 | } |
| 241 | // ensure the validator is not already paused |
| 242 | if validator.MaxPausedHeight != 0 { |
| 243 | return ErrValidatorPaused() |
| 244 | } |
| 245 | // ensure the validator is not unstaking |
| 246 | if validator.UnstakingHeight != 0 { |
| 247 | return ErrValidatorUnstaking() |
| 248 | } |
| 249 | // ensure the validator is not a delegate |
| 250 | if validator.Delegate { |
| 251 | return ErrValidatorIsADelegate() |
| 252 | } |
| 253 | // get validator the parameters from state |
| 254 | params, err := s.GetParamsVal() |
| 255 | if err != nil { |
| 256 | return err |
| 257 | } |
| 258 | // calculate the max paused height by adding MaxPauseBlocks to current height |
| 259 | maxPausedHeight := s.Height() + params.MaxPauseBlocks |
| 260 | // set the validator as paused in the state |
| 261 | return s.SetValidatorPaused(address, validator, maxPausedHeight) |
| 262 | } |
| 263 | |
| 264 | // HandleMessageUnpause() is the proper handler for an `Unpause` message |
| 265 | func (s *StateMachine) HandleMessageUnpause(msg *MessageUnpause) lib.ErrorI { |