From abe2c5d770df1360fd314e52bbec11ae5fc2b5ea Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Thu, 21 Sep 2023 01:41:40 +0530 Subject: [PATCH 01/12] Update call.go --- rpc/call.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/rpc/call.go b/rpc/call.go index d499df3a..5e0844bc 100644 --- a/rpc/call.go +++ b/rpc/call.go @@ -15,15 +15,8 @@ func (provider *Provider) Call(ctx context.Context, request FunctionCall, blockI } var result []*felt.Felt if err := do(ctx, provider.c, "starknet_call", &result, request, blockID); err != nil { - switch { - case errors.Is(err, ErrContractNotFound): - return nil, ErrContractNotFound - case errors.Is(err, ErrContractError): - return nil, ErrContractError - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - } - return nil, err + + return nil, , tryUnwrapToRPCErr(err, ErrContractNotFound, ErrContractError, ErrBlockNotFound) } return result, nil } From 4fea87bf898cb95966452f8c4206fb300d22dc62 Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Thu, 21 Sep 2023 02:03:05 +0530 Subject: [PATCH 02/12] Update contract.go --- rpc/contract.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/rpc/contract.go b/rpc/contract.go index bb413803..036620ec 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -14,13 +14,8 @@ import ( func (provider *Provider) Class(ctx context.Context, blockID BlockID, classHash *felt.Felt) (ClassOutput, error) { var rawClass map[string]any if err := do(ctx, provider.c, "starknet_getClass", &rawClass, blockID, classHash); err != nil { - switch { - case errors.Is(err, ErrClassHashNotFound): - return nil, ErrClassHashNotFound - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - } - return nil, err + + return nil, tryUnwrapToRPCErr(err, ErrClassHashNotFound, ErrBlockNotFound) } return typecastClassOutput(&rawClass) From 04f1fe291a0329a42d4d0c1e244ede95b861d282 Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Thu, 21 Sep 2023 02:04:28 +0530 Subject: [PATCH 03/12] Update contract.go --- rpc/contract.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/rpc/contract.go b/rpc/contract.go index 036620ec..666f4941 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -26,13 +26,8 @@ func (provider *Provider) Class(ctx context.Context, blockID BlockID, classHash func (provider *Provider) ClassAt(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (ClassOutput, error) { var rawClass map[string]any if err := do(ctx, provider.c, "starknet_getClassAt", &rawClass, blockID, contractAddress); err != nil { - switch { - case errors.Is(err, ErrContractNotFound): - return nil, ErrContractNotFound - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - } - return nil, err + + return nil, tryUnwrapToRPCErr(err, ErrClassHashNotFound, ErrBlockNotFound) } return typecastClassOutput(&rawClass) } From c1a423a6271047d8a73a6d0a6f73b852d0004183 Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Thu, 21 Sep 2023 02:22:59 +0530 Subject: [PATCH 04/12] Update contract.go --- rpc/contract.go | 51 +++++++++++-------------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) diff --git a/rpc/contract.go b/rpc/contract.go index 666f4941..b2fa04cf 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -27,7 +27,7 @@ func (provider *Provider) ClassAt(ctx context.Context, blockID BlockID, contract var rawClass map[string]any if err := do(ctx, provider.c, "starknet_getClassAt", &rawClass, blockID, contractAddress); err != nil { - return nil, tryUnwrapToRPCErr(err, ErrClassHashNotFound, ErrBlockNotFound) + return nil, tryUnwrapToRPCErr(err, ErrContractNotFound, ErrBlockNotFound) } return typecastClassOutput(&rawClass) } @@ -59,13 +59,8 @@ func typecastClassOutput(rawClass *map[string]any) (ClassOutput, error) { func (provider *Provider) ClassHashAt(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*felt.Felt, error) { var result *felt.Felt if err := do(ctx, provider.c, "starknet_getClassHashAt", &result, blockID, contractAddress); err != nil { - switch { - case errors.Is(err, ErrContractNotFound): - return nil, ErrContractNotFound - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - } - return nil, err + + return nil, tryUnwrapToRPCErr(err, ErrContractNotFound, ErrBlockNotFound) } return result, nil } @@ -75,13 +70,8 @@ func (provider *Provider) StorageAt(ctx context.Context, contractAddress *felt.F var value string hashKey := fmt.Sprintf("0x%x", types.GetSelectorFromName(key)) if err := do(ctx, provider.c, "starknet_getStorageAt", &value, contractAddress, hashKey, blockID); err != nil { - switch { - case errors.Is(err, ErrContractNotFound): - return "", ErrContractNotFound - case errors.Is(err, ErrBlockNotFound): - return "", ErrBlockNotFound - } - return "", err + + return "", tryUnwrapToRPCErr(err, ErrContractNotFound, ErrBlockNotFound) } return value, nil } @@ -90,13 +80,8 @@ func (provider *Provider) StorageAt(ctx context.Context, contractAddress *felt.F func (provider *Provider) Nonce(ctx context.Context, blockID BlockID, contractAddress *felt.Felt) (*string, error) { nonce := "" if err := do(ctx, provider.c, "starknet_getNonce", &nonce, blockID, contractAddress); err != nil { - switch { - case errors.Is(err, ErrContractNotFound): - return nil, ErrContractNotFound - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - } - return nil, err + + return nil, tryUnwrapToRPCErr(err, ErrContractNotFound, ErrBlockNotFound) } return &nonce, nil } @@ -112,15 +97,8 @@ func (provider *Provider) EstimateFee(ctx context.Context, requests []Broadcaste // } var raw []FeeEstimate if err := do(ctx, provider.c, "starknet_estimateFee", &raw, requests, blockID); err != nil { - switch { - case errors.Is(err, ErrContractNotFound): - return nil, ErrContractNotFound - case errors.Is(err, ErrContractError): - return nil, ErrContractError - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - } - return nil, err + + return nil, tryUnwrapToRPCErr(err, ErrContractNotFound,ErrContractError, ErrBlockNotFound) } return raw, nil } @@ -129,15 +107,8 @@ func (provider *Provider) EstimateFee(ctx context.Context, requests []Broadcaste func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1, blockID BlockID) (*FeeEstimate, error) { var raw FeeEstimate if err := do(ctx, provider.c, "starknet_estimateMessageFee", &raw, msg, blockID); err != nil { - switch { - case errors.Is(err, ErrContractNotFound): - return nil, ErrContractNotFound - case errors.Is(err, ErrContractError): - return nil, ErrContractError - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - } - return nil, err + + return nil, tryUnwrapToRPCErr(err, ErrContractNotFound,ErrContractError, ErrBlockNotFound) } return &raw, nil } From 0698bbe9131414d3d687da091bb41411a66b9e9d Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Fri, 22 Sep 2023 02:44:22 +0530 Subject: [PATCH 05/12] Update events.go --- rpc/events.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/rpc/events.go b/rpc/events.go index a50860b8..e04e7460 100644 --- a/rpc/events.go +++ b/rpc/events.go @@ -9,17 +9,8 @@ import ( func (provider *Provider) Events(ctx context.Context, input EventsInput) (*EventChunk, error) { var result EventChunk if err := do(ctx, provider.c, "starknet_getEvents", &result, input); err != nil { - switch { - case errors.Is(err, ErrPageSizeTooBig): - return nil, ErrPageSizeTooBig - case errors.Is(err, ErrInvalidContinuationToken): - return nil, ErrInvalidContinuationToken - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - case errors.Is(err, ErrTooManyKeysInFilter): - return nil, ErrTooManyKeysInFilter - } - return nil, err + + return nil, tryUnwrapToRPCErr(err, ErrPageSizeTooBig , ErrInvalidContinuationToken , ErrBlockNotFound ,ErrTooManyKeysInFilter) } return &result, nil } From fe5905ae8142de9a9f50b54c82d1a41fee07125d Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Fri, 22 Sep 2023 22:13:44 +0530 Subject: [PATCH 06/12] Update call.go --- rpc/call.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/call.go b/rpc/call.go index 5e0844bc..0cbb6272 100644 --- a/rpc/call.go +++ b/rpc/call.go @@ -16,7 +16,7 @@ func (provider *Provider) Call(ctx context.Context, request FunctionCall, blockI var result []*felt.Felt if err := do(ctx, provider.c, "starknet_call", &result, request, blockID); err != nil { - return nil, , tryUnwrapToRPCErr(err, ErrContractNotFound, ErrContractError, ErrBlockNotFound) + return nil, tryUnwrapToRPCErr(err, ErrContractNotFound, ErrContractError, ErrBlockNotFound) } return result, nil } From db454f45c94a5d081ba9c4ece78b3315e25bc562 Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Fri, 22 Sep 2023 22:28:56 +0530 Subject: [PATCH 07/12] Update transaction.go --- rpc/transaction.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/rpc/transaction.go b/rpc/transaction.go index 10cdefa4..3f82da6a 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -74,13 +74,9 @@ func (provider *Provider) TransactionByHash(ctx context.Context, hash *felt.Felt func (provider *Provider) TransactionByBlockIdAndIndex(ctx context.Context, blockID BlockID, index uint64) (Transaction, error) { var tx TXN if err := do(ctx, provider.c, "starknet_getTransactionByBlockIdAndIndex", &tx, blockID, index); err != nil { - switch { - case errors.Is(err, ErrInvalidTxnIndex): - return nil, ErrInvalidTxnIndex - case errors.Is(err, ErrBlockNotFound): - return nil, ErrBlockNotFound - } - return nil, err + + return nil,tryUnwrapToRPCErr(err, ErrInvalidTxnIndex ,ErrBlockNotFound) + } return adaptTransaction(tx) } From 1e01036d546c816a9894d64bdd2ea1db7032a2bc Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Mon, 16 Oct 2023 18:40:34 +0530 Subject: [PATCH 08/12] Update block.go --- rpc/block.go | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/rpc/block.go b/rpc/block.go index 7625d357..921b8d45 100644 --- a/rpc/block.go +++ b/rpc/block.go @@ -22,11 +22,8 @@ func (provider *Provider) BlockNumber(ctx context.Context) (uint64, error) { // BlockHashAndNumber gets block information given the block number or its hash. func (provider *Provider) BlockHashAndNumber(ctx context.Context) (*BlockHashAndNumberOutput, error) { var block BlockHashAndNumberOutput - if err := do(ctx, provider.c, "starknet_blockHashAndNumber", &block); err != nil { - if errors.Is(err, errNotFound) { - return nil, ErrNoBlocks - } - return nil, err + if err := do(ctx, provider.c, "starknet_blockHashAndNumber", &block); err != nil { + return nil, tryUnwrapToRPCErr(err, ErrNoBlocks ) } return &block, nil } @@ -52,11 +49,8 @@ func WithBlockTag(tag string) BlockID { // BlockWithTxHashes gets block information given the block id. func (provider *Provider) BlockWithTxHashes(ctx context.Context, blockID BlockID) (interface{}, error) { var result BlockTxHashes - if err := do(ctx, provider.c, "starknet_getBlockWithTxHashes", &result, blockID); err != nil { - if errors.Is(err, errNotFound) { - return nil, ErrBlockNotFound - } - return nil, err + if err := do(ctx, provider.c, "starknet_getBlockWithTxHashes", &result, blockID); err != nil { + return nil, tryUnwrapToRPCErr(err,ErrBlockNotFound ) } // if header.Hash == nil it's a pending block @@ -75,11 +69,8 @@ func (provider *Provider) BlockWithTxHashes(ctx context.Context, blockID BlockID // StateUpdate gets the information about the result of executing the requested block. func (provider *Provider) StateUpdate(ctx context.Context, blockID BlockID) (*StateUpdateOutput, error) { var state StateUpdateOutput - if err := do(ctx, provider.c, "starknet_getStateUpdate", &state, blockID); err != nil { - if errors.Is(err, errNotFound) { - return nil, ErrBlockNotFound - } - return nil, err + if err := do(ctx, provider.c, "starknet_getStateUpdate", &state, blockID); err != nil { + return nil,tryUnwrapToRPCErr(err,ErrBlockNotFound ) } return &state, nil } @@ -100,10 +91,7 @@ func (provider *Provider) BlockTransactionCount(ctx context.Context, blockID Blo func (provider *Provider) BlockWithTxs(ctx context.Context, blockID BlockID) (interface{}, error) { var result Block if err := do(ctx, provider.c, "starknet_getBlockWithTxs", &result, blockID); err != nil { - if errors.Is(err, errNotFound) { - return nil, ErrBlockNotFound - } - return nil, err + return nil, tryUnwrapToRPCErr(err,ErrBlockNotFound ) } // if header.Hash == nil it's a pending block if result.BlockHeader.BlockHash == nil { From 023dcaa3320f2d81d0ffd8cce812810b5a49fbd8 Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:39:50 +0530 Subject: [PATCH 09/12] Update transaction.go --- rpc/transaction.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/rpc/transaction.go b/rpc/transaction.go index a68dfdc4..4a4dea65 100644 --- a/rpc/transaction.go +++ b/rpc/transaction.go @@ -62,11 +62,8 @@ func (provider *Provider) TransactionByHash(ctx context.Context, hash *felt.Felt // todo: update to return a custom Transaction type, then use adapt function var tx TXN if err := do(ctx, provider.c, "starknet_getTransactionByHash", &tx, hash); err != nil { - if errors.Is(err, ErrHashNotFound) { - return nil, ErrHashNotFound - } - return nil, err - } + return nil, tryUnwrapToRPCErr(err,ErrHashNotFound) +} return adaptTransaction(tx) } @@ -86,10 +83,7 @@ func (provider *Provider) TransactionReceipt(ctx context.Context, transactionHas var receipt UnknownTransactionReceipt err := do(ctx, provider.c, "starknet_getTransactionReceipt", &receipt, transactionHash) if err != nil { - if errors.Is(err, ErrHashNotFound) { - return nil, ErrHashNotFound - } - return nil, err + return nil, tryUnwrapToRPCErr(err,ErrHashNotFound) } return receipt.TransactionReceipt, nil } From 80d578ccb01c3fc8bbc009eb3becf35e631f6326 Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Thu, 19 Oct 2023 16:30:14 +0530 Subject: [PATCH 10/12] Update call.go --- rpc/call.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/call.go b/rpc/call.go index 0cbb6272..44b52eae 100644 --- a/rpc/call.go +++ b/rpc/call.go @@ -2,7 +2,7 @@ package rpc import ( "context" - "errors" + "github.com/NethermindEth/juno/core/felt" ) From 5fe60cf570f088d67aa86b462c85dbd481139595 Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Thu, 19 Oct 2023 16:30:49 +0530 Subject: [PATCH 11/12] Update contract.go --- rpc/contract.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/contract.go b/rpc/contract.go index 8445b601..c56868f1 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -3,7 +3,7 @@ package rpc import ( "context" "encoding/json" - "errors" + "fmt" "github.com/NethermindEth/juno/core/felt" From a52eedc06209aa939afe9d94640c903810a82feb Mon Sep 17 00:00:00 2001 From: Bitcoinnoobie <109748565+Bitcoinnoobie@users.noreply.github.com> Date: Thu, 19 Oct 2023 16:31:13 +0530 Subject: [PATCH 12/12] Update events.go --- rpc/events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/events.go b/rpc/events.go index e04e7460..d8d63651 100644 --- a/rpc/events.go +++ b/rpc/events.go @@ -2,7 +2,7 @@ package rpc import ( "context" - "errors" + ) // Events returns all events matching the given filter