mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
fix filter conditions
This commit is contained in:
parent
cf647a821f
commit
f51fcaeebd
4 changed files with 25 additions and 7 deletions
|
|
@ -342,7 +342,6 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type
|
||||||
}
|
}
|
||||||
var filter *Filter
|
var filter *Filter
|
||||||
if crit.BlockHash != nil {
|
if crit.BlockHash != nil {
|
||||||
// TODO: return pruned history error here where it would apply
|
|
||||||
// Block filter requested, construct a single-shot filter
|
// Block filter requested, construct a single-shot filter
|
||||||
filter = api.sys.NewBlockFilter(*crit.BlockHash, crit.Addresses, crit.Topics)
|
filter = api.sys.NewBlockFilter(*crit.BlockHash, crit.Addresses, crit.Topics)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -355,10 +354,11 @@ func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*type
|
||||||
if crit.ToBlock != nil {
|
if crit.ToBlock != nil {
|
||||||
end = crit.ToBlock.Int64()
|
end = crit.ToBlock.Int64()
|
||||||
}
|
}
|
||||||
|
// Block numbers below 0 are special cases.
|
||||||
if begin > 0 && end > 0 && begin > end {
|
if begin > 0 && end > 0 && begin > end {
|
||||||
return nil, errInvalidBlockRange
|
return nil, errInvalidBlockRange
|
||||||
}
|
}
|
||||||
if begin < int64(api.events.backend.HistoryPruningCutoff()) {
|
if begin > 0 && begin < int64(api.events.backend.HistoryPruningCutoff()) {
|
||||||
return nil, &prunedHistoryError{}
|
return nil, &prunedHistoryError{}
|
||||||
}
|
}
|
||||||
// Construct the range filter
|
// Construct the range filter
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,9 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
|
||||||
if header == nil {
|
if header == nil {
|
||||||
return nil, errors.New("unknown block")
|
return nil, errors.New("unknown block")
|
||||||
}
|
}
|
||||||
|
if header.Number.Uint64() < f.sys.backend.HistoryPruningCutoff() {
|
||||||
|
return nil, &prunedHistoryError{}
|
||||||
|
}
|
||||||
return f.blockLogs(ctx, header)
|
return f.blockLogs(ctx, header)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,11 +117,19 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
|
||||||
return 0, errors.New("safe header not found")
|
return 0, errors.New("safe header not found")
|
||||||
}
|
}
|
||||||
return hdr.Number.Uint64(), nil
|
return hdr.Number.Uint64(), nil
|
||||||
|
case rpc.EarliestBlockNumber.Int64():
|
||||||
|
earliest := f.sys.backend.HistoryPruningCutoff()
|
||||||
|
hdr, _ := f.sys.backend.HeaderByNumber(ctx, rpc.BlockNumber(earliest))
|
||||||
|
if hdr == nil {
|
||||||
|
return 0, errors.New("earliest header not found")
|
||||||
|
}
|
||||||
|
return hdr.Number.Uint64(), nil
|
||||||
|
default:
|
||||||
|
if number < 0 {
|
||||||
|
return 0, errors.New("negative block number")
|
||||||
|
}
|
||||||
|
return uint64(number), nil
|
||||||
}
|
}
|
||||||
if number < 0 {
|
|
||||||
return 0, errors.New("negative block number")
|
|
||||||
}
|
|
||||||
return uint64(number), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// range query need to resolve the special begin/end block number
|
// range query need to resolve the special begin/end block number
|
||||||
|
|
|
||||||
|
|
@ -310,6 +310,14 @@ func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*typ
|
||||||
return nil, errPendingLogsUnsupported
|
return nil, errPendingLogsUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if from == rpc.EarliestBlockNumber {
|
||||||
|
from = rpc.BlockNumber(es.backend.HistoryPruningCutoff())
|
||||||
|
}
|
||||||
|
// Queries beyond the pruning cutoff are not supported.
|
||||||
|
if uint64(from) < es.backend.HistoryPruningCutoff() {
|
||||||
|
return nil, &prunedHistoryError{}
|
||||||
|
}
|
||||||
|
|
||||||
// only interested in new mined logs
|
// only interested in new mined logs
|
||||||
if from == rpc.LatestBlockNumber && to == rpc.LatestBlockNumber {
|
if from == rpc.LatestBlockNumber && to == rpc.LatestBlockNumber {
|
||||||
return es.subscribeLogs(crit, logs), nil
|
return es.subscribeLogs(crit, logs), nil
|
||||||
|
|
|
||||||
|
|
@ -1369,7 +1369,6 @@ func (api *TransactionAPI) GetRawTransactionByHash(ctx context.Context, hash com
|
||||||
|
|
||||||
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
|
// GetTransactionReceipt returns the transaction receipt for the given transaction hash.
|
||||||
func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
|
func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
|
||||||
// TODO(s1na): transaction lookup should be pruned as well.
|
|
||||||
found, tx, blockHash, blockNumber, index, err := api.b.GetTransaction(ctx, hash)
|
found, tx, blockHash, blockNumber, index, err := api.b.GetTransaction(ctx, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, NewTxIndexingError() // transaction is not fully indexed
|
return nil, NewTxIndexingError() // transaction is not fully indexed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue