Skip to content

Commit

Permalink
Refactoring: remove transaction status method from API interface
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Nov 15, 2024
1 parent b98cb20 commit 03af5b1
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 68 deletions.
1 change: 0 additions & 1 deletion pkg/indexer/receiver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 0 additions & 9 deletions pkg/indexer/receiver/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions pkg/indexer/receiver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions pkg/indexer/receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 2 additions & 41 deletions pkg/indexer/status_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 03af5b1

Please sign in to comment.