From 8e94e5fa437b13f359a5056fc81bb64a1ff746fa Mon Sep 17 00:00:00 2001 From: "aleksej.paschenko" Date: Tue, 28 Nov 2023 17:03:46 +0300 Subject: [PATCH] Add liteapi.ConvertSendMessagePayloadToMessage --- liteapi/utils.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/liteapi/utils.go b/liteapi/utils.go index 1d1859cf..b4a31a46 100644 --- a/liteapi/utils.go +++ b/liteapi/utils.go @@ -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 }