This commit is contained in:
zsfelfoldi 2016-06-22 02:37:38 +02:00
parent 8a2044789a
commit 9db3551545
2 changed files with 27 additions and 25 deletions

View file

@ -80,7 +80,7 @@ func NewPublicFilterAPI(apiBackend ethapi.Backend) *PublicFilterAPI {
apiBackend: apiBackend,
mux: apiBackend.EventMux(),
chainDb: apiBackend.ChainDb(),
filterManager: NewFilterSystem(mux),
filterManager: NewFilterSystem(apiBackend.EventMux()),
filterMapping: make(map[string]int),
logQueue: make(map[int]*logQueue),
blockQueue: make(map[int]*hashQueue),
@ -434,14 +434,15 @@ func (s *PublicFilterAPI) NewFilter(args NewFilterArgs) (string, error) {
}
// GetLogs returns the logs matching the given argument.
func (s *PublicFilterAPI) GetLogs(args NewFilterArgs) []vmlog {
func (s *PublicFilterAPI) GetLogs(ctx context.Context, args NewFilterArgs) ([]vmlog, error) {
filter := New(s.apiBackend)
filter.SetBeginBlock(args.FromBlock.Int64())
filter.SetEndBlock(args.ToBlock.Int64())
filter.SetAddresses(args.Addresses)
filter.SetTopics(args.Topics)
return toRPCLogs(filter.Find(), false)
logs, err := filter.Find(ctx)
return toRPCLogs(logs, false), err
}
// UninstallFilter removes the filter with the given filter id.
@ -527,17 +528,18 @@ func (s *PublicFilterAPI) logFilterChanged(id int) []vmlog {
}
// GetFilterLogs returns the logs for the filter with the given id.
func (s *PublicFilterAPI) GetFilterLogs(filterId string) []vmlog {
func (s *PublicFilterAPI) GetFilterLogs(ctx context.Context, filterId string) ([]vmlog, error) {
id, ok := s.filterMapping[filterId]
if !ok {
return toRPCLogs(nil, false)
return toRPCLogs(nil, false), nil
}
if filter := s.filterManager.Get(id); filter != nil {
return toRPCLogs(filter.Find(), false)
logs, err := filter.Find(ctx)
return toRPCLogs(logs, false), err
}
return toRPCLogs(nil, false)
return toRPCLogs(nil, false), nil
}
// GetFilterChanges returns the logs for the filter with the given id since last time is was called.

View file

@ -17,16 +17,17 @@
package filters
import (
"math"
// "math"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
// "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/rpc"
"golang.org/x/net/context"
)
type AccountChange struct {
@ -78,7 +79,7 @@ func (self *Filter) SetTopics(topics [][]common.Hash) {
}
// Run filters logs with the current parameters set
func (self *Filter) Find() vm.Logs {
func (self *Filter) Find(ctx context.Context) (vm.Logs, error) {
headBlockNumber := self.apiBackend.HeaderByNumber(rpc.LatestBlockNumber).Number.Uint64()
var beginBlockNo uint64 = uint64(self.begin)
@ -93,13 +94,13 @@ func (self *Filter) Find() vm.Logs {
// if no addresses are present we can't make use of fast search which
// uses the mipmap bloom filters to check for fast inclusion and uses
// higher range probability in order to ensure at least a false positive
if len(self.addresses) == 0 {
return self.getLogs(beginBlockNo, endBlockNo)
}
return self.mipFind(beginBlockNo, endBlockNo, 0)
// if len(self.addresses) == 0 {
return self.getLogs(ctx, beginBlockNo, endBlockNo)
// }
// return self.mipFind(beginBlockNo, endBlockNo, 0)
}
func (self *Filter) mipFind(start, end uint64, depth int) (logs vm.Logs) {
/*func (self *Filter) mipFind(start, end uint64, depth int) (logs vm.Logs) {
level := core.MIPMapLevels[depth]
// normalise numerator so we can work in level specific batches and
// work with the proper range checks
@ -127,25 +128,24 @@ func (self *Filter) mipFind(start, end uint64, depth int) (logs vm.Logs) {
}
return logs
}
func (self *Filter) getLogs(start, end uint64) (logs vm.Logs) {
var block *types.Block
}*/
func (self *Filter) getLogs(ctx context.Context, start, end uint64) (logs vm.Logs, err error) {
for i := start; i <= end; i++ {
header := self.apiBackend.HeaderByNumber(rpc.BlockNumber(i))
if header == nil {
return logs
return logs, nil
}
// Use bloom filtering to see if this block is interesting given the
// current parameters
if self.bloomFilter(header.Bloom) {
// Get the logs of the block
var (
receipts = self.apiBackend.GetReceipts(ctx, header.Hash())
unfiltered vm.Logs
)
receipts, err := self.apiBackend.GetReceipts(ctx, header.Hash())
if err != nil {
return nil, err
}
var unfiltered vm.Logs
for _, receipt := range receipts {
unfiltered = append(unfiltered, receipt.Logs...)
}
@ -153,7 +153,7 @@ func (self *Filter) getLogs(start, end uint64) (logs vm.Logs) {
}
}
return logs
return logs, nil
}
func includes(addresses []common.Address, a common.Address) bool {