From 0b085e4bd9130dbbfed9a7936e6caddeee31c1d0 Mon Sep 17 00:00:00 2001 From: rianhughes Date: Fri, 10 Nov 2023 12:37:11 +0200 Subject: [PATCH] rpcv06 implement v3 transactions --- rpc/types_broadcast_transaction.go | 12 ++++++ rpc/types_transaction.go | 51 ++++++++++++++++++++-- rpc/types_transaction_interfaces.go | 67 ++++++++--------------------- 3 files changed, 78 insertions(+), 52 deletions(-) diff --git a/rpc/types_broadcast_transaction.go b/rpc/types_broadcast_transaction.go index fcfdf50e..fad057b6 100644 --- a/rpc/types_broadcast_transaction.go +++ b/rpc/types_broadcast_transaction.go @@ -9,6 +9,7 @@ var ( _ BroadcastTxn = BroadcastInvokev1Txn{} _ BroadcastTxn = BroadcastDeclareV1Txn{} _ BroadcastTxn = BroadcastDeclareV2Txn{} + _ BroadcastTxn = BroadcastDeclareTxnV3{} _ BroadcastTxn = BroadcastDeployAccountTxn{} ) @@ -56,6 +57,17 @@ type BroadcastDeclareV2Txn struct { ContractClass ContractClass `json:"contract_class"` } +type BroadcastDeclareTxnV3 struct { + Type TransactionType `json:"type"` + SenderAddress *felt.Felt `json:"sender_address"` + CompiledClassHash *felt.Felt `json:"compiled_class_hash"` + Version NumAsHex `json:"version"` + Signature []*felt.Felt `json:"signature"` + Nonce *felt.Felt `json:"nonce"` + ContractClass *ContractClass `json:"contract_class"` + L1Gas *ResourceLimits `json:"l1_gas"` +} + type BroadcastDeployAccountTxn struct { DeployAccountTxn } diff --git a/rpc/types_transaction.go b/rpc/types_transaction.go index 6a1e737e..a8397ee8 100644 --- a/rpc/types_transaction.go +++ b/rpc/types_transaction.go @@ -45,6 +45,20 @@ type InvokeTxnV1 struct { // The data expected by the account's `execute` function (in most usecases, this includes the called contract address and a function selector) Calldata []*felt.Felt `json:"calldata"` } +type InvokeTxnV3 struct { + Type TransactionType `json:"type"` + SenderAddress *felt.Felt `json:"sender_address"` + Calldata []*felt.Felt `json:"calldata"` + Version TransactionVersion `json:"version"` + Signature []*felt.Felt `json:"signature"` + Nonce *felt.Felt `json:"nonce"` + L1Gas *ResourceLimits `json:"l1_gas"` +} + +type ResourceLimits struct { + MaxAmount *NumAsHex `json:"max_amount"` // The max amount of the resource that can be used in the tx + MaxPricePerUnit *NumAsHex `json:"max_price_per_unit"` // The max price per unit of this resource for this tx +} type L1HandlerTxn struct { Type TransactionType `json:"type,omitempty"` @@ -89,6 +103,17 @@ type DeclareTxnV2 struct { ClassHash *felt.Felt `json:"class_hash"` } +type DeclareTxnV3 struct { + Type TransactionType `json:"type"` + SenderAddress *felt.Felt `json:"sender_address"` + CompiledClassHash *felt.Felt `json:"compiled_class_hash"` + Version TransactionVersion `json:"version"` + Signature []*felt.Felt `json:"signature"` + Nonce *felt.Felt `json:"nonce"` + ClassHash *felt.Felt `json:"class_hash"` + L1Gas *ResourceLimits `json:"l1_gas"` +} + // DeployTxn The structure of a deploy transaction. Note that this transaction type is deprecated and will no longer be supported in future versions type DeployTxn struct { // ClassHash The hash of the deployed contract's class @@ -117,6 +142,17 @@ type DeployAccountTxn struct { ConstructorCalldata []*felt.Felt `json:"constructor_calldata"` } +type DeployAccountTxnV3 struct { + Type TransactionType `json:"type"` + Version TransactionVersion `json:"version"` + Signature []*felt.Felt `json:"signature"` + Nonce *felt.Felt `json:"nonce"` + ContractAddressSalt *felt.Felt `json:"contract_address_salt"` + ConstructorCalldata []*felt.Felt `json:"constructor_calldata"` + ClassHash *felt.Felt `json:"class_hash"` + L1Gas *ResourceLimits `json:"l1_gas"` +} + type UnknownTransaction struct{ Transaction } // UnmarshalJSON unmarshals the JSON data into an UnknownTransaction object. @@ -222,15 +258,22 @@ func remarshal(v interface{}, dst interface{}) error { type TransactionVersion string const ( - TransactionV0 TransactionVersion = "0x0" - TransactionV1 TransactionVersion = "0x1" - TransactionV2 TransactionVersion = "0x2" + TransactionV0 TransactionVersion = "0x0" + TransactionV0Variant TransactionVersion = "0x100000000000000000000000000000000" + TransactionV1 TransactionVersion = "0x1" + TransactionV1Variant TransactionVersion = "0x100000000000000000000000000000001" + TransactionV2 TransactionVersion = "0x2" + TransactionV2Variant TransactionVersion = "0x100000000000000000000000000000002" + TransactionV3 TransactionVersion = "0x2" + TransactionV3Variant TransactionVersion = "0x100000000000000000000000000000003" ) // BigInt returns a big integer corresponding to the transaction version. // // Parameters: -// none +// +// none +// // Returns: // - *big.Int: a pointer to a big.Int // - error: an error if the conversion fails diff --git a/rpc/types_transaction_interfaces.go b/rpc/types_transaction_interfaces.go index 15f695e6..1af5a6d9 100644 --- a/rpc/types_transaction_interfaces.go +++ b/rpc/types_transaction_interfaces.go @@ -4,6 +4,7 @@ type AddDeclareTxnInput interface{} var _ AddDeclareTxnInput = DeclareTxnV1{} var _ AddDeclareTxnInput = DeclareTxnV2{} +var _ AddDeclareTxnInput = DeclareTxnV3{} type Transaction interface { GetType() TransactionType @@ -11,88 +12,55 @@ type Transaction interface { var _ Transaction = InvokeTxnV0{} var _ Transaction = InvokeTxnV1{} +var _ Transaction = InvokeTxnV3{} var _ Transaction = DeclareTxnV1{} var _ Transaction = DeclareTxnV2{} +var _ Transaction = DeclareTxnV3{} var _ Transaction = DeployTxn{} var _ Transaction = DeployAccountTxn{} +var _ Transaction = DeployAccountTxnV3{} var _ Transaction = L1HandlerTxn{} -// GetType returns the transaction type of the InvokeTxnV0 struct. -// -// Parameters: -// none -// Returns: -// - TransactionType: the transaction type func (tx InvokeTxnV0) GetType() TransactionType { return tx.Type } -// GetType returns the type of the InvokeTxnV1 transaction. -// -// Parameters: -// none -// Returns: -// - TransactionType: the transaction type func (tx InvokeTxnV1) GetType() TransactionType { return tx.Type } -// GetType returns the TransactionType of the DeclareTxnV0 object. -// -// Parameters: -// none -// Returns: -// - TransactionType: the transaction type +func (tx InvokeTxnV3) GetType() TransactionType { + return tx.Type +} + func (tx DeclareTxnV0) GetType() TransactionType { return tx.Type } -// GetType returns the transaction type of DeclareTxnV1. -// -// Parameters: -// none -// Returns: -// - TransactionType: the transaction type func (tx DeclareTxnV1) GetType() TransactionType { return tx.Type } -// GetType returns the type of the transaction. -// -// Parameters: -// none -// Returns: -// - TransactionType: the transaction type func (tx DeclareTxnV2) GetType() TransactionType { return tx.Type } -// GetType returns the type of the DeployTxn. -// -// Parameters: -// none -// Returns: -// - TransactionType: the transaction type +func (tx DeclareTxnV3) GetType() TransactionType { + return tx.Type +} + func (tx DeployTxn) GetType() TransactionType { return tx.Type } -// GetType returns the transaction type of the DeployAccountTxn. -// -// Parameters: -// none -// Returns: -// - TransactionType: the transaction type func (tx DeployAccountTxn) GetType() TransactionType { return tx.Type } -// GetType returns the transaction type of the L1HandlerTxn. -// -// Parameters: -// none -// Returns: -// - TransactionType: the transaction type +func (tx DeployAccountTxnV3) GetType() TransactionType { + return tx.Type +} + func (tx L1HandlerTxn) GetType() TransactionType { return tx.Type } @@ -104,13 +72,16 @@ type InvokeTxnType interface{} var _ InvokeTxnType = InvokeTxnV0{} var _ InvokeTxnType = InvokeTxnV1{} +var _ InvokeTxnType = InvokeTxnV3{} type DeclareTxnType interface{} var _ DeclareTxnType = DeclareTxnV0{} var _ DeclareTxnType = DeclareTxnV1{} var _ DeclareTxnType = DeclareTxnV2{} +var _ DeclareTxnType = DeclareTxnV3{} type DeployAccountType interface{} var _ DeployAccountType = DeployAccountTxn{} +var _ DeployAccountType = DeployAccountTxnV3{}