Repository: NethermindEth/juno
Pull request #332 (2022-08-08 13:33:51)

Fix rpc and sync process DEPLOY transaction type
## Changes:
- Remove not required fields from `CommonTxnProperties`
- Fix `ContractAddress` and `ContractAddressSalt`

## Types of changes

What types of changes does your code introduce?

- Bugfix (non-breaking change which fixes an issue)

## Testing
**Requires testing**

- No



codecov[bot]: # [Codecov](https://codecov.io/gh/NethermindEth/juno/pull/332?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth) Report
> Merging [#332](https://codecov.io/gh/NethermindEth/juno/pull/332?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth) (d86bf8e) into [main](https://codecov.io/gh/NethermindEth/juno/commit/3f4eb50c10af6162fd19cfdff89e51a6d142cf55?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth) (3f4eb50) will **not change** coverage.
> The diff coverage is `100.00%`.

> :exclamation: Current head d86bf8e differs from pull request most recent head d3639bb. Consider uploading reports for the commit d3639bb to get more accurate results

```diff
@@            Coverage Diff            @@
##              main      #332   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           60        60           
  Lines         6780      6779    -1     
=========================================
- Hits          6780      6779    -1     
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `100.00% <100.00%> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/NethermindEth/juno/pull/332?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth) | Coverage Δ | |
|---|---|---|
| [internal/sync/sync.go](https://codecov.io/gh/NethermindEth/juno/pull/332/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#diff-aW50ZXJuYWwvc3luYy9zeW5jLmdv) | `100.00% <ø> (ø)` | |
| [pkg/types/transaction.go](https://codecov.io/gh/NethermindEth/juno/pull/332/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#diff-cGtnL3R5cGVzL3RyYW5zYWN0aW9uLmdv) | `100.00% <ø> (ø)` | |
| [internal/db/transaction/manager.go](https://codecov.io/gh/NethermindEth/juno/pull/332/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#diff-aW50ZXJuYWwvZGIvdHJhbnNhY3Rpb24vbWFuYWdlci5nbw==) | `100.00% <100.00%> (ø)` | |
| [pkg/felt/felt.go](https://codecov.io/gh/NethermindEth/juno/pull/332/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#diff-cGtnL2ZlbHQvZmVsdC5nbw==) | `100.00% <0.00%> (ø)` | |
| [pkg/crypto/weierstrass/weierstrass.go](https://codecov.io/gh/NethermindEth/juno/pull/332/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth#diff-cGtnL2NyeXB0by93ZWllcnN0cmFzcy93ZWllcnN0cmFzcy5nbw==) | `100.00% <0.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=NethermindEth).


Patch:
diff --git a/go.mod b/go.mod
index 4726e968..e5229eca 100644
--- a/go.mod
+++ b/go.mod
@@ -87,7 +87,7 @@ require (
 	github.com/spf13/afero v1.8.2 // indirect
 	github.com/spf13/cast v1.5.0 // indirect
 	github.com/spf13/jwalterweatherman v1.1.0 // indirect
-	github.com/spf13/pflag v1.0.5 // indirect
+	github.com/spf13/pflag v1.0.5
 	github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4 // indirect
 	github.com/subosito/gotenv v1.3.0 // indirect
 	github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
diff --git a/internal/db/transaction/manager.go b/internal/db/transaction/manager.go
index bf70666c..d00f0462 100644
--- a/internal/db/transaction/manager.go
+++ b/internal/db/transaction/manager.go
@@ -93,7 +93,7 @@ func marshalTransaction(transaction types.IsTransaction) ([]byte, error) {
 		deploy := Deploy{
 			ClassHash:           tx.ClassHash.ByteSlice(),
 			ContractAddress:     tx.ContractAddress.ByteSlice(),
-			ContractAddressSalt: tx.ContractAddress.ByteSlice(),
+			ContractAddressSalt: tx.ContractAddressSalt.ByteSlice(),
 			ConstructorCallData: marshalFelts(tx.ConstructorCallData),
 		}
 		protoTx.Tx = &Transaction_Deploy{&deploy}
@@ -139,7 +139,8 @@ func unmarshalTransaction(b []byte) (types.IsTransaction, error) {
 		out := types.TransactionDeploy{
 			Hash:                new(felt.Felt).SetBytes(protoTx.Hash),
 			ClassHash:           new(felt.Felt).SetBytes(tx.ClassHash),
-			ContractAddress:     new(felt.Felt).SetBytes(tx.ContractAddressSalt),
+			ContractAddress:     new(felt.Felt).SetBytes(tx.ContractAddress),
+			ContractAddressSalt: new(felt.Felt).SetBytes(tx.ContractAddressSalt),
 			ConstructorCallData: unmarshalFelts(tx.ConstructorCallData),
 		}
 		return &out, nil
diff --git a/internal/rpc/starknet/types.go b/internal/rpc/starknet/types.go
index 3d91f42a..bab91675 100644
--- a/internal/rpc/starknet/types.go
+++ b/internal/rpc/starknet/types.go
@@ -172,14 +172,12 @@ func NewTxn(tx types.IsTransaction) (Txn, error) {
 }
 
 type CommonTxnProperties struct {
-	TxnHash          string   `json:"txn_hash"`
-	MaxFee           string   `json:"max_fee"`
-	Version          string   `json:"version"`
-	Signature        []string `json:"signature"`
-	Status           string   `json:"status"`
-	TransactionIndex string   `json:"transaction_index"`
-	Nonce            string   `json:"nonce"`
-	Type             string   `json:"type"`
+	TxnHash   string   `json:"txn_hash"`
+	MaxFee    string   `json:"max_fee"`
+	Version   string   `json:"version"`
+	Signature []string `json:"signature"`
+	Nonce     string   `json:"nonce"`
+	Type      string   `json:"type"`
 }
 
 type FunctionCall struct {
@@ -251,7 +249,10 @@ func (*DeclareTxn) isTxn() {}
 type DeployTxn struct {
 	TxnHash             string   `json:"txn_hash"`
 	ClassHash           string   `json:"class_hash"`
+	Version             string   `json:"version"`
+	Type                string   `json:"type"`
 	ContractAddress     string   `json:"contract_address"`
+	ContractAddressSalt string   `json:"contract_address_salt"`
 	ConstructorCalldata []string `json:"constructor_calldata"`
 }
 
@@ -263,7 +264,10 @@ func NewDeployTxn(txn *types.TransactionDeploy) *DeployTxn {
 	return &DeployTxn{
 		TxnHash:             txn.Hash.Hex0x(),
 		ClassHash:           txn.ClassHash.Hex0x(),
+		Version:             "0x0", // XXX: hardcoded version for now
+		Type:                "DEPLOY",
 		ContractAddress:     txn.ContractAddress.Hex0x(),
+		ContractAddressSalt: txn.ContractAddressSalt.Hex0x(),
 		ConstructorCalldata: callData,
 	}
 }
diff --git a/internal/sync/sync.go b/internal/sync/sync.go
index c351c7e5..87959cdd 100644
--- a/internal/sync/sync.go
+++ b/internal/sync/sync.go
@@ -531,6 +531,7 @@ func feederTransactionToDBTransaction(info *feeder.TransactionInfo) types.IsTran
 		return &types.TransactionDeploy{
 			Hash:                new(felt.Felt).SetHex(info.Transaction.TransactionHash),
 			ContractAddress:     new(felt.Felt).SetHex(info.Transaction.ContractAddress),
+			ContractAddressSalt: new(felt.Felt).SetHex(info.Transaction.ContractAddressSalt),
 			ClassHash:           new(felt.Felt).SetHex(info.Transaction.ClassHash),
 			ConstructorCallData: constructorCalldata,
 		}
diff --git a/pkg/feeder/types.go b/pkg/feeder/types.go
index 12621ed6..afdcee4a 100644
--- a/pkg/feeder/types.go
+++ b/pkg/feeder/types.go
@@ -72,6 +72,7 @@ type TxnSpecificInfo struct {
 	TransactionHash     string   `json:"transaction_hash"`
 	MaxFee              string   `json:"max_fee"`
 	Type                string   `json:"type"`
+	ContractAddressSalt string   `json:"contract_address_salt"`
 }
 
 // L1ToL2Message Represents a StarkNet L1-to-L2 message.
diff --git a/pkg/types/transaction.go b/pkg/types/transaction.go
index 73c3e78f..0eb5059c 100644
--- a/pkg/types/transaction.go
+++ b/pkg/types/transaction.go
@@ -12,6 +12,7 @@ type TransactionDeploy struct {
 	Hash                *felt.Felt
 	ClassHash           *felt.Felt
 	ContractAddress     *felt.Felt
+	ContractAddressSalt *felt.Felt
 	ConstructorCallData []*felt.Felt
 }
 


Test patch:
diff --git a/internal/db/transaction/manager_test.go b/internal/db/transaction/manager_test.go
index 44cf0c0f..02e4c390 100644
--- a/internal/db/transaction/manager_test.go
+++ b/internal/db/transaction/manager_test.go
@@ -63,7 +63,8 @@ var txs = []types.IsTransaction{
 			new(felt.Felt).SetHex("06cf6c2f36d36b08e591e4489e92ca882bb67b9c39a3afccf011972a8de467f0"),
 			new(felt.Felt).SetHex("7ab344d88124307c07b56f6c59c12f4543e9c96398727854a322dea82c73240"),
 		},
-		ClassHash: new(felt.Felt).SetHex("0x10455c752b86932ce552f2b0fe81a880746649b9aee7e0d842bf3f52378f9f8"),
+		ClassHash:           new(felt.Felt).SetHex("0x10455c752b86932ce552f2b0fe81a880746649b9aee7e0d842bf3f52378f9f8"),
+		ContractAddressSalt: new(felt.Felt).SetHex("0x546c86dc6e40a5e5492b782d8964e9a4274ff6ecb16d31eb09cee45a3564015"),
 	},
 	&types.TransactionDeploy{
 		Hash:            new(felt.Felt).SetHex("0x12c96ae3c050771689eb261c9bf78fac2580708c7f1f3d69a9647d8be59f1e1"),
@@ -72,7 +73,8 @@ var txs = []types.IsTransaction{
 			new(felt.Felt).SetHex("0xcfc2e2866fd08bfb4ac73b70e0c136e326ae18fc797a2c090c8811c695577e"),
 			new(felt.Felt).SetHex("0x5f1dd5a5aef88e0498eeca4e7b2ea0fa7110608c11531278742f0b5499af4b3"),
 		},
-		ClassHash: new(felt.Felt).SetHex("0x10455c752b86932ce552f2b0fe81a880746649b9aee7e0d842bf3f52378f9f8"),
+		ClassHash:           new(felt.Felt).SetHex("0x10455c752b86932ce552f2b0fe81a880746649b9aee7e0d842bf3f52378f9f8"),
+		ContractAddressSalt: new(felt.Felt).SetHex("0x12afa0f342ece0468ca9810f0ea59f9c7204af32d1b8b0d318c4f2fe1f384e"),
 	},
 	&types.TransactionDeclare{
 		Hash:          new(felt.Felt).SetHex("0x12c96ae3c050771689eb261c9bf78fac2580708c7f1f3d69a9647d8be59f1e2"),