Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update go library #30

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.21

require (
github.com/dipdup-io/starknet-go-api v0.0.0-20240110155038-c97c6d82a0eb
github.com/dipdup-io/starknet-go-api v0.0.0-20240130002112-e07f784ea34e
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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ github.com/denisenkom/go-mssqldb v0.12.3 h1:pBSGx9Tq67pBOTLmxNuirNTeB8Vjmf886Kx+
github.com/denisenkom/go-mssqldb v0.12.3/go.mod h1:k0mtMFOnU+AihqFxPMiF05rtiDrorD1Vrm1KEz5hxDo=
github.com/dipdup-io/starknet-go-api v0.0.0-20240110155038-c97c6d82a0eb h1:IAJCAcl/bS47DVWAedA94j/EwfG4Xt/LeBLwEOonKn4=
github.com/dipdup-io/starknet-go-api v0.0.0-20240110155038-c97c6d82a0eb/go.mod h1:y3KGLFQtwzUBcT0X2LMj6CxocUimr/A9XYg+j0KIRDE=
github.com/dipdup-io/starknet-go-api v0.0.0-20240130002112-e07f784ea34e h1:oFFZ77W368tOQuCwReeB3PEpjkJeEGOciOgJFYp+1Y8=
github.com/dipdup-io/starknet-go-api v0.0.0-20240130002112-e07f784ea34e/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
10 changes: 8 additions & 2 deletions pkg/indexer/parser/version/v0/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (parser EventParser) Parse(ctx context.Context, txCtx data.TxContext, contr
Height: txCtx.Height,
Time: txCtx.Time,
Order: event.Order,
Data: event.Data,
Keys: event.Keys,
Data: make([]string, len(event.Data)),
Keys: make([]string, len(event.Keys)),
ContractID: txCtx.ContractId,
Contract: txCtx.Contract,
DeclareID: txCtx.DeclareID,
Expand All @@ -58,6 +58,12 @@ func (parser EventParser) Parse(ctx context.Context, txCtx data.TxContext, contr
FeeID: txCtx.FeeID,
InternalID: txCtx.InternalID,
}
for i := range event.Data {
model.Data[i] = event.Data[i].String()
}
for i := range event.Keys {
model.Keys[i] = event.Keys[i].String()
}

if address, err := parser.resolver.FindAddressByHash(ctx, starknetData.Felt(event.FromAddress)); err != nil {
return model, err
Expand Down
12 changes: 9 additions & 3 deletions pkg/indexer/parser/version/v0/fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func (parser FeeParser) ParseInvocation(ctx context.Context, txCtx data.TxContex
CallType: storage.NewCallType(feeInvocation.CallType),
EntrypointType: storage.NewEntrypointType(feeInvocation.EntrypointType),
Selector: feeInvocation.Selector.Bytes(),
Result: feeInvocation.Result,
Calldata: feeInvocation.Calldata,
Result: make([]string, len(feeInvocation.Result)),
Calldata: make([]string, len(feeInvocation.Calldata)),

DeclareID: txCtx.DeclareID,
DeployID: txCtx.DeployID,
Expand All @@ -132,6 +132,12 @@ func (parser FeeParser) ParseInvocation(ctx context.Context, txCtx data.TxContex
Messages: make([]storage.Message, 0),
Internals: make([]storage.Internal, 0),
}
for i := range feeInvocation.Result {
tx.Result[i] = feeInvocation.Result[i].String()
}
for i := range feeInvocation.Calldata {
tx.Calldata[i] = feeInvocation.Calldata[i].String()
}

if class, err := parser.resolver.FindClassByHash(ctx, feeInvocation.ClassHash, tx.Height); err != nil {
return nil, err
Expand Down Expand Up @@ -210,7 +216,7 @@ func (parser FeeParser) ParseInvocation(ctx context.Context, txCtx data.TxContex
if len(feeInvocation.Calldata) > 0 && len(tx.Selector) > 0 {
if isExecute && !hasExecute {
tx.Entrypoint = encoding.ExecuteEntrypoint
tx.ParsedCalldata, err = abi.DecodeExecuteCallData(feeInvocation.Calldata)
tx.ParsedCalldata, err = abi.DecodeExecuteCallData(tx.Calldata)
} else {
tx.ParsedCalldata, tx.Entrypoint, err = decode.CalldataBySelector(contractAbi, tx.Selector, tx.Calldata)
}
Expand Down
20 changes: 13 additions & 7 deletions pkg/indexer/parser/version/v0/internal_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (parser InternalTxParser) Parse(ctx context.Context, txCtx parserData.TxCon
CallType: storage.NewCallType(internal.CallType),
EntrypointType: storage.NewEntrypointType(internal.EntrypointType),
Selector: internal.Selector.Bytes(),
Result: internal.Result,
Calldata: internal.Calldata,
Result: make([]string, len(internal.Result)),
Calldata: make([]string, len(internal.Calldata)),

DeclareID: txCtx.DeclareID,
DeployID: txCtx.DeployID,
Expand All @@ -75,6 +75,12 @@ func (parser InternalTxParser) Parse(ctx context.Context, txCtx parserData.TxCon
Messages: make([]storage.Message, 0),
Internals: make([]storage.Internal, 0),
}
for i := range internal.Result {
tx.Result[i] = internal.Result[i].String()
}
for i := range internal.Calldata {
tx.Calldata[i] = internal.Calldata[i].String()
}

if class, err := parser.Resolver.FindClassByHash(ctx, internal.ClassHash, tx.Height); err != nil {
return tx, err
Expand Down Expand Up @@ -167,12 +173,12 @@ func (parser InternalTxParser) Parse(ctx context.Context, txCtx parserData.TxCon
switch {
case isExecute && !has:
tx.Entrypoint = encoding.ExecuteEntrypoint
tx.ParsedCalldata, err = abi.DecodeExecuteCallData(internal.Calldata)
tx.ParsedCalldata, err = abi.DecodeExecuteCallData(tx.Calldata)
case isChangeModules && !has:
tx.Entrypoint = encoding.ChangeModulesEntrypoint
tx.ParsedCalldata, err = abi.DecodeChangeModulesCallData(internal.Calldata)
tx.ParsedCalldata, err = abi.DecodeChangeModulesCallData(tx.Calldata)
default:
tx.ParsedCalldata, tx.Entrypoint, err = decode.InternalCalldata(contractAbi, tx.Selector, internal.Calldata, tx.EntrypointType)
tx.ParsedCalldata, tx.Entrypoint, err = decode.InternalCalldata(contractAbi, tx.Selector, tx.Calldata, tx.EntrypointType)
}

if err != nil {
Expand All @@ -184,9 +190,9 @@ func (parser InternalTxParser) Parse(ctx context.Context, txCtx parserData.TxCon
switch {
case isExecute && !has:
case isChangeModules && !has:
tx.ParsedResult, err = abi.DecodeChangeModulesResult(internal.Result)
tx.ParsedResult, err = abi.DecodeChangeModulesResult(tx.Result)
default:
tx.ParsedResult, err = decode.Result(contractAbi, internal.Result, tx.Selector, tx.EntrypointType)
tx.ParsedResult, err = decode.Result(contractAbi, tx.Result, tx.Selector, tx.EntrypointType)
}
if err != nil {
switch {
Expand Down
5 changes: 4 additions & 1 deletion pkg/indexer/parser/version/v0/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (parser MessageParser) Parse(ctx context.Context, txCtx parserData.TxContex
Time: txCtx.Time,
Order: msg.Order,
Selector: msg.Selector.String(),
Payload: msg.Payload,
Payload: make([]string, len(msg.Payload)),
Nonce: msg.Nonce.Decimal(),
ContractID: txCtx.ContractId,
DeclareID: txCtx.DeclareID,
Expand All @@ -42,6 +42,9 @@ func (parser MessageParser) Parse(ctx context.Context, txCtx parserData.TxContex
FeeID: txCtx.FeeID,
InternalID: txCtx.InternalID,
}
for i := range msg.Payload {
message.Payload[i] = msg.Payload[i].String()
}
if txCtx.ProxyId > 0 {
message.ContractID = txCtx.ProxyId
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/indexer/receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r *Receiver) worker(ctx context.Context, height uint64) {
default:
}

response, err := r.api.GetBlock(ctx, blockId)
response, err := r.api.GetBlock(ctx, blockId, false)
if err != nil {
if errors.Is(err, context.Canceled) {
return
Expand Down Expand Up @@ -195,7 +195,7 @@ func (r *Receiver) Head(ctx context.Context) (uint64, error) {

response, err := r.api.GetBlock(requestCtx, starknetData.BlockID{
String: starknetData.Latest,
})
}, true)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func (r *Receiver) GetBlockStatus(ctx context.Context, height uint64) (storage.S
return storage.NewStatus(response.Result.Status), nil
}

response, err := r.api.GetBlock(requestCtx, blockId)
response, err := r.api.GetBlock(requestCtx, blockId, false)
if err != nil {
return storage.StatusUnknown, err
}
Expand Down
Loading