aboutsummaryrefslogtreecommitdiffstats
path: root/whisper/envelope.go
diff options
context:
space:
mode:
Diffstat (limited to 'whisper/envelope.go')
-rw-r--r--whisper/envelope.go42
1 files changed, 24 insertions, 18 deletions
diff --git a/whisper/envelope.go b/whisper/envelope.go
index 9d28dfa6b..3c477ad9f 100644
--- a/whisper/envelope.go
+++ b/whisper/envelope.go
@@ -1,11 +1,9 @@
package whisper
import (
- "bytes"
"crypto/ecdsa"
"encoding/binary"
"fmt"
- "io"
"time"
"github.com/ethereum/go-ethereum/crypto"
@@ -28,22 +26,6 @@ type Envelope struct {
hash Hash
}
-func NewEnvelopeFromReader(reader io.Reader) (*Envelope, error) {
- var envelope Envelope
-
- buf := new(bytes.Buffer)
- buf.ReadFrom(reader)
-
- h := H(crypto.Sha3(buf.Bytes()))
- if err := rlp.Decode(buf, &envelope); err != nil {
- return nil, err
- }
-
- envelope.hash = h
-
- return &envelope, nil
-}
-
func (self *Envelope) Hash() Hash {
if self.hash == EmptyHash {
self.hash = H(crypto.Sha3(ethutil.Encode(self)))
@@ -126,3 +108,27 @@ func (self *Envelope) withoutNonce() interface{} {
func (self *Envelope) RlpData() interface{} {
return []interface{}{self.Expiry, self.Ttl, ethutil.ByteSliceToInterface(self.Topics), self.Data, self.Nonce}
}
+
+func (self *Envelope) DecodeRLP(s *rlp.Stream) error {
+ var extenv struct {
+ Expiry uint32
+ Ttl uint32
+ Topics [][]byte
+ Data []byte
+ Nonce uint32
+ }
+ if err := s.Decode(&extenv); err != nil {
+ return err
+ }
+
+ self.Expiry = extenv.Expiry
+ self.Ttl = extenv.Ttl
+ self.Topics = extenv.Topics
+ self.Data = extenv.Data
+ self.Nonce = extenv.Nonce
+
+ // TODO We should use the stream directly here.
+ self.hash = H(crypto.Sha3(ethutil.Encode(self)))
+
+ return nil
+}