CheckMessage() performs basic validations on the msg payload
(msg *anypb.Any)
| 259 | |
| 260 | // CheckMessage() performs basic validations on the msg payload |
| 261 | func (s *StateMachine) CheckMessage(msg *anypb.Any) (message lib.MessageI, err lib.ErrorI) { |
| 262 | // ensure the message isn't nil |
| 263 | if msg == nil { |
| 264 | return nil, lib.ErrEmptyMessage() |
| 265 | } |
| 266 | // extract the message from an protobuf any |
| 267 | proto, err := lib.FromAny(msg) |
| 268 | if err != nil { |
| 269 | return nil, err |
| 270 | } |
| 271 | // cast the proto message to a Message interface that may be interpreted |
| 272 | message, ok := proto.(lib.MessageI) |
| 273 | // if cast fails, throw an error |
| 274 | if !ok { |
| 275 | return nil, ErrInvalidTxMessage() |
| 276 | } |
| 277 | // do stateless checks on the message |
| 278 | if err = message.Check(); err != nil { |
| 279 | return nil, err |
| 280 | } |
| 281 | // return the message as the interface |
| 282 | return message, nil |
| 283 | } |
| 284 | |
| 285 | // CheckFee() validates the fee amount is sufficient to pay for a transaction |
| 286 | func (s *StateMachine) CheckFee(fee uint64, msg lib.MessageI) (err lib.ErrorI) { |