Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC v0.8.0 #629

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5b5485a
fix::> introduced comman AddTransaction function in account package
PsychoPunkSage Jul 11, 2024
db1fefc
fix::> replace all the instances of Add<Type>Transaction in example/t…
PsychoPunkSage Jul 11, 2024
5132f1d
fix::> func name and doc changes made
PsychoPunkSage Jul 15, 2024
cc8dab3
fix::> account_test.go changed
PsychoPunkSage Jul 15, 2024
0de86de
fix::> examples error solved
PsychoPunkSage Jul 15, 2024
3b3d684
fix::> Removed type assertions, created generic TransactionResponse s…
PsychoPunkSage Jul 15, 2024
762544c
fix::> removed unnecessary lines
PsychoPunkSage Jul 16, 2024
91be01a
fix:> made required changes
PsychoPunkSage Jul 17, 2024
b9d9980
fix::> removed unnecessary comments
PsychoPunkSage Jul 18, 2024
0b5ac0b
fix::> renamed test function
PsychoPunkSage Jul 19, 2024
d4a83a1
Merge branch 'main' into issue-590-3
rianhughes Jul 23, 2024
f35d88f
Thiagodeev/rpcv08 write methods, blockHeader and error 53 (#626)
thiagodeev Sep 30, 2024
34e41a7
Adjusts TransactionStatus
thiagodeev Sep 30, 2024
cdd6056
Adjusts EstimateFee
thiagodeev Sep 30, 2024
7ce62aa
Fixes blockTest error
thiagodeev Sep 30, 2024
7ebed76
Merge branch 'main' into v0.8.0
thiagodeev Sep 30, 2024
2d2a4cd
Merge branch 'main' into thiagodeev/rpcv08-txn-status
thiagodeev Oct 2, 2024
66432ac
Merge branch 'main' into issue-590-3
thiagodeev Oct 3, 2024
8deb612
Merge branch 'main' into v0.8.0
thiagodeev Oct 3, 2024
9cb1fb9
Merge pull request #592 from PsychoPunkSage/issue-590-3
thiagodeev Oct 3, 2024
6449e31
Merge pull request #628 from NethermindEth/thiagodeev/rpcv08-txn-status
thiagodeev Oct 4, 2024
470f18c
Adds GetStorageProof method (#635)
thiagodeev Oct 28, 2024
2013420
Adds GetMessagesStatus method (#634)
thiagodeev Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 26 additions & 30 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type AccountInterface interface {
}

var _ AccountInterface = &Account{}
var _ rpc.RpcProvider = &Account{}

type Account struct {
provider rpc.RpcProvider
Expand Down Expand Up @@ -513,40 +512,37 @@ func (account *Account) WaitForTransactionReceipt(ctx context.Context, transacti
}
}

// AddInvokeTransaction generates an invoke transaction and adds it to the account's provider.
// SendTransaction can send Invoke, Declare, and Deploy transactions. It provides a unified way to send different transactions.
//
// Parameters:
// - ctx: the context.Context object for the transaction.
// - invokeTx: the invoke transaction to be added.
// - txn: the Broadcast Transaction to be sent.
// Returns:
// - *rpc.AddInvokeTransactionResponse: The response for the AddInvokeTransactionResponse
// - *rpc.TransactionResponse: the transaction response.
// - error: an error if any.
func (account *Account) AddInvokeTransaction(ctx context.Context, invokeTx rpc.BroadcastInvokeTxnType) (*rpc.AddInvokeTransactionResponse, error) {
return account.provider.AddInvokeTransaction(ctx, invokeTx)
}

// AddDeclareTransaction adds a declare transaction to the account.
//
// Parameters:
// - ctx: The context.Context for the request.
// - declareTransaction: The input for adding a declare transaction.
// Returns:
// - *rpc.AddDeclareTransactionResponse: The response for adding a declare transaction
// - error: an error, if any
func (account *Account) AddDeclareTransaction(ctx context.Context, declareTransaction rpc.BroadcastDeclareTxnType) (*rpc.AddDeclareTransactionResponse, error) {
return account.provider.AddDeclareTransaction(ctx, declareTransaction)
}

// AddDeployAccountTransaction adds a deploy account transaction to the account.
//
// Parameters:
// - ctx: The context.Context object for the function.
// - deployAccountTransaction: The rpc.DeployAccountTxn object representing the deploy account transaction.
// Returns:
// - *rpc.AddDeployAccountTransactionResponse: a pointer to rpc.AddDeployAccountTransactionResponse
// - error: an error if any
func (account *Account) AddDeployAccountTransaction(ctx context.Context, deployAccountTransaction rpc.BroadcastAddDeployTxnType) (*rpc.AddDeployAccountTransactionResponse, error) {
return account.provider.AddDeployAccountTransaction(ctx, deployAccountTransaction)
func (account *Account) SendTransaction(ctx context.Context, txn rpc.BroadcastTxn) (*rpc.TransactionResponse, error) {
switch tx := txn.(type) {
case rpc.BroadcastInvokeTxnType:
resp, err := account.provider.AddInvokeTransaction(ctx, tx)
if err != nil {
return nil, err
}
return &rpc.TransactionResponse{TransactionHash: resp.TransactionHash}, nil
case rpc.BroadcastDeclareTxnType:
resp, err := account.provider.AddDeclareTransaction(ctx, tx)
if err != nil {
return nil, err
}
return &rpc.TransactionResponse{TransactionHash: resp.TransactionHash, ClassHash: resp.ClassHash}, nil
case rpc.BroadcastAddDeployTxnType:
resp, err := account.provider.AddDeployAccountTransaction(ctx, tx)
if err != nil {
return nil, err
}
return &rpc.TransactionResponse{TransactionHash: resp.TransactionHash, ContractAddress: resp.ContractAddress}, nil
default:
return nil, errors.New("unsupported transaction type")
}
}

// BlockHashAndNumber returns the block hash and number for the account.
Expand Down
12 changes: 6 additions & 6 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func TestSignMOCK(t *testing.T) {
// Returns:
//
// none
func TestAddInvoke(t *testing.T) {
func TestSendInvokeTxn(t *testing.T) {

type testSetType struct {
ExpectedErr error
Expand Down Expand Up @@ -526,7 +526,7 @@ func TestAddInvoke(t *testing.T) {
err = acnt.SignInvokeTransaction(context.Background(), &test.InvokeTx.InvokeTxnV1)
require.NoError(t, err)

resp, err := acnt.AddInvokeTransaction(context.Background(), test.InvokeTx)
resp, err := acnt.SendTransaction(context.Background(), test.InvokeTx)
if err != nil {
require.Equal(t, test.ExpectedErr.Error(), err.Error(), "AddInvokeTransaction returned an unexpected error")
require.Nil(t, resp)
Expand All @@ -552,7 +552,7 @@ func TestAddInvoke(t *testing.T) {
// Returns:
//
// none
func TestAddDeployAccountDevnet(t *testing.T) {
func TestSendDeployAccountDevnet(t *testing.T) {
if testEnv != "devnet" {
t.Skip("Skipping test as it requires a devnet environment")
}
Expand Down Expand Up @@ -595,7 +595,7 @@ func TestAddDeployAccountDevnet(t *testing.T) {
_, err = devnet.Mint(precomputedAddress, new(big.Int).SetUint64(10000000000000000000))
require.NoError(t, err)

resp, err := acnt.AddDeployAccountTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx})
resp, err := acnt.SendTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx})
require.Nil(t, err, "AddDeployAccountTransaction gave an Error")
require.NotNil(t, resp, "AddDeployAccountTransaction resp not nil")
}
Expand Down Expand Up @@ -1106,7 +1106,7 @@ func TestWaitForTransactionReceipt(t *testing.T) {
// Returns:
//
// none
func TestAddDeclareTxn(t *testing.T) {
func TestSendDeclareTxn(t *testing.T) {
if testEnv != "testnet" {
t.Skip("Skipping test as it requires a testnet environment")
}
Expand Down Expand Up @@ -1174,7 +1174,7 @@ func TestAddDeclareTxn(t *testing.T) {
ContractClass: class,
}

resp, err := acnt.AddDeclareTransaction(context.Background(), broadcastTx)
resp, err := acnt.SendTransaction(context.Background(), broadcastTx)

if err != nil {
require.Equal(t, rpc.ErrDuplicateTx.Error(), err.Error(), "AddDeclareTransaction error not what expected")
Expand Down
2 changes: 1 addition & 1 deletion examples/deployAccount/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func main() {
fmt.Scan(&input)

// Send transaction to the network
resp, err := accnt.AddDeployAccountTransaction(context.Background(), tx)
resp, err := accnt.SendTransaction(context.Background(), tx)
if err != nil {
fmt.Println("Error returned from AddDeployAccountTransaction: ")
setup.PanicRPC(err)
Expand Down
2 changes: 1 addition & 1 deletion examples/deployContractUDC/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func main() {
}

// After the signing we finally call the AddInvokeTransaction in order to invoke the contract function
resp, err := accnt.AddInvokeTransaction(context.Background(), InvokeTx)
resp, err := accnt.SendTransaction(context.Background(), InvokeTx)
if err != nil {
setup.PanicRPC(err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simpleInvoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func main() {
}

// After the signing we finally call the AddInvokeTransaction in order to invoke the contract function
resp, err := accnt.AddInvokeTransaction(context.Background(), InvokeTx)
resp, err := accnt.SendTransaction(context.Background(), InvokeTx)
if err != nil {
setup.PanicRPC(err)
}
Expand Down
30 changes: 30 additions & 0 deletions mocks/mock_rpc_provider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions rpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,21 @@ func (provider *Provider) EstimateMessageFee(ctx context.Context, msg MsgFromL1,
}
return &raw, nil
}

// Get merkle paths in one of the state tries: global state, classes, individual contract.
// A single request can query for any mix of the three types of storage proofs (classes, contracts, and storage)
//
// Parameters:
// - ctx: The context of the function call
// - storageProofInput: an input containing at least one of the fields filled
// Returns:
// - *StorageProofResult: the proofs of the field passed in the input
// - error: an error if any occurred during the execution
func (provider *Provider) GetStorageProof(ctx context.Context, storageProofInput StorageProofInput) (*StorageProofResult, error) {
var raw StorageProofResult
if err := do(ctx, provider.c, "starknet_getStorageProof", &raw, storageProofInput); err != nil {

return nil, tryUnwrapToRPCErr(err, ErrBlockNotFound, ErrStorageProofNotSupported)
}
return &raw, nil
}
Loading
Loading