From 77808115d9d397b2aaa7b70f9dc1b47d00591438 Mon Sep 17 00:00:00 2001 From: weiihann Date: Tue, 10 Dec 2024 13:28:39 +0800 Subject: [PATCH] use resolveBlockRange --- rpc/subscriptions.go | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/rpc/subscriptions.go b/rpc/subscriptions.go index 0dac69df8..5f5050049 100644 --- a/rpc/subscriptions.go +++ b/rpc/subscriptions.go @@ -38,28 +38,9 @@ func (h *Handler) SubscribeEvents(ctx context.Context, fromAddr *felt.Felt, keys return nil, ErrTooManyKeysInFilter } - var requestedHeader *core.Header - headHeader, err := h.bcReader.HeadsHeader() - if err != nil { - return nil, ErrInternal.CloneWithData(err.Error()) - } - - if blockID == nil { - requestedHeader = headHeader - } else { - if blockID.Pending { - return nil, ErrCallOnPending - } - - var rpcErr *jsonrpc.Error - requestedHeader, rpcErr = h.blockHeaderByID(blockID) - if rpcErr != nil { - return nil, rpcErr - } - - if headHeader.Number >= maxBlocksBack && requestedHeader.Number <= headHeader.Number-maxBlocksBack { - return nil, ErrTooManyBlocksBack - } + requestedHeader, headHeader, rpcErr := h.resolveBlockRange(blockID) + if rpcErr != nil { + return nil, rpcErr } id := h.idgen()