mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
eth: latest subscription
This commit is contained in:
parent
7f90a0fff7
commit
0859bd75b7
2 changed files with 10 additions and 3 deletions
|
|
@ -45,7 +45,7 @@ var (
|
||||||
errPendingLogsUnsupported = errors.New("pending logs are not supported")
|
errPendingLogsUnsupported = errors.New("pending logs are not supported")
|
||||||
errExceedMaxTopics = errors.New("exceed max topics")
|
errExceedMaxTopics = errors.New("exceed max topics")
|
||||||
errExceedMaxAddresses = errors.New("exceed max addresses")
|
errExceedMaxAddresses = errors.New("exceed max addresses")
|
||||||
errInvalidFromBlock = errors.New("from block can be only a number, or \"safe\", or \"finalized\"")
|
errInvalidFromBlock = errors.New(`from block can be only a number, or "latest", "safe", "finalized"`)
|
||||||
errInvalidToBlock = errors.New("log subscription does not support history block range")
|
errInvalidToBlock = errors.New("log subscription does not support history block range")
|
||||||
errInvalidFromToBlock = errors.New("invalid from and to block combination: from > to")
|
errInvalidFromToBlock = errors.New("invalid from and to block combination: from > to")
|
||||||
)
|
)
|
||||||
|
|
@ -291,7 +291,7 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
|
||||||
|
|
||||||
// logs is the inner implementation of logs subscription.
|
// logs is the inner implementation of logs subscription.
|
||||||
// The following criteria are valid:
|
// The following criteria are valid:
|
||||||
// * from: nil, to: nil -> yield live logs.
|
// * from: nil | latest, to: nil -> yield live logs.
|
||||||
// * from: blockNum | safe | finalized, to: nil -> historical beginning at `from` to head, then live logs.
|
// * from: blockNum | safe | finalized, to: nil -> historical beginning at `from` to head, then live logs.
|
||||||
// * Every other case should fail with an error.
|
// * Every other case should fail with an error.
|
||||||
func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.Subscription, crit FilterCriteria) error {
|
func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.Subscription, crit FilterCriteria) error {
|
||||||
|
|
@ -303,8 +303,10 @@ func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.S
|
||||||
}
|
}
|
||||||
from := rpc.BlockNumber(crit.FromBlock.Int64())
|
from := rpc.BlockNumber(crit.FromBlock.Int64())
|
||||||
switch from {
|
switch from {
|
||||||
case rpc.LatestBlockNumber, rpc.PendingBlockNumber:
|
case rpc.PendingBlockNumber:
|
||||||
return errInvalidFromBlock
|
return errInvalidFromBlock
|
||||||
|
case rpc.LatestBlockNumber:
|
||||||
|
return api.liveLogs(notifier, rpcSub, crit)
|
||||||
case rpc.SafeBlockNumber, rpc.FinalizedBlockNumber:
|
case rpc.SafeBlockNumber, rpc.FinalizedBlockNumber:
|
||||||
header, err := api.sys.backend.HeaderByNumber(ctx, from)
|
header, err := api.sys.backend.HeaderByNumber(ctx, from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -847,6 +847,11 @@ func TestLogsSubscription(t *testing.T) {
|
||||||
FilterCriteria{FromBlock: big.NewInt(-101)},
|
FilterCriteria{FromBlock: big.NewInt(-101)},
|
||||||
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, errInvalidFromBlock, nil,
|
nil, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, errInvalidFromBlock, nil,
|
||||||
},
|
},
|
||||||
|
// from "latest" - should work like live logs only
|
||||||
|
{
|
||||||
|
FilterCriteria{FromBlock: big.NewInt(rpc.LatestBlockNumber.Int64())},
|
||||||
|
liveLogs, newMockNotifier(), &rpc.Subscription{ID: rpc.NewID()}, nil, nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// subscribe logs
|
// subscribe logs
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue