diff --git a/cmd/firestarknet/fetcher.go b/cmd/firestarknet/fetcher.go index 9bdb08f..f43ce36 100644 --- a/cmd/firestarknet/fetcher.go +++ b/cmd/firestarknet/fetcher.go @@ -6,12 +6,13 @@ import ( "strconv" "time" - snRPC "github.com/NethermindEth/starknet.go/rpc" + starknetRPC "github.com/NethermindEth/starknet.go/rpc" "github.com/spf13/cobra" "github.com/streamingfast/cli/sflags" - goRPC "github.com/streamingfast/eth-go/rpc" + ethRPC "github.com/streamingfast/eth-go/rpc" firecore "github.com/streamingfast/firehose-core" "github.com/streamingfast/firehose-core/blockpoller" + firecoreRPC "github.com/streamingfast/firehose-core/rpc" "github.com/streamingfast/logging" "go.uber.org/zap" ) @@ -60,22 +61,21 @@ func fetchRunE(logger *zap.Logger, tracer logging.Tracer) firecore.CommandExecut latestBlockRetryInterval := sflags.MustGetDuration(cmd, "latest-block-retry-interval") - rpcClients := make([]*snRPC.Provider, 0, len(rpcEndpoints)) + starknetClients := firecoreRPC.NewClients[*starknetRPC.Provider]() for _, rpcEndpoint := range rpcEndpoints { - client, err := snRPC.NewProvider(rpcEndpoint) + client, err := starknetRPC.NewProvider(rpcEndpoint) if err != nil { return fmt.Errorf("creating rpc client: %w", err) } - rpcClients = append(rpcClients, client) + starknetClients.Add(client) } - ethRpcEndpoints := make([]*goRPC.Client, 0, len(ethEndpoints)) + ethClients := firecoreRPC.NewClients[*ethRPC.Client]() for _, ethEndpoint := range ethEndpoints { - client := goRPC.NewClient(ethEndpoint) - ethRpcEndpoints = append(ethRpcEndpoints, client) + ethClients.Add(ethRPC.NewClient(ethEndpoint)) } - starkClients := rpc.NewRPCClient(ethRpcEndpoints) - rpcFetcher := rpc.NewFetcher(rpcClients, starkClients, fetchLIBContractAddress, fetchInterval, latestBlockRetryInterval, logger) + + rpcFetcher := rpc.NewFetcher(starknetClients, ethClients, fetchLIBContractAddress, fetchInterval, latestBlockRetryInterval, logger) poller := blockpoller.New( rpcFetcher, diff --git a/go.mod b/go.mod index 982789b..9d1d205 100644 --- a/go.mod +++ b/go.mod @@ -4,18 +4,19 @@ go 1.22.0 toolchain go1.22.3 -//github.com/NethermindEth/starknet.go => github.com/streamingfast/starknet.go v0.0.0-20240611192319-738f3725b214 + replace github.com/jhump/protoreflect => github.com/streamingfast/protoreflect v0.0.0-20231205191344-4b629d20ce8d +//replace github.com/streamingfast/firehose-core => ../firehose-core require ( github.com/NethermindEth/juno v0.3.1 github.com/NethermindEth/starknet.go v0.7.1-0.20240614122559-0d2f96428b45 - github.com/hashicorp/go-multierror v1.1.1 + github.com/ethereum/go-ethereum v1.13.8 github.com/spf13/cobra v1.8.0 - github.com/streamingfast/bstream v0.0.2-0.20240603153252-ec8d37625188 + github.com/streamingfast/bstream v0.0.2-0.20240619142813-9d23840859bf github.com/streamingfast/cli v0.0.4-0.20240412191021-5f81842cb71d github.com/streamingfast/eth-go v0.0.0-20240312122859-216e183c0b7f - github.com/streamingfast/firehose-core v1.5.1 + github.com/streamingfast/firehose-core v1.5.4-0.20240627115820-5e86b3073da6 github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091 go.uber.org/zap v1.27.0 google.golang.org/protobuf v1.33.0 @@ -69,7 +70,6 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/envoyproxy/go-control-plane v0.12.0 // indirect github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect - github.com/ethereum/go-ethereum v1.13.8 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect @@ -90,6 +90,7 @@ require ( github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/holiman/uint256 v1.2.4 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -164,7 +165,7 @@ require ( github.com/streamingfast/pbgo v0.0.6-0.20240430190514-722fe9d82e5d // indirect github.com/streamingfast/sf-tracing v0.0.0-20240430173521-888827872b90 // indirect github.com/streamingfast/shutter v1.5.0 // indirect - github.com/streamingfast/substreams v1.7.3 // indirect + github.com/streamingfast/substreams v1.8.0 // indirect github.com/stretchr/testify v1.8.4 // indirect github.com/subosito/gotenv v1.4.2 // indirect github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf // indirect @@ -174,7 +175,7 @@ require ( github.com/tidwall/pretty v1.2.1 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect - github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c // indirect + github.com/whyrusleeping/tar-utils v0.0.0-20201201191210-20a61371de5b // indirect github.com/x448/float16 v0.8.4 // indirect github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869 // indirect go.opencensus.io v0.24.0 // indirect @@ -190,7 +191,7 @@ require ( go.uber.org/atomic v1.10.0 // indirect go.uber.org/automaxprocs v1.5.2 // indirect go.uber.org/multierr v1.10.0 // indirect - golang.org/x/crypto v0.21.0 // indirect + golang.org/x/crypto v0.23.0 // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/mod v0.14.0 // indirect golang.org/x/net v0.22.0 // indirect diff --git a/go.sum b/go.sum index ebad2aa..09197b6 100644 --- a/go.sum +++ b/go.sum @@ -561,8 +561,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.15.0 h1:js3yy885G8xwJa6iOISGFwd+qlUo5AvyXb7CiihdtiU= github.com/spf13/viper v1.15.0/go.mod h1:fFcTBJxvhhzSJiZy8n+PeW6t8l+KeT/uTARa0jHOQLA= -github.com/streamingfast/bstream v0.0.2-0.20240603153252-ec8d37625188 h1:aso0Q0qT9h1ICG6//G9P0VQpql2c2A87J8YMUaJipQs= -github.com/streamingfast/bstream v0.0.2-0.20240603153252-ec8d37625188/go.mod h1:n5wy+Vmwp4xbjXO7B81MAkAgjnf1vJ/lI2y6hWWyFbg= +github.com/streamingfast/bstream v0.0.2-0.20240619142813-9d23840859bf h1:LXFIz2pyTlIMNzyifvKsZpFLcLbJkTcRyu7OlABV1S0= +github.com/streamingfast/bstream v0.0.2-0.20240619142813-9d23840859bf/go.mod h1:n5wy+Vmwp4xbjXO7B81MAkAgjnf1vJ/lI2y6hWWyFbg= github.com/streamingfast/cli v0.0.4-0.20240412191021-5f81842cb71d h1:9tsEt2tLCp94CW6MyJZY+Rw6+t0WH2kioBR6ucO6P/E= github.com/streamingfast/cli v0.0.4-0.20240412191021-5f81842cb71d/go.mod h1:og+6lDBPLZ24lbF/YISmVsSduZUZwXSmJGD3pZ/sW2Y= github.com/streamingfast/dauth v0.0.0-20240222213226-519afc16cf84 h1:yCvuNcwQ21J4Ua6YrAmHDBx3bjK04y+ssEYBe65BXRU= @@ -585,8 +585,8 @@ github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839 h1:K6mJPvh1 github.com/streamingfast/dtracing v0.0.0-20220305214756-b5c0e8699839/go.mod h1:huOJyjMYS6K8upTuxDxaNd+emD65RrXoVBvh8f1/7Ns= github.com/streamingfast/eth-go v0.0.0-20240312122859-216e183c0b7f h1:1LwsmRVENfGsPHrVEOCJ7FKQ1YyFcg7+USuHdd/TIkw= github.com/streamingfast/eth-go v0.0.0-20240312122859-216e183c0b7f/go.mod h1:UEm8dqibr3c3A1iIA3CHpkhN7j3X78prN7/55sXf3A0= -github.com/streamingfast/firehose-core v1.5.1 h1:BiX3okg3Wl/NVFfX76SaXOWRndQpfyeIYiVk04VbbwM= -github.com/streamingfast/firehose-core v1.5.1/go.mod h1:xUHlSTxMnGTvB+YVHtv4MCh/SXxlhg5puHMrTXHSe0I= +github.com/streamingfast/firehose-core v1.5.4-0.20240627115820-5e86b3073da6 h1:ooT7/FlCZ2W50TmYVr9qSTGhN91bhaWxIYnYGc2pqRs= +github.com/streamingfast/firehose-core v1.5.4-0.20240627115820-5e86b3073da6/go.mod h1:TXmSr7tnJdqcDrYG2l+BwURjX0rGYKsUNcWkcL6GROw= github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0 h1:g8eEYbFSykyzIyuxNMmHEUGGUvJE0ivmqZagLDK42gw= github.com/streamingfast/jsonpb v0.0.0-20210811021341-3670f0aa02d0/go.mod h1:cTNObq2Uofb330y05JbbZZ6RwE6QUXw5iVcHk1Fx3fk= github.com/streamingfast/logging v0.0.0-20210811175431-f3b44b61606a/go.mod h1:4GdqELhZOXj4xwc4IaBmzofzdErGynnaSzuzxy0ZIBo= @@ -604,8 +604,8 @@ github.com/streamingfast/sf-tracing v0.0.0-20240430173521-888827872b90 h1:94Hllk github.com/streamingfast/sf-tracing v0.0.0-20240430173521-888827872b90/go.mod h1:e6tKS/udlfXFUTQBYfDDdISfjULvQXet1kBrOeRfgI4= github.com/streamingfast/shutter v1.5.0 h1:NpzDYzj0HVpSiDJVO/FFSL6QIK/YKOxY0gJAtyaTOgs= github.com/streamingfast/shutter v1.5.0/go.mod h1:B/T6efqdeMGbGwjzPS1ToXzYZI4kDzI5/u4I+7qbjY8= -github.com/streamingfast/substreams v1.7.3 h1:V4YOJt4tAzivaLpC7nSVDdULMuczj7QfJUTyHAT2qkM= -github.com/streamingfast/substreams v1.7.3/go.mod h1:ao5xpjglDohCmwzRUlJtTNGUn+nXGR2AXBnYQEbvQaI= +github.com/streamingfast/substreams v1.8.0 h1:mVo6TTVRcwLB1TuFdZXI1GBVJnmREfJEt8sRFybWkLQ= +github.com/streamingfast/substreams v1.8.0/go.mod h1:XtL4RgQawes9/a9iM9d6bAABacfIuekY+jceszF7u2c= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -640,8 +640,8 @@ github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0h github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tsenart/deadcode v0.0.0-20160724212837-210d2dc333e9/go.mod h1:q+QjxYvZ+fpjMXqs+XEriussHjSYqeXVnAdSV1tkMYk= -github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c h1:GGsyl0dZ2jJgVT+VvWBf/cNijrHRhkrTjkmp5wg7li0= -github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c/go.mod h1:xxcJeBb7SIUl/Wzkz1eVKJE/CB34YNrqX2TQI6jY9zs= +github.com/whyrusleeping/tar-utils v0.0.0-20201201191210-20a61371de5b h1:wA3QeTsaAXybLL2kb2cKhCAQTHgYTMwuI8lBlJSv5V8= +github.com/whyrusleeping/tar-utils v0.0.0-20201201191210-20a61371de5b/go.mod h1:xT1Y5p2JR2PfSZihE0s4mjdJaRGp1waCTf5JzhQLBck= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869 h1:7v7L5lsfw4w8iqBBXETukHo4IPltmD+mWoLRYUmeGN8= @@ -712,8 +712,8 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= diff --git a/rpc/fetcher.go b/rpc/fetcher.go index addb8bd..6d8c648 100644 --- a/rpc/fetcher.go +++ b/rpc/fetcher.go @@ -9,59 +9,38 @@ import ( pbstarknet "firehose-starknet/pb/sf/starknet/type/v1" "github.com/NethermindEth/juno/core/felt" - snRPC "github.com/NethermindEth/starknet.go/rpc" + starknetRPC "github.com/NethermindEth/starknet.go/rpc" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/hashicorp/go-multierror" pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1" "github.com/streamingfast/eth-go" - goRPC "github.com/streamingfast/eth-go/rpc" + ethRPC "github.com/streamingfast/eth-go/rpc" + firecoreRPC "github.com/streamingfast/firehose-core/rpc" "go.uber.org/zap" "google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/known/timestamppb" ) -type RPCClient[C any] struct { - clients []C -} - -func NewRPCClient[C any](clients []C) *RPCClient[C] { - return &RPCClient[C]{clients: clients} -} - -func (r *RPCClient[C]) WithClient(ctx context.Context, f func(client C) error) error { - var errs error - for _, client := range r.clients { - err := f(client) - if err != nil { - errs = multierror.Append(errs, err) - continue - } - return errs - } - return nil -} - type Fetcher struct { - rpcClients []*snRPC.Provider - starkClients *RPCClient[*goRPC.Client] + starknetClients *firecoreRPC.Clients[*starknetRPC.Provider] + ethClients *firecoreRPC.Clients[*ethRPC.Client] fetchInterval time.Duration latestBlockRetryInterval time.Duration logger *zap.Logger latestBlockNum uint64 - ethCallLIBParams goRPC.CallParams + ethCallLIBParams ethRPC.CallParams } func NewFetcher( - rpcClients []*snRPC.Provider, - starkClients *RPCClient[*goRPC.Client], + starknetClients *firecoreRPC.Clients[*starknetRPC.Provider], + ethClient *firecoreRPC.Clients[*ethRPC.Client], fetchLIBContractAddress string, fetchInterval time.Duration, latestBlockRetryInterval time.Duration, logger *zap.Logger) *Fetcher { return &Fetcher{ - rpcClients: rpcClients, - starkClients: starkClients, + starknetClients: starknetClients, + ethClients: ethClient, fetchInterval: fetchInterval, latestBlockRetryInterval: latestBlockRetryInterval, logger: logger, @@ -110,9 +89,8 @@ func (f *Fetcher) Fetch(ctx context.Context, requestBlockNum uint64) (b *pbbstre lib = requestBlockNum - 1 } - //todo: fix receipt //todo: track state update - // u, err := f.rpcClients[0].StateUpdate(ctx, snRPC.BlockID(requestBlockNum)) + // u, err := f.rpcClients[0].StateUpdate(ctx, starknetRPC.BlockID(requestBlockNum)) // if err != nil { // return nil, false, fmt.Errorf("fetching state update for block %d: %w", requestBlockNum, err) // } @@ -131,81 +109,50 @@ func (f *Fetcher) Fetch(ctx context.Context, requestBlockNum uint64) (b *pbbstre } func (f *Fetcher) fetchBlockNumber(ctx context.Context, blockHash *felt.Felt) (uint64, error) { - var errs error - for _, rpcClient := range f.rpcClients { - i, err := rpcClient.BlockWithTxHashes(ctx, snRPC.WithBlockHash(blockHash)) + return firecoreRPC.WithClients(f.starknetClients, func(client *starknetRPC.Provider) (uint64, error) { + bn, err := client.BlockWithTxHashes(ctx, starknetRPC.WithBlockHash(blockHash)) if err != nil { - f.logger.Warn("failed to fetch latest block num, trying next client", zap.Error(err)) - errs = multierror.Append(errs, err) - continue + return 0, fmt.Errorf("unable to fetch block number: %w", err) } - return i.(*snRPC.BlockTxHashes).BlockNumber, nil - } - - return 0, errs + return bn.(*starknetRPC.BlockTxHashes).BlockNumber, nil + }) } func (f *Fetcher) fetchLatestBlockNum(ctx context.Context) (uint64, error) { - var errs error - for _, rpcClient := range f.rpcClients { - blockNum, err := rpcClient.BlockNumber(ctx) + return firecoreRPC.WithClients(f.starknetClients, func(client *starknetRPC.Provider) (uint64, error) { + blockNum, err := client.BlockNumber(ctx) if err != nil { - f.logger.Warn("failed to fetch latest block num, trying next client", zap.Error(err)) - errs = multierror.Append(errs, err) - continue + return 0, fmt.Errorf("unable to fetch latest block num: %w", err) } return blockNum, nil - } - - return 0, errs + }) } func (f *Fetcher) fetchLIB(ctx context.Context) (uint64, error) { - var libNum *uint64 - err := f.starkClients.WithClient(ctx, func(client *goRPC.Client) error { + return firecoreRPC.WithClients(f.ethClients, func(client *ethRPC.Client) (uint64, error) { blockNum, err := client.Call(ctx, f.ethCallLIBParams) if err != nil { - f.logger.Warn("failed to fetch latest block num, trying next client", zap.Error(err)) - return err + return 0, fmt.Errorf("unable to fetch LIB: %w", err) } blockNum = cleanBlockNum(blockNum) b, err := hexutil.DecodeUint64(blockNum) if err != nil { - return fmt.Errorf("unable to parse block number %s: %w", blockNum, err) + return 0, fmt.Errorf("unable to parse block number %s: %w", blockNum, err) } - fmt.Println("LIB", b) - libNum = &b - return nil - }) - - if err != nil { - return 0, err - } - - if libNum == nil { - return 0, fmt.Errorf("unable to fetch LIB") - } - return *libNum, nil + return b, nil + }) } -func (f *Fetcher) fetchBlock(ctx context.Context, requestBlockNum uint64) (*snRPC.BlockWithReceipts, error) { - var errs error - for _, rpcClient := range f.rpcClients { - i, err := rpcClient.BlockWithReceipts(ctx, snRPC.WithBlockNumber(requestBlockNum)) +func (f *Fetcher) fetchBlock(ctx context.Context, requestBlockNum uint64) (*starknetRPC.BlockWithReceipts, error) { + return firecoreRPC.WithClients(f.starknetClients, func(client *starknetRPC.Provider) (*starknetRPC.BlockWithReceipts, error) { + b, err := client.BlockWithReceipts(ctx, starknetRPC.WithBlockNumber(requestBlockNum)) if err != nil { - f.logger.Warn("failed to fetch block from rpc", zap.Uint64("block_num", requestBlockNum), zap.Error(err)) - errs = multierror.Append(errs, err) - continue + return nil, fmt.Errorf("unable to fetch block: %w", err) } - - block := i.(*snRPC.BlockWithReceipts) - - return block, nil - } - - return nil, errs + return b.(*starknetRPC.BlockWithReceipts), nil + }) } func cleanBlockNum(blockNum string) string { @@ -215,14 +162,14 @@ func cleanBlockNum(blockNum string) string { return blockNum } -func newEthCallLIBParams(contractAddress string) goRPC.CallParams { - return goRPC.CallParams{ +func newEthCallLIBParams(contractAddress string) ethRPC.CallParams { + return ethRPC.CallParams{ Data: eth.MustNewMethodDef("stateBlockNumber() (int256)").NewCall().MustEncode(), To: eth.MustNewAddress(contractAddress), } } -func convertBlock(b *snRPC.BlockWithReceipts) (*pbbstream.Block, error) { +func convertBlock(b *starknetRPC.BlockWithReceipts) (*pbbstream.Block, error) { block := &pbstarknet.Block{ BlockHash: b.BlockHash.String(), BlockNumber: b.BlockNumber, @@ -272,18 +219,18 @@ func convertBlock(b *snRPC.BlockWithReceipts) (*pbbstream.Block, error) { return bstreamBlock, nil } -func convertL1DAMode(mode snRPC.L1DAMode) pbstarknet.L1_DA_MODE { +func convertL1DAMode(mode starknetRPC.L1DAMode) pbstarknet.L1_DA_MODE { switch mode { - case snRPC.L1DAModeBlob: + case starknetRPC.L1DAModeBlob: return pbstarknet.L1_DA_MODE_BLOB - case snRPC.L1DAModeCalldata: + case starknetRPC.L1DAModeCalldata: return pbstarknet.L1_DA_MODE_CALLDATA default: panic(fmt.Errorf("unknown L1DAMode %v", mode)) } } -func convertL1DataGasPrice(l snRPC.ResourcePrice) *pbstarknet.L1GasPrice { +func convertL1DataGasPrice(l starknetRPC.ResourcePrice) *pbstarknet.L1GasPrice { f := "0x0" if l.PriceInFRI != nil { f = l.PriceInFRI.String() @@ -297,7 +244,7 @@ func convertL1DataGasPrice(l snRPC.ResourcePrice) *pbstarknet.L1GasPrice { PriceInWei: w, } } -func convertL1GasPrice(l snRPC.ResourcePrice) *pbstarknet.L1GasPrice { +func convertL1GasPrice(l starknetRPC.ResourcePrice) *pbstarknet.L1GasPrice { f := "0x0" if l.PriceInFRI != nil { f = l.PriceInFRI.String() @@ -312,7 +259,7 @@ func convertL1GasPrice(l snRPC.ResourcePrice) *pbstarknet.L1GasPrice { } } -func convertTransactionWithReceipt(tx snRPC.TransactionWithReceipt) (*pbstarknet.TransactionWithReceipt, error) { +func convertTransactionWithReceipt(tx starknetRPC.TransactionWithReceipt) (*pbstarknet.TransactionWithReceipt, error) { t := &pbstarknet.TransactionWithReceipt{} convertAndSetTransaction(t, tx.Transaction.Transaction) @@ -321,51 +268,51 @@ func convertTransactionWithReceipt(tx snRPC.TransactionWithReceipt) (*pbstarknet return t, nil } -func convertAndSetTransaction(out *pbstarknet.TransactionWithReceipt, in snRPC.Transaction) { +func convertAndSetTransaction(out *pbstarknet.TransactionWithReceipt, in starknetRPC.Transaction) { switch i := in.(type) { - case snRPC.InvokeTxnV0: + case starknetRPC.InvokeTxnV0: out.Transaction = convertInvokeTransactionV0(i) - case snRPC.InvokeTxnV1: + case starknetRPC.InvokeTxnV1: out.Transaction = convertInvokeTransactionV1(i) - case snRPC.InvokeTxnV3: + case starknetRPC.InvokeTxnV3: out.Transaction = convertInvokeTransactionV3(i) - case snRPC.L1HandlerTxn: + case starknetRPC.L1HandlerTxn: out.Transaction = convertL1HandlerTransaction(i) - case snRPC.DeclareTxnV0: + case starknetRPC.DeclareTxnV0: out.Transaction = convertDeclareTransactionV0(i) - case snRPC.DeclareTxnV1: + case starknetRPC.DeclareTxnV1: out.Transaction = convertDeclareTransactionV1(i) - case snRPC.DeclareTxnV2: + case starknetRPC.DeclareTxnV2: out.Transaction = convertDeclareTransactionV2(i) - case snRPC.DeclareTxnV3: + case starknetRPC.DeclareTxnV3: out.Transaction = convertDeclareTransactionV3(i) - case snRPC.DeployTxn: + case starknetRPC.DeployTxn: out.Transaction = convertDeployTransactionV0(i) - case snRPC.DeployAccountTxn: + case starknetRPC.DeployAccountTxn: out.Transaction = convertDeployAccountTransactionV0(i) - case snRPC.DeployAccountTxnV3: + case starknetRPC.DeployAccountTxnV3: out.Transaction = convertDeployAccountTransactionV3(i) default: panic(fmt.Errorf("unknown transaction type %T", in)) } } -func convertAndSetReceipt(in snRPC.TransactionReceipt) *pbstarknet.TransactionReceipt { +func convertAndSetReceipt(in starknetRPC.TransactionReceipt) *pbstarknet.TransactionReceipt { out := &pbstarknet.TransactionReceipt{} switch r := in.(type) { - case snRPC.InvokeTransactionReceipt: + case starknetRPC.InvokeTransactionReceipt: // nothing to do - out = createCommonTransactionReceipt(snRPC.CommonTransactionReceipt(r)) - case snRPC.DeclareTransactionReceipt: + out = createCommonTransactionReceipt(starknetRPC.CommonTransactionReceipt(r)) + case starknetRPC.DeclareTransactionReceipt: // nothing to do - out = createCommonTransactionReceipt(snRPC.CommonTransactionReceipt(r)) - case snRPC.L1HandlerTransactionReceipt: + out = createCommonTransactionReceipt(starknetRPC.CommonTransactionReceipt(r)) + case starknetRPC.L1HandlerTransactionReceipt: out = createCommonTransactionReceipt(r.CommonTransactionReceipt) out.MessageHash = string(r.MessageHash) - case snRPC.DeployTransactionReceipt: + case starknetRPC.DeployTransactionReceipt: out = createCommonTransactionReceipt(r.CommonTransactionReceipt) out.ContractAddress = r.ContractAddress.String() - case snRPC.DeployAccountTransactionReceipt: + case starknetRPC.DeployAccountTransactionReceipt: out = createCommonTransactionReceipt(r.CommonTransactionReceipt) out.ContractAddress = r.ContractAddress.String() default: @@ -374,7 +321,7 @@ func convertAndSetReceipt(in snRPC.TransactionReceipt) *pbstarknet.TransactionRe return out } -func createCommonTransactionReceipt(common snRPC.CommonTransactionReceipt) *pbstarknet.TransactionReceipt { +func createCommonTransactionReceipt(common starknetRPC.CommonTransactionReceipt) *pbstarknet.TransactionReceipt { return &pbstarknet.TransactionReceipt{ Type: string(common.Type), TransactionHash: common.TransactionHash.String(), @@ -391,7 +338,7 @@ func createCommonTransactionReceipt(common snRPC.CommonTransactionReceipt) *pbst } } -func convertExecutionResources(r snRPC.ExecutionResources) *pbstarknet.ExecutionResources { +func convertExecutionResources(r starknetRPC.ExecutionResources) *pbstarknet.ExecutionResources { return &pbstarknet.ExecutionResources{ DataAvailability: convertDataAvailability(r.DataAvailability), Steps: uint64(r.Steps), @@ -407,14 +354,14 @@ func convertExecutionResources(r snRPC.ExecutionResources) *pbstarknet.Execution } } -func convertDataAvailability(a snRPC.DataAvailability) *pbstarknet.DataAvailability { +func convertDataAvailability(a starknetRPC.DataAvailability) *pbstarknet.DataAvailability { return &pbstarknet.DataAvailability{ L1DataGas: uint64(a.L1DataGas), L1Gas: uint64(a.L1Gas), } } -func convertEvents(events []snRPC.Event) []*pbstarknet.Event { +func convertEvents(events []starknetRPC.Event) []*pbstarknet.Event { out := make([]*pbstarknet.Event, len(events)) for i, e := range events { @@ -428,7 +375,7 @@ func convertEvents(events []snRPC.Event) []*pbstarknet.Event { return out } -func convertMessageSent(msg []snRPC.MsgToL1) []*pbstarknet.MessagesSent { +func convertMessageSent(msg []starknetRPC.MsgToL1) []*pbstarknet.MessagesSent { out := make([]*pbstarknet.MessagesSent, len(msg)) for i, m := range msg { @@ -443,7 +390,7 @@ func convertMessageSent(msg []snRPC.MsgToL1) []*pbstarknet.MessagesSent { } -func convertInvokeTransactionV0(tx snRPC.InvokeTxnV0) *pbstarknet.TransactionWithReceipt_InvokeTransactionV0 { +func convertInvokeTransactionV0(tx starknetRPC.InvokeTxnV0) *pbstarknet.TransactionWithReceipt_InvokeTransactionV0 { return &pbstarknet.TransactionWithReceipt_InvokeTransactionV0{ InvokeTransactionV0: &pbstarknet.InvokeTransactionV0{ Type: string(tx.GetType()), @@ -457,7 +404,7 @@ func convertInvokeTransactionV0(tx snRPC.InvokeTxnV0) *pbstarknet.TransactionWit } } -func convertInvokeTransactionV1(tx snRPC.InvokeTxnV1) *pbstarknet.TransactionWithReceipt_InvokeTransactionV1 { +func convertInvokeTransactionV1(tx starknetRPC.InvokeTxnV1) *pbstarknet.TransactionWithReceipt_InvokeTransactionV1 { return &pbstarknet.TransactionWithReceipt_InvokeTransactionV1{ InvokeTransactionV1: &pbstarknet.InvokeTransactionV1{ Type: string(tx.GetType()), @@ -471,7 +418,7 @@ func convertInvokeTransactionV1(tx snRPC.InvokeTxnV1) *pbstarknet.TransactionWit } } -func convertInvokeTransactionV3(tx snRPC.InvokeTxnV3) *pbstarknet.TransactionWithReceipt_InvokeTransactionV3 { +func convertInvokeTransactionV3(tx starknetRPC.InvokeTxnV3) *pbstarknet.TransactionWithReceipt_InvokeTransactionV3 { return &pbstarknet.TransactionWithReceipt_InvokeTransactionV3{ InvokeTransactionV3: &pbstarknet.InvokeTransactionV3{ Type: string(tx.GetType()), @@ -490,7 +437,7 @@ func convertInvokeTransactionV3(tx snRPC.InvokeTxnV3) *pbstarknet.TransactionWit } } -func convertL1HandlerTransaction(tx snRPC.L1HandlerTxn) *pbstarknet.TransactionWithReceipt_L1HandlerTransaction { +func convertL1HandlerTransaction(tx starknetRPC.L1HandlerTxn) *pbstarknet.TransactionWithReceipt_L1HandlerTransaction { return &pbstarknet.TransactionWithReceipt_L1HandlerTransaction{ L1HandlerTransaction: &pbstarknet.L1HandlerTransaction{ Version: string(tx.Version), @@ -503,7 +450,7 @@ func convertL1HandlerTransaction(tx snRPC.L1HandlerTxn) *pbstarknet.TransactionW } } -func convertDeclareTransactionV0(tx snRPC.DeclareTxnV0) *pbstarknet.TransactionWithReceipt_DeclareTransactionV0 { +func convertDeclareTransactionV0(tx starknetRPC.DeclareTxnV0) *pbstarknet.TransactionWithReceipt_DeclareTransactionV0 { return &pbstarknet.TransactionWithReceipt_DeclareTransactionV0{ DeclareTransactionV0: &pbstarknet.DeclareTransactionV0{ Type: string(tx.GetType()), @@ -516,7 +463,7 @@ func convertDeclareTransactionV0(tx snRPC.DeclareTxnV0) *pbstarknet.TransactionW } } -func convertDeclareTransactionV1(tx snRPC.DeclareTxnV1) *pbstarknet.TransactionWithReceipt_DeclareTransactionV1 { +func convertDeclareTransactionV1(tx starknetRPC.DeclareTxnV1) *pbstarknet.TransactionWithReceipt_DeclareTransactionV1 { return &pbstarknet.TransactionWithReceipt_DeclareTransactionV1{ DeclareTransactionV1: &pbstarknet.DeclareTransactionV1{ Type: string(tx.GetType()), @@ -530,7 +477,7 @@ func convertDeclareTransactionV1(tx snRPC.DeclareTxnV1) *pbstarknet.TransactionW } } -func convertDeclareTransactionV2(tx snRPC.DeclareTxnV2) *pbstarknet.TransactionWithReceipt_DeclareTransactionV2 { +func convertDeclareTransactionV2(tx starknetRPC.DeclareTxnV2) *pbstarknet.TransactionWithReceipt_DeclareTransactionV2 { return &pbstarknet.TransactionWithReceipt_DeclareTransactionV2{ DeclareTransactionV2: &pbstarknet.DeclareTransactionV2{ Type: string(tx.GetType()), @@ -543,7 +490,7 @@ func convertDeclareTransactionV2(tx snRPC.DeclareTxnV2) *pbstarknet.TransactionW }, } } -func convertDeclareTransactionV3(tx snRPC.DeclareTxnV3) *pbstarknet.TransactionWithReceipt_DeclareTransactionV3 { +func convertDeclareTransactionV3(tx starknetRPC.DeclareTxnV3) *pbstarknet.TransactionWithReceipt_DeclareTransactionV3 { return &pbstarknet.TransactionWithReceipt_DeclareTransactionV3{ DeclareTransactionV3: &pbstarknet.DeclareTransactionV3{ Type: string(tx.GetType()), @@ -563,7 +510,7 @@ func convertDeclareTransactionV3(tx snRPC.DeclareTxnV3) *pbstarknet.TransactionW } } -func convertDeployTransactionV0(tx snRPC.DeployTxn) *pbstarknet.TransactionWithReceipt_DeployTransactionV0 { +func convertDeployTransactionV0(tx starknetRPC.DeployTxn) *pbstarknet.TransactionWithReceipt_DeployTransactionV0 { return &pbstarknet.TransactionWithReceipt_DeployTransactionV0{ DeployTransactionV0: &pbstarknet.DeployTransactionV0{ Version: string(tx.Version), @@ -576,7 +523,7 @@ func convertDeployTransactionV0(tx snRPC.DeployTxn) *pbstarknet.TransactionWithR } -func convertDeployAccountTransactionV0(tx snRPC.DeployAccountTxn) *pbstarknet.TransactionWithReceipt_DeployAccountTransactionV1 { +func convertDeployAccountTransactionV0(tx starknetRPC.DeployAccountTxn) *pbstarknet.TransactionWithReceipt_DeployAccountTransactionV1 { return &pbstarknet.TransactionWithReceipt_DeployAccountTransactionV1{ DeployAccountTransactionV1: &pbstarknet.DeployAccountTransactionV1{ Type: string(tx.GetType()), @@ -592,7 +539,7 @@ func convertDeployAccountTransactionV0(tx snRPC.DeployAccountTxn) *pbstarknet.Tr } -func convertDeployAccountTransactionV3(tx snRPC.DeployAccountTxnV3) *pbstarknet.TransactionWithReceipt_DeployAccountTransactionV3 { +func convertDeployAccountTransactionV3(tx starknetRPC.DeployAccountTxnV3) *pbstarknet.TransactionWithReceipt_DeployAccountTransactionV3 { return &pbstarknet.TransactionWithReceipt_DeployAccountTransactionV3{ DeployAccountTransactionV3: &pbstarknet.DeployAccountTransactionV3{ Type: string(tx.GetType()), @@ -618,7 +565,7 @@ func convertFeltArray(in []*felt.Felt) []string { return out } -func convertResourceBounds(in snRPC.ResourceBoundsMapping) *pbstarknet.ResourceBounds { +func convertResourceBounds(in starknetRPC.ResourceBoundsMapping) *pbstarknet.ResourceBounds { return &pbstarknet.ResourceBounds{ L1Gas: &pbstarknet.Resource{ MaxAmount: string(in.L1Gas.MaxAmount),