HandleMessageUnstake() is the proper handler for an `Unstake` message
(msg *MessageUnstake)
| 197 | |
| 198 | // HandleMessageUnstake() is the proper handler for an `Unstake` message |
| 199 | func (s *StateMachine) HandleMessageUnstake(msg *MessageUnstake) lib.ErrorI { |
| 200 | // extract an address object from the address bytes in the message |
| 201 | address := crypto.NewAddressFromBytes(msg.Address) |
| 202 | // get validator object from state |
| 203 | validator, err := s.GetValidator(address) |
| 204 | if err != nil { |
| 205 | return err |
| 206 | } |
| 207 | // check if the validator is already unstaking |
| 208 | if validator.UnstakingHeight != 0 { |
| 209 | return ErrValidatorUnstaking() |
| 210 | } |
| 211 | // get the governance parameters for 'unstaking blocks' |
| 212 | p, err := s.GetParamsVal() |
| 213 | if err != nil { |
| 214 | return err |
| 215 | } |
| 216 | // get unstaking blocks parameter |
| 217 | var unstakingBlocks uint64 |
| 218 | // if the validator isn't a delegator |
| 219 | if !validator.Delegate { |
| 220 | // use UnstakingBlocks for validators |
| 221 | unstakingBlocks = p.UnstakingBlocks |
| 222 | } else { |
| 223 | // use UnstakingBlocks for delegators |
| 224 | unstakingBlocks = p.DelegateUnstakingBlocks |
| 225 | } |
| 226 | // calculate the unstaking height for the validator |
| 227 | unstakingHeight := s.Height() + unstakingBlocks |
| 228 | // set the validator as 'unstaking' in the state |
| 229 | return s.SetValidatorUnstaking(address, validator, unstakingHeight) |
| 230 | } |
| 231 | |
| 232 | // HandleMessagePause() is the proper handler for an `Pause` message |
| 233 | func (s *StateMachine) HandleMessagePause(msg *MessagePause) lib.ErrorI { |