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

Method CheckMessage

fsm/transaction.go:261–283  ·  view source on GitHub ↗

CheckMessage() performs basic validations on the msg payload

(msg *anypb.Any)

Source from the content-addressed store, hash-verified

259
260// CheckMessage() performs basic validations on the msg payload
261func (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
286func (s *StateMachine) CheckFee(fee uint64, msg lib.MessageI) (err lib.ErrorI) {

Callers 2

CheckTxMethod · 0.95
TestCheckMessageFunction · 0.80

Calls 4

ErrEmptyMessageFunction · 0.92
FromAnyFunction · 0.92
ErrInvalidTxMessageFunction · 0.85
CheckMethod · 0.65

Tested by 1

TestCheckMessageFunction · 0.64