Skip to content

Commit

Permalink
Fix: skip transaction if its class is undeclared
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jun 10, 2024
1 parent 5aac15b commit 28eb72e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/dipdup-io/starknet-indexer
go 1.22

require (
github.com/dipdup-io/starknet-go-api v0.0.0-20240517123614-8bb965043f0b
github.com/dipdup-io/starknet-go-api v0.0.0-20240610163809-69297a8e3cac
github.com/dipdup-io/workerpool v0.0.4
github.com/dipdup-net/go-lib v0.3.3
github.com/dipdup-net/indexer-sdk v0.0.4
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisenkom/go-mssqldb v0.12.3 h1:pBSGx9Tq67pBOTLmxNuirNTeB8Vjmf886Kx+8Y+8shw=
github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDrorD1Vrm1KEz5hxDo=
github.com/dipdup-io/starknet-go-api v0.0.0-20240428115333-9db5c96f6b81 h1:jKSCsoLYm4uuO4tu/0pcBthvixgXII4KQQCVmcoL3Cc=
github.com/dipdup-io/starknet-go-api v0.0.0-20240428115333-9db5c96f6b81/go.mod h1:y3KGLFQtwzUBcT0X2LMj6CxocUimr/A9XYg+j0KIRDE=
github.com/dipdup-io/starknet-go-api v0.0.0-20240428184801-e7a7f9b05da9 h1:gLnNH4kZZXjHBG3WVmwi91giiGHPol0VszqOdalNMXA=
github.com/dipdup-io/starknet-go-api v0.0.0-20240428184801-e7a7f9b05da9/go.mod h1:y3KGLFQtwzUBcT0X2LMj6CxocUimr/A9XYg+j0KIRDE=
github.com/dipdup-io/starknet-go-api v0.0.0-20240517123614-8bb965043f0b h1:mIonvNL2IM9/2kyGvSuqV1ut0yL1W4kpPP5ojTyA3SY=
github.com/dipdup-io/starknet-go-api v0.0.0-20240517123614-8bb965043f0b/go.mod h1:y3KGLFQtwzUBcT0X2LMj6CxocUimr/A9XYg+j0KIRDE=
github.com/dipdup-io/starknet-go-api v0.0.0-20240610163809-69297a8e3cac h1:mlbq1oUC0yKwDXfdWvWMOEGYZT6RuCsNtJNT9UGRTIs=
github.com/dipdup-io/starknet-go-api v0.0.0-20240610163809-69297a8e3cac/go.mod h1:y3KGLFQtwzUBcT0X2LMj6CxocUimr/A9XYg+j0KIRDE=
github.com/dipdup-io/workerpool v0.0.4 h1:m58fuFY3VIPRc+trWpjw2Lsm4FvIgtjP/4VRe79r+/s=
github.com/dipdup-io/workerpool v0.0.4/go.mod h1:m6YMqx7M+fORTyabHD/auKymBRpbDax0t1aPZ1i7GZA=
github.com/dipdup-net/go-lib v0.3.3 h1:vTUI+sT4L+x+eiMf712Cg8EtlqUCMiN6M3vcNaPlCw8=
Expand Down
7 changes: 7 additions & 0 deletions pkg/indexer/parser/resolver/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ import (

"github.com/dipdup-io/starknet-go-api/pkg/data"
"github.com/dipdup-io/starknet-go-api/pkg/encoding"
api "github.com/dipdup-io/starknet-go-api/pkg/rpc"
"github.com/dipdup-io/starknet-indexer/internal/starknet"
"github.com/dipdup-io/starknet-indexer/internal/storage"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)

var ErrUndeclaredClass = errors.New("undeclared class")

// ReceiveClass -
func (resolver *Resolver) ReceiveClass(ctx context.Context, class *storage.Class) error {
rawClass, err := resolver.receiver.GetClass(ctx, encoding.EncodeHex(class.Hash))
if err != nil {
if e, ok := err.(*api.Error); ok && e.Code == 28 {
return ErrUndeclaredClass
}
return err
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/indexer/parser/version/v0/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ func (parser FeeParser) ParseInvocation(ctx context.Context, txCtx data.TxContex
}

if err := parser.resolver.ReceiveClass(ctx, &tx.Class); err != nil {
if errors.Is(err, resolver.ErrUndeclaredClass) {
return nil, nil
}
return nil, err
}
tx.Class.Height = tx.Height
Expand Down
6 changes: 3 additions & 3 deletions pkg/indexer/parser/version/v0/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ func (parser InternalTxParser) Parse(ctx context.Context, txCtx parserData.TxCon
}

if err := parser.Resolver.ReceiveClass(ctx, &tx.Class); err != nil {
if errors.Is(err, resolver.ErrUndeclaredClass) {
return tx, nil
}
return tx, err
}
tx.Class.Height = tx.Height
}

// txHash := encoding.EncodeHex(tx.Hash)
// log.Info().Msg(txHash)

if len(tx.Selector) > 0 && internal.Selector != "0x0" {
var (
_, has = contractAbi.GetByTypeAndSelector(internal.EntrypointType, encoding.EncodeHex(tx.Selector))
Expand Down

0 comments on commit 28eb72e

Please sign in to comment.