From b3ed77ebd32fcf765576469372fbaa1d34a4f924 Mon Sep 17 00:00:00 2001 From: Carmen Cabrera Date: Thu, 13 Jul 2023 10:37:51 -0400 Subject: [PATCH] change rpcv02 package to rpc small docs modification update workflows --- .github/workflows/test.yml | 33 +-------- .../workflows/{rpcv02.yml => test_rpc.yml} | 18 ++--- account.go | 68 +++++++++---------- accountrpcv02_test.go => accountrpcv_test.go | 10 +-- contracts/account_test.go | 8 +-- contracts/accounts.go | 8 +-- contracts/contracts.go | 14 ++-- contracts/contracts_test.go | 20 +++--- contracts/contractsv02.go | 36 +++++----- contracts/main_test.go | 8 +-- contracts/sessionkey.go | 2 +- docs/developers.md | 9 +-- gateway/class.go | 10 +-- gateway/code.go | 24 +++---- gateway/gateway_test.go | 4 +- gateway/provider.go | 6 +- gateway/starknet.go | 10 +-- gateway/starknet_test.go | 12 ++-- plugins/xsessions/accounts_test.go | 6 +- plugins/xsessions/plugin_test.go | 16 ++--- plugins/xsessions/sessionkey_test.go | 2 +- plugins/xsessions/xsessions_test.go | 6 +- providers_test.go | 12 ++-- {rpcv02 => rpc}/.env.template | 0 {rpcv02 => rpc}/README.md | 0 {rpcv02 => rpc}/block.go | 2 +- {rpcv02 => rpc}/block_test.go | 6 +- {rpcv02 => rpc}/call.go | 2 +- {rpcv02 => rpc}/call_test.go | 2 +- {rpcv02 => rpc}/chain.go | 2 +- {rpcv02 => rpc}/client.go | 2 +- {rpcv02 => rpc}/contract.go | 2 +- {rpcv02 => rpc}/contract_test.go | 2 +- {rpcv02 => rpc}/errors.go | 2 +- {rpcv02 => rpc}/events.go | 2 +- {rpcv02 => rpc}/events_test.go | 2 +- {rpcv02 => rpc}/json_test.go | 2 +- {rpcv02 => rpc}/mock_test.go | 2 +- {rpcv02 => rpc}/provider.go | 2 +- {rpcv02 => rpc}/provider_test.go | 2 +- {rpcv02 => rpc}/spy_test.go | 2 +- ...7cf0dafc8c188f80c3450615944a469428f7f.json | 0 {rpcv02 => rpc}/tests/block.json | 0 {rpcv02 => rpc}/tests/declareTx.json | 0 {rpcv02 => rpc}/trace.go | 2 +- {rpcv02 => rpc}/trace_test.go | 2 +- {rpcv02 => rpc}/transaction.go | 2 +- {rpcv02 => rpc}/transaction_test.go | 2 +- {rpcv02 => rpc}/types.go | 2 +- {rpcv02 => rpc}/types_block.go | 2 +- {rpcv02 => rpc}/types_contract.go | 2 +- {rpcv02 => rpc}/types_contract_test.go | 2 +- {rpcv02 => rpc}/types_event.go | 2 +- {rpcv02 => rpc}/types_transaction.go | 2 +- {rpcv02 => rpc}/types_transaction_receipt.go | 2 +- {rpcv02 => rpc}/types_transaction_response.go | 2 +- {rpcv02 => rpc}/types_transaction_test.go | 2 +- {rpcv02 => rpc}/types_types_block_test.go | 2 +- {rpcv02 => rpc}/write.go | 2 +- {rpcv02 => rpc}/write_test.go | 2 +- types/types.go | 2 +- 61 files changed, 191 insertions(+), 221 deletions(-) rename .github/workflows/{rpcv02.yml => test_rpc.yml} (74%) rename accountrpcv02_test.go => accountrpcv_test.go (94%) rename {rpcv02 => rpc}/.env.template (100%) rename {rpcv02 => rpc}/README.md (100%) rename {rpcv02 => rpc}/block.go (99%) rename {rpcv02 => rpc}/block_test.go (99%) rename {rpcv02 => rpc}/call.go (97%) rename {rpcv02 => rpc}/call_test.go (99%) rename {rpcv02 => rpc}/chain.go (98%) rename {rpcv02 => rpc}/client.go (97%) rename {rpcv02 => rpc}/contract.go (99%) rename {rpcv02 => rpc}/contract_test.go (99%) rename {rpcv02 => rpc}/errors.go (98%) rename {rpcv02 => rpc}/events.go (96%) rename {rpcv02 => rpc}/events_test.go (99%) rename {rpcv02 => rpc}/json_test.go (99%) rename {rpcv02 => rpc}/mock_test.go (99%) rename {rpcv02 => rpc}/provider.go (99%) rename {rpcv02 => rpc}/provider_test.go (99%) rename {rpcv02 => rpc}/spy_test.go (99%) rename {rpcv02 => rpc}/tests/0x1efa8f84fd4dff9e2902ec88717cf0dafc8c188f80c3450615944a469428f7f.json (100%) rename {rpcv02 => rpc}/tests/block.json (100%) rename {rpcv02 => rpc}/tests/declareTx.json (100%) rename {rpcv02 => rpc}/trace.go (96%) rename {rpcv02 => rpc}/trace_test.go (98%) rename {rpcv02 => rpc}/transaction.go (99%) rename {rpcv02 => rpc}/transaction_test.go (99%) rename {rpcv02 => rpc}/types.go (99%) rename {rpcv02 => rpc}/types_block.go (99%) rename {rpcv02 => rpc}/types_contract.go (99%) rename {rpcv02 => rpc}/types_contract_test.go (97%) rename {rpcv02 => rpc}/types_event.go (98%) rename {rpcv02 => rpc}/types_transaction.go (99%) rename {rpcv02 => rpc}/types_transaction_receipt.go (99%) rename {rpcv02 => rpc}/types_transaction_response.go (97%) rename {rpcv02 => rpc}/types_transaction_test.go (96%) rename {rpcv02 => rpc}/types_types_block_test.go (99%) rename {rpcv02 => rpc}/write.go (99%) rename {rpcv02 => rpc}/write_test.go (99%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27ed13d6..b1515ed7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,25 +31,10 @@ jobs: run: ./.bin/devnet.sh - name: Test contracts deployment and execute - run: cd contracts && go test -env devnet -v -run "^(TestGateway|TestRPCv01)" . - - - name: Test RPC v0.1 with mocks - run: cd rpcv01 && go test -v . - - - name: Preinstall RPC v0.1 contracts on devnet - run: cd rpcv01 && go test -timeout 600s -v -env devnet -run TestDeployTransaction . && sleep 5 - env: - TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }} - INTEGRATION_BASE: "http://localhost:5050/rpc" + run: cd contracts && go test -env devnet -v -run "^(TestGateway|TestRPC)" . - name: Test Accounts (starknet.go) on devnet - run: go test -timeout 600s -v -env devnet -run "^(TestGateway|TestRPCv01|TestGeneral)" . - env: - TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }} - INTEGRATION_BASE: "http://localhost:5050/rpc" - - - name: Test RPC v0.1 on devnet - run: cd rpcv01 && go test -timeout 600s -v -env devnet . + run: go test -timeout 600s -v -env devnet -run "^(TestGateway|TestRPC|TestGeneral)" . env: TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }} INTEGRATION_BASE: "http://localhost:5050/rpc" @@ -57,20 +42,8 @@ jobs: - name: Test sessionkey on devnet run: cd plugins/xsessions && ./sessionkey.sh - - name: Test RPC v0.1 on testnet - run: cd rpcv01 && go test -timeout 1200s -v -env testnet . - env: - TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }} - INTEGRATION_BASE: "https://starknet-goerli.cartridge.gg/rpc/v0.1" - - - name: Test RPC v0.1 with mainnet - run: cd rpcv01 && go test -timeout 600s -v -env mainnet . - env: - TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }} - INTEGRATION_BASE: "https://starknet.cartridge.gg/rpc/v0.1" - - name: Test Gateway with testnet run: cd gateway && go test -v -env testnet . - name: Test Gateway with devnet - run: cd gateway && go test -v -env devnet . + run: cd gateway && go test -v -env devnet . \ No newline at end of file diff --git a/.github/workflows/rpcv02.yml b/.github/workflows/test_rpc.yml similarity index 74% rename from .github/workflows/rpcv02.yml rename to .github/workflows/test_rpc.yml index f006e1a5..41919ad3 100644 --- a/.github/workflows/rpcv02.yml +++ b/.github/workflows/test_rpc.yml @@ -1,4 +1,4 @@ -name: rpcv02 +name: rpc on: push: @@ -29,28 +29,28 @@ jobs: run: ./.bin/devnet.sh # Test rpc on devnet - - name: Test RPC v0.2 on devnet - run: cd rpcv02 && go test -timeout 600s -v -env devnet . + - name: Test RPC on devnet + run: cd rpc && go test -timeout 600s -v -env devnet . env: TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }} INTEGRATION_BASE: "http://localhost:5050/rpc" # Test rpc on mock - - name: Test RPC v0.2 with mocks - run: cd rpcv02 && go test -v . + - name: Test RPC with mocks + run: cd rpc && go test -v . # Test rpc on testnet - - name: Test RPC v0.2 on testnet + - name: Test RPC on testnet run: echo "Skip for now - need public endpoint that follows rpc spec" - #run: cd rpcv02 && go test -timeout 1200s -v -env testnet . + #run: cd rpc && go test -timeout 1200s -v -env testnet . env: TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }} INTEGRATION_BASE: "https://starknet-goerli.cartridge.gg/" # Test rpc on mainnet - - name: Test RPC v0.2 with mainnet + - name: Test RPC with mainnet run: echo "Skip for now - need public endpoint that follows rpc spec" - #run: cd rpcv02 && go test -timeout 600s -v -env mainnet . + #run: cd rpc && go test -timeout 600s -v -env mainnet . env: TESTNET_ACCOUNT_PRIVATE_KEY: ${{ secrets.TESTNET_ACCOUNT_PRIVATE_KEY }} INTEGRATION_BASE: "https://starknet.cartridge.gg/" diff --git a/account.go b/account.go index 94b90bda..4d82e4a2 100644 --- a/account.go +++ b/account.go @@ -8,7 +8,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/gateway" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" ) @@ -31,7 +31,7 @@ type account interface { Nonce(ctx context.Context) (*big.Int, error) EstimateFee(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.FeeEstimate, error) Execute(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.AddInvokeTransactionOutput, error) - Declare(ctx context.Context, classHash string, contract rpcv02.ContractClass, details types.ExecuteDetails) (types.AddDeclareResponse, error) + Declare(ctx context.Context, classHash string, contract rpc.ContractClass, details types.ExecuteDetails) (types.AddDeclareResponse, error) Deploy(ctx context.Context, classHash string, details types.ExecuteDetails) (*types.AddDeployResponse, error) } @@ -44,12 +44,12 @@ type AccountPlugin interface { type ProviderType string const ( - ProviderRPCv02 ProviderType = "rpcv02" + ProviderRPC ProviderType = "rpc" ProviderGateway ProviderType = "gateway" ) type Account struct { - rpcv02 *rpcv02.Provider + rpc *rpc.Provider sequencer *gateway.GatewayProvider provider ProviderType chainId string @@ -108,20 +108,20 @@ func newAccount(sender, address *felt.Felt, ks Keystore, options ...AccountOptio func setAccountProvider(account *Account, provider interface{}) error { switch p := provider.(type) { - case *rpcv02.Provider: + case *rpc.Provider: chainID, err := p.ChainID(context.Background()) if err != nil { return err } account.chainId = chainID - account.provider = ProviderRPCv02 - account.rpcv02 = p + account.provider = ProviderRPC + account.rpc = p return nil } return errors.New("unsupported provider") } -func NewRPCAccount[Provider *rpcv02.Provider](sender, address *felt.Felt, ks Keystore, provider Provider, options ...AccountOptionFunc) (*Account, error) { +func NewRPCAccount[Provider *rpc.Provider](sender, address *felt.Felt, ks Keystore, provider Provider, options ...AccountOptionFunc) (*Account, error) { account, err := newAccount(sender, address, ks, options...) if err != nil { return nil, err @@ -147,17 +147,17 @@ func NewGatewayAccount(sender, address *felt.Felt, ks Keystore, provider *gatewa func (account *Account) Call(ctx context.Context, call types.FunctionCall) ([]string, error) { switch account.provider { - case ProviderRPCv02: - if account.rpcv02 == nil { + case ProviderRPC: + if account.rpc == nil { return nil, ErrUnsupportedAccount } - return account.rpcv02.Call( + return account.rpc.Call( ctx, - rpcv02.FunctionCall{ + rpc.FunctionCall{ ContractAddress: call.ContractAddress, EntryPointSelector: call.EntryPointSelector, Calldata: call.Calldata}, - rpcv02.WithBlockTag("latest")) + rpc.WithBlockTag("latest")) case ProviderGateway: if account.sequencer == nil { return nil, ErrUnsupportedAccount @@ -235,10 +235,10 @@ func (account *Account) Nonce(ctx context.Context) (*big.Int, error) { switch account.version { case 1: switch account.provider { - case ProviderRPCv02: - nonce, err := account.rpcv02.Nonce( + case ProviderRPC: + nonce, err := account.rpc.Nonce( ctx, - rpcv02.WithBlockTag("latest"), + rpc.WithBlockTag("latest"), account.AccountAddress, ) if err != nil { @@ -256,7 +256,7 @@ func (account *Account) Nonce(ctx context.Context) (*big.Int, error) { return nil, fmt.Errorf("version %d unsupported", account.version) } -func (account *Account) prepFunctionInvokeRPCv02(ctx context.Context, messageType string, calls []types.FunctionCall, details types.ExecuteDetails) (*rpcv02.BroadcastedInvokeV1Transaction, error) { +func (account *Account) prepFunctionInvokeRPC(ctx context.Context, messageType string, calls []types.FunctionCall, details types.ExecuteDetails) (*rpc.BroadcastedInvokeV1Transaction, error) { if messageType != "invoke" && messageType != "estimate" { return nil, errors.New("unsupported message type") } @@ -281,7 +281,7 @@ func (account *Account) prepFunctionInvokeRPCv02(ctx context.Context, messageTyp } // starknet.go currently only supports V1 - version := rpcv02.TransactionV1 + version := rpc.TransactionV1 var txHash *big.Int switch messageType { @@ -300,7 +300,7 @@ func (account *Account) prepFunctionInvokeRPCv02(ctx context.Context, messageTyp case "estimate": if account.version == 1 { // version, _ = big.NewInt(0).SetString("0x100000000000000000000000000000001", 0) - version = rpcv02.TransactionV1 + version = rpc.TransactionV1 } versionBig, err := version.BigInt() if err != nil { @@ -347,8 +347,8 @@ func (account *Account) prepFunctionInvokeRPCv02(ctx context.Context, messageTyp if err != nil { return nil, err } - return &rpcv02.BroadcastedInvokeV1Transaction{ - BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{ + return &rpc.BroadcastedInvokeV1Transaction{ + BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{ MaxFee: maxFeeFelt, Version: version, Signature: []*felt.Felt{s1Felt, s2Felt}, @@ -440,24 +440,24 @@ func (account *Account) prepFunctionInvoke(ctx context.Context, messageType stri func (account *Account) EstimateFee(ctx context.Context, calls []types.FunctionCall, details types.ExecuteDetails) (*types.FeeEstimate, error) { switch account.provider { - case ProviderRPCv02: - call, err := account.prepFunctionInvokeRPCv02(ctx, "estimate", calls, details) + case ProviderRPC: + call, err := account.prepFunctionInvokeRPC(ctx, "estimate", calls, details) if err != nil { return nil, err } switch account.version { case 1: - estimates, err := account.rpcv02.EstimateFee(ctx, []rpcv02.BroadcastedTransaction{rpcv02.BroadcastedInvokeV1Transaction{ - BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{ + estimates, err := account.rpc.EstimateFee(ctx, []rpc.BroadcastedTransaction{rpc.BroadcastedInvokeV1Transaction{ + BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{ MaxFee: call.MaxFee, - Version: rpcv02.TransactionV1, + Version: rpc.TransactionV1, Signature: call.Signature, Nonce: call.Nonce, Type: "INVOKE", }, Calldata: call.Calldata, SenderAddress: account.AccountAddress, - }}, rpcv02.WithBlockTag("latest")) + }}, rpc.WithBlockTag("latest")) if err != nil { return nil, err } @@ -490,17 +490,17 @@ func (account *Account) Execute(ctx context.Context, calls []types.FunctionCall, details.MaxFee = maxFee switch account.provider { - case ProviderRPCv02: - call, err := account.prepFunctionInvokeRPCv02(ctx, "invoke", calls, details) + case ProviderRPC: + call, err := account.prepFunctionInvokeRPC(ctx, "invoke", calls, details) if err != nil { return nil, err } switch account.version { case 1: - resp, err := account.rpcv02.AddInvokeTransaction(ctx, rpcv02.BroadcastedInvokeV1Transaction{ - BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{ + resp, err := account.rpc.AddInvokeTransaction(ctx, rpc.BroadcastedInvokeV1Transaction{ + BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{ MaxFee: call.MaxFee, - Version: rpcv02.TransactionV1, + Version: rpc.TransactionV1, Signature: call.Signature, Nonce: call.Nonce, Type: "INVOKE", @@ -526,9 +526,9 @@ func (account *Account) Execute(ctx context.Context, calls []types.FunctionCall, return nil, ErrUnsupportedAccount } -func (account *Account) Declare(ctx context.Context, classHash string, contract rpcv02.ContractClass, details types.ExecuteDetails) (types.AddDeclareResponse, error) { +func (account *Account) Declare(ctx context.Context, classHash string, contract rpc.ContractClass, details types.ExecuteDetails) (types.AddDeclareResponse, error) { switch account.provider { - case ProviderRPCv02: + case ProviderRPC: panic("unsupported") case ProviderGateway: version := big.NewInt(1) diff --git a/accountrpcv02_test.go b/accountrpcv_test.go similarity index 94% rename from accountrpcv02_test.go rename to accountrpcv_test.go index 318fdb5e..5f0d50a0 100644 --- a/accountrpcv02_test.go +++ b/accountrpcv_test.go @@ -10,13 +10,13 @@ import ( "time" "github.com/NethermindEth/juno/core/felt" - rpc "github.com/NethermindEth/starknet.go/rpcv02" + rpc "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" ) // TestAccountNonce tests the account Nonce -func TestRPCv02Account_Nonce(t *testing.T) { +func TestRPCAccount_Nonce(t *testing.T) { testConfig := beforeRPCEach(t) type testSetType struct { @@ -61,7 +61,7 @@ func TestRPCv02Account_Nonce(t *testing.T) { } // TestAccountEstimateFee tests the account EstimateFee -func TestRPCv02Account_EstimateFee(t *testing.T) { +func TestRPCAccount_EstimateFee(t *testing.T) { testConfig := beforeRPCEach(t) type testSetType struct { @@ -119,7 +119,7 @@ func TestRPCv02Account_EstimateFee(t *testing.T) { } // TestRPCAccount_Execute tests the account Execute method -func TestRPCv02Account_Execute(t *testing.T) { +func TestRPCAccount_Execute(t *testing.T) { testConfig := beforeRPCEach(t) type testSetType struct { @@ -157,7 +157,7 @@ func TestRPCv02Account_Execute(t *testing.T) { fmt.Println("transaction_hash:", execute.TransactionHash) ctx, cancel := context.WithTimeout(ctx, 600*time.Second) defer cancel() - status, err := account.rpcv02.WaitForTransaction(ctx, execute.TransactionHash, 8*time.Second) + status, err := account.rpc.WaitForTransaction(ctx, execute.TransactionHash, 8*time.Second) if err != nil { t.Fatal("declare should succeed, instead:", err) } diff --git a/contracts/account_test.go b/contracts/account_test.go index 19eda9e5..58097262 100644 --- a/contracts/account_test.go +++ b/contracts/account_test.go @@ -64,7 +64,7 @@ func TestGateway_InstallAccounts(t *testing.T) { } } -func TestRPCv02_InstallAccounts(t *testing.T) { +func TestRPC_InstallAccounts(t *testing.T) { godotenv.Load() testConfiguration := beforeEach(t) @@ -75,7 +75,7 @@ func TestRPCv02_InstallAccounts(t *testing.T) { } devnet := []TestCase{} - for _, provider := range []starknetgo.ProviderType{starknetgo.ProviderRPCv02} { + for _, provider := range []starknetgo.ProviderType{starknetgo.ProviderRPC} { for _, version := range []string{"v1"} { for _, proxy := range []bool{false, true} { for _, plugin := range []bool{false, true} { @@ -99,10 +99,10 @@ func TestRPCv02_InstallAccounts(t *testing.T) { var accountManager *AccountManager var err error switch test.providerType { - case starknetgo.ProviderRPCv02: + case starknetgo.ProviderRPC: accountManager, err = InstallAndWaitForAccount( ctx, - testConfiguration.rpcv02, + testConfiguration.rpc, privateKey, test.CompiledContract, ) diff --git a/contracts/accounts.go b/contracts/accounts.go index 3f83c5f6..29ecd54a 100644 --- a/contracts/accounts.go +++ b/contracts/accounts.go @@ -13,7 +13,7 @@ import ( starknetgo "github.com/NethermindEth/starknet.go" "github.com/NethermindEth/starknet.go/artifacts" "github.com/NethermindEth/starknet.go/gateway" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/utils" ) @@ -58,8 +58,8 @@ const ( func guessProviderType(p interface{}) (Provider, error) { switch v := p.(type) { - case *rpcv02.Provider: - provider := RPCv02Provider(*v) + case *rpc.Provider: + provider := RPCProvider(*v) return &provider, nil case *gateway.GatewayProvider: provider := GatewayProvider(*v) @@ -72,7 +72,7 @@ func guessProviderType(p interface{}) (Provider, error) { // // Deprecated: this function should be replaced by InstallAndWaitForAccount // that will use the DEPLOY_ACCOUNT syscall. -func InstallAndWaitForAccount[V *rpcv02.Provider | *gateway.GatewayProvider](ctx context.Context, provider V, privateKey *big.Int, compiledContracts artifacts.CompiledContract) (*AccountManager, error) { +func InstallAndWaitForAccount[V *rpc.Provider | *gateway.GatewayProvider](ctx context.Context, provider V, privateKey *big.Int, compiledContracts artifacts.CompiledContract) (*AccountManager, error) { if len(compiledContracts.AccountCompiled) == 0 { return nil, errors.New("empty account") } diff --git a/contracts/contracts.go b/contracts/contracts.go index 9c8c07a4..8b83f4b0 100644 --- a/contracts/contracts.go +++ b/contracts/contracts.go @@ -10,7 +10,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/gateway" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/types" ) @@ -29,7 +29,7 @@ type GatewayProvider gateway.GatewayProvider func (p *GatewayProvider) declareAndWaitWithWallet(ctx context.Context, compiledClass []byte) (*DeclareOutput, error) { provider := gateway.GatewayProvider(*p) - class := rpcv02.ContractClass{} + class := rpc.ContractClass{} if err := json.Unmarshal(compiledClass, &class); err != nil { return nil, err } @@ -42,7 +42,7 @@ func (p *GatewayProvider) declareAndWaitWithWallet(ctx context.Context, compiled return nil, err } if !receipt.Status.IsTransactionFinal() || - rpcv02.TransactionState(receipt.Status.String()) == rpcv02.TransactionRejected { + rpc.TransactionState(receipt.Status.String()) == rpc.TransactionRejected { return nil, fmt.Errorf("wrong status: %s", receipt.Status) } return &DeclareOutput{ @@ -54,7 +54,7 @@ func (p *GatewayProvider) declareAndWaitWithWallet(ctx context.Context, compiled // TODO: remove compiledClass from the interface func (p *GatewayProvider) deployAccountAndWaitNoWallet(ctx context.Context, classHash *felt.Felt, compiledClass []byte, salt string, inputs []string) (*DeployOutput, error) { provider := gateway.GatewayProvider(*p) - class := rpcv02.ContractClass{} + class := rpc.ContractClass{} if err := json.Unmarshal(compiledClass, &class); err != nil { return nil, err @@ -99,13 +99,13 @@ func (p *GatewayProvider) deployAccountAndWaitNoWallet(ctx context.Context, clas // DEPLOY_ACCOUNT for an account. func (p *GatewayProvider) deployAndWaitNoWallet(ctx context.Context, compiledClass []byte, salt string, inputs []string) (*DeployOutput, error) { provider := gateway.GatewayProvider(*p) - class := rpcv02.ContractClass{} + class := rpc.ContractClass{} if err := json.Unmarshal(compiledClass, &class); err != nil { return nil, err } - tx, err := provider.Deploy(ctx, class, rpcv02.DeployAccountTxn{}) + tx, err := provider.Deploy(ctx, class, rpc.DeployAccountTxn{}) - // tx, err := provider.Deploy(ctx, class, rpcv02.DeployRequest{ + // tx, err := provider.Deploy(ctx, class, rpc.DeployRequest{ // ContractAddressSalt: salt, // ConstructorCalldata: inputs, // }) diff --git a/contracts/contracts_test.go b/contracts/contracts_test.go index 2ea028d3..cfdc9d13 100644 --- a/contracts/contracts_test.go +++ b/contracts/contracts_test.go @@ -57,7 +57,7 @@ func TestGateway_InstallCounter(t *testing.T) { } } -func TestRPCv02_InstallCounter(t *testing.T) { +func TestRPC_InstallCounter(t *testing.T) { godotenv.Load() testConfiguration := beforeEach(t) @@ -71,7 +71,7 @@ func TestRPCv02_InstallCounter(t *testing.T) { TestCases := map[string][]TestCase{ "devnet": { { - providerType: starknetgo.ProviderRPCv02, + providerType: starknetgo.ProviderRPC, CompiledClass: artifacts.CounterCompiled, Salt: "0x01", Inputs: []string{}, @@ -85,8 +85,8 @@ func TestRPCv02_InstallCounter(t *testing.T) { var err error var tx *DeployOutput switch test.providerType { - case starknetgo.ProviderRPCv02: - provider := RPCv02Provider(*testConfiguration.rpcv02) + case starknetgo.ProviderRPC: + provider := RPCProvider(*testConfiguration.rpc) tx, err = provider.deployAndWaitWithWallet(ctx, test.CompiledClass, test.Salt, test.Inputs) default: t.Fatal("unsupported client type", test.providerType) @@ -169,7 +169,7 @@ func TestGateway_LoadAndExecuteCounter(t *testing.T) { } } -func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { +func TestRPC_LoadAndExecuteCounter(t *testing.T) { godotenv.Load() testConfiguration := beforeEach(t) @@ -183,7 +183,7 @@ func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { "devnet": { { privateKey: "0xe3e70682c2094cac629f6fbed82c07cd", - providerType: starknetgo.ProviderRPCv02, + providerType: starknetgo.ProviderRPC, accountContract: artifacts.AccountContracts[ACCOUNT_VERSION1][false][false], }, }, @@ -201,13 +201,13 @@ func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { k := types.SNValToBN(test.privateKey) ks.Put(fakeSenderAddress, k) switch test.providerType { - case starknetgo.ProviderRPCv02: + case starknetgo.ProviderRPC: pk, _ := big.NewInt(0).SetString(test.privateKey, 0) fmt.Println("befor") accountManager := &AccountManager{} accountManager, err := InstallAndWaitForAccount( ctx, - testConfiguration.rpcv02, + testConfiguration.rpc, pk, test.accountContract, ) @@ -220,13 +220,13 @@ func TestRPCv02_LoadAndExecuteCounter(t *testing.T) { t.Fatal("error deploying account", err) } fmt.Printf("current balance is %d\n", mint.NewBalance) - provider := RPCv02Provider(*testConfiguration.rpcv02) + provider := RPCProvider(*testConfiguration.rpc) counterTransaction, err = provider.deployAndWaitWithWallet(ctx, artifacts.CounterCompiled, "0x0", []string{}) if err != nil { t.Fatal("should succeed, instead", err) } fmt.Println("deployment transaction", counterTransaction.TransactionHash) - account, err = starknetgo.NewRPCAccount(utils.TestHexToFelt(t, fakeSenderAddress), utils.TestHexToFelt(t, accountManager.AccountAddress), ks, testConfiguration.rpcv02, starknetgo.AccountVersion1) + account, err = starknetgo.NewRPCAccount(utils.TestHexToFelt(t, fakeSenderAddress), utils.TestHexToFelt(t, accountManager.AccountAddress), ks, testConfiguration.rpc, starknetgo.AccountVersion1) if err != nil { t.Fatal("should succeed, instead", err) } diff --git a/contracts/contractsv02.go b/contracts/contractsv02.go index 6f9e1c18..fe46246d 100644 --- a/contracts/contractsv02.go +++ b/contracts/contractsv02.go @@ -10,16 +10,16 @@ import ( "time" "github.com/NethermindEth/juno/core/felt" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" ) -type RPCv02Provider rpcv02.Provider +type RPCProvider rpc.Provider -func (p *RPCv02Provider) declareAndWaitWithWallet(ctx context.Context, compiledClass []byte) (*DeclareOutput, error) { - provider := rpcv02.Provider(*p) - class := rpcv02.ContractClass{} +func (p *RPCProvider) declareAndWaitWithWallet(ctx context.Context, compiledClass []byte) (*DeclareOutput, error) { + provider := rpc.Provider(*p) + class := rpc.ContractClass{} if err := json.Unmarshal(compiledClass, &class); err != nil { return nil, err } @@ -27,8 +27,8 @@ func (p *RPCv02Provider) declareAndWaitWithWallet(ctx context.Context, compiledC if err != nil { return nil, err } - tx, err := provider.AddDeclareTransaction(ctx, rpcv02.BroadcastedDeclareTransaction{ - BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{ + tx, err := provider.AddDeclareTransaction(ctx, rpc.BroadcastedDeclareTransaction{ + BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{ Type: "DECLARE", MaxFee: new(felt.Felt).SetUint64(10000), Version: "0x01", @@ -58,9 +58,9 @@ func (p *RPCv02Provider) declareAndWaitWithWallet(ctx context.Context, compiledC }, nil } -func (p *RPCv02Provider) deployAccountAndWaitNoWallet(ctx context.Context, classHash *felt.Felt, compiledClass []byte, salt string, inputs []string) (*DeployOutput, error) { - provider := rpcv02.Provider(*p) - class := rpcv02.ContractClass{} +func (p *RPCProvider) deployAccountAndWaitNoWallet(ctx context.Context, classHash *felt.Felt, compiledClass []byte, salt string, inputs []string) (*DeployOutput, error) { + provider := rpc.Provider(*p) + class := rpc.ContractClass{} if err := json.Unmarshal(compiledClass, &class); err != nil { return nil, err } @@ -76,8 +76,8 @@ func (p *RPCv02Provider) deployAccountAndWaitNoWallet(ctx context.Context, class return nil, err } - tx, err := provider.AddDeployAccountTransaction(ctx, rpcv02.BroadcastedDeployAccountTransaction{ - BroadcastedTxnCommonProperties: rpcv02.BroadcastedTxnCommonProperties{ + tx, err := provider.AddDeployAccountTransaction(ctx, rpc.BroadcastedDeployAccountTransaction{ + BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{ MaxFee: new(felt.Felt).SetUint64(1), Version: "0x01", Nonce: new(felt.Felt).SetUint64(2), // TODO: nonce handling @@ -107,9 +107,9 @@ func (p *RPCv02Provider) deployAccountAndWaitNoWallet(ctx context.Context, class }, nil } -func (p *RPCv02Provider) deployAndWaitWithWallet(ctx context.Context, compiledClass []byte, salt string, inputs []string) (*DeployOutput, error) { - provider := rpcv02.Provider(*p) - class := rpcv02.ContractClass{} +func (p *RPCProvider) deployAndWaitWithWallet(ctx context.Context, compiledClass []byte, salt string, inputs []string) (*DeployOutput, error) { + provider := rpc.Provider(*p) + class := rpc.ContractClass{} if err := json.Unmarshal(compiledClass, &class); err != nil { return nil, err } @@ -125,9 +125,9 @@ func (p *RPCv02Provider) deployAndWaitWithWallet(ctx context.Context, compiledCl } // TODO: use UDC via account - tx, err := provider.AddDeployTransaction(ctx, rpcv02.BroadcastedDeployTxn{ - DeployTransactionProperties: rpcv02.DeployTransactionProperties{ - Version: rpcv02.TransactionV1, + tx, err := provider.AddDeployTransaction(ctx, rpc.BroadcastedDeployTxn{ + DeployTransactionProperties: rpc.DeployTransactionProperties{ + Version: rpc.TransactionV1, ContractAddressSalt: saltFelt, ConstructorCalldata: inputsFelt, }, diff --git a/contracts/main_test.go b/contracts/main_test.go index 6dce8fff..85558f2e 100644 --- a/contracts/main_test.go +++ b/contracts/main_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/NethermindEth/starknet.go/gateway" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" ethrpc "github.com/ethereum/go-ethereum/rpc" "github.com/joho/godotenv" ) @@ -26,7 +26,7 @@ func TestMain(m *testing.M) { } type testConfiguration struct { - rpcv02 *rpcv02.Provider + rpc *rpc.Provider gateway *gateway.GatewayProvider RPCBaseURL string GWBaseURL string @@ -53,8 +53,8 @@ func beforeEach(t *testing.T) *testConfiguration { if err != nil { t.Fatal("connect should succeed, instead:", err) } - clientv02 := rpcv02.NewProvider(c) - testConfig.rpcv02 = clientv02 + clientv02 := rpc.NewProvider(c) + testConfig.rpc = clientv02 gw := gateway.NewProvider(gateway.WithBaseURL(testConfig.GWBaseURL)) testConfig.gateway = gw } diff --git a/contracts/sessionkey.go b/contracts/sessionkey.go index 5bb05039..15a7efac 100644 --- a/contracts/sessionkey.go +++ b/contracts/sessionkey.go @@ -30,7 +30,7 @@ func signSessionKey(privateKey, accountAddress, counterAddress, selector, sessio ) } -// func (ap *AccountManager) ExecuteWithSessionKey(counterAddress, selector string, provider *rpcv02.Provider) (string, error) { +// func (ap *AccountManager) ExecuteWithSessionKey(counterAddress, selector string, provider *rpc.Provider) (string, error) { // sessionPrivateKey, _ := starknetgo.Curve.GetRandomPrivateKey() // sessionPublicKey, _, _ := starknetgo.Curve.PrivateToPoint(sessionPrivateKey) diff --git a/docs/developers.md b/docs/developers.md index 392c06f1..c604a2ae 100644 --- a/docs/developers.md +++ b/docs/developers.md @@ -4,8 +4,8 @@ This document points some things you might want to know when onboarding on starknet.go. For now, we have listed a number of questions that we would like you know before you contribute: + - What is the difference between `rpc` and `gateway`? -- What version of `rpc` should I use - Where are the resources about the protocol? - How to interact with accounts? - How to better understand the protocol? @@ -31,14 +31,11 @@ provide an access to both and tries to share a common interface between the 2. Be careful that when you are doing something on the project, you should pay attention to the 2 interfaces, even if the implementations are specific. -## What version of `rpc` should I use? + ## Where do I find resources about the protocol specifications? diff --git a/gateway/class.go b/gateway/class.go index 5602d5d6..a7dbceb7 100644 --- a/gateway/class.go +++ b/gateway/class.go @@ -6,11 +6,11 @@ import ( "net/url" "github.com/NethermindEth/juno/core/felt" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" ) // TODO: returns DeprecatedContractClass | SierraContractClass -func (sg *Gateway) ClassByHash(ctx context.Context, hash string) (*rpcv02.ContractClass, error) { +func (sg *Gateway) ClassByHash(ctx context.Context, hash string) (*rpc.ContractClass, error) { req, err := sg.newRequest(ctx, http.MethodGet, "/get_class_by_hash", nil) if err != nil { return nil, err @@ -20,7 +20,7 @@ func (sg *Gateway) ClassByHash(ctx context.Context, hash string) (*rpcv02.Contra "classHash": []string{hash}, }) - var resp rpcv02.ContractClass + var resp rpc.ContractClass return &resp, sg.do(req, &resp) } @@ -41,10 +41,10 @@ func (sg *Gateway) ClassHashAt(ctx context.Context, address string) (*felt.Felt, return resp, nil } -func (sg *Gateway) Class(context.Context, string) (*rpcv02.ContractClass, error) { +func (sg *Gateway) Class(context.Context, string) (*rpc.ContractClass, error) { panic("not implemented") } -func (sg *Gateway) ClassAt(context.Context, string) (*rpcv02.ContractClass, error) { +func (sg *Gateway) ClassAt(context.Context, string) (*rpc.ContractClass, error) { panic("not implemented") } diff --git a/gateway/code.go b/gateway/code.go index 22a7c621..94c49f1f 100644 --- a/gateway/code.go +++ b/gateway/code.go @@ -8,14 +8,14 @@ import ( "net/http" "net/url" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" ) type Bytecode []string type Code struct { Bytecode Bytecode `json:"bytecode"` - Abi *rpcv02.ABI `json:"abi"` + Abi *rpc.ABI `json:"abi"` } func (c *Code) UnmarshalJSON(content []byte) error { @@ -47,21 +47,21 @@ func (c *Code) UnmarshalJSON(content []byte) error { return err } - abiPointer := rpcv02.ABI{} + abiPointer := rpc.ABI{} for _, abi := range abis { if checkABI, ok := abi.(map[string]interface{}); ok { - var ab rpcv02.ABIEntry + var ab rpc.ABIEntry abiType, ok := checkABI["type"].(string) if !ok { return fmt.Errorf("unknown abi type %v", checkABI["type"]) } switch abiType { - case string(rpcv02.ABITypeConstructor), string(rpcv02.ABITypeFunction), string(rpcv02.ABITypeL1Handler): - ab = &rpcv02.FunctionABIEntry{} - case string(rpcv02.ABITypeStruct): - ab = &rpcv02.StructABIEntry{} - case string(rpcv02.ABITypeEvent): - ab = &rpcv02.EventABIEntry{} + case string(rpc.ABITypeConstructor), string(rpc.ABITypeFunction), string(rpc.ABITypeL1Handler): + ab = &rpc.FunctionABIEntry{} + case string(rpc.ABITypeStruct): + ab = &rpc.StructABIEntry{} + case string(rpc.ABITypeEvent): + ab = &rpc.EventABIEntry{} default: return fmt.Errorf("unknown ABI type %v", checkABI["type"]) } @@ -100,7 +100,7 @@ func (sg *Gateway) CodeAt(ctx context.Context, contract string, blockNumber *big return &resp, sg.do(req, &resp) } -func (sg *Gateway) FullContract(ctx context.Context, contract string) (*rpcv02.ContractClass, error) { +func (sg *Gateway) FullContract(ctx context.Context, contract string) (*rpc.ContractClass, error) { req, err := sg.newRequest(ctx, http.MethodGet, "/get_full_contract", nil) if err != nil { return nil, err @@ -108,6 +108,6 @@ func (sg *Gateway) FullContract(ctx context.Context, contract string) (*rpcv02.C appendQueryValues(req, url.Values{"contractAddress": []string{contract}}) - var resp rpcv02.ContractClass + var resp rpc.ContractClass return &resp, sg.do(req, &resp) } diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go index f7d73c43..dbf6ebbc 100644 --- a/gateway/gateway_test.go +++ b/gateway/gateway_test.go @@ -12,7 +12,7 @@ import ( starknetgo "github.com/NethermindEth/starknet.go" "github.com/NethermindEth/starknet.go/gateway" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/test" "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" @@ -55,7 +55,7 @@ func setupDevnet(ctx context.Context) error { return fmt.Errorf("could not connect to devnet: %v", err) } - contract := rpcv02.ContractClass{} + contract := rpc.ContractClass{} if err := json.Unmarshal(counterCompiled, &contract); err != nil { return err } diff --git a/gateway/provider.go b/gateway/provider.go index 09d24a02..fcf45100 100644 --- a/gateway/provider.go +++ b/gateway/provider.go @@ -5,7 +5,7 @@ import ( "math/big" "github.com/NethermindEth/juno/core/felt" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" ) type GatewayProvider struct { @@ -46,7 +46,7 @@ func (p *GatewayProvider) TransactionByHash(ctx context.Context, hash string) (* return &t.Transaction, nil } -func (p *GatewayProvider) Class(ctx context.Context, classHash string) (*rpcv02.ContractClass, error) { +func (p *GatewayProvider) Class(ctx context.Context, classHash string) (*rpc.ContractClass, error) { panic("not implemented") } @@ -54,6 +54,6 @@ func (p *GatewayProvider) ClassHashAt(ctx context.Context, contractAddress strin panic("not implemented") } -func (p *GatewayProvider) ClassAt(ctx context.Context, contractAddress string) (*rpcv02.ContractClass, error) { +func (p *GatewayProvider) ClassAt(ctx context.Context, contractAddress string) (*rpc.ContractClass, error) { panic("not implemented") } diff --git a/gateway/starknet.go b/gateway/starknet.go index 45b46ecc..813fc64e 100644 --- a/gateway/starknet.go +++ b/gateway/starknet.go @@ -11,7 +11,7 @@ import ( "strings" "github.com/NethermindEth/juno/core/felt" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/types" "github.com/google/go-querystring/query" ) @@ -142,7 +142,7 @@ func (sg *Gateway) Invoke(ctx context.Context, invoke types.FunctionInvoke) (*ty /* 'add_transaction' wrapper for compressing and deploying a compiled StarkNet contract */ -func (sg *Gateway) Deploy(ctx context.Context, contract rpcv02.ContractClass, deployRequest rpcv02.DeployAccountTxn) (resp types.AddDeployResponse, err error) { +func (sg *Gateway) Deploy(ctx context.Context, contract rpc.ContractClass, deployRequest rpc.DeployAccountTxn) (resp types.AddDeployResponse, err error) { panic("deploy transaction has been removed, use account.Deploy() instead") } @@ -197,7 +197,7 @@ func (sg *Gateway) DeployAccount(ctx context.Context, deployAccountRequest types /* 'add_transaction' wrapper for compressing and declaring a contract class */ -func (sg *Gateway) Declare(ctx context.Context, contract rpcv02.ContractClass, declareRequest DeclareRequest) (resp types.AddDeclareResponse, err error) { +func (sg *Gateway) Declare(ctx context.Context, contract rpc.ContractClass, declareRequest DeclareRequest) (resp types.AddDeclareResponse, err error) { declareRequest.Type = DECLARE req, err := sg.newRequest(ctx, http.MethodPost, "/add_transaction", declareRequest) @@ -208,7 +208,7 @@ func (sg *Gateway) Declare(ctx context.Context, contract rpcv02.ContractClass, d return resp, sg.do(req, &resp) } -// type DeployRequest rpcv02.DeployRequest +// type DeployRequest rpc.DeployRequest // func (d DeployRequest) MarshalJSON() ([]byte, error) { // calldata := []string{} @@ -226,7 +226,7 @@ type DeclareRequest struct { MaxFee string `json:"max_fee"` Nonce string `json:"nonce"` Signature []string `json:"signature"` - ContractClass rpcv02.ContractClass `json:"contract_class"` + ContractClass rpc.ContractClass `json:"contract_class"` } func (sg *Gateway) StateUpdate(ctx context.Context, opts *BlockOptions) (*StateUpdate, error) { diff --git a/gateway/starknet_test.go b/gateway/starknet_test.go index e7892fef..062ebbc6 100644 --- a/gateway/starknet_test.go +++ b/gateway/starknet_test.go @@ -11,7 +11,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/artifacts" "github.com/NethermindEth/starknet.go/gateway" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" devtest "github.com/NethermindEth/starknet.go/test" "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" @@ -36,7 +36,7 @@ func TestDeclare(t *testing.T) { for _, env := range testSet { gw := testConfig.client - accountClass := rpcv02.ContractClass{} + accountClass := rpc.ContractClass{} err := json.Unmarshal(accountCompiled, &accountClass) if err != nil { t.Fatalf("could not parse contract: %v\n", err) @@ -73,13 +73,13 @@ func TestDeployCounterContract(t *testing.T) { gw := testConfig.client - counterClass := rpcv02.ContractClass{} + counterClass := rpc.ContractClass{} err := json.Unmarshal(counterCompiled, &counterClass) if err != nil { t.Fatalf("could not parse contract: %v\n", err) } - tx, err := gw.Deploy(context.Background(), counterClass, rpcv02.DeployAccountTxn{ - DeployAccountTransactionProperties: rpcv02.DeployAccountTransactionProperties{ + tx, err := gw.Deploy(context.Background(), counterClass, rpc.DeployAccountTxn{ + DeployAccountTransactionProperties: rpc.DeployAccountTransactionProperties{ ContractAddressSalt: utils.TestHexToFelt(t, "0x01"), ConstructorCalldata: []*felt.Felt{}, }, @@ -148,7 +148,7 @@ func TestDeployAccountContract(t *testing.T) { for _, test := range testSet { gw := testConfig.client // Step 1: deploy the a class - accountClass := rpcv02.ContractClass{} + accountClass := rpc.ContractClass{} err := json.Unmarshal(accountCompiled, &accountClass) if err != nil { t.Fatalf("could not parse account: %v\n", err) diff --git a/plugins/xsessions/accounts_test.go b/plugins/xsessions/accounts_test.go index 22e5dccc..405e1176 100644 --- a/plugins/xsessions/accounts_test.go +++ b/plugins/xsessions/accounts_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/NethermindEth/starknet.go/artifacts" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" ctypes "github.com/NethermindEth/starknet.go/types" ) @@ -47,9 +47,9 @@ var counterCompiled = artifacts.CounterCompiled // TestCounter_DeployContract func TestCounter_DeployContract(t *testing.T) { - provider := beforeEachRPCv02(t) + provider := beforeEachRPC(t) - counterClass := rpcv02.ContractClass{} + counterClass := rpc.ContractClass{} inputs := []string{} if err := json.Unmarshal(counterCompiled, &counterClass); err != nil { diff --git a/plugins/xsessions/plugin_test.go b/plugins/xsessions/plugin_test.go index 35ee7457..216066a2 100644 --- a/plugins/xsessions/plugin_test.go +++ b/plugins/xsessions/plugin_test.go @@ -15,7 +15,7 @@ import ( "time" "github.com/NethermindEth/juno/core/felt" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" "github.com/NethermindEth/starknet.go/types" "github.com/NethermindEth/starknet.go/utils" "github.com/joho/godotenv" @@ -23,9 +23,9 @@ import ( // RegisterClass func RegisterClass(t *testing.T, pluginCompiled []byte) string { - provider := beforeEachRPCv02(t) + provider := beforeEachRPC(t) - yeasayerClass := rpcv02.ContractClass{} + yeasayerClass := rpc.ContractClass{} if err := json.Unmarshal(pluginCompiled, &yeasayerClass); err != nil { t.Fatal(err) } @@ -60,8 +60,8 @@ func RegisterClass(t *testing.T, pluginCompiled []byte) string { // DeployContract func DeployContract(t *testing.T, contractCompiled []byte, inputs []string) string { - provider := beforeEachRPCv02(t) - contractClass := rpcv02.ContractClass{} + provider := beforeEachRPC(t) + contractClass := rpc.ContractClass{} if err := json.Unmarshal(contractCompiled, &contractClass); err != nil { t.Fatal(err) @@ -126,14 +126,14 @@ func MintEth(t *testing.T, accountAddress string) { // CheckEth func CheckEth(t *testing.T, accountAddress string) string { - provider := beforeEachRPCv02(t) + provider := beforeEachRPC(t) ctx := context.Background() - output, err := provider.Call(ctx, rpcv02.FunctionCall{ + output, err := provider.Call(ctx, rpc.FunctionCall{ ContractAddress: utils.TestHexToFelt(t, devnetEth), EntryPointSelector: types.GetSelectorFromNameFelt("balanceOf"), Calldata: []*felt.Felt{utils.TestHexToFelt(t, accountAddress)}, }, - rpcv02.WithBlockTag("latest"), + rpc.WithBlockTag("latest"), ) if err != nil { log.Fatal("could not call Eth", err) diff --git a/plugins/xsessions/sessionkey_test.go b/plugins/xsessions/sessionkey_test.go index f85532e9..a715a6d7 100644 --- a/plugins/xsessions/sessionkey_test.go +++ b/plugins/xsessions/sessionkey_test.go @@ -93,7 +93,7 @@ func TestSessionKey_CheckEth(t *testing.T) { // IncrementWithSessionKeyPlugin func IncrementWithSessionKeyPlugin(t *testing.T, accountAddress string, pluginClass string, token *SessionKeyToken, counterAddress string) { - provider := beforeEachRPCv02(t) + provider := beforeEachRPC(t) // shim a keystore into existing tests. // use a string representation of the PK as a fake sender address for the keystore ks := starknetgo.NewMemKeystore() diff --git a/plugins/xsessions/xsessions_test.go b/plugins/xsessions/xsessions_test.go index 6760a00f..5f0c019a 100644 --- a/plugins/xsessions/xsessions_test.go +++ b/plugins/xsessions/xsessions_test.go @@ -6,13 +6,13 @@ import ( "os" "testing" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" ethrpc "github.com/ethereum/go-ethereum/rpc" "github.com/joho/godotenv" ) // beforeEach checks the configuration and initializes it before running the script -func beforeEachRPCv02(t *testing.T) *rpcv02.Provider { +func beforeEachRPC(t *testing.T) *rpc.Provider { t.Helper() godotenv.Load(".env.devnet") url := os.Getenv("STARKNET_NODE_URL") @@ -23,7 +23,7 @@ func beforeEachRPCv02(t *testing.T) *rpcv02.Provider { if err != nil { t.Fatal("connect should succeed, instead:", err) } - provider := rpcv02.NewProvider(c) + provider := rpc.NewProvider(c) t.Cleanup(func() { c.Close() }) diff --git a/providers_test.go b/providers_test.go index 02f90029..a99ee5f9 100644 --- a/providers_test.go +++ b/providers_test.go @@ -15,7 +15,7 @@ import ( "github.com/NethermindEth/juno/core/felt" "github.com/NethermindEth/starknet.go/artifacts" "github.com/NethermindEth/starknet.go/gateway" - "github.com/NethermindEth/starknet.go/rpcv02" + "github.com/NethermindEth/starknet.go/rpc" devtest "github.com/NethermindEth/starknet.go/test" "github.com/NethermindEth/starknet.go/types" ethrpc "github.com/ethereum/go-ethereum/rpc" @@ -89,15 +89,15 @@ var ( ) func InstallCounterContract(provider *gateway.GatewayProvider) (string, error) { - class := rpcv02.ContractClass{} + class := rpc.ContractClass{} if err := json.Unmarshal(artifacts.CounterCompiled, &class); err != nil { return "", err } ctx := context.Background() ctx, cancel := context.WithTimeout(ctx, time.Second*60) defer cancel() - tx, err := provider.Deploy(context.Background(), class, rpcv02.DeployAccountTxn{ - DeployAccountTransactionProperties: rpcv02.DeployAccountTransactionProperties{ + tx, err := provider.Deploy(context.Background(), class, rpc.DeployAccountTxn{ + DeployAccountTransactionProperties: rpc.DeployAccountTransactionProperties{ ContractAddressSalt: &felt.Zero, ConstructorCalldata: []*felt.Felt{}, }}) @@ -137,7 +137,7 @@ func beforeGatewayEach(t *testing.T) *testGatewayConfiguration { // testConfiguration is a type that is used to configure tests type testRPCConfiguration struct { - providerv02 *rpcv02.Provider + providerv02 *rpc.Provider base string } @@ -200,7 +200,7 @@ func beforeRPCEach(t *testing.T) *testRPCConfiguration { if err != nil { t.Fatal("connect should succeed, instead:", err) } - clientv02 := rpcv02.NewProvider(c) + clientv02 := rpc.NewProvider(c) testConfig.providerv02 = clientv02 return &testConfig } diff --git a/rpcv02/.env.template b/rpc/.env.template similarity index 100% rename from rpcv02/.env.template rename to rpc/.env.template diff --git a/rpcv02/README.md b/rpc/README.md similarity index 100% rename from rpcv02/README.md rename to rpc/README.md diff --git a/rpcv02/block.go b/rpc/block.go similarity index 99% rename from rpcv02/block.go rename to rpc/block.go index 2e22ca20..c9947349 100644 --- a/rpcv02/block.go +++ b/rpc/block.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/block_test.go b/rpc/block_test.go similarity index 99% rename from rpcv02/block_test.go rename to rpc/block_test.go index 4852d863..d3ba38c5 100644 --- a/rpcv02/block_test.go +++ b/rpc/block_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" @@ -412,7 +412,7 @@ func TestBlockWithTxsAndDeployOrDeclare(t *testing.T) { } blockWithTxs, ok := blockWithTxsInterface.(*Block) if !ok { - t.Fatalf("expecting *rpcv02.Block, instead %T", blockWithTxsInterface) + t.Fatalf("expecting *rpc.Block, instead %T", blockWithTxsInterface) } diff, err := spy.Compare(blockWithTxs, false) if err != nil { @@ -509,7 +509,7 @@ func TestCaptureUnsupportedBlockTxn(t *testing.T) { } blockWithTxs, ok := blockWithTxsInterface.(*Block) if !ok { - t.Fatalf("expecting *rpcv02.Block, instead %T", blockWithTxsInterface) + t.Fatalf("expecting *rpc.Block, instead %T", blockWithTxsInterface) } for k, v := range blockWithTxs.Transactions { _, okv1 := v.(InvokeTxnV1) diff --git a/rpcv02/call.go b/rpc/call.go similarity index 97% rename from rpcv02/call.go rename to rpc/call.go index 1632dfcc..e67dcf94 100644 --- a/rpcv02/call.go +++ b/rpc/call.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/call_test.go b/rpc/call_test.go similarity index 99% rename from rpcv02/call_test.go rename to rpc/call_test.go index ec7efbdb..54009ecb 100644 --- a/rpcv02/call_test.go +++ b/rpc/call_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/chain.go b/rpc/chain.go similarity index 98% rename from rpcv02/chain.go rename to rpc/chain.go index 0620904f..9747d30b 100644 --- a/rpcv02/chain.go +++ b/rpc/chain.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/client.go b/rpc/client.go similarity index 97% rename from rpcv02/client.go rename to rpc/client.go index 8dfc13c5..7c5170fe 100644 --- a/rpcv02/client.go +++ b/rpc/client.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/contract.go b/rpc/contract.go similarity index 99% rename from rpcv02/contract.go rename to rpc/contract.go index b0debe75..6ae5ba78 100644 --- a/rpcv02/contract.go +++ b/rpc/contract.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/contract_test.go b/rpc/contract_test.go similarity index 99% rename from rpcv02/contract_test.go rename to rpc/contract_test.go index 492d555f..828ec500 100644 --- a/rpcv02/contract_test.go +++ b/rpc/contract_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/errors.go b/rpc/errors.go similarity index 98% rename from rpcv02/errors.go rename to rpc/errors.go index c3d01c96..b98b3d67 100644 --- a/rpcv02/errors.go +++ b/rpc/errors.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc type RPCError struct { code int diff --git a/rpcv02/events.go b/rpc/events.go similarity index 96% rename from rpcv02/events.go rename to rpc/events.go index ef69f66a..a6c059fc 100644 --- a/rpcv02/events.go +++ b/rpc/events.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/events_test.go b/rpc/events_test.go similarity index 99% rename from rpcv02/events_test.go rename to rpc/events_test.go index 6f5cf821..ec0aa2a7 100644 --- a/rpcv02/events_test.go +++ b/rpc/events_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/json_test.go b/rpc/json_test.go similarity index 99% rename from rpcv02/json_test.go rename to rpc/json_test.go index f03eeff1..3e8bb4eb 100644 --- a/rpcv02/json_test.go +++ b/rpc/json_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "encoding/json" diff --git a/rpcv02/mock_test.go b/rpc/mock_test.go similarity index 99% rename from rpcv02/mock_test.go rename to rpc/mock_test.go index cc348b07..7a5af083 100644 --- a/rpcv02/mock_test.go +++ b/rpc/mock_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/provider.go b/rpc/provider.go similarity index 99% rename from rpcv02/provider.go rename to rpc/provider.go index 8604dfd6..75b8419b 100644 --- a/rpcv02/provider.go +++ b/rpc/provider.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/provider_test.go b/rpc/provider_test.go similarity index 99% rename from rpcv02/provider_test.go rename to rpc/provider_test.go index 4ba7863c..2c8dbae3 100644 --- a/rpcv02/provider_test.go +++ b/rpc/provider_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/spy_test.go b/rpc/spy_test.go similarity index 99% rename from rpcv02/spy_test.go rename to rpc/spy_test.go index 0d80d96a..6c06f714 100644 --- a/rpcv02/spy_test.go +++ b/rpc/spy_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/tests/0x1efa8f84fd4dff9e2902ec88717cf0dafc8c188f80c3450615944a469428f7f.json b/rpc/tests/0x1efa8f84fd4dff9e2902ec88717cf0dafc8c188f80c3450615944a469428f7f.json similarity index 100% rename from rpcv02/tests/0x1efa8f84fd4dff9e2902ec88717cf0dafc8c188f80c3450615944a469428f7f.json rename to rpc/tests/0x1efa8f84fd4dff9e2902ec88717cf0dafc8c188f80c3450615944a469428f7f.json diff --git a/rpcv02/tests/block.json b/rpc/tests/block.json similarity index 100% rename from rpcv02/tests/block.json rename to rpc/tests/block.json diff --git a/rpcv02/tests/declareTx.json b/rpc/tests/declareTx.json similarity index 100% rename from rpcv02/tests/declareTx.json rename to rpc/tests/declareTx.json diff --git a/rpcv02/trace.go b/rpc/trace.go similarity index 96% rename from rpcv02/trace.go rename to rpc/trace.go index f9cd9a3c..506e5cd4 100644 --- a/rpcv02/trace.go +++ b/rpc/trace.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/trace_test.go b/rpc/trace_test.go similarity index 98% rename from rpcv02/trace_test.go rename to rpc/trace_test.go index e7f38a40..c10d0d91 100644 --- a/rpcv02/trace_test.go +++ b/rpc/trace_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/transaction.go b/rpc/transaction.go similarity index 99% rename from rpcv02/transaction.go rename to rpc/transaction.go index a23507de..99bfa010 100644 --- a/rpcv02/transaction.go +++ b/rpc/transaction.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/transaction_test.go b/rpc/transaction_test.go similarity index 99% rename from rpcv02/transaction_test.go rename to rpc/transaction_test.go index aacf30a1..abaccf5e 100644 --- a/rpcv02/transaction_test.go +++ b/rpc/transaction_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/types.go b/rpc/types.go similarity index 99% rename from rpcv02/types.go rename to rpc/types.go index 8ff6ac5a..19c7abc1 100644 --- a/rpcv02/types.go +++ b/rpc/types.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "encoding/json" diff --git a/rpcv02/types_block.go b/rpc/types_block.go similarity index 99% rename from rpcv02/types_block.go rename to rpc/types_block.go index 8d0b9ae7..8798ac3a 100644 --- a/rpcv02/types_block.go +++ b/rpc/types_block.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "errors" diff --git a/rpcv02/types_contract.go b/rpc/types_contract.go similarity index 99% rename from rpcv02/types_contract.go rename to rpc/types_contract.go index e05a2aee..a929acf1 100644 --- a/rpcv02/types_contract.go +++ b/rpc/types_contract.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "bytes" diff --git a/rpcv02/types_contract_test.go b/rpc/types_contract_test.go similarity index 97% rename from rpcv02/types_contract_test.go rename to rpc/types_contract_test.go index 1003b12d..a812f4c2 100644 --- a/rpcv02/types_contract_test.go +++ b/rpc/types_contract_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "encoding/json" diff --git a/rpcv02/types_event.go b/rpc/types_event.go similarity index 98% rename from rpcv02/types_event.go rename to rpc/types_event.go index bf7f2a40..e18f0da6 100644 --- a/rpcv02/types_event.go +++ b/rpc/types_event.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import "github.com/NethermindEth/juno/core/felt" diff --git a/rpcv02/types_transaction.go b/rpc/types_transaction.go similarity index 99% rename from rpcv02/types_transaction.go rename to rpc/types_transaction.go index 7b74a351..6c8c6e66 100644 --- a/rpcv02/types_transaction.go +++ b/rpc/types_transaction.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "encoding/json" diff --git a/rpcv02/types_transaction_receipt.go b/rpc/types_transaction_receipt.go similarity index 99% rename from rpcv02/types_transaction_receipt.go rename to rpc/types_transaction_receipt.go index 56111de6..cefd33bc 100644 --- a/rpcv02/types_transaction_receipt.go +++ b/rpc/types_transaction_receipt.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "encoding/json" diff --git a/rpcv02/types_transaction_response.go b/rpc/types_transaction_response.go similarity index 97% rename from rpcv02/types_transaction_response.go rename to rpc/types_transaction_response.go index c86481de..afca19c9 100644 --- a/rpcv02/types_transaction_response.go +++ b/rpc/types_transaction_response.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import "github.com/NethermindEth/juno/core/felt" diff --git a/rpcv02/types_transaction_test.go b/rpc/types_transaction_test.go similarity index 96% rename from rpcv02/types_transaction_test.go rename to rpc/types_transaction_test.go index 879e4862..7939fec2 100644 --- a/rpcv02/types_transaction_test.go +++ b/rpc/types_transaction_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "encoding/json" diff --git a/rpcv02/types_types_block_test.go b/rpc/types_types_block_test.go similarity index 99% rename from rpcv02/types_types_block_test.go rename to rpc/types_types_block_test.go index 6a108fdf..f9f9dbd9 100644 --- a/rpcv02/types_types_block_test.go +++ b/rpc/types_types_block_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( _ "embed" diff --git a/rpcv02/write.go b/rpc/write.go similarity index 99% rename from rpcv02/write.go rename to rpc/write.go index c769b98f..7b55c2b2 100644 --- a/rpcv02/write.go +++ b/rpc/write.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/rpcv02/write_test.go b/rpc/write_test.go similarity index 99% rename from rpcv02/write_test.go rename to rpc/write_test.go index 1cf0a16b..4439bb85 100644 --- a/rpcv02/write_test.go +++ b/rpc/write_test.go @@ -1,4 +1,4 @@ -package rpcv02 +package rpc import ( "context" diff --git a/types/types.go b/types/types.go index 94ff5d55..cda53398 100644 --- a/types/types.go +++ b/types/types.go @@ -31,7 +31,7 @@ type AddDeployResponse struct { // Type string `json:"type"` // ContractAddressSalt string `json:"contract_address_salt"` // ConstructorCalldata []string `json:"constructor_calldata"` -// ContractDefinition rpcv02.ContractClass `json:"contract_definition"` +// ContractDefinition rpc.ContractClass `json:"contract_definition"` // } type DeployAccountRequest struct {