Skip to content

Commit

Permalink
rpcv06 implement v3 transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Nov 10, 2023
1 parent 96944d9 commit 0b085e4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 52 deletions.
12 changes: 12 additions & 0 deletions rpc/types_broadcast_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (
_ BroadcastTxn = BroadcastInvokev1Txn{}
_ BroadcastTxn = BroadcastDeclareV1Txn{}
_ BroadcastTxn = BroadcastDeclareV2Txn{}
_ BroadcastTxn = BroadcastDeclareTxnV3{}
_ BroadcastTxn = BroadcastDeployAccountTxn{}
)

Expand Down Expand Up @@ -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
}
51 changes: 47 additions & 4 deletions rpc/types_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
67 changes: 19 additions & 48 deletions rpc/types_transaction_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,95 +4,63 @@ type AddDeclareTxnInput interface{}

var _ AddDeclareTxnInput = DeclareTxnV1{}
var _ AddDeclareTxnInput = DeclareTxnV2{}
var _ AddDeclareTxnInput = DeclareTxnV3{}

type Transaction interface {
GetType() TransactionType
}

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
}
Expand All @@ -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{}

0 comments on commit 0b085e4

Please sign in to comment.