Skip to content

Commit

Permalink
change rpcv02 package to rpc
Browse files Browse the repository at this point in the history
small docs modification
  • Loading branch information
cicr99 committed Jul 25, 2023
1 parent a4cfd1c commit e63a55b
Show file tree
Hide file tree
Showing 59 changed files with 179 additions and 182 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/rpcv02.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: rpcv02
name: rpc

on:
push:
Expand Down Expand Up @@ -30,27 +30,27 @@ jobs:

# Test rpc on devnet
- name: Test RPC v0.2 on devnet
run: cd rpcv02 && go test -timeout 600s -v -env 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 .
run: cd rpc && go test -v .

# Test rpc on testnet
- name: Test RPC v0.2 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
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/"
68 changes: 34 additions & 34 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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",
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions accountrpcv02_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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} {
Expand All @@ -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,
)
Expand Down
8 changes: 4 additions & 4 deletions contracts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand All @@ -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")
}
Expand Down
14 changes: 7 additions & 7 deletions contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand All @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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,
// })
Expand Down
Loading

0 comments on commit e63a55b

Please sign in to comment.