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

Add support of 0.13.3 #41

Merged
merged 3 commits into from
Sep 12, 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.22

require (
github.com/dipdup-io/starknet-go-api v0.0.0-20240616154215-7c9a3f27407d
github.com/dipdup-io/starknet-go-api v0.0.0-20240912083038-27d5587efb86
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-20240616154215-7c9a3f27407d h1:i7TIDgh0vyr+2zFm9PsOy8iPn5bzmAOIiM84U7d7dp8=
github.com/dipdup-io/starknet-go-api v0.0.0-20240616154215-7c9a3f27407d/go.mod h1:y3KGLFQtwzUBcT0X2LMj6CxocUimr/A9XYg+j0KIRDE=
github.com/dipdup-io/starknet-go-api v0.0.0-20240912083038-27d5587efb86 h1:XBcAdrZc6FsaNK/WqLCMpkI1nU8fFdHzQZ0pf7k8kLE=
github.com/dipdup-io/starknet-go-api v0.0.0-20240912083038-27d5587efb86/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
13 changes: 11 additions & 2 deletions pkg/indexer/decode/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,24 @@ func CalldataForL1Handler(contractAbi abi.Abi, selector []byte, calldata []strin

// Event -
func Event(contractAbi abi.Abi, keys []string, data []string) (map[string]any, string, error) {
if len(keys) != 1 {
var values []string
switch len(keys) {
case 0:
return nil, "", nil
case 1:
values = make([]string, len(data))
copy(values, data)
default:
values = make([]string, len(keys[1:]))
copy(values, keys[1:])
values = append(values, data...)
}
selector := encoding.EncodeHex(encoding.MustDecodeHex(keys[0]))
event, ok := contractAbi.GetEventBySelector(selector)
if !ok {
return nil, "", nil
}
parsed, err := abi.DecodeEventData(data, *event, contractAbi.Structs, contractAbi.Enums)
parsed, err := abi.DecodeEventData(values, *event, contractAbi.Structs, contractAbi.Enums)
return parsed, event.Name, err
}

Expand Down
121 changes: 121 additions & 0 deletions pkg/indexer/decode/decode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package decode

import (
"testing"

"github.com/dipdup-io/starknet-go-api/pkg/abi"
"github.com/stretchr/testify/require"
)

func TestEvent(t *testing.T) {
type args struct {
contractAbi abi.Abi
keys []string
data []string
}
tests := []struct {
name string
args args
want map[string]any
want1 string
}{
{
name: "transfer before v0.13.3",
args: args{
contractAbi: abi.Abi{
EventsBySelector: map[string]*abi.EventItem{
"99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9": {
Type: abi.Type{
Name: "Transfer",
Type: "event",
},
Data: []abi.Type{
{
Name: "from",
Type: "core::starknet::contract_address::ContractAddress",
},
{
Name: "to",
Type: "core::starknet::contract_address::ContractAddress",
},
{
Name: "amount",
Type: "core::integer::u256",
},
},
Keys: []abi.Type{},
},
},
},
keys: []string{
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9",
},
data: []string{
"0x3a39bfdf7aad9504978afc793d5c1e2c8d9fc6f2e02720aebc52c9817a83e42",
"0x0",
"0x21dcf820ad93f",
"0x0",
},
},
want: map[string]any{
"from": "0x3a39bfdf7aad9504978afc793d5c1e2c8d9fc6f2e02720aebc52c9817a83e42",
"to": "0x0",
"amount": "595727030606143",
},
want1: "Transfer",
}, {
name: "transfer after v0.13.3",
args: args{
contractAbi: abi.Abi{
EventsBySelector: map[string]*abi.EventItem{
"99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9": {
Type: abi.Type{
Name: "Transfer",
Type: "event",
},
Data: []abi.Type{
{
Name: "amount",
Type: "core::integer::u256",
},
},
Keys: []abi.Type{
{
Name: "from",
Type: "core::starknet::contract_address::ContractAddress",
},
{
Name: "to",
Type: "core::starknet::contract_address::ContractAddress",
},
},
},
},
},
keys: []string{
"0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9",
"0x3a39bfdf7aad9504978afc793d5c1e2c8d9fc6f2e02720aebc52c9817a83e42",
"0x0",
},
data: []string{
"0x21dcf820ad93f",
"0x0",
},
},
want: map[string]any{
"from": "0x3a39bfdf7aad9504978afc793d5c1e2c8d9fc6f2e02720aebc52c9817a83e42",
"to": "0x0",
"amount": "595727030606143",
},
want1: "Transfer",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, got1, err := Event(tt.args.contractAbi, tt.args.keys, tt.args.data)
require.NoError(t, err)
require.Equal(t, tt.want, got)
require.Equal(t, tt.want1, got1)
})
}
}
2 changes: 1 addition & 1 deletion pkg/indexer/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func createParser(
"0.10.0", "0.10.1", "0.10.2", "0.10.3",
"0.11.0", "0.11.0.2", "0.11.1", "0.11.2",
"0.12.0", "0.12.1", "0.12.2", "0.12.3",
"0.13.0", "0.13.1", "0.13.1.1", "0.13.2", "0.13.2.1":
"0.13.0", "0.13.1", "0.13.1.1", "0.13.2", "0.13.2.1", "0.13.3":
return v0.New(resolver, cache, blocks), nil
default:
return nil, errors.Errorf("unknown starknet version: %s", *version)
Expand Down
Loading