diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-07-12 22:36:07 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-07-12 23:16:54 +0800 |
commit | e1f1d3085c6b868de93313700cac8a325e9b148b (patch) | |
tree | b5a2c834735e0a1405a975d3552df07aebe0e2e0 /accounts/abi/bind | |
parent | 96339daf40989072ff2a9e8b476da6698da45dc7 (diff) | |
download | go-tangerine-e1f1d3085c6b868de93313700cac8a325e9b148b.tar go-tangerine-e1f1d3085c6b868de93313700cac8a325e9b148b.tar.gz go-tangerine-e1f1d3085c6b868de93313700cac8a325e9b148b.tar.bz2 go-tangerine-e1f1d3085c6b868de93313700cac8a325e9b148b.tar.lz go-tangerine-e1f1d3085c6b868de93313700cac8a325e9b148b.tar.xz go-tangerine-e1f1d3085c6b868de93313700cac8a325e9b148b.tar.zst go-tangerine-e1f1d3085c6b868de93313700cac8a325e9b148b.zip |
accounts, eth, les: blockhash based filtering on all code paths
Diffstat (limited to 'accounts/abi/bind')
-rw-r--r-- | accounts/abi/bind/backends/simulated.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index fd69538d5..fa8828f61 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -324,18 +324,24 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa // // TODO(karalabe): Deprecate when the subscription one can return past data too. func (b *SimulatedBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error) { - // Initialize unset filter boundaried to run from genesis to chain head - from := int64(0) - if query.FromBlock != nil { - from = query.FromBlock.Int64() - } - to := int64(-1) - if query.ToBlock != nil { - to = query.ToBlock.Int64() + var filter *filters.Filter + if query.BlockHash != nil { + // Block filter requested, construct a single-shot filter + filter = filters.NewBlockFilter(&filterBackend{b.database, b.blockchain}, *query.BlockHash, query.Addresses, query.Topics) + } else { + // Initialize unset filter boundaried to run from genesis to chain head + from := int64(0) + if query.FromBlock != nil { + from = query.FromBlock.Int64() + } + to := int64(-1) + if query.ToBlock != nil { + to = query.ToBlock.Int64() + } + // Construct the range filter + filter = filters.NewRangeFilter(&filterBackend{b.database, b.blockchain}, from, to, query.Addresses, query.Topics) } - // Construct and execute the filter - filter := filters.New(&filterBackend{b.database, b.blockchain}, from, to, query.Addresses, query.Topics) - + // Run the filter and return all the logs logs, err := filter.Logs(ctx) if err != nil { return nil, err @@ -430,6 +436,10 @@ func (fb *filterBackend) HeaderByNumber(ctx context.Context, block rpc.BlockNumb return fb.bc.GetHeaderByNumber(uint64(block.Int64())), nil } +func (fb *filterBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { + return fb.bc.GetHeaderByHash(hash), nil +} + func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { number := rawdb.ReadHeaderNumber(fb.db, hash) if number == nil { |