aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-20 19:07:06 +0800
committerobscuren <geffobscura@gmail.com>2015-03-20 19:07:06 +0800
commit55fdf3e46272ec50a4d55f519b542df790920306 (patch)
tree34f5fdd4551b03a6c69f3639f3f1f715aa6d9b99
parentb4a51de6020ce0fdee47eb6c7d63a13647b7e3c4 (diff)
downloadgo-tangerine-55fdf3e46272ec50a4d55f519b542df790920306.tar
go-tangerine-55fdf3e46272ec50a4d55f519b542df790920306.tar.gz
go-tangerine-55fdf3e46272ec50a4d55f519b542df790920306.tar.bz2
go-tangerine-55fdf3e46272ec50a4d55f519b542df790920306.tar.lz
go-tangerine-55fdf3e46272ec50a4d55f519b542df790920306.tar.xz
go-tangerine-55fdf3e46272ec50a4d55f519b542df790920306.tar.zst
go-tangerine-55fdf3e46272ec50a4d55f519b542df790920306.zip
Listen to tx pre event and trigger 'pending'
-rw-r--r--core/filter.go2
-rw-r--r--event/filter/eth_filter.go7
-rw-r--r--rpc/api.go27
3 files changed, 20 insertions, 16 deletions
diff --git a/core/filter.go b/core/filter.go
index 487e82902..0aebcbf69 100644
--- a/core/filter.go
+++ b/core/filter.go
@@ -34,7 +34,7 @@ type Filter struct {
topics [][][]byte
BlockCallback func(*types.Block, state.Logs)
- PendingCallback func(*types.Block, state.Logs)
+ PendingCallback func(*types.Transaction)
LogsCallback func(state.Logs)
}
diff --git a/event/filter/eth_filter.go b/event/filter/eth_filter.go
index cb75d7e1a..ab811e90e 100644
--- a/event/filter/eth_filter.go
+++ b/event/filter/eth_filter.go
@@ -62,8 +62,9 @@ func (self *FilterManager) GetFilter(id int) *core.Filter {
func (self *FilterManager) filterLoop() {
// Subscribe to events
events := self.eventMux.Subscribe(
- core.PendingBlockEvent{},
+ //core.PendingBlockEvent{},
core.ChainEvent{},
+ core.TxPreEvent{},
state.Logs(nil))
out:
@@ -82,11 +83,11 @@ out:
}
self.filterMu.RUnlock()
- case core.PendingBlockEvent:
+ case core.TxPreEvent:
self.filterMu.RLock()
for _, filter := range self.filters {
if filter.PendingCallback != nil {
- filter.PendingCallback(event.Block, event.Logs)
+ filter.PendingCallback(event.Tx)
}
}
self.filterMu.RUnlock()
diff --git a/rpc/api.go b/rpc/api.go
index afc0bd455..fcf2ac9dc 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -180,21 +180,24 @@ func (self *EthereumApi) NewFilterString(args *FilterStringArgs, reply *interfac
var id int
filter := core.NewFilter(self.xeth().Backend())
- callback := func(block *types.Block, logs state.Logs) {
- self.logMut.Lock()
- defer self.logMut.Unlock()
-
- for _, log := range logs {
- self.logs[id].add(log)
- }
- self.logs[id].add(&state.StateLog{})
- }
-
switch args.Word {
case "pending":
- filter.PendingCallback = callback
+ filter.PendingCallback = func(tx *types.Transaction) {
+ self.logMut.Lock()
+ defer self.logMut.Unlock()
+
+ self.logs[id].add(&state.StateLog{})
+ }
case "latest":
- filter.BlockCallback = callback
+ filter.BlockCallback = func(block *types.Block, logs state.Logs) {
+ self.logMut.Lock()
+ defer self.logMut.Unlock()
+
+ for _, log := range logs {
+ self.logs[id].add(log)
+ }
+ self.logs[id].add(&state.StateLog{})
+ }
default:
return NewValidationError("Word", "Must be `latest` or `pending`")
}