MCPcopy
hub / github.com/canopy-network/canopy / HandleMessageUnstake

Method HandleMessageUnstake

fsm/message.go:199–230  ·  view source on GitHub ↗

HandleMessageUnstake() is the proper handler for an `Unstake` message

(msg *MessageUnstake)

Source from the content-addressed store, hash-verified

197
198// HandleMessageUnstake() is the proper handler for an `Unstake` message
199func (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
233func (s *StateMachine) HandleMessagePause(msg *MessagePause) lib.ErrorI {

Callers 2

HandleMessageMethod · 0.95
TestMessageUnstakeFunction · 0.80

Calls 6

GetValidatorMethod · 0.95
GetParamsValMethod · 0.95
HeightMethod · 0.95
SetValidatorUnstakingMethod · 0.95
NewAddressFromBytesFunction · 0.92
ErrValidatorUnstakingFunction · 0.85

Tested by 1

TestMessageUnstakeFunction · 0.64