Skip to content

Commit

Permalink
Add liteapi.ConvertSendMessagePayloadToMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Nov 30, 2023
1 parent ea31b3f commit 8e94e5f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions liteapi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@ import (

// VerifySendMessagePayload verifies that the given payload is an external message ready to be sent to the blockchain.
func VerifySendMessagePayload(payload []byte) error {
_, err := ConvertSendMessagePayloadToMessage(payload)
return err
}

// ConvertSendMessagePayloadToMessage converts the given payload to a tlb.Message.
// It also verifies that the message is an external message ready to be sent to the blockchain.
func ConvertSendMessagePayloadToMessage(payload []byte) (*tlb.Message, error) {
roots, err := boc.DeserializeBoc(payload)
if err != nil {
return err
return nil, err
}
if len(roots) != 1 {
return fmt.Errorf("external message is not a valid bag of cells")
return nil, fmt.Errorf("external message is not a valid bag of cells")
}
root := roots[0]
if root.Level() != 0 {
return fmt.Errorf("external message must have zero level")
return nil, fmt.Errorf("external message must have zero level")
}
var msg tlb.Message
if err := tlb.Unmarshal(root, &msg); err != nil {
return fmt.Errorf("external message is not a tlb.Message")
return nil, fmt.Errorf("external message is not a tlb.Message")
}
if msg.Info.SumType != "ExtInMsgInfo" {
return fmt.Errorf("external message must begin with ext_in_msg_info$10")
return nil, fmt.Errorf("external message must begin with ext_in_msg_info$10")
}
return nil
return &msg, nil
}

0 comments on commit 8e94e5f

Please sign in to comment.