mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-04-18 17:13:08 +00:00
fix compilation issues
This commit is contained in:
parent
ff7345b541
commit
088cc0f11b
@ -3,6 +3,9 @@ package common
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash"
|
||||
"sync"
|
||||
|
||||
@ -27,6 +30,27 @@ func ToMessageHash(b []byte) MessageHash {
|
||||
return result
|
||||
}
|
||||
|
||||
func ToMessageHashFromStringFormat(val string) (MessageHash, error) {
|
||||
if len(val) == 0 {
|
||||
return MessageHash{}, errors.New("empty message hash string not allowed")
|
||||
}
|
||||
|
||||
if len(val) < 2 || val[:2] != "0x" {
|
||||
return MessageHash{}, errors.New("string must start with 0x")
|
||||
}
|
||||
|
||||
// Remove "0x" prefix for hex decoding
|
||||
hexStr := val[2:]
|
||||
|
||||
// Verify the remaining string is valid hex
|
||||
v, err := hex.DecodeString(hexStr)
|
||||
if err != nil {
|
||||
return MessageHash{}, fmt.Errorf("invalid hex string: %v", err)
|
||||
|
||||
}
|
||||
return MessageHash(v), nil
|
||||
}
|
||||
|
||||
var sha256Pool = sync.Pool{New: func() interface{} {
|
||||
return sha256.New()
|
||||
}}
|
||||
|
||||
@ -1015,7 +1015,7 @@ func (n *WakuNode) RelayPublish(ctx context.Context, message *common.WakuMessage
|
||||
wg.Wait()
|
||||
if C.getRet(resp) == C.RET_OK {
|
||||
msgHash := C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
|
||||
parsedMsgHash, err := common.ToMessageHash(msgHash)
|
||||
parsedMsgHash, err := common.ToMessageHashFromStringFormat(msgHash)
|
||||
if err != nil {
|
||||
return common.MessageHash([32]byte{}), err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user