From 03af5b11575bb37615bf832f6374ee7cfc359223 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 15 Nov 2024 14:07:31 +0300 Subject: [PATCH] Refactoring: remove transaction status method from API interface --- pkg/indexer/receiver/api.go | 1 - pkg/indexer/receiver/feeder.go | 9 ------- pkg/indexer/receiver/node.go | 9 ------- pkg/indexer/receiver/receiver.go | 8 ------ pkg/indexer/status_checker.go | 43 ++------------------------------ 5 files changed, 2 insertions(+), 68 deletions(-) diff --git a/pkg/indexer/receiver/api.go b/pkg/indexer/receiver/api.go index b74039f..d07819c 100644 --- a/pkg/indexer/receiver/api.go +++ b/pkg/indexer/receiver/api.go @@ -14,7 +14,6 @@ type API interface { TraceBlock(ctx context.Context, blockId starknetData.BlockID) ([]starknet.Trace, error) GetStateUpdate(ctx context.Context, blockId starknetData.BlockID) (starknetData.StateUpdate, error) GetBlockStatus(ctx context.Context, height uint64) (storage.Status, error) - TransactionStatus(ctx context.Context, hash string) (storage.Status, error) GetClass(ctx context.Context, hash string) (starknetData.Class, error) Head(ctx context.Context) (uint64, error) } diff --git a/pkg/indexer/receiver/feeder.go b/pkg/indexer/receiver/feeder.go index 0dd7e89..48bf9bc 100644 --- a/pkg/indexer/receiver/feeder.go +++ b/pkg/indexer/receiver/feeder.go @@ -80,15 +80,6 @@ func (f *Feeder) GetBlockStatus(ctx context.Context, height uint64) (storage.Sta return storage.NewStatus(response.Status), nil } -func (f *Feeder) TransactionStatus(ctx context.Context, hash string) (storage.Status, error) { - response, err := f.api.GetTransactionStatus(ctx, hash) - if err != nil { - return storage.StatusUnknown, err - } - - return storage.NewStatus(response.Status), nil -} - func (f *Feeder) GetClass(ctx context.Context, hash string) (starknetData.Class, error) { blockId := starknetData.BlockID{ String: starknetData.Latest, diff --git a/pkg/indexer/receiver/node.go b/pkg/indexer/receiver/node.go index 64bc0dc..64a35a8 100644 --- a/pkg/indexer/receiver/node.go +++ b/pkg/indexer/receiver/node.go @@ -149,15 +149,6 @@ func (n *Node) GetBlockStatus(ctx context.Context, height uint64) (storage.Statu return storage.NewStatus(response.Result.Status), nil } -func (n *Node) TransactionStatus(ctx context.Context, hash string) (storage.Status, error) { - response, err := n.api.GetTransactionStatus(ctx, hash) - if err != nil { - return storage.StatusUnknown, err - } - - return storage.NewStatus(response.Result.Finality), nil -} - func (n *Node) GetClass(ctx context.Context, hash string) (starknetData.Class, error) { blockId := starknetData.BlockID{ String: starknetData.Latest, diff --git a/pkg/indexer/receiver/receiver.go b/pkg/indexer/receiver/receiver.go index b616e27..c97514b 100644 --- a/pkg/indexer/receiver/receiver.go +++ b/pkg/indexer/receiver/receiver.go @@ -183,14 +183,6 @@ func (r *Receiver) GetClass(ctx context.Context, hash string) (starknetData.Clas return r.api.GetClass(requestCtx, hash) } -// TransactionStatus - -func (r *Receiver) TransactionStatus(ctx context.Context, hash string) (storage.Status, error) { - requestCtx, cancel := context.WithTimeout(ctx, r.timeout) - defer cancel() - - return r.api.TransactionStatus(requestCtx, hash) -} - // GetBlockStatus - func (r *Receiver) GetBlockStatus(ctx context.Context, height uint64) (storage.Status, error) { requestCtx, cancel := context.WithTimeout(ctx, r.timeout) diff --git a/pkg/indexer/status_checker.go b/pkg/indexer/status_checker.go index 2a6df64..3a50908 100644 --- a/pkg/indexer/status_checker.go +++ b/pkg/indexer/status_checker.go @@ -4,7 +4,6 @@ import ( "context" "time" - "github.com/dipdup-io/starknet-go-api/pkg/encoding" "github.com/dipdup-io/starknet-indexer/internal/storage" "github.com/dipdup-io/starknet-indexer/internal/storage/postgres" "github.com/dipdup-io/starknet-indexer/pkg/indexer/receiver" @@ -15,41 +14,7 @@ import ( ) type acceptedOnL2 struct { - Height uint64 - TransactionHash []byte -} - -func newAcceptedOnL2FromIndexingBlock(block storage.Block) acceptedOnL2 { - a := acceptedOnL2{ - Height: block.Height, - } - - if block.InvokeCount > 0 { - a.TransactionHash = block.Invoke[0].Hash - return a - } - - if block.DeclareCount > 0 { - a.TransactionHash = block.Declare[0].Hash - return a - } - - if block.DeployCount > 0 { - a.TransactionHash = block.Deploy[0].Hash - return a - } - - if block.DeployAccountCount > 0 { - a.TransactionHash = block.DeployAccount[0].Hash - return a - } - - if block.L1HandlerCount > 0 { - a.TransactionHash = block.L1Handler[0].Hash - return a - } - - return a + Height uint64 } type statusChecker struct { @@ -186,14 +151,10 @@ func (checker *statusChecker) check(ctx context.Context) error { } func (checker *statusChecker) addBlock(block storage.Block) { - checker.acceptedOnL2.Push(newAcceptedOnL2FromIndexingBlock(block)) + checker.acceptedOnL2.Push(acceptedOnL2{block.Height}) } func (checker *statusChecker) getStatus(ctx context.Context, item acceptedOnL2) (storage.Status, error) { - if len(item.TransactionHash) > 0 { - return checker.receiver.TransactionStatus(ctx, encoding.EncodeHex(item.TransactionHash)) - } - return checker.receiver.GetBlockStatus(ctx, item.Height) }