Skip to content

Commit

Permalink
Add declareV2
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Aug 21, 2023
1 parent e409e6e commit 876b9ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 4 additions & 3 deletions rpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func TestBlockWithTxsAndDeployOrDeclare(t *testing.T) {
},
Status: "ACCEPTED_ON_L1",
Transactions: []Transaction{
DeclareTxn{
DeclareTxnV1{
CommonTransaction: CommonTransaction{
TransactionHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"),
BroadcastedTxnCommonProperties: BroadcastedTxnCommonProperties{
Expand Down Expand Up @@ -515,10 +515,11 @@ func TestCaptureUnsupportedBlockTxn(t *testing.T) {
_, okv1 := v.(InvokeTxnV1)
_, okv0 := v.(InvokeTxnV0)
_, okl1 := v.(L1HandlerTxn)
_, okdec := v.(DeclareTxn)
_, okdec := v.(DeclareTxnV1)
_, okdecv2 := v.(DeclareTxnV2)
_, okdep := v.(DeployTxn)
_, okdepac := v.(DeployAccountTxn)
if !okv0 && !okv1 && !okl1 && !okdec && !okdep && !okdepac {
if !okv0 && !okv1 && !okl1 && !okdec && !okdep && !okdepac && !okdecv2 {
t.Fatalf("New Type Detected %T at Block(%d)/Txn(%d)", v, i, k)
}
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func adaptTransaction(t TXN) (Transaction, error) {
json.Unmarshal(txMarshalled, &tx)
return tx, nil
case TransactionType_Declare:
var tx DeclareTxn
var tx DeclareTxnV2
json.Unmarshal(txMarshalled, &tx)
return tx, nil
case TransactionType_DeployAccount:
Expand Down
15 changes: 12 additions & 3 deletions rpc/types_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (tx L1HandlerTxn) Hash() *felt.Felt {
return tx.TransactionHash
}

type DeclareTxn struct {
type DeclareTxnV1 struct {
CommonTransaction

// ClassHash the hash of the declared class
Expand All @@ -103,7 +103,16 @@ type DeclareTxn struct {
SenderAddress *felt.Felt `json:"sender_address"`
}

func (tx DeclareTxn) Hash() *felt.Felt {
type DeclareTxnV2 struct {
DeclareTxnV1
CompiledClassHash *felt.Felt `json:"compiled_class_hash,omitempty"`
}

func (tx DeclareTxnV1) Hash() *felt.Felt {
return tx.TransactionHash
}

func (tx DeclareTxnV2) Hash() *felt.Felt {
return tx.TransactionHash
}

Expand Down Expand Up @@ -195,7 +204,7 @@ func unmarshalTxn(t interface{}) (Transaction, error) {
case map[string]interface{}:
switch TransactionType(casted["type"].(string)) {
case TransactionType_Declare:
var txn DeclareTxn
var txn DeclareTxnV2
remarshal(casted, &txn)
return txn, nil
case TransactionType_Deploy:
Expand Down

0 comments on commit 876b9ec

Please sign in to comment.