whisper: fix message payload

error handling and empty payload
This commit is contained in:
Jarrad Hope 2016-06-15 14:37:40 +02:00
parent 4f3f6e28d5
commit 79328a5f01
2 changed files with 6 additions and 2 deletions

View file

@ -178,6 +178,9 @@ func (s *PublicWhisperAPI) Post(args PostArgs) (bool, error) {
// construct whisper message with transmission options
message := NewMessage(common.FromHex(args.Payload))
if len(message.Payload) == 0 && len(args.Payload) > 0 {
message.Payload = []byte(args.Payload)
}
options := Options{
To: crypto.ToECDSAPub(common.FromHex(args.To)),
TTL: time.Duration(args.TTL) * time.Second,

View file

@ -302,10 +302,11 @@ func (self *Whisper) open(envelope *Envelope) *Message {
// Iterate over the keys and try to decrypt the message
for _, key := range self.keys {
message, err := envelope.Open(key)
if err == nil {
switch err {
case nil:
message.To = &key.PublicKey
return message
} else if err == ecies.ErrInvalidPublicKey {
case ecies.ErrInvalidPublicKey:
return message
}
}