diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-04-17 21:45:44 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-04-28 15:47:35 +0800 |
commit | 3563c59b12b0b8b5fd15847bf97d71dfd8416207 (patch) | |
tree | f059a2bcbd7edb25c595bbad30514828fc1a5282 /xeth/xeth.go | |
parent | 182d484aa70bcd5b22117f02333b1fd3b1535dcb (diff) | |
download | dexon-3563c59b12b0b8b5fd15847bf97d71dfd8416207.tar.gz dexon-3563c59b12b0b8b5fd15847bf97d71dfd8416207.tar.zst dexon-3563c59b12b0b8b5fd15847bf97d71dfd8416207.zip |
rpc, whisper, xeth: polish whisper RPC interface
Diffstat (limited to 'xeth/xeth.go')
-rw-r--r-- | xeth/xeth.go | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/xeth/xeth.go b/xeth/xeth.go index 693acb910..e7e553036 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -452,14 +452,15 @@ func (self *XEth) AllLogs(earliest, latest int64, skip, max int, address []strin return filter.Find() } -func (p *XEth) NewWhisperFilter(opts *Options) int { +func (p *XEth) NewWhisperFilter(to, from string, topics []string) int { var id int - opts.Fn = func(msg WhisperMessage) { + callback := func(msg WhisperMessage) { p.messagesMut.Lock() defer p.messagesMut.Unlock() - p.messages[id].add(msg) // = append(p.messages[id], msg) + + p.messages[id].insert(msg) } - id = p.Whisper().Watch(opts) + id = p.Whisper().Watch(to, from, topics, callback) p.messages[id] = &whisperFilter{timeout: time.Now()} return id } @@ -478,7 +479,7 @@ func (self *XEth) MessagesChanged(id int) []WhisperMessage { defer self.messagesMut.Unlock() if self.messages[id] != nil { - return self.messages[id].get() + return self.messages[id].retrieve() } return nil @@ -731,22 +732,6 @@ func (m callmsg) Gas() *big.Int { return m.gas } func (m callmsg) Value() *big.Int { return m.value } func (m callmsg) Data() []byte { return m.data } -type whisperFilter struct { - messages []WhisperMessage - timeout time.Time - id int -} - -func (w *whisperFilter) add(msgs ...WhisperMessage) { - w.messages = append(w.messages, msgs...) -} -func (w *whisperFilter) get() []WhisperMessage { - w.timeout = time.Now() - tmp := w.messages - w.messages = nil - return tmp -} - type logFilter struct { logs state.Logs timeout time.Time |