Listen to tx pre event and trigger 'pending'
This commit is contained in:
parent
b4a51de602
commit
55fdf3e462
|
@ -34,7 +34,7 @@ type Filter struct {
|
||||||
topics [][][]byte
|
topics [][][]byte
|
||||||
|
|
||||||
BlockCallback func(*types.Block, state.Logs)
|
BlockCallback func(*types.Block, state.Logs)
|
||||||
PendingCallback func(*types.Block, state.Logs)
|
PendingCallback func(*types.Transaction)
|
||||||
LogsCallback func(state.Logs)
|
LogsCallback func(state.Logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,9 @@ func (self *FilterManager) GetFilter(id int) *core.Filter {
|
||||||
func (self *FilterManager) filterLoop() {
|
func (self *FilterManager) filterLoop() {
|
||||||
// Subscribe to events
|
// Subscribe to events
|
||||||
events := self.eventMux.Subscribe(
|
events := self.eventMux.Subscribe(
|
||||||
core.PendingBlockEvent{},
|
//core.PendingBlockEvent{},
|
||||||
core.ChainEvent{},
|
core.ChainEvent{},
|
||||||
|
core.TxPreEvent{},
|
||||||
state.Logs(nil))
|
state.Logs(nil))
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
@ -82,11 +83,11 @@ out:
|
||||||
}
|
}
|
||||||
self.filterMu.RUnlock()
|
self.filterMu.RUnlock()
|
||||||
|
|
||||||
case core.PendingBlockEvent:
|
case core.TxPreEvent:
|
||||||
self.filterMu.RLock()
|
self.filterMu.RLock()
|
||||||
for _, filter := range self.filters {
|
for _, filter := range self.filters {
|
||||||
if filter.PendingCallback != nil {
|
if filter.PendingCallback != nil {
|
||||||
filter.PendingCallback(event.Block, event.Logs)
|
filter.PendingCallback(event.Tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.filterMu.RUnlock()
|
self.filterMu.RUnlock()
|
||||||
|
|
27
rpc/api.go
27
rpc/api.go
|
@ -180,21 +180,24 @@ func (self *EthereumApi) NewFilterString(args *FilterStringArgs, reply *interfac
|
||||||
var id int
|
var id int
|
||||||
filter := core.NewFilter(self.xeth().Backend())
|
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 {
|
switch args.Word {
|
||||||
case "pending":
|
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":
|
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:
|
default:
|
||||||
return NewValidationError("Word", "Must be `latest` or `pending`")
|
return NewValidationError("Word", "Must be `latest` or `pending`")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue