diff --git a/account/account.go b/account/account.go index 1607e34b..baae79b6 100644 --- a/account/account.go +++ b/account/account.go @@ -3,6 +3,7 @@ package account import ( "context" "errors" + "fmt" "time" "github.com/NethermindEth/juno/core/crypto" @@ -29,12 +30,12 @@ var ( //go:generate mockgen -destination=../mocks/mock_account.go -package=mocks -source=account.go AccountInterface type AccountInterface interface { Sign(ctx context.Context, msg *felt.Felt) ([]*felt.Felt, error) - 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 + TransactionHashInvoke(invokeTxn rpc.BroadcastInvokeTxnType) (*felt.Felt, error) + TransactionHashDeployAccount(tx rpc.BroadcastAddDeployTxnType, contractAddress *felt.Felt) (*felt.Felt, error) + TransactionHashDeclare(tx rpc.BroadcastDeclareTxnType) (*felt.Felt, error) + SignInvokeTransaction(ctx context.Context, tx rpc.BroadcastInvokeTxnType) error + SignDeployAccountTransaction(ctx context.Context, tx rpc.BroadcastAddDeployTxnType, precomputeAddress *felt.Felt) error + SignDeclareTransaction(ctx context.Context, tx rpc.BroadcastDeclareTxnType) 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) } @@ -108,9 +109,9 @@ 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.BroadcastInvokeTxnType) error { - txHash, err := account.TransactionHashInvoke(*invokeTx) + txHash, err := account.TransactionHashInvoke(invokeTx) if err != nil { return err } @@ -118,7 +119,17 @@ func (account *Account) SignInvokeTransaction(ctx context.Context, invokeTx *rpc if err != nil { return err } - invokeTx.Signature = signature + + switch tx := (invokeTx).(type) { + case rpc.BroadcastInvokev0Txn: + tx.Signature = signature + case rpc.BroadcastInvokev1Txn: + tx.Signature = signature + case rpc.BroadcastInvokev3Txn: + tx.Signature = signature + default: + return fmt.Errorf("unsupported (invoke) transaction type: %v", tx) + } return nil } @@ -130,9 +141,9 @@ 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, deployAccountTx rpc.BroadcastAddDeployTxnType, precomputeAddress *felt.Felt) error { - hash, err := account.TransactionHashDeployAccount(*tx, precomputeAddress) + hash, err := account.TransactionHashDeployAccount(deployAccountTx, precomputeAddress) if err != nil { return err } @@ -140,7 +151,15 @@ func (account *Account) SignDeployAccountTransaction(ctx context.Context, tx *rp if err != nil { return err } - tx.Signature = signature + + switch tx := (deployAccountTx).(type) { + case rpc.BroadcastDeployAccountTxn: + tx.Signature = signature + case rpc.BroadcastDeployAccountTxnV3: + tx.Signature = signature + default: + return fmt.Errorf("unsupported (deploy account) transaction type: %v", tx) + } return nil } @@ -151,9 +170,9 @@ 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, declareTx rpc.BroadcastDeclareTxnType) error { - hash, err := account.TransactionHashDeclare(*tx) + hash, err := account.TransactionHashDeclare(declareTx) if err != nil { return err } @@ -161,7 +180,17 @@ func (account *Account) SignDeclareTransaction(ctx context.Context, tx *rpc.Decl if err != nil { return err } - tx.Signature = signature + + switch tx := (declareTx).(type) { + case rpc.BroadcastDeclareTxnV1: + tx.Signature = signature + case rpc.BroadcastDeclareTxnV2: + tx.Signature = signature + case rpc.BroadcastDeclareTxnV3: + tx.Signature = signature + default: + return fmt.Errorf("unsupported (declare) transaction type: %v", tx) + } return nil } @@ -173,11 +202,11 @@ func (account *Account) SignDeclareTransaction(ctx context.Context, tx *rpc.Decl // Returns: // - *felt.Felt: the calculated transaction hash // - error: an error if any -func (account *Account) TransactionHashDeployAccount(tx rpc.DeployAccountType, contractAddress *felt.Felt) (*felt.Felt, error) { +func (account *Account) TransactionHashDeployAccount(tx rpc.BroadcastAddDeployTxnType, contractAddress *felt.Felt) (*felt.Felt, error) { // https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/transactions/#deploy_account_transaction switch txn := tx.(type) { - case rpc.DeployAccountTxn: + case rpc.BroadcastDeployAccountTxn: calldata := []*felt.Felt{txn.ClassHash, txn.ContractAddressSalt} calldata = append(calldata, txn.ConstructorCalldata...) calldataHash, err := hash.ComputeHashOnElementsFelt(calldata) @@ -201,7 +230,7 @@ func (account *Account) TransactionHashDeployAccount(tx rpc.DeployAccountType, c account.ChainId, []*felt.Felt{txn.Nonce}, ) - case rpc.DeployAccountTxnV3: + case rpc.BroadcastDeployAccountTxnV3: if txn.Version == "" || txn.ResourceBounds == (rpc.ResourceBoundsMapping{}) || txn.Nonce == nil || txn.PayMasterData == nil { return nil, ErrNotAllParametersSet } @@ -256,11 +285,11 @@ func (account *Account) TransactionHashDeployAccount(tx rpc.DeployAccountType, c // - error: an error, if any // If the transaction type is unsupported, the function returns an error. -func (account *Account) TransactionHashInvoke(tx rpc.InvokeTxnType) (*felt.Felt, error) { +func (account *Account) TransactionHashInvoke(tx rpc.BroadcastInvokeTxnType) (*felt.Felt, error) { // https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/transactions/#v0_hash_calculation switch txn := tx.(type) { - case rpc.InvokeTxnV0: + case rpc.BroadcastInvokev0Txn: if txn.Version == "" || len(txn.Calldata) == 0 || txn.MaxFee == nil || txn.EntryPointSelector == nil { return nil, ErrNotAllParametersSet } @@ -285,7 +314,7 @@ func (account *Account) TransactionHashInvoke(tx rpc.InvokeTxnType) (*felt.Felt, []*felt.Felt{}, ) - case rpc.InvokeTxnV1: + case rpc.BroadcastInvokev1Txn: if txn.Version == "" || len(txn.Calldata) == 0 || txn.Nonce == nil || txn.MaxFee == nil || txn.SenderAddress == nil { return nil, ErrNotAllParametersSet } @@ -308,7 +337,7 @@ func (account *Account) TransactionHashInvoke(tx rpc.InvokeTxnType) (*felt.Felt, account.ChainId, []*felt.Felt{txn.Nonce}, ) - case rpc.InvokeTxnV3: + case rpc.BroadcastInvokev3Txn: // https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-8.md#protocol-changes if txn.Version == "" || txn.ResourceBounds == (rpc.ResourceBoundsMapping{}) || len(txn.Calldata) == 0 || txn.Nonce == nil || txn.SenderAddress == nil || txn.PayMasterData == nil || txn.AccountDeploymentData == nil { return nil, ErrNotAllParametersSet @@ -387,42 +416,25 @@ func dataAvailabilityMode(feeDAMode, nonceDAMode rpc.DataAvailabilityMode) (uint // - error: an error, if any // // If the `tx` parameter is not one of the supported types, the function returns an error `ErrTxnTypeUnSupported`. -func (account *Account) TransactionHashDeclare(tx rpc.DeclareTxnType) (*felt.Felt, error) { +func (account *Account) TransactionHashDeclare(tx rpc.BroadcastDeclareTxnType) (*felt.Felt, error) { switch txn := tx.(type) { - case rpc.DeclareTxnV0: - // Due to inconsistencies in version 0 hash calculation we don't calculate the hash - return nil, ErrTxnVersionUnSupported - case rpc.DeclareTxnV1: - if txn.SenderAddress == nil || txn.Version == "" || txn.ClassHash == nil || txn.MaxFee == nil || txn.Nonce == nil { + case rpc.BroadcastDeclareTxnV1: + if txn.ContractClass.Program == "" || txn.SenderAddress == nil || txn.Version == "" || txn.MaxFee == nil || txn.Nonce == nil { return nil, ErrNotAllParametersSet } - calldataHash, err := hash.ComputeHashOnElementsFelt([]*felt.Felt{txn.ClassHash}) - if err != nil { - return nil, err + case rpc.BroadcastDeclareTxnV2: + if txn.ContractClass.SierraProgram == nil || txn.CompiledClassHash == nil || txn.SenderAddress == nil || txn.Version == "" || txn.MaxFee == nil || txn.Nonce == nil { + return nil, ErrNotAllParametersSet } - txnVersionFelt, err := new(felt.Felt).SetString(string(txn.Version)) + classHash, err := hash.ClassHash(txn.ContractClass) if err != nil { return nil, err } - return hash.CalculateTransactionHashCommon( - PREFIX_DECLARE, - txnVersionFelt, - txn.SenderAddress, - &felt.Zero, - calldataHash, - txn.MaxFee, - account.ChainId, - []*felt.Felt{txn.Nonce}, - ) - case rpc.DeclareTxnV2: - if txn.CompiledClassHash == nil || txn.SenderAddress == nil || txn.Version == "" || txn.ClassHash == nil || txn.MaxFee == nil || txn.Nonce == nil { - return nil, ErrNotAllParametersSet - } - calldataHash, err := hash.ComputeHashOnElementsFelt([]*felt.Felt{txn.ClassHash}) + calldataHash, err := hash.ComputeHashOnElementsFelt([]*felt.Felt{classHash}) if err != nil { return nil, err } @@ -441,9 +453,9 @@ func (account *Account) TransactionHashDeclare(tx rpc.DeclareTxnType) (*felt.Fel account.ChainId, []*felt.Felt{txn.Nonce, txn.CompiledClassHash}, ) - case rpc.DeclareTxnV3: + case rpc.BroadcastDeclareTxnV3: // https://github.com/starknet-io/SNIPs/blob/main/SNIPS/snip-8.md#protocol-changes - if txn.Version == "" || txn.ResourceBounds == (rpc.ResourceBoundsMapping{}) || txn.Nonce == nil || txn.SenderAddress == nil || txn.PayMasterData == nil || txn.AccountDeploymentData == nil || + if txn.ContractClass.SierraProgram == nil || txn.Version == "" || txn.ResourceBounds == (rpc.ResourceBoundsMapping{}) || txn.Nonce == nil || txn.SenderAddress == nil || txn.PayMasterData == nil || txn.AccountDeploymentData == nil || txn.ClassHash == nil || txn.CompiledClassHash == nil { return nil, ErrNotAllParametersSet } diff --git a/account/account_test.go b/account/account_test.go index 0e0a36df..3b16aeb7 100644 --- a/account/account_test.go +++ b/account/account_test.go @@ -167,14 +167,14 @@ func TestTransactionHashInvoke(t *testing.T) { account, err := account.NewAccount(mockRpcProvider, test.AccountAddress, test.PubKey, ks, 0) require.NoError(t, err, "error returned from account.NewAccount()") invokeTxn := rpc.BroadcastInvokev1Txn{ - InvokeTxnV1: rpc.InvokeTxnV1{ + InvokeTxnV1: &rpc.InvokeTxnV1{ Calldata: test.FnCall.Calldata, Nonce: test.TxDetails.Nonce, MaxFee: test.TxDetails.MaxFee, SenderAddress: account.AccountAddress, Version: test.TxDetails.Version, }} - hash, err := account.TransactionHashInvoke(invokeTxn.InvokeTxnV1) + hash, err := account.TransactionHashInvoke(invokeTxn) require.NoError(t, err, "error returned from account.TransactionHash()") require.Equal(t, test.ExpectedHash.String(), hash.String(), "transaction hash does not match expected") }) @@ -462,7 +462,7 @@ func TestAddInvoke(t *testing.T) { PubKey: utils.TestHexToFelt(t, "0x022288424ec8116c73d2e2ed3b0663c5030d328d9c0fb44c2b54055db467f31e"), PrivKey: utils.TestHexToFelt(t, "0x04818374f8071c3b4c3070ff7ce766e7b9352628df7b815ea4de26e0fadb5cc9"), // InvokeTx: rpc.BroadcastInvokev1Txn{ - InvokeTxnV1: rpc.InvokeTxnV1{ + InvokeTxnV1: &rpc.InvokeTxnV1{ Nonce: new(felt.Felt).SetUint64(5), MaxFee: utils.TestHexToFelt(t, "0x26112A960026"), Version: rpc.TransactionV1, @@ -486,7 +486,7 @@ func TestAddInvoke(t *testing.T) { PubKey: utils.TestHexToFelt(t, "0x022288424ec8116c73d2e2ed3b0663c5030d328d9c0fb44c2b54055db467f31e"), PrivKey: utils.TestHexToFelt(t, "0x04818374f8071c3b4c3070ff7ce766e7b9352628df7b815ea4de26e0fadb5cc9"), InvokeTx: rpc.BroadcastInvokev1Txn{ - InvokeTxnV1: rpc.InvokeTxnV1{ + InvokeTxnV1: &rpc.InvokeTxnV1{ Nonce: new(felt.Felt).SetUint64(8), MaxFee: utils.TestHexToFelt(t, "0x1f6410500832"), Version: rpc.TransactionV1, @@ -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) @@ -590,12 +590,12 @@ 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) - resp, err := acnt.AddDeployAccountTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: tx}) + resp, err := acnt.AddDeployAccountTransaction(context.Background(), rpc.BroadcastDeployAccountTxn{DeployAccountTxn: &tx}) require.Nil(t, err, "AddDeployAccountTransaction gave an Error") require.NotNil(t, resp, "AddDeployAccountTransaction resp not nil") } @@ -629,7 +629,8 @@ func TestTransactionHashDeclare(t *testing.T) { require.NoError(t, err) type testSetType struct { - Txn rpc.DeclareTxnType + // Txn rpc.DeclareTxnType + Txn rpc.BroadcastDeclareTxnType ExpectedHash *felt.Felt ExpectedErr error } @@ -637,7 +638,7 @@ func TestTransactionHashDeclare(t *testing.T) { "mock": { { // https://sepolia.voyager.online/tx/0x28e430cc73715bd1052e8db4f17b053c53dd8174341cba4b1a337b9fecfa8c3 - Txn: rpc.DeclareTxnV2{ + Txn: rpc.BroadcastDeclareTxnV2{ Nonce: utils.TestHexToFelt(t, "0x1"), Type: rpc.TransactionType_Declare, Version: rpc.TransactionV2, @@ -646,8 +647,8 @@ func TestTransactionHashDeclare(t *testing.T) { utils.TestHexToFelt(t, "0x4f28b1c15379c0ceb1855c09ed793e7583f875a802cbf310a8c0c971835c5cf")}, SenderAddress: utils.TestHexToFelt(t, "0x0019bd7ebd72368deb5f160f784e21aa46cd09e06a61dc15212456b5597f47b8"), CompiledClassHash: utils.TestHexToFelt(t, "0x017f655f7a639a49ea1d8d56172e99cff8b51f4123b733f0378dfd6378a2cd37"), - ClassHash: utils.TestHexToFelt(t, "0x01f372292df22d28f2d4c5798734421afe9596e6a566b8bc9b7b50e26521b855"), - MaxFee: utils.TestHexToFelt(t, "0x177e06ff6cab2"), + // ClassHash: utils.TestHexToFelt(t, "0x01f372292df22d28f2d4c5798734421afe9596e6a566b8bc9b7b50e26521b855"), + MaxFee: utils.TestHexToFelt(t, "0x177e06ff6cab2"), }, ExpectedHash: utils.TestHexToFelt(t, "0x28e430cc73715bd1052e8db4f17b053c53dd8174341cba4b1a337b9fecfa8c3"), ExpectedErr: nil, @@ -656,7 +657,7 @@ func TestTransactionHashDeclare(t *testing.T) { "testnet": { { // https://sepolia.voyager.online/tx/0x28e430cc73715bd1052e8db4f17b053c53dd8174341cba4b1a337b9fecfa8c3 - Txn: rpc.DeclareTxnV2{ + Txn: rpc.BroadcastDeclareTxnV2{ Nonce: utils.TestHexToFelt(t, "0x1"), Type: rpc.TransactionType_Declare, Version: rpc.TransactionV2, @@ -665,8 +666,8 @@ func TestTransactionHashDeclare(t *testing.T) { utils.TestHexToFelt(t, "0x4f28b1c15379c0ceb1855c09ed793e7583f875a802cbf310a8c0c971835c5cf")}, SenderAddress: utils.TestHexToFelt(t, "0x0019bd7ebd72368deb5f160f784e21aa46cd09e06a61dc15212456b5597f47b8"), CompiledClassHash: utils.TestHexToFelt(t, "0x017f655f7a639a49ea1d8d56172e99cff8b51f4123b733f0378dfd6378a2cd37"), - ClassHash: utils.TestHexToFelt(t, "0x01f372292df22d28f2d4c5798734421afe9596e6a566b8bc9b7b50e26521b855"), - MaxFee: utils.TestHexToFelt(t, "0x177e06ff6cab2"), + // ClassHash: utils.TestHexToFelt(t, "0x01f372292df22d28f2d4c5798734421afe9596e6a566b8bc9b7b50e26521b855"), + MaxFee: utils.TestHexToFelt(t, "0x177e06ff6cab2"), }, ExpectedHash: utils.TestHexToFelt(t, "0x28e430cc73715bd1052e8db4f17b053c53dd8174341cba4b1a337b9fecfa8c3"), ExpectedErr: nil, @@ -691,7 +692,7 @@ func TestTransactionHashInvokeV3(t *testing.T) { require.NoError(t, err) type testSetType struct { - Txn rpc.DeclareTxnType + Txn rpc.BroadcastInvokeTxnType ExpectedHash *felt.Felt ExpectedErr error } @@ -699,55 +700,56 @@ func TestTransactionHashInvokeV3(t *testing.T) { "mock": { { // https://sepolia.voyager.online/tx/0x8eb1104170ec42fd27c09ea78822dfb083ddd15324480f856bff01bc65e9d9 - Txn: rpc.InvokeTxnV3{ - Nonce: utils.TestHexToFelt(t, "0x12eaa"), - Type: rpc.TransactionType_Invoke, - Version: rpc.TransactionV3, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x7121c34d7073fd21b73801000278883b332a6f8cdf90d7a84358748de811480"), - utils.TestHexToFelt(t, "0x3df8c38724b89e9baa8dc0d0cb8fd14a8ca65308d7ca831793cc67394803b6c")}, - ResourceBounds: rpc.ResourceBoundsMapping{ - L1Gas: rpc.ResourceBounds{ - MaxAmount: "0x2b", - MaxPricePerUnit: "0x2eb31cc948ef", - }, - L2Gas: rpc.ResourceBounds{ - MaxAmount: "0x0", - MaxPricePerUnit: "0x0", + Txn: rpc.BroadcastInvokev3Txn{ + InvokeTxnV3: &rpc.InvokeTxnV3{ + Nonce: utils.TestHexToFelt(t, "0x12eaa"), + Type: rpc.TransactionType_Invoke, + Version: rpc.TransactionV3, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x7121c34d7073fd21b73801000278883b332a6f8cdf90d7a84358748de811480"), + utils.TestHexToFelt(t, "0x3df8c38724b89e9baa8dc0d0cb8fd14a8ca65308d7ca831793cc67394803b6c")}, + ResourceBounds: rpc.ResourceBoundsMapping{ + L1Gas: rpc.ResourceBounds{ + MaxAmount: "0x2b", + MaxPricePerUnit: "0x2eb31cc948ef", + }, + L2Gas: rpc.ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, }, - }, - Tip: "0x0", - PayMasterData: []*felt.Felt{}, - AccountDeploymentData: []*felt.Felt{}, - SenderAddress: utils.TestHexToFelt(t, "0x1d091b30a2d20ca2509579f8beae26934bfdc3725c0b497f50b353b7a3c636f"), - Calldata: utils.TestHexArrToFelt(t, []string{ - "0x1", - "0x132303a40ae2f271f4e1b707596a63f6f2921c4d400b38822548ed1bb0cbe0", - "0xc844fd57777b0cd7e75c8ea68deec0adf964a6308da7a58de32364b7131cc8", - "0x13", - "0x46f1db039a8aa6edb473195b98421579517d79bbe026e74bbc3f172af0798", - "0x1c4104", - "0xde9f47f476fed1e72a6159aba4f458ac74cbbbf88a951758a1fc0276e27211", - "0x66417c6a", - "0x104030200000000000000000000000000000000000000000000000000000000", - "0x4", - "0x431d563dc0", - "0x4329326f60", - "0x432cdda6a2", - "0x433403bcd6", - "0xbc2ee78d0e41b9dd1", - "0x1", - "0x2", - "0x75a8626edb90cc9983ae1dfca05c485c8ca6ca507f925ac8f28366aa8d7c211", - "0x83b812e83b07feb3e898aa55db8552138580d63e4f827e28e2531bd308db29", - "0x2e7dc996ebf724c1cf18d668fc3455df4245749ebc0724101cbc6c9cb13c962", - "0x49e384b4c21fbb10318f461c7804432e068c7ff196647b4f3b470b4431c40e6", - "0x2389f278922589f5f5d39b17339dc7ef80f13c8eb20b173c9eba52503c60874", - "0x4225d1c8ee8e451a25e30c10689ef898e11ccf5c0f68d0fc7876c47b318e946", - }), - NonceDataMode: rpc.DAModeL1, - FeeMode: rpc.DAModeL1, - }, + Tip: "0x0", + PayMasterData: []*felt.Felt{}, + AccountDeploymentData: []*felt.Felt{}, + SenderAddress: utils.TestHexToFelt(t, "0x1d091b30a2d20ca2509579f8beae26934bfdc3725c0b497f50b353b7a3c636f"), + Calldata: utils.TestHexArrToFelt(t, []string{ + "0x1", + "0x132303a40ae2f271f4e1b707596a63f6f2921c4d400b38822548ed1bb0cbe0", + "0xc844fd57777b0cd7e75c8ea68deec0adf964a6308da7a58de32364b7131cc8", + "0x13", + "0x46f1db039a8aa6edb473195b98421579517d79bbe026e74bbc3f172af0798", + "0x1c4104", + "0xde9f47f476fed1e72a6159aba4f458ac74cbbbf88a951758a1fc0276e27211", + "0x66417c6a", + "0x104030200000000000000000000000000000000000000000000000000000000", + "0x4", + "0x431d563dc0", + "0x4329326f60", + "0x432cdda6a2", + "0x433403bcd6", + "0xbc2ee78d0e41b9dd1", + "0x1", + "0x2", + "0x75a8626edb90cc9983ae1dfca05c485c8ca6ca507f925ac8f28366aa8d7c211", + "0x83b812e83b07feb3e898aa55db8552138580d63e4f827e28e2531bd308db29", + "0x2e7dc996ebf724c1cf18d668fc3455df4245749ebc0724101cbc6c9cb13c962", + "0x49e384b4c21fbb10318f461c7804432e068c7ff196647b4f3b470b4431c40e6", + "0x2389f278922589f5f5d39b17339dc7ef80f13c8eb20b173c9eba52503c60874", + "0x4225d1c8ee8e451a25e30c10689ef898e11ccf5c0f68d0fc7876c47b318e946", + }), + NonceDataMode: rpc.DAModeL1, + FeeMode: rpc.DAModeL1, + }}, ExpectedHash: utils.TestHexToFelt(t, "0x8eb1104170ec42fd27c09ea78822dfb083ddd15324480f856bff01bc65e9d9"), ExpectedErr: nil, }, @@ -755,55 +757,56 @@ func TestTransactionHashInvokeV3(t *testing.T) { "testnet": { { // https://sepolia.voyager.online/tx/0x8eb1104170ec42fd27c09ea78822dfb083ddd15324480f856bff01bc65e9d9 - Txn: rpc.InvokeTxnV3{ - Nonce: utils.TestHexToFelt(t, "0x12eaa"), - Type: rpc.TransactionType_Invoke, - Version: rpc.TransactionV3, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x7121c34d7073fd21b73801000278883b332a6f8cdf90d7a84358748de811480"), - utils.TestHexToFelt(t, "0x3df8c38724b89e9baa8dc0d0cb8fd14a8ca65308d7ca831793cc67394803b6c")}, - ResourceBounds: rpc.ResourceBoundsMapping{ - L1Gas: rpc.ResourceBounds{ - MaxAmount: "0x2b", - MaxPricePerUnit: "0x2eb31cc948ef", - }, - L2Gas: rpc.ResourceBounds{ - MaxAmount: "0x0", - MaxPricePerUnit: "0x0", + Txn: rpc.BroadcastInvokev3Txn{ + InvokeTxnV3: &rpc.InvokeTxnV3{ + Nonce: utils.TestHexToFelt(t, "0x12eaa"), + Type: rpc.TransactionType_Invoke, + Version: rpc.TransactionV3, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x7121c34d7073fd21b73801000278883b332a6f8cdf90d7a84358748de811480"), + utils.TestHexToFelt(t, "0x3df8c38724b89e9baa8dc0d0cb8fd14a8ca65308d7ca831793cc67394803b6c")}, + ResourceBounds: rpc.ResourceBoundsMapping{ + L1Gas: rpc.ResourceBounds{ + MaxAmount: "0x2b", + MaxPricePerUnit: "0x2eb31cc948ef", + }, + L2Gas: rpc.ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, }, - }, - Tip: "0x0", - PayMasterData: []*felt.Felt{}, - AccountDeploymentData: []*felt.Felt{}, - SenderAddress: utils.TestHexToFelt(t, "0x1d091b30a2d20ca2509579f8beae26934bfdc3725c0b497f50b353b7a3c636f"), - Calldata: utils.TestHexArrToFelt(t, []string{ - "0x1", - "0x132303a40ae2f271f4e1b707596a63f6f2921c4d400b38822548ed1bb0cbe0", - "0xc844fd57777b0cd7e75c8ea68deec0adf964a6308da7a58de32364b7131cc8", - "0x13", - "0x46f1db039a8aa6edb473195b98421579517d79bbe026e74bbc3f172af0798", - "0x1c4104", - "0xde9f47f476fed1e72a6159aba4f458ac74cbbbf88a951758a1fc0276e27211", - "0x66417c6a", - "0x104030200000000000000000000000000000000000000000000000000000000", - "0x4", - "0x431d563dc0", - "0x4329326f60", - "0x432cdda6a2", - "0x433403bcd6", - "0xbc2ee78d0e41b9dd1", - "0x1", - "0x2", - "0x75a8626edb90cc9983ae1dfca05c485c8ca6ca507f925ac8f28366aa8d7c211", - "0x83b812e83b07feb3e898aa55db8552138580d63e4f827e28e2531bd308db29", - "0x2e7dc996ebf724c1cf18d668fc3455df4245749ebc0724101cbc6c9cb13c962", - "0x49e384b4c21fbb10318f461c7804432e068c7ff196647b4f3b470b4431c40e6", - "0x2389f278922589f5f5d39b17339dc7ef80f13c8eb20b173c9eba52503c60874", - "0x4225d1c8ee8e451a25e30c10689ef898e11ccf5c0f68d0fc7876c47b318e946", - }), - NonceDataMode: rpc.DAModeL1, - FeeMode: rpc.DAModeL1, - }, + Tip: "0x0", + PayMasterData: []*felt.Felt{}, + AccountDeploymentData: []*felt.Felt{}, + SenderAddress: utils.TestHexToFelt(t, "0x1d091b30a2d20ca2509579f8beae26934bfdc3725c0b497f50b353b7a3c636f"), + Calldata: utils.TestHexArrToFelt(t, []string{ + "0x1", + "0x132303a40ae2f271f4e1b707596a63f6f2921c4d400b38822548ed1bb0cbe0", + "0xc844fd57777b0cd7e75c8ea68deec0adf964a6308da7a58de32364b7131cc8", + "0x13", + "0x46f1db039a8aa6edb473195b98421579517d79bbe026e74bbc3f172af0798", + "0x1c4104", + "0xde9f47f476fed1e72a6159aba4f458ac74cbbbf88a951758a1fc0276e27211", + "0x66417c6a", + "0x104030200000000000000000000000000000000000000000000000000000000", + "0x4", + "0x431d563dc0", + "0x4329326f60", + "0x432cdda6a2", + "0x433403bcd6", + "0xbc2ee78d0e41b9dd1", + "0x1", + "0x2", + "0x75a8626edb90cc9983ae1dfca05c485c8ca6ca507f925ac8f28366aa8d7c211", + "0x83b812e83b07feb3e898aa55db8552138580d63e4f827e28e2531bd308db29", + "0x2e7dc996ebf724c1cf18d668fc3455df4245749ebc0724101cbc6c9cb13c962", + "0x49e384b4c21fbb10318f461c7804432e068c7ff196647b4f3b470b4431c40e6", + "0x2389f278922589f5f5d39b17339dc7ef80f13c8eb20b173c9eba52503c60874", + "0x4225d1c8ee8e451a25e30c10689ef898e11ccf5c0f68d0fc7876c47b318e946", + }), + NonceDataMode: rpc.DAModeL1, + FeeMode: rpc.DAModeL1, + }}, ExpectedHash: utils.TestHexToFelt(t, "0x8eb1104170ec42fd27c09ea78822dfb083ddd15324480f856bff01bc65e9d9"), ExpectedErr: nil, }, @@ -827,7 +830,7 @@ func TestTransactionHashdeployAccount(t *testing.T) { require.NoError(t, err) type testSetType struct { - Txn rpc.DeployAccountType + Txn rpc.BroadcastAddDeployTxnType SenderAddress *felt.Felt ExpectedHash *felt.Felt ExpectedErr error @@ -836,55 +839,57 @@ func TestTransactionHashdeployAccount(t *testing.T) { "mock": { { // https://sepolia.voyager.online/tx/0x66d1d9d50d308a9eb16efedbad208b0672769a545a0b828d357757f444e9188 - Txn: rpc.DeployAccountTxn{ - Nonce: utils.TestHexToFelt(t, "0x0"), - Type: rpc.TransactionType_DeployAccount, - MaxFee: utils.TestHexToFelt(t, "0x1d2109b99cf94"), - Version: rpc.TransactionV1, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x427df9a1a4a0b7b9011a758524b8a6c2595aac9140608fe24c66efe04b340d7"), - utils.TestHexToFelt(t, "0x4edc73cd97dab7458a08fec6d7c0e1638c3f1111646fc8a91508b4f94b36310"), - }, - ClassHash: utils.TestHexToFelt(t, "0x1e60c8722677cfb7dd8dbea5be86c09265db02cdfe77113e77da7d44c017388"), - ContractAddressSalt: utils.TestHexToFelt(t, "0x15d621f9515c6197d3117eb1a25c7a4a669317be8f49831e03fcc00d855352e"), - ConstructorCalldata: []*felt.Felt{ - utils.TestHexToFelt(t, "0x960532cfba33384bbec41aa669727a9c51e995c87e101c86706aaf244f7e4e"), - }, - }, + Txn: rpc.BroadcastDeployAccountTxn{ + DeployAccountTxn: &rpc.DeployAccountTxn{ + Nonce: utils.TestHexToFelt(t, "0x0"), + Type: rpc.TransactionType_DeployAccount, + MaxFee: utils.TestHexToFelt(t, "0x1d2109b99cf94"), + Version: rpc.TransactionV1, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x427df9a1a4a0b7b9011a758524b8a6c2595aac9140608fe24c66efe04b340d7"), + utils.TestHexToFelt(t, "0x4edc73cd97dab7458a08fec6d7c0e1638c3f1111646fc8a91508b4f94b36310"), + }, + ClassHash: utils.TestHexToFelt(t, "0x1e60c8722677cfb7dd8dbea5be86c09265db02cdfe77113e77da7d44c017388"), + ContractAddressSalt: utils.TestHexToFelt(t, "0x15d621f9515c6197d3117eb1a25c7a4a669317be8f49831e03fcc00d855352e"), + ConstructorCalldata: []*felt.Felt{ + utils.TestHexToFelt(t, "0x960532cfba33384bbec41aa669727a9c51e995c87e101c86706aaf244f7e4e"), + }, + }}, SenderAddress: utils.TestHexToFelt(t, "0x05dd5faeddd4a9e01231f3bb9b95ec93426d08977b721c222e45fd98c5f353ff"), ExpectedHash: utils.TestHexToFelt(t, "0x66d1d9d50d308a9eb16efedbad208b0672769a545a0b828d357757f444e9188"), ExpectedErr: nil, }, { // https://sepolia.voyager.online/tx/0x4bf28fb0142063f1b9725ae490c6949e6f1842c79b49f7cc674b7e3f5ad4875 - Txn: rpc.DeployAccountTxnV3{ - Nonce: utils.TestHexToFelt(t, "0x0"), - Type: rpc.TransactionType_DeployAccount, - Version: rpc.TransactionV3, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0xaa580d6fd4bc056d6a9a49833e7fc966fe5f20cc283e05854e44a5d4516958"), - utils.TestHexToFelt(t, "0x41a57fcb19908321f8e44c425ea419a1de272efd99888503ee0cdc0ddb6aee4")}, - ResourceBounds: rpc.ResourceBoundsMapping{ - L1Gas: rpc.ResourceBounds{ - MaxAmount: "0x38", - MaxPricePerUnit: "0x7cd9b6080b35", - }, - L2Gas: rpc.ResourceBounds{ - MaxAmount: "0x0", - MaxPricePerUnit: "0x0", + Txn: rpc.BroadcastDeployAccountTxnV3{ + DeployAccountTxnV3: &rpc.DeployAccountTxnV3{ + Nonce: utils.TestHexToFelt(t, "0x0"), + Type: rpc.TransactionType_DeployAccount, + Version: rpc.TransactionV3, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0xaa580d6fd4bc056d6a9a49833e7fc966fe5f20cc283e05854e44a5d4516958"), + utils.TestHexToFelt(t, "0x41a57fcb19908321f8e44c425ea419a1de272efd99888503ee0cdc0ddb6aee4")}, + ResourceBounds: rpc.ResourceBoundsMapping{ + L1Gas: rpc.ResourceBounds{ + MaxAmount: "0x38", + MaxPricePerUnit: "0x7cd9b6080b35", + }, + L2Gas: rpc.ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, }, - }, - Tip: "0x0", - PayMasterData: []*felt.Felt{}, - NonceDataMode: rpc.DAModeL1, - FeeMode: rpc.DAModeL1, - ClassHash: utils.TestHexToFelt(t, "0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b"), - ConstructorCalldata: utils.TestHexArrToFelt(t, []string{ - "0x1a09f0001cc46f82b1a805d07c13e235248a44ed13d87f170d7d925e3c86082", - "0x0", - }), - ContractAddressSalt: utils.TestHexToFelt(t, "0x1a09f0001cc46f82b1a805d07c13e235248a44ed13d87f170d7d925e3c86082"), - }, + Tip: "0x0", + PayMasterData: []*felt.Felt{}, + NonceDataMode: rpc.DAModeL1, + FeeMode: rpc.DAModeL1, + ClassHash: utils.TestHexToFelt(t, "0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b"), + ConstructorCalldata: utils.TestHexArrToFelt(t, []string{ + "0x1a09f0001cc46f82b1a805d07c13e235248a44ed13d87f170d7d925e3c86082", + "0x0", + }), + ContractAddressSalt: utils.TestHexToFelt(t, "0x1a09f0001cc46f82b1a805d07c13e235248a44ed13d87f170d7d925e3c86082"), + }}, SenderAddress: utils.TestHexToFelt(t, "0x0365633b6c2ca24b461747d2fe8e0c19a3637a954ee703a7ed0e5d1d9644ad1a"), ExpectedHash: utils.TestHexToFelt(t, "0x4bf28fb0142063f1b9725ae490c6949e6f1842c79b49f7cc674b7e3f5ad4875"), ExpectedErr: nil, @@ -893,55 +898,57 @@ func TestTransactionHashdeployAccount(t *testing.T) { "testnet": { { // https://sepolia.voyager.online/tx/0x66d1d9d50d308a9eb16efedbad208b0672769a545a0b828d357757f444e9188 - Txn: rpc.DeployAccountTxn{ - Nonce: utils.TestHexToFelt(t, "0x0"), - Type: rpc.TransactionType_DeployAccount, - MaxFee: utils.TestHexToFelt(t, "0x1d2109b99cf94"), - Version: rpc.TransactionV1, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0x427df9a1a4a0b7b9011a758524b8a6c2595aac9140608fe24c66efe04b340d7"), - utils.TestHexToFelt(t, "0x4edc73cd97dab7458a08fec6d7c0e1638c3f1111646fc8a91508b4f94b36310"), - }, - ClassHash: utils.TestHexToFelt(t, "0x1e60c8722677cfb7dd8dbea5be86c09265db02cdfe77113e77da7d44c017388"), - ContractAddressSalt: utils.TestHexToFelt(t, "0x15d621f9515c6197d3117eb1a25c7a4a669317be8f49831e03fcc00d855352e"), - ConstructorCalldata: []*felt.Felt{ - utils.TestHexToFelt(t, "0x960532cfba33384bbec41aa669727a9c51e995c87e101c86706aaf244f7e4e"), - }, - }, + Txn: rpc.BroadcastDeployAccountTxn{ + DeployAccountTxn: &rpc.DeployAccountTxn{ + Nonce: utils.TestHexToFelt(t, "0x0"), + Type: rpc.TransactionType_DeployAccount, + MaxFee: utils.TestHexToFelt(t, "0x1d2109b99cf94"), + Version: rpc.TransactionV1, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0x427df9a1a4a0b7b9011a758524b8a6c2595aac9140608fe24c66efe04b340d7"), + utils.TestHexToFelt(t, "0x4edc73cd97dab7458a08fec6d7c0e1638c3f1111646fc8a91508b4f94b36310"), + }, + ClassHash: utils.TestHexToFelt(t, "0x1e60c8722677cfb7dd8dbea5be86c09265db02cdfe77113e77da7d44c017388"), + ContractAddressSalt: utils.TestHexToFelt(t, "0x15d621f9515c6197d3117eb1a25c7a4a669317be8f49831e03fcc00d855352e"), + ConstructorCalldata: []*felt.Felt{ + utils.TestHexToFelt(t, "0x960532cfba33384bbec41aa669727a9c51e995c87e101c86706aaf244f7e4e"), + }, + }}, SenderAddress: utils.TestHexToFelt(t, "0x05dd5faeddd4a9e01231f3bb9b95ec93426d08977b721c222e45fd98c5f353ff"), ExpectedHash: utils.TestHexToFelt(t, "0x66d1d9d50d308a9eb16efedbad208b0672769a545a0b828d357757f444e9188"), ExpectedErr: nil, }, { // https://sepolia.voyager.online/tx/0x4bf28fb0142063f1b9725ae490c6949e6f1842c79b49f7cc674b7e3f5ad4875 - Txn: rpc.DeployAccountTxnV3{ - Nonce: utils.TestHexToFelt(t, "0x0"), - Type: rpc.TransactionType_DeployAccount, - Version: rpc.TransactionV3, - Signature: []*felt.Felt{ - utils.TestHexToFelt(t, "0xaa580d6fd4bc056d6a9a49833e7fc966fe5f20cc283e05854e44a5d4516958"), - utils.TestHexToFelt(t, "0x41a57fcb19908321f8e44c425ea419a1de272efd99888503ee0cdc0ddb6aee4")}, - ResourceBounds: rpc.ResourceBoundsMapping{ - L1Gas: rpc.ResourceBounds{ - MaxAmount: "0x38", - MaxPricePerUnit: "0x7cd9b6080b35", + Txn: rpc.BroadcastDeployAccountTxnV3{ + DeployAccountTxnV3: &rpc.DeployAccountTxnV3{ + Nonce: utils.TestHexToFelt(t, "0x0"), + Type: rpc.TransactionType_DeployAccount, + Version: rpc.TransactionV3, + Signature: []*felt.Felt{ + utils.TestHexToFelt(t, "0xaa580d6fd4bc056d6a9a49833e7fc966fe5f20cc283e05854e44a5d4516958"), + utils.TestHexToFelt(t, "0x41a57fcb19908321f8e44c425ea419a1de272efd99888503ee0cdc0ddb6aee4")}, + ResourceBounds: rpc.ResourceBoundsMapping{ + L1Gas: rpc.ResourceBounds{ + MaxAmount: "0x38", + MaxPricePerUnit: "0x7cd9b6080b35", + }, + L2Gas: rpc.ResourceBounds{ + MaxAmount: "0x0", + MaxPricePerUnit: "0x0", + }, }, - L2Gas: rpc.ResourceBounds{ - MaxAmount: "0x0", - MaxPricePerUnit: "0x0", - }, - }, - Tip: "0x0", - PayMasterData: []*felt.Felt{}, - NonceDataMode: rpc.DAModeL1, - FeeMode: rpc.DAModeL1, - ClassHash: utils.TestHexToFelt(t, "0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b"), - ConstructorCalldata: utils.TestHexArrToFelt(t, []string{ - "0x1a09f0001cc46f82b1a805d07c13e235248a44ed13d87f170d7d925e3c86082", - "0x0", - }), - ContractAddressSalt: utils.TestHexToFelt(t, "0x1a09f0001cc46f82b1a805d07c13e235248a44ed13d87f170d7d925e3c86082"), - }, + Tip: "0x0", + PayMasterData: []*felt.Felt{}, + NonceDataMode: rpc.DAModeL1, + FeeMode: rpc.DAModeL1, + ClassHash: utils.TestHexToFelt(t, "0x29927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b"), + ConstructorCalldata: utils.TestHexArrToFelt(t, []string{ + "0x1a09f0001cc46f82b1a805d07c13e235248a44ed13d87f170d7d925e3c86082", + "0x0", + }), + ContractAddressSalt: utils.TestHexToFelt(t, "0x1a09f0001cc46f82b1a805d07c13e235248a44ed13d87f170d7d925e3c86082"), + }}, SenderAddress: utils.TestHexToFelt(t, "0x0365633b6c2ca24b461747d2fe8e0c19a3637a954ee703a7ed0e5d1d9644ad1a"), ExpectedHash: utils.TestHexToFelt(t, "0x4bf28fb0142063f1b9725ae490c6949e6f1842c79b49f7cc674b7e3f5ad4875"), ExpectedErr: nil, @@ -1135,7 +1142,7 @@ func TestAddDeclareTxn(t *testing.T) { var class rpc.ContractClass err = json.Unmarshal(content, &class) require.NoError(t, err) - classHash, err := hash.ClassHash(class) + _, err = hash.ClassHash(class) require.NoError(t, err) // Compiled Class Hash @@ -1147,7 +1154,7 @@ func TestAddDeclareTxn(t *testing.T) { require.NoError(t, err) compClassHash := hash.CompiledClassHash(casmClass) - tx := rpc.DeclareTxnV2{ + tx := rpc.BroadcastDeclareTxnV2{ Nonce: utils.TestHexToFelt(t, "0xd"), MaxFee: utils.TestHexToFelt(t, "0xc5cb22092551"), Type: rpc.TransactionType_Declare, @@ -1158,10 +1165,9 @@ func TestAddDeclareTxn(t *testing.T) { }, SenderAddress: AccountAddress, CompiledClassHash: compClassHash, - ClassHash: classHash, } - err = acnt.SignDeclareTransaction(context.Background(), &tx) + err = acnt.SignDeclareTransaction(context.Background(), tx) require.NoError(t, err) broadcastTx := rpc.BroadcastDeclareTxnV2{ @@ -1172,7 +1178,6 @@ func TestAddDeclareTxn(t *testing.T) { Signature: tx.Signature, SenderAddress: tx.SenderAddress, CompiledClassHash: tx.CompiledClassHash, - ContractClass: class, } resp, err := acnt.AddDeclareTransaction(context.Background(), broadcastTx) diff --git a/examples/deployAccount/main.go b/examples/deployAccount/main.go index 24152bf0..70f0032a 100644 --- a/examples/deployAccount/main.go +++ b/examples/deployAccount/main.go @@ -61,7 +61,7 @@ func main() { // Create transaction data tx := rpc.BroadcastDeployAccountTxn{ - DeployAccountTxn: rpc.DeployAccountTxn{ + DeployAccountTxn: &rpc.DeployAccountTxn{ Nonce: &felt.Zero, // Contract accounts start with nonce zero. MaxFee: new(felt.Felt).SetUint64(7268996239700), Type: rpc.TransactionType_DeployAccount, @@ -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) } @@ -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) } diff --git a/examples/deployContractUDC/main.go b/examples/deployContractUDC/main.go index 31ddc0c5..9a2bbdad 100644 --- a/examples/deployContractUDC/main.go +++ b/examples/deployContractUDC/main.go @@ -74,7 +74,7 @@ func main() { // Build the InvokeTx struct InvokeTx := rpc.BroadcastInvokev1Txn{ - InvokeTxnV1: rpc.InvokeTxnV1{ + InvokeTxnV1: &rpc.InvokeTxnV1{ MaxFee: new(felt.Felt).SetUint64(100000000000000), Version: rpc.TransactionV1, Nonce: nonce, @@ -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) } @@ -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) } diff --git a/examples/simpleInvoke/main.go b/examples/simpleInvoke/main.go index 2ed8ca89..8dc3935b 100644 --- a/examples/simpleInvoke/main.go +++ b/examples/simpleInvoke/main.go @@ -65,7 +65,7 @@ func main() { // Building the InvokeTx struct InvokeTx := rpc.BroadcastInvokev1Txn{ - InvokeTxnV1: rpc.InvokeTxnV1{ + InvokeTxnV1: &rpc.InvokeTxnV1{ MaxFee: new(felt.Felt).SetUint64(100000000000000), Version: rpc.TransactionV1, Nonce: nonce, @@ -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) } @@ -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) } diff --git a/mocks/mock_account.go b/mocks/mock_account.go index 95eee23d..00a4e4c9 100644 --- a/mocks/mock_account.go +++ b/mocks/mock_account.go @@ -73,7 +73,7 @@ func (mr *MockAccountInterfaceMockRecorder) Sign(ctx, msg any) *gomock.Call { } // SignDeclareTransaction mocks base method. -func (m *MockAccountInterface) SignDeclareTransaction(ctx context.Context, tx *rpc.DeclareTxnV2) error { +func (m *MockAccountInterface) SignDeclareTransaction(ctx context.Context, tx *rpc.BroadcastDeclareTxnV2) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignDeclareTransaction", ctx, tx) ret0, _ := ret[0].(error) @@ -87,7 +87,7 @@ func (mr *MockAccountInterfaceMockRecorder) SignDeclareTransaction(ctx, tx any) } // SignDeployAccountTransaction mocks base method. -func (m *MockAccountInterface) SignDeployAccountTransaction(ctx context.Context, tx *rpc.DeployAccountTxn, precomputeAddress *felt.Felt) error { +func (m *MockAccountInterface) SignDeployAccountTransaction(ctx context.Context, tx *rpc.BroadcastDeployAccountTxn, precomputeAddress *felt.Felt) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignDeployAccountTransaction", ctx, tx, precomputeAddress) ret0, _ := ret[0].(error) @@ -101,7 +101,7 @@ func (mr *MockAccountInterfaceMockRecorder) SignDeployAccountTransaction(ctx, tx } // SignInvokeTransaction mocks base method. -func (m *MockAccountInterface) SignInvokeTransaction(ctx context.Context, tx *rpc.InvokeTxnV1) error { +func (m *MockAccountInterface) SignInvokeTransaction(ctx context.Context, tx *rpc.BroadcastInvokev1Txn) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "SignInvokeTransaction", ctx, tx) ret0, _ := ret[0].(error) diff --git a/rpc/types_broadcast_transaction.go b/rpc/types_broadcast_transaction.go index 167d28a0..9f65bfe1 100644 --- a/rpc/types_broadcast_transaction.go +++ b/rpc/types_broadcast_transaction.go @@ -43,7 +43,7 @@ var ( ) type BroadcastInvokev0Txn struct { - InvokeTxnV0 + *InvokeTxnV0 } func (tx BroadcastInvokev0Txn) GetCalldata() []*felt.Felt { @@ -51,7 +51,7 @@ func (tx BroadcastInvokev0Txn) GetCalldata() []*felt.Felt { } type BroadcastInvokev1Txn struct { - InvokeTxnV1 + *InvokeTxnV1 } func (tx BroadcastInvokev1Txn) GetCalldata() []*felt.Felt { @@ -59,7 +59,7 @@ func (tx BroadcastInvokev1Txn) GetCalldata() []*felt.Felt { } type BroadcastInvokev3Txn struct { - InvokeTxnV3 + *InvokeTxnV3 } func (tx BroadcastInvokev3Txn) GetCalldata() []*felt.Felt { @@ -98,7 +98,7 @@ func (tx BroadcastDeclareTxnV2) GetContractClass() interface{} { } type BroadcastDeclareTxnV3 struct { - DeclareTxnV3 + *DeclareTxnV3 ContractClass *ContractClass `json:"contract_class"` } @@ -107,7 +107,7 @@ func (tx BroadcastDeclareTxnV3) GetContractClass() interface{} { } type BroadcastDeployAccountTxn struct { - DeployAccountTxn + *DeployAccountTxn } func (tx BroadcastDeployAccountTxn) GetConstructorCalldata() []*felt.Felt { @@ -115,7 +115,7 @@ func (tx BroadcastDeployAccountTxn) GetConstructorCalldata() []*felt.Felt { } type BroadcastDeployAccountTxnV3 struct { - DeployAccountTxnV3 + *DeployAccountTxnV3 } func (tx BroadcastDeployAccountTxnV3) GetConstructorCalldata() []*felt.Felt { diff --git a/rpc/types_contract_test.go b/rpc/types_contract_test.go index 87bd79d4..c39c938d 100644 --- a/rpc/types_contract_test.go +++ b/rpc/types_contract_test.go @@ -16,14 +16,15 @@ const ( // tests the successful unmarshalling of valid JSON into a DeprecatedContractClass // object. // -// It reads the content of a file, then unmarshals the content into a +// It reads the content of a file, then unmarshals the content into a // DeprecatedContractClass object using the json.Unmarshal function. If any error // occurs during the process, the test fails. // // Parameters: // - t: The testing.T object used for reporting test failures and logging. // Returns: -// none +// +// none func TestDeprecatedContractClass_UnmarshalValidJSON_Successful(t *testing.T) { content, err := os.ReadFile(validDeprecatedContractCompiledPath) if err != nil { @@ -45,7 +46,8 @@ func TestDeprecatedContractClass_UnmarshalValidJSON_Successful(t *testing.T) { // Parameters: // - t: The testing.T object used for reporting test failures and logging. // Returns: -// none +// +// none func TestContractClass_UnmarshalValidJSON_Successful(t *testing.T) { content, err := os.ReadFile(validContractCompiledPath) if err != nil { diff --git a/rpc/write_test.go b/rpc/write_test.go index 90e3038b..476b2404 100644 --- a/rpc/write_test.go +++ b/rpc/write_test.go @@ -33,7 +33,7 @@ func TestDeclareTransaction(t *testing.T) { }, { DeclareTx: BroadcastDeclareTxnV3{ - DeclareTxnV3: DeclareTxnV3{ + DeclareTxnV3: &DeclareTxnV3{ Type: TransactionType_Declare, Version: TransactionV3, Signature: []*felt.Felt{}, @@ -106,7 +106,7 @@ func TestAddInvokeTransaction(t *testing.T) { "mainnet": {}, "mock": { { - InvokeTx: BroadcastInvokev1Txn{InvokeTxnV1{SenderAddress: new(felt.Felt).SetUint64(123)}}, + InvokeTx: BroadcastInvokev1Txn{&InvokeTxnV1{SenderAddress: new(felt.Felt).SetUint64(123)}}, ExpectedResp: AddInvokeTransactionResponse{&felt.Zero}, ExpectedError: &RPCError{ Code: ErrUnexpectedError.Code, @@ -114,13 +114,13 @@ func TestAddInvokeTransaction(t *testing.T) { Data: "Something crazy happened"}, }, { - InvokeTx: BroadcastInvokev1Txn{InvokeTxnV1{}}, + InvokeTx: BroadcastInvokev1Txn{&InvokeTxnV1{}}, ExpectedResp: AddInvokeTransactionResponse{utils.TestHexToFelt(t, "0xdeadbeef")}, ExpectedError: nil, }, { InvokeTx: BroadcastInvokev3Txn{ - InvokeTxnV3{ + &InvokeTxnV3{ Type: TransactionType_Invoke, Version: TransactionV3, Signature: []*felt.Felt{ @@ -194,7 +194,7 @@ func TestAddDeployAccountTansaction(t *testing.T) { "mainnet": {}, "mock": { { - DeployTx: BroadcastDeployAccountTxn{DeployAccountTxn{}}, + DeployTx: BroadcastDeployAccountTxn{&DeployAccountTxn{}}, ExpectedResp: AddDeployAccountTransactionResponse{ TransactionHash: utils.TestHexToFelt(t, "0x32b272b6d0d584305a460197aa849b5c7a9a85903b66e9d3e1afa2427ef093e"), ContractAddress: utils.TestHexToFelt(t, "0x0"), @@ -203,7 +203,7 @@ func TestAddDeployAccountTansaction(t *testing.T) { }, { DeployTx: BroadcastDeployAccountTxnV3{ - DeployAccountTxnV3{ + &DeployAccountTxnV3{ Type: TransactionType_DeployAccount, Version: TransactionV3, ClassHash: utils.TestHexToFelt(t, "0x2338634f11772ea342365abd5be9d9dc8a6f44f159ad782fdebd3db5d969738"),