mirror of https://github.com/ethereum/go-ethereum
parent
182d484aa7
commit
3563c59b12
@ -0,0 +1,26 @@ |
|||||||
|
// Contains the external API side message filter for watching, pooling and polling
|
||||||
|
// matched whisper messages.
|
||||||
|
|
||||||
|
package xeth |
||||||
|
|
||||||
|
import "time" |
||||||
|
|
||||||
|
// whisperFilter is the message cache matching a specific filter, accumulating
|
||||||
|
// inbound messages until the are requested by the client.
|
||||||
|
type whisperFilter struct { |
||||||
|
id int // Filter identifier
|
||||||
|
cache []WhisperMessage // Cache of messages not yet polled
|
||||||
|
timeout time.Time // Time when the last message batch was queries
|
||||||
|
} |
||||||
|
|
||||||
|
// insert injects a new batch of messages into the filter cache.
|
||||||
|
func (w *whisperFilter) insert(msgs ...WhisperMessage) { |
||||||
|
w.cache = append(w.cache, msgs...) |
||||||
|
} |
||||||
|
|
||||||
|
// retrieve fetches all the cached messages from the filter.
|
||||||
|
func (w *whisperFilter) retrieve() (messages []WhisperMessage) { |
||||||
|
messages, w.cache = w.cache, nil |
||||||
|
w.timeout = time.Now() |
||||||
|
return |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
// Contains the external API representation of a whisper message.
|
||||||
|
|
||||||
|
package xeth |
||||||
|
|
||||||
|
import ( |
||||||
|
"github.com/ethereum/go-ethereum/common" |
||||||
|
"github.com/ethereum/go-ethereum/crypto" |
||||||
|
"github.com/ethereum/go-ethereum/whisper" |
||||||
|
) |
||||||
|
|
||||||
|
// WhisperMessage is the external API representation of a whisper.Message.
|
||||||
|
type WhisperMessage struct { |
||||||
|
ref *whisper.Message |
||||||
|
|
||||||
|
Payload string `json:"payload"` |
||||||
|
To string `json:"to"` |
||||||
|
From string `json:"from"` |
||||||
|
Sent int64 `json:"sent"` |
||||||
|
} |
||||||
|
|
||||||
|
// NewWhisperMessage converts an internal message into an API version.
|
||||||
|
func NewWhisperMessage(message *whisper.Message) WhisperMessage { |
||||||
|
return WhisperMessage{ |
||||||
|
ref: message, |
||||||
|
|
||||||
|
Payload: common.ToHex(message.Payload), |
||||||
|
From: common.ToHex(crypto.FromECDSAPub(message.Recover())), |
||||||
|
To: common.ToHex(crypto.FromECDSAPub(message.To)), |
||||||
|
Sent: message.Sent, |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue