@@ -227,8 +227,9 @@ type newMessageOverride struct {
227227 Padding hexutil.Bytes
228228}
229229
230- // Post a message on the Whisper network.
231- func (api * PublicWhisperAPI ) Post (ctx context.Context , req NewMessage ) (bool , error ) {
230+ // Post posts a message on the Whisper network.
231+ // returns the hash of the message in case of success.
232+ func (api * PublicWhisperAPI ) Post (ctx context.Context , req NewMessage ) (hexutil.Bytes , error ) {
232233 var (
233234 symKeyGiven = len (req .SymKeyID ) > 0
234235 pubKeyGiven = len (req .PublicKey ) > 0
@@ -237,7 +238,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
237238
238239 // user must specify either a symmetric or an asymmetric key
239240 if (symKeyGiven && pubKeyGiven ) || (! symKeyGiven && ! pubKeyGiven ) {
240- return false , ErrSymAsym
241+ return nil , ErrSymAsym
241242 }
242243
243244 params := & MessageParams {
@@ -252,57 +253,68 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (bool, er
252253 // Set key that is used to sign the message
253254 if len (req .Sig ) > 0 {
254255 if params .Src , err = api .w .GetPrivateKey (req .Sig ); err != nil {
255- return false , err
256+ return nil , err
256257 }
257258 }
258259
259260 // Set symmetric key that is used to encrypt the message
260261 if symKeyGiven {
261262 if params .Topic == (TopicType {}) { // topics are mandatory with symmetric encryption
262- return false , ErrNoTopics
263+ return nil , ErrNoTopics
263264 }
264265 if params .KeySym , err = api .w .GetSymKey (req .SymKeyID ); err != nil {
265- return false , err
266+ return nil , err
266267 }
267268 if ! validateDataIntegrity (params .KeySym , aesKeyLength ) {
268- return false , ErrInvalidSymmetricKey
269+ return nil , ErrInvalidSymmetricKey
269270 }
270271 }
271272
272273 // Set asymmetric key that is used to encrypt the message
273274 if pubKeyGiven {
274275 params .Dst = crypto .ToECDSAPub (req .PublicKey )
275276 if ! ValidatePublicKey (params .Dst ) {
276- return false , ErrInvalidPublicKey
277+ return nil , ErrInvalidPublicKey
277278 }
278279 }
279280
280281 // encrypt and sent message
281282 whisperMsg , err := NewSentMessage (params )
282283 if err != nil {
283- return false , err
284+ return nil , err
284285 }
285286
287+ var result []byte
286288 env , err := whisperMsg .Wrap (params )
287289 if err != nil {
288- return false , err
290+ return nil , err
289291 }
290292
291293 // send to specific node (skip PoW check)
292294 if len (req .TargetPeer ) > 0 {
293295 n , err := discover .ParseNode (req .TargetPeer )
294296 if err != nil {
295- return false , fmt .Errorf ("failed to parse target peer: %s" , err )
297+ return nil , fmt .Errorf ("failed to parse target peer: %s" , err )
298+ }
299+ err = api .w .SendP2PMessage (n .ID [:], env )
300+ if err == nil {
301+ hash := env .Hash ()
302+ result = hash [:]
296303 }
297- return true , api . w . SendP2PMessage ( n . ID [:], env )
304+ return result , err
298305 }
299306
300307 // ensure that the message PoW meets the node's minimum accepted PoW
301308 if req .PowTarget < api .w .MinPow () {
302- return false , ErrTooLowPoW
309+ return nil , ErrTooLowPoW
303310 }
304311
305- return true , api .w .Send (env )
312+ err = api .w .Send (env )
313+ if err == nil {
314+ hash := env .Hash ()
315+ result = hash [:]
316+ }
317+ return result , err
306318}
307319
308320//go:generate gencodec -type Criteria -field-override criteriaOverride -out gen_criteria_json.go
0 commit comments