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

chore::> Change input type of SignInvokeTransaction, SignDeployAccountTransaction, and SignDeclareTransaction #591

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
12 changes: 6 additions & 6 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ type AccountInterface interface {
TransactionHashInvoke(invokeTxn rpc.InvokeTxnType) (*felt.Felt, error)
TransactionHashDeployAccount(tx rpc.DeployAccountType, contractAddress *felt.Felt) (*felt.Felt, error)
TransactionHashDeclare(tx rpc.DeclareTxnType) (*felt.Felt, error)
SignInvokeTransaction(ctx context.Context, tx *rpc.InvokeTxnV1) error
SignDeployAccountTransaction(ctx context.Context, tx *rpc.DeployAccountTxn, precomputeAddress *felt.Felt) error
SignDeclareTransaction(ctx context.Context, tx *rpc.DeclareTxnV2) error
SignInvokeTransaction(ctx context.Context, tx *rpc.BroadcastInvokev1Txn) error
PsychoPunkSage marked this conversation as resolved.
Show resolved Hide resolved
SignDeployAccountTransaction(ctx context.Context, tx *rpc.BroadcastDeployAccountTxn, precomputeAddress *felt.Felt) error
SignDeclareTransaction(ctx context.Context, tx *rpc.BroadcastDeclareTxnV2) error
PrecomputeAccountAddress(salt *felt.Felt, classHash *felt.Felt, constructorCalldata []*felt.Felt) (*felt.Felt, error)
WaitForTransactionReceipt(ctx context.Context, transactionHash *felt.Felt, pollInterval time.Duration) (*rpc.TransactionReceiptWithBlockInfo, error)
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func (account *Account) Sign(ctx context.Context, msg *felt.Felt) ([]*felt.Felt,
// - invokeTx: the InvokeTxnV1 struct representing the transaction to be invoked.
// Returns:
// - error: an error if there was an error in the signing or invoking process
func (account *Account) SignInvokeTransaction(ctx context.Context, invokeTx *rpc.InvokeTxnV1) error {
func (account *Account) SignInvokeTransaction(ctx context.Context, invokeTx *rpc.BroadcastInvokev1Txn) error {

txHash, err := account.TransactionHashInvoke(*invokeTx)
if err != nil {
Expand All @@ -130,7 +130,7 @@ func (account *Account) SignInvokeTransaction(ctx context.Context, invokeTx *rpc
// - precomputeAddress: the precomputed address for the transaction
// Returns:
// - error: an error if any
func (account *Account) SignDeployAccountTransaction(ctx context.Context, tx *rpc.DeployAccountTxn, precomputeAddress *felt.Felt) error {
func (account *Account) SignDeployAccountTransaction(ctx context.Context, tx *rpc.BroadcastDeployAccountTxn, precomputeAddress *felt.Felt) error {

hash, err := account.TransactionHashDeployAccount(*tx, precomputeAddress)
if err != nil {
Expand All @@ -151,7 +151,7 @@ func (account *Account) SignDeployAccountTransaction(ctx context.Context, tx *rp
// - tx: the *rpc.DeclareTxnV2
// Returns:
// - error: an error if any
func (account *Account) SignDeclareTransaction(ctx context.Context, tx *rpc.DeclareTxnV2) error {
func (account *Account) SignDeclareTransaction(ctx context.Context, tx *rpc.BroadcastDeclareTxnV2) error {

hash, err := account.TransactionHashDeclare(*tx)
if err != nil {
Expand Down
49 changes: 26 additions & 23 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func TestAddInvoke(t *testing.T) {
test.InvokeTx.Calldata, err = acnt.FmtCalldata([]rpc.FunctionCall{test.FnCall})
require.NoError(t, err)

err = acnt.SignInvokeTransaction(context.Background(), &test.InvokeTx.InvokeTxnV1)
err = acnt.SignInvokeTransaction(context.Background(), &test.InvokeTx)
require.NoError(t, err)

resp, err := acnt.AddInvokeTransaction(context.Background(), test.InvokeTx)
Expand Down Expand Up @@ -590,7 +590,7 @@ func TestAddDeployAccountDevnet(t *testing.T) {

precomputedAddress, err := acnt.PrecomputeAccountAddress(fakeUserPub, classHash, tx.ConstructorCalldata)
require.Nil(t, err)
require.NoError(t, acnt.SignDeployAccountTransaction(context.Background(), &tx, precomputedAddress))
require.NoError(t, acnt.SignDeployAccountTransaction(context.Background(), &rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx}, precomputedAddress))

_, err = devnet.Mint(precomputedAddress, new(big.Int).SetUint64(10000000000000000000))
require.NoError(t, err)
Expand Down Expand Up @@ -1147,32 +1147,35 @@ func TestAddDeclareTxn(t *testing.T) {
require.NoError(t, err)
compClassHash := hash.CompiledClassHash(casmClass)

tx := rpc.DeclareTxnV2{
Nonce: utils.TestHexToFelt(t, "0xd"),
MaxFee: utils.TestHexToFelt(t, "0xc5cb22092551"),
Type: rpc.TransactionType_Declare,
Version: rpc.TransactionV2,
Signature: []*felt.Felt{
utils.TestHexToFelt(t, "0x2975276c978f3cfbfa621b71085a910fe92ec32ba5995d8d70cfdd9c6db0ece"),
utils.TestHexToFelt(t, "0x2f6eb4f42809ae38c8dfea82018451330ddcb276b63dde3ca8c64815e8f2fc0"),
},
SenderAddress: AccountAddress,
CompiledClassHash: compClassHash,
ClassHash: classHash,
}
tx := rpc.BroadcastDeclareTxnV2{
DeclareTxnV2: rpc.DeclareTxnV2{
Nonce: utils.TestHexToFelt(t, "0xd"),
MaxFee: utils.TestHexToFelt(t, "0xc5cb22092551"),
Type: rpc.TransactionType_Declare,
Version: rpc.TransactionV2,
Signature: []*felt.Felt{
utils.TestHexToFelt(t, "0x2975276c978f3cfbfa621b71085a910fe92ec32ba5995d8d70cfdd9c6db0ece"),
utils.TestHexToFelt(t, "0x2f6eb4f42809ae38c8dfea82018451330ddcb276b63dde3ca8c64815e8f2fc0"),
},
SenderAddress: AccountAddress,
CompiledClassHash: compClassHash,
ClassHash: classHash,
}}

err = acnt.SignDeclareTransaction(context.Background(), &tx)
require.NoError(t, err)

broadcastTx := rpc.BroadcastDeclareTxnV2{
Nonce: tx.Nonce,
MaxFee: tx.MaxFee,
Type: tx.Type,
Version: tx.Version,
Signature: tx.Signature,
SenderAddress: tx.SenderAddress,
CompiledClassHash: tx.CompiledClassHash,
ContractClass: class,
DeclareTxnV2: rpc.DeclareTxnV2{
Nonce: tx.Nonce,
MaxFee: tx.MaxFee,
Type: tx.Type,
Version: tx.Version,
Signature: tx.Signature,
SenderAddress: tx.SenderAddress,
CompiledClassHash: tx.CompiledClassHash,
},
ContractClass: class,
}

resp, err := acnt.AddDeclareTransaction(context.Background(), broadcastTx)
Expand Down
4 changes: 2 additions & 2 deletions examples/deployAccount/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func main() {
fmt.Println("PrecomputedAddress:", precomputedAddress)

// Sign the transaction
err = accnt.SignDeployAccountTransaction(context.Background(), &tx.DeployAccountTxn, precomputedAddress)
err = accnt.SignDeployAccountTransaction(context.Background(), &tx, precomputedAddress)
if err != nil {
panic(err)
}
Expand All @@ -100,7 +100,7 @@ func main() {
}
tx.MaxFee = new(felt.Felt).SetUint64(newFee + newFee/5) // fee + 20% to be sure
// Signing the transaction again
err = accnt.SignDeployAccountTransaction(context.Background(), &tx.DeployAccountTxn, precomputedAddress)
err = accnt.SignDeployAccountTransaction(context.Background(), &tx, precomputedAddress)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/deployContractUDC/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func main() {
}

// Sign the transaction
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx.InvokeTxnV1)
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx)
if err != nil {
panic(err)
}
Expand All @@ -121,7 +121,7 @@ func main() {
}
InvokeTx.MaxFee = new(felt.Felt).SetUint64(newFee + newFee/5) // fee + 20% to be sure
// Signing the transaction again
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx.InvokeTxnV1)
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/simpleInvoke/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func main() {
}

// Signing of the transaction that is done by the account
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx.InvokeTxnV1)
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx)
if err != nil {
panic(err)
}
Expand All @@ -113,7 +113,7 @@ func main() {
}
InvokeTx.MaxFee = new(felt.Felt).SetUint64(newFee + newFee/5) // fee + 20% to be sure
// Signing the transaction again
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx.InvokeTxnV1)
err = accnt.SignInvokeTransaction(context.Background(), &InvokeTx)
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions mocks/mock_account.go

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

11 changes: 2 additions & 9 deletions rpc/types_broadcast_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,8 @@ func (tx BroadcastDeclareTxnV1) GetContractClass() interface{} {
}

type BroadcastDeclareTxnV2 struct {
Type TransactionType `json:"type"`
// SenderAddress the address of the account contract sending the declaration transaction
SenderAddress *felt.Felt `json:"sender_address"`
CompiledClassHash *felt.Felt `json:"compiled_class_hash"`
MaxFee *felt.Felt `json:"max_fee"`
Version TransactionVersion `json:"version"`
Signature []*felt.Felt `json:"signature"`
Nonce *felt.Felt `json:"nonce"`
ContractClass ContractClass `json:"contract_class"`
DeclareTxnV2
PsychoPunkSage marked this conversation as resolved.
Show resolved Hide resolved
ContractClass ContractClass `json:"contract_class"`
}

func (tx BroadcastDeclareTxnV2) GetContractClass() interface{} {
Expand Down
Loading