From 5b5485a578b921f87395fad1c90438a65a32bac8 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Thu, 11 Jul 2024 18:15:09 +0530 Subject: [PATCH 01/10] fix::> introduced comman AddTransaction function in account package --- account/account.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/account/account.go b/account/account.go index 1607e34b..40eaec16 100644 --- a/account/account.go +++ b/account/account.go @@ -533,6 +533,27 @@ func (account *Account) WaitForTransactionReceipt(ctx context.Context, transacti } } +// AddTransaction calls dynamically one of AddTransaction methods +// +// Parameters: +// - ctx: the context.Context object for the transaction. +// - txn: this Broadcast Transaction to be called. +// Returns: +// - interface{} returns required Broadcast txn return value. +// - error: an error if any. +func (account *Account) AddTransaction(ctx context.Context, txn rpc.BroadcastTxn) (interface{}, error) { + switch tx := txn.(type) { + case rpc.BroadcastInvokeTxnType: + return account.AddInvokeTransaction(ctx, tx) + case rpc.BroadcastDeclareTxnType: + return account.AddDeclareTransaction(ctx, tx) + case rpc.BroadcastAddDeployTxnType: + return account.AddDeployAccountTransaction(ctx, tx) + default: + return nil, errors.New("unsupported transaction type") + } +} + // AddInvokeTransaction generates an invoke transaction and adds it to the account's provider. // // Parameters: From db1fefc6b028b017364db2d46706995d75c51062 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Thu, 11 Jul 2024 18:41:44 +0530 Subject: [PATCH 02/10] fix::> replace all the instances of AddTransaction in example/test with AddTransaction --- account/account_test.go | 14 +++++++------- examples/deployAccount/main.go | 7 ++++--- examples/deployContractUDC/main.go | 6 +++--- examples/simpleInvoke/main.go | 6 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/account/account_test.go b/account/account_test.go index 0e0a36df..63941f3d 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -526,10 +526,10 @@ 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.AddTransaction(context.Background(), test.InvokeTx) if err != nil { require.Equal(t, test.ExpectedErr.Error(), err.Error(), "AddInvokeTransaction returned an unexpected error") - require.Nil(t, resp) + require.Nil(t, resp.(*rpc.AddInvokeTransactionResponse)) } } @@ -595,9 +595,9 @@ 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.AddTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx}) require.Nil(t, err, "AddDeployAccountTransaction gave an Error") - require.NotNil(t, resp, "AddDeployAccountTransaction resp not nil") + require.NotNil(t, resp.(*rpc.AddDeployAccountTransactionResponse), "AddDeployAccountTransaction resp not nil") } // TestTransactionHashDeclare tests the TransactionHashDeclare function. @@ -1175,13 +1175,13 @@ func TestAddDeclareTxn(t *testing.T) { ContractClass: class, } - resp, err := acnt.AddDeclareTransaction(context.Background(), broadcastTx) + resp, err := acnt.AddTransaction(context.Background(), broadcastTx) if err != nil { require.Equal(t, rpc.ErrDuplicateTx.Error(), err.Error(), "AddDeclareTransaction error not what expected") } else { - require.Equal(t, expectedTxHash.String(), resp.TransactionHash.String(), "AddDeclareTransaction TxHash not what expected") - require.Equal(t, expectedClassHash.String(), resp.ClassHash.String(), "AddDeclareTransaction ClassHash not what expected") + require.Equal(t, expectedTxHash.String(), resp.(*rpc.AddDeclareTransactionResponse).TransactionHash.String(), "AddDeclareTransaction TxHash not what expected") + require.Equal(t, expectedClassHash.String(), resp.(*rpc.AddDeclareTransactionResponse).ClassHash.String(), "AddDeclareTransaction ClassHash not what expected") } } diff --git a/examples/deployAccount/main.go b/examples/deployAccount/main.go index 24152bf0..8357ba45 100644 --- a/examples/deployAccount/main.go +++ b/examples/deployAccount/main.go @@ -121,13 +121,14 @@ func main() { fmt.Scan(&input) // Send transaction to the network - resp, err := accnt.AddDeployAccountTransaction(context.Background(), tx) + // resp, err := accnt.AddDeployAccountTransaction(context.Background(), tx) + resp, err := accnt.AddTransaction(context.Background(), tx) if err != nil { fmt.Println("Error returned from AddDeployAccountTransaction: ") setup.PanicRPC(err) } fmt.Println("AddDeployAccountTransaction successfully submitted! Wait a few minutes to see it in Voyager.") - fmt.Printf("Transaction hash: %v \n", resp.TransactionHash) - fmt.Printf("Contract address: %v \n", resp.ContractAddress) + fmt.Printf("Transaction hash: %v \n", resp.(*rpc.AddDeployAccountTransactionResponse).TransactionHash) + fmt.Printf("Contract address: %v \n", resp.(*rpc.AddDeployAccountTransactionResponse).ContractAddress) } diff --git a/examples/deployContractUDC/main.go b/examples/deployContractUDC/main.go index 31ddc0c5..43a83365 100644 --- a/examples/deployContractUDC/main.go +++ b/examples/deployContractUDC/main.go @@ -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.AddTransaction(context.Background(), InvokeTx) if err != nil { setup.PanicRPC(err) } @@ -137,13 +137,13 @@ func main() { time.Sleep(time.Second * 3) // Waiting 3 seconds //Getting the transaction status - txStatus, err := client.GetTransactionStatus(context.Background(), resp.TransactionHash) + txStatus, err := client.GetTransactionStatus(context.Background(), resp.(*rpc.AddInvokeTransactionResponse).TransactionHash) if err != nil { setup.PanicRPC(err) } // This returns us with the transaction hash and status - fmt.Printf("Transaction hash response: %v\n", resp.TransactionHash) + fmt.Printf("Transaction hash response: %v\n", resp.(*rpc.AddInvokeTransactionResponse).TransactionHash) fmt.Printf("Transaction execution status: %s\n", txStatus.ExecutionStatus) fmt.Printf("Transaction status: %s\n", txStatus.FinalityStatus) } diff --git a/examples/simpleInvoke/main.go b/examples/simpleInvoke/main.go index 2ed8ca89..9f3a5b2d 100644 --- a/examples/simpleInvoke/main.go +++ b/examples/simpleInvoke/main.go @@ -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.AddTransaction(context.Background(), InvokeTx) if err != nil { setup.PanicRPC(err) } @@ -129,13 +129,13 @@ func main() { time.Sleep(time.Second * 3) // Waiting 3 seconds //Getting the transaction status - txStatus, err := client.GetTransactionStatus(context.Background(), resp.TransactionHash) + txStatus, err := client.GetTransactionStatus(context.Background(), resp.(*rpc.AddInvokeTransactionResponse).TransactionHash) if err != nil { setup.PanicRPC(err) } // This returns us with the transaction hash and status - fmt.Printf("Transaction hash response: %v\n", resp.TransactionHash) + fmt.Printf("Transaction hash response: %v\n", resp.(*rpc.AddInvokeTransactionResponse).TransactionHash) fmt.Printf("Transaction execution status: %s\n", txStatus.ExecutionStatus) fmt.Printf("Transaction status: %s\n", txStatus.FinalityStatus) From 5132f1dbb3a1e89ed7aa607165dd23e28e3d76e9 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 15 Jul 2024 11:10:13 +0530 Subject: [PATCH 03/10] fix::> func name and doc changes made --- account/account.go | 68 ++++++++++++------------------- rpc/types_transaction_response.go | 6 +++ 2 files changed, 32 insertions(+), 42 deletions(-) diff --git a/account/account.go b/account/account.go index 40eaec16..180e23ed 100644 --- a/account/account.go +++ b/account/account.go @@ -40,7 +40,6 @@ type AccountInterface interface { } var _ AccountInterface = &Account{} -var _ rpc.RpcProvider = &Account{} type Account struct { provider rpc.RpcProvider @@ -533,62 +532,47 @@ func (account *Account) WaitForTransactionReceipt(ctx context.Context, transacti } } -// AddTransaction calls dynamically one of AddTransaction methods +// 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. -// - txn: this Broadcast Transaction to be called. +// - txn: this Broadcast Transaction to be sent. // Returns: // - interface{} returns required Broadcast txn return value. // - error: an error if any. -func (account *Account) AddTransaction(ctx context.Context, txn rpc.BroadcastTxn) (interface{}, error) { +func (account *Account) SendTransaction(ctx context.Context, txn rpc.BroadcastTxn) (interface{}, error) { switch tx := txn.(type) { case rpc.BroadcastInvokeTxnType: - return account.AddInvokeTransaction(ctx, tx) + return account.provider.AddInvokeTransaction(ctx, tx) case rpc.BroadcastDeclareTxnType: - return account.AddDeclareTransaction(ctx, tx) + return account.provider.AddDeclareTransaction(ctx, tx) case rpc.BroadcastAddDeployTxnType: - return account.AddDeployAccountTransaction(ctx, tx) + return account.provider.AddDeployAccountTransaction(ctx, tx) default: return nil, errors.New("unsupported transaction type") } } -// AddInvokeTransaction generates an invoke transaction and adds it to the account's provider. -// -// Parameters: -// - ctx: the context.Context object for the transaction. -// - invokeTx: the invoke transaction to be added. -// Returns: -// - *rpc.AddInvokeTransactionResponse: The response for the AddInvokeTransactionResponse -// - 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 convertToTransactionResponse(resp interface{}) *rpc.TransactionResponse { +// switch r := resp.(type) { +// case *rpc.AddInvokeTransactionResponse: +// return &rpc.TransactionResponse{ +// TransactionHash: r.TransactionHash, +// } +// case *rpc.AddDeclareTransactionResponse: +// return &rpc.TransactionResponse{ +// TransactionHash: r.TransactionHash, +// ClassHash: r.ClassHash, +// } +// case *rpc.AddDeployAccountTransactionResponse: +// return &rpc.TransactionResponse{ +// TransactionHash: r.TransactionHash, +// ContractAddress: r.ContractAddress, +// } +// default: +// return nil +// } +// } // BlockHashAndNumber returns the block hash and number for the account. // diff --git a/rpc/types_transaction_response.go b/rpc/types_transaction_response.go index 3e94c07d..15920f94 100644 --- a/rpc/types_transaction_response.go +++ b/rpc/types_transaction_response.go @@ -18,3 +18,9 @@ type AddDeployAccountTransactionResponse struct { type AddInvokeTransactionResponse struct { TransactionHash *felt.Felt `json:"transaction_hash"` } + +// type TransactionResponse struct { +// TransactionHash *felt.Felt `json:"transaction_hash"` +// ClassHash *felt.Felt `json:"class_hash"` +// ContractAddress *felt.Felt `json:"contract_address"` +// } From cc8dab37b6d8afc172055ec2ab2a5ab267b58cec Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 15 Jul 2024 11:11:19 +0530 Subject: [PATCH 04/10] fix::> account_test.go changed --- account/account_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/account/account_test.go b/account/account_test.go index 63941f3d..d2ab4c09 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -526,7 +526,7 @@ func TestAddInvoke(t *testing.T) { err = acnt.SignInvokeTransaction(context.Background(), &test.InvokeTx.InvokeTxnV1) require.NoError(t, err) - resp, err := acnt.AddTransaction(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.(*rpc.AddInvokeTransactionResponse)) @@ -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.AddTransaction(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.(*rpc.AddDeployAccountTransactionResponse), "AddDeployAccountTransaction resp not nil") } @@ -1175,7 +1175,7 @@ func TestAddDeclareTxn(t *testing.T) { ContractClass: class, } - resp, err := acnt.AddTransaction(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") From 0de86de28a099f94906551b36072b0457159ff1c Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 15 Jul 2024 11:13:19 +0530 Subject: [PATCH 05/10] fix::> examples error solved --- examples/deployAccount/main.go | 2 +- examples/deployContractUDC/main.go | 2 +- examples/simpleInvoke/main.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/deployAccount/main.go b/examples/deployAccount/main.go index 8357ba45..cae67f6b 100644 --- a/examples/deployAccount/main.go +++ b/examples/deployAccount/main.go @@ -122,7 +122,7 @@ func main() { // Send transaction to the network // resp, err := accnt.AddDeployAccountTransaction(context.Background(), tx) - resp, err := accnt.AddTransaction(context.Background(), tx) + resp, err := accnt.SendTransaction(context.Background(), tx) if err != nil { fmt.Println("Error returned from AddDeployAccountTransaction: ") setup.PanicRPC(err) diff --git a/examples/deployContractUDC/main.go b/examples/deployContractUDC/main.go index 43a83365..95a08137 100644 --- a/examples/deployContractUDC/main.go +++ b/examples/deployContractUDC/main.go @@ -128,7 +128,7 @@ func main() { } // After the signing we finally call the AddInvokeTransaction in order to invoke the contract function - resp, err := accnt.AddTransaction(context.Background(), InvokeTx) + resp, err := accnt.SendTransaction(context.Background(), InvokeTx) if err != nil { setup.PanicRPC(err) } diff --git a/examples/simpleInvoke/main.go b/examples/simpleInvoke/main.go index 9f3a5b2d..1e9a2df9 100644 --- a/examples/simpleInvoke/main.go +++ b/examples/simpleInvoke/main.go @@ -120,7 +120,7 @@ func main() { } // After the signing we finally call the AddInvokeTransaction in order to invoke the contract function - resp, err := accnt.AddTransaction(context.Background(), InvokeTx) + resp, err := accnt.SendTransaction(context.Background(), InvokeTx) if err != nil { setup.PanicRPC(err) } From 3b3d684ed63ed2e3c093ba2c5f42c1a7c57d9ab3 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 15 Jul 2024 11:24:12 +0530 Subject: [PATCH 06/10] fix::> Removed type assertions, created generic TransactionResponse struct, and transaction type converter --- account/account.go | 41 ++++++++++++------------------ account/account_test.go | 8 +++--- examples/deployAccount/main.go | 4 +-- examples/deployContractUDC/main.go | 4 +-- examples/simpleInvoke/main.go | 4 +-- rpc/types_transaction_response.go | 31 ++++++++++++++++++---- 6 files changed, 52 insertions(+), 40 deletions(-) diff --git a/account/account.go b/account/account.go index 180e23ed..c8d222db 100644 --- a/account/account.go +++ b/account/account.go @@ -540,40 +540,31 @@ func (account *Account) WaitForTransactionReceipt(ctx context.Context, transacti // Returns: // - interface{} returns required Broadcast txn return value. // - error: an error if any. -func (account *Account) SendTransaction(ctx context.Context, txn rpc.BroadcastTxn) (interface{}, error) { +func (account *Account) SendTransaction(ctx context.Context, txn rpc.BroadcastTxn) (*rpc.TransactionResponse, error) { switch tx := txn.(type) { case rpc.BroadcastInvokeTxnType: - return account.provider.AddInvokeTransaction(ctx, tx) + resp, err := account.provider.AddInvokeTransaction(ctx, tx) + if err != nil { + return nil, err + } + return rpc.ConvertToTransactionResponse(resp), nil case rpc.BroadcastDeclareTxnType: - return account.provider.AddDeclareTransaction(ctx, tx) + resp, err := account.provider.AddDeclareTransaction(ctx, tx) + if err != nil { + return nil, err + } + return rpc.ConvertToTransactionResponse(resp), nil case rpc.BroadcastAddDeployTxnType: - return account.provider.AddDeployAccountTransaction(ctx, tx) + resp, err := account.provider.AddDeployAccountTransaction(ctx, tx) + if err != nil { + return nil, err + } + return rpc.ConvertToTransactionResponse(resp), nil default: return nil, errors.New("unsupported transaction type") } } -// func convertToTransactionResponse(resp interface{}) *rpc.TransactionResponse { -// switch r := resp.(type) { -// case *rpc.AddInvokeTransactionResponse: -// return &rpc.TransactionResponse{ -// TransactionHash: r.TransactionHash, -// } -// case *rpc.AddDeclareTransactionResponse: -// return &rpc.TransactionResponse{ -// TransactionHash: r.TransactionHash, -// ClassHash: r.ClassHash, -// } -// case *rpc.AddDeployAccountTransactionResponse: -// return &rpc.TransactionResponse{ -// TransactionHash: r.TransactionHash, -// ContractAddress: r.ContractAddress, -// } -// default: -// return nil -// } -// } - // BlockHashAndNumber returns the block hash and number for the account. // // Parameters: diff --git a/account/account_test.go b/account/account_test.go index d2ab4c09..bfef61d3 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -529,7 +529,7 @@ func TestAddInvoke(t *testing.T) { 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.(*rpc.AddInvokeTransactionResponse)) + require.Nil(t, resp) } } @@ -597,7 +597,7 @@ func TestAddDeployAccountDevnet(t *testing.T) { resp, err := acnt.SendTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx}) require.Nil(t, err, "AddDeployAccountTransaction gave an Error") - require.NotNil(t, resp.(*rpc.AddDeployAccountTransactionResponse), "AddDeployAccountTransaction resp not nil") + require.NotNil(t, resp, "AddDeployAccountTransaction resp not nil") } // TestTransactionHashDeclare tests the TransactionHashDeclare function. @@ -1180,8 +1180,8 @@ func TestAddDeclareTxn(t *testing.T) { if err != nil { require.Equal(t, rpc.ErrDuplicateTx.Error(), err.Error(), "AddDeclareTransaction error not what expected") } else { - require.Equal(t, expectedTxHash.String(), resp.(*rpc.AddDeclareTransactionResponse).TransactionHash.String(), "AddDeclareTransaction TxHash not what expected") - require.Equal(t, expectedClassHash.String(), resp.(*rpc.AddDeclareTransactionResponse).ClassHash.String(), "AddDeclareTransaction ClassHash not what expected") + require.Equal(t, expectedTxHash.String(), resp.TransactionHash.String(), "AddDeclareTransaction TxHash not what expected") + require.Equal(t, expectedClassHash.String(), resp.ClassHash.String(), "AddDeclareTransaction ClassHash not what expected") } } diff --git a/examples/deployAccount/main.go b/examples/deployAccount/main.go index cae67f6b..e013fc7c 100644 --- a/examples/deployAccount/main.go +++ b/examples/deployAccount/main.go @@ -129,6 +129,6 @@ func main() { } fmt.Println("AddDeployAccountTransaction successfully submitted! Wait a few minutes to see it in Voyager.") - fmt.Printf("Transaction hash: %v \n", resp.(*rpc.AddDeployAccountTransactionResponse).TransactionHash) - fmt.Printf("Contract address: %v \n", resp.(*rpc.AddDeployAccountTransactionResponse).ContractAddress) + fmt.Printf("Transaction hash: %v \n", resp.TransactionHash) + fmt.Printf("Contract address: %v \n", resp.ContractAddress) } diff --git a/examples/deployContractUDC/main.go b/examples/deployContractUDC/main.go index 95a08137..90f66e85 100644 --- a/examples/deployContractUDC/main.go +++ b/examples/deployContractUDC/main.go @@ -137,13 +137,13 @@ func main() { time.Sleep(time.Second * 3) // Waiting 3 seconds //Getting the transaction status - txStatus, err := client.GetTransactionStatus(context.Background(), resp.(*rpc.AddInvokeTransactionResponse).TransactionHash) + txStatus, err := client.GetTransactionStatus(context.Background(), resp.TransactionHash) if err != nil { setup.PanicRPC(err) } // This returns us with the transaction hash and status - fmt.Printf("Transaction hash response: %v\n", resp.(*rpc.AddInvokeTransactionResponse).TransactionHash) + fmt.Printf("Transaction hash response: %v\n", resp.TransactionHash) fmt.Printf("Transaction execution status: %s\n", txStatus.ExecutionStatus) fmt.Printf("Transaction status: %s\n", txStatus.FinalityStatus) } diff --git a/examples/simpleInvoke/main.go b/examples/simpleInvoke/main.go index 1e9a2df9..09be957e 100644 --- a/examples/simpleInvoke/main.go +++ b/examples/simpleInvoke/main.go @@ -129,13 +129,13 @@ func main() { time.Sleep(time.Second * 3) // Waiting 3 seconds //Getting the transaction status - txStatus, err := client.GetTransactionStatus(context.Background(), resp.(*rpc.AddInvokeTransactionResponse).TransactionHash) + txStatus, err := client.GetTransactionStatus(context.Background(), resp.TransactionHash) if err != nil { setup.PanicRPC(err) } // This returns us with the transaction hash and status - fmt.Printf("Transaction hash response: %v\n", resp.(*rpc.AddInvokeTransactionResponse).TransactionHash) + fmt.Printf("Transaction hash response: %v\n", resp.TransactionHash) fmt.Printf("Transaction execution status: %s\n", txStatus.ExecutionStatus) fmt.Printf("Transaction status: %s\n", txStatus.FinalityStatus) diff --git a/rpc/types_transaction_response.go b/rpc/types_transaction_response.go index 15920f94..5d0b319d 100644 --- a/rpc/types_transaction_response.go +++ b/rpc/types_transaction_response.go @@ -19,8 +19,29 @@ type AddInvokeTransactionResponse struct { TransactionHash *felt.Felt `json:"transaction_hash"` } -// type TransactionResponse struct { -// TransactionHash *felt.Felt `json:"transaction_hash"` -// ClassHash *felt.Felt `json:"class_hash"` -// ContractAddress *felt.Felt `json:"contract_address"` -// } +type TransactionResponse struct { + TransactionHash *felt.Felt `json:"transaction_hash"` + ClassHash *felt.Felt `json:"class_hash"` + ContractAddress *felt.Felt `json:"contract_address"` +} + +func ConvertToTransactionResponse(resp interface{}) *TransactionResponse { + switch r := resp.(type) { + case *AddInvokeTransactionResponse: + return &TransactionResponse{ + TransactionHash: r.TransactionHash, + } + case *AddDeclareTransactionResponse: + return &TransactionResponse{ + TransactionHash: r.TransactionHash, + ClassHash: r.ClassHash, + } + case *AddDeployAccountTransactionResponse: + return &TransactionResponse{ + TransactionHash: r.TransactionHash, + ContractAddress: r.ContractAddress, + } + default: + return nil + } +} From 762544c6eca3a8fc78f052206a804fa5c06c83e7 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Tue, 16 Jul 2024 17:19:57 +0530 Subject: [PATCH 07/10] fix::> removed unnecessary lines --- examples/deployAccount/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/deployAccount/main.go b/examples/deployAccount/main.go index e013fc7c..8f56d68c 100644 --- a/examples/deployAccount/main.go +++ b/examples/deployAccount/main.go @@ -121,7 +121,6 @@ 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: ") From 91be01a66134209e9609d5e9d2bd343fc74bd1a7 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 17 Jul 2024 20:23:23 +0530 Subject: [PATCH 08/10] fix:> made required changes --- account/account.go | 10 +++---- rpc/types_transaction_response.go | 44 +++++++++++++++---------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/account/account.go b/account/account.go index c8d222db..a12baede 100644 --- a/account/account.go +++ b/account/account.go @@ -536,9 +536,9 @@ func (account *Account) WaitForTransactionReceipt(ctx context.Context, transacti // // Parameters: // - ctx: the context.Context object for the transaction. -// - txn: this Broadcast Transaction to be sent. +// - txn: the Broadcast Transaction to be sent. // Returns: -// - interface{} returns required Broadcast txn return value. +// - *rpc.TransactionResponse: the transaction response. // - error: an error if any. func (account *Account) SendTransaction(ctx context.Context, txn rpc.BroadcastTxn) (*rpc.TransactionResponse, error) { switch tx := txn.(type) { @@ -547,19 +547,19 @@ func (account *Account) SendTransaction(ctx context.Context, txn rpc.BroadcastTx if err != nil { return nil, err } - return rpc.ConvertToTransactionResponse(resp), nil + 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.ConvertToTransactionResponse(resp), nil + 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.ConvertToTransactionResponse(resp), nil + return &rpc.TransactionResponse{TransactionHash: resp.TransactionHash, ContractAddress: resp.ContractAddress}, nil default: return nil, errors.New("unsupported transaction type") } diff --git a/rpc/types_transaction_response.go b/rpc/types_transaction_response.go index 5d0b319d..bfce40e1 100644 --- a/rpc/types_transaction_response.go +++ b/rpc/types_transaction_response.go @@ -21,27 +21,27 @@ type AddInvokeTransactionResponse struct { type TransactionResponse struct { TransactionHash *felt.Felt `json:"transaction_hash"` - ClassHash *felt.Felt `json:"class_hash"` - ContractAddress *felt.Felt `json:"contract_address"` + ClassHash *felt.Felt `json:"class_hash,omitempty"` + ContractAddress *felt.Felt `json:"contract_address,omitempty"` } -func ConvertToTransactionResponse(resp interface{}) *TransactionResponse { - switch r := resp.(type) { - case *AddInvokeTransactionResponse: - return &TransactionResponse{ - TransactionHash: r.TransactionHash, - } - case *AddDeclareTransactionResponse: - return &TransactionResponse{ - TransactionHash: r.TransactionHash, - ClassHash: r.ClassHash, - } - case *AddDeployAccountTransactionResponse: - return &TransactionResponse{ - TransactionHash: r.TransactionHash, - ContractAddress: r.ContractAddress, - } - default: - return nil - } -} +// func ConvertToTransactionResponse(resp interface{}) *TransactionResponse { +// switch r := resp.(type) { +// case *AddInvokeTransactionResponse: +// return &TransactionResponse{ +// TransactionHash: r.TransactionHash, +// } +// case *AddDeclareTransactionResponse: +// return &TransactionResponse{ +// TransactionHash: r.TransactionHash, +// ClassHash: r.ClassHash, +// } +// case *AddDeployAccountTransactionResponse: +// return &TransactionResponse{ +// TransactionHash: r.TransactionHash, +// ContractAddress: r.ContractAddress, +// } +// default: +// return nil +// } +// } From b9d9980a16cac2ba185993c1438312e12e7bad3b Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Thu, 18 Jul 2024 11:23:41 +0530 Subject: [PATCH 09/10] fix::> removed unnecessary comments --- rpc/types_transaction_response.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/rpc/types_transaction_response.go b/rpc/types_transaction_response.go index bfce40e1..cf4fd33d 100644 --- a/rpc/types_transaction_response.go +++ b/rpc/types_transaction_response.go @@ -24,24 +24,3 @@ type TransactionResponse struct { ClassHash *felt.Felt `json:"class_hash,omitempty"` ContractAddress *felt.Felt `json:"contract_address,omitempty"` } - -// func ConvertToTransactionResponse(resp interface{}) *TransactionResponse { -// switch r := resp.(type) { -// case *AddInvokeTransactionResponse: -// return &TransactionResponse{ -// TransactionHash: r.TransactionHash, -// } -// case *AddDeclareTransactionResponse: -// return &TransactionResponse{ -// TransactionHash: r.TransactionHash, -// ClassHash: r.ClassHash, -// } -// case *AddDeployAccountTransactionResponse: -// return &TransactionResponse{ -// TransactionHash: r.TransactionHash, -// ContractAddress: r.ContractAddress, -// } -// default: -// return nil -// } -// } From 0b5ac0b8395747415983043421dce802f6cbda98 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Fri, 19 Jul 2024 12:17:49 +0530 Subject: [PATCH 10/10] fix::> renamed test function --- account/account_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/account/account_test.go b/account/account_test.go index bfef61d3..b254d04d 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -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 @@ -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") } @@ -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") }