Skip to content

Commit

Permalink
remove Deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Aug 18, 2023
1 parent e409e6e commit a645a4a
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 78 deletions.
15 changes: 6 additions & 9 deletions contracts/contractsv02.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ func (p *RPCProvider) deployAndWaitWithWallet(ctx context.Context, compiledClass
if err := json.Unmarshal(compiledClass, &class); err != nil {
return nil, err
}
fmt.Println("a")

saltFelt, err := utils.HexToFelt(salt)
if err != nil {
return nil, err
Expand All @@ -125,15 +123,14 @@ func (p *RPCProvider) deployAndWaitWithWallet(ctx context.Context, compiledClass
}

// TODO: use UDC via account
tx, err := provider.AddDeployTransaction(ctx, rpc.BroadcastedDeployTxn{
DeployTransactionProperties: rpc.DeployTransactionProperties{
Version: rpc.TransactionV1,
ContractAddressSalt: saltFelt,
ConstructorCalldata: inputsFelt,
tx, err := provider.AddDeployAccountTransaction(ctx, rpc.BroadcastedDeployAccountTransaction{
BroadcastedTxnCommonProperties: rpc.BroadcastedTxnCommonProperties{
Version: rpc.TransactionV1,
},
ContractClass: class,
ContractAddressSalt: saltFelt,
ConstructorCalldata: inputsFelt,
})
fmt.Println("b")

if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type api interface {
TransactionReceipt(ctx context.Context, transactionHash *felt.Felt) (TransactionReceipt, error)
AddInvokeTransaction(ctx context.Context, broadcastedInvoke BroadcastedInvokeTransaction) (*AddInvokeTransactionResponse, error)
AddDeclareTransaction(ctx context.Context, declareTransaction BroadcastedDeclareTransaction) (*AddDeclareTransactionResponse, error)
AddDeployAccountTransaction(ctx context.Context, deployAccountTransaction BroadcastedDeployAccountTransaction) (*AddDeployTransactionResponse, error)
AddDeployAccountTransaction(ctx context.Context, deployAccountTransaction BroadcastedDeployAccountTransaction) (*AddDeployAccountTransactionResponse, error)
}

var _ api = &Provider{}
6 changes: 1 addition & 5 deletions rpc/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ func adaptTransaction(t TXN) (Transaction, error) {
var tx L1HandlerTxn
json.Unmarshal(txMarshalled, &tx)
return tx, nil
case TransactionType_Deploy:
var tx DeployTxn
json.Unmarshal(txMarshalled, &tx)
return tx, nil
default:
panic("not a transaction")
}
Expand Down Expand Up @@ -112,7 +108,7 @@ func (provider *Provider) WaitForTransaction(ctx context.Context, transactionHas
if r.Status.IsTransactionFinal() {
return r.Status, nil
}
case DeployTransactionReceipt:
case DeployAccountTransactionReceipt:
if r.Status.IsTransactionFinal() {
return r.Status, nil
}
Expand Down
25 changes: 1 addition & 24 deletions rpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,6 @@ func TestDeployOrDeclareReceipt(t *testing.T) {
ExpectedTxnReceipt TransactionReceipt
}

var receiptTxn310843_14 = DeployTransactionReceipt{
CommonTransactionReceipt: CommonTransactionReceipt{
TransactionHash: utils.TestHexToFelt(t, "0x035bd2978d2061b3463498f83c09322ed6a82e4b2a188506525e272a7adcdf6a"),
ActualFee: &felt.Zero,
Status: "ACCEPTED_ON_L1",
BlockHash: utils.TestHexToFelt(t, "0x0424fba26a7760b63895abe0c366c2d254cb47090c6f9e91ba2b3fa0824d4fc9"),
BlockNumber: 310843,
Type: "DEPLOY",
MessagesSent: []MsgToL1{},
Events: []Event{},
},
ContractAddress: "0x21c40b1377353924e185c9536469787dbe0cdb77b6877fa3a9946b795c71ec7",
}

var receiptTxn300114_3 = DeclareTransactionReceipt(
CommonTransactionReceipt{
TransactionHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"),
Expand All @@ -307,10 +293,6 @@ func TestDeployOrDeclareReceipt(t *testing.T) {
testSet := map[string][]testSetType{
"mock": {},
"testnet": {
{
TxnHash: utils.TestHexToFelt(t, "0x35bd2978d2061b3463498f83c09322ed6a82e4b2a188506525e272a7adcdf6a"),
ExpectedTxnReceipt: receiptTxn310843_14,
},
{
TxnHash: utils.TestHexToFelt(t, "0x46a9f52a96b2d226407929e04cb02507e531f7c78b9196fc8c910351d8c33f3"),
ExpectedTxnReceipt: receiptTxn300114_3,
Expand All @@ -329,16 +311,11 @@ func TestDeployOrDeclareReceipt(t *testing.T) {
if txReceiptInterface == nil {
t.Fatal("transaction receipt should exist")
}
txnDeployReceipt, ok1 := txReceiptInterface.(DeployTransactionReceipt)
txnDeclareReceipt, ok2 := txReceiptInterface.(DeclareTransactionReceipt)
if !ok1 && !ok2 {
if !ok2 {
t.Fatalf("transaction receipt should be Deploy or Declare, instead %T", txReceiptInterface)
}
switch {
case ok1:
if !cmp.Equal(test.ExpectedTxnReceipt, txnDeployReceipt) {
t.Fatalf("the expected transaction blocks to match, instead: %s", cmp.Diff(test.ExpectedTxnReceipt, txnDeployReceipt))
}
case ok2:
if !cmp.Equal(test.ExpectedTxnReceipt, txnDeclareReceipt) {
t.Fatalf("the expected transaction blocks to match, instead: %s", cmp.Diff(test.ExpectedTxnReceipt, txnDeclareReceipt))
Expand Down
4 changes: 0 additions & 4 deletions rpc/types_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ func unmarshalTxn(t interface{}) (Transaction, error) {
var txn DeclareTxn
remarshal(casted, &txn)
return txn, nil
case TransactionType_Deploy:
var txn DeployTxn
remarshal(casted, &txn)
return txn, nil
case TransactionType_DeployAccount:
var txn DeployAccountTxn
remarshal(casted, &txn)
Expand Down
23 changes: 1 addition & 22 deletions rpc/types_transaction_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type TransactionType string

const (
TransactionType_Declare TransactionType = "DECLARE"
TransactionType_Deploy TransactionType = "DEPLOY"
TransactionType_DeployAccount TransactionType = "DEPLOY_ACCOUNT"
TransactionType_Invoke TransactionType = "INVOKE"
TransactionType_L1Handler TransactionType = "L1_HANDLER"
Expand All @@ -48,8 +47,6 @@ func (tt *TransactionType) UnmarshalJSON(data []byte) error {
switch unquoted {
case "DECLARE":
*tt = TransactionType_Declare
case "DEPLOY":
*tt = TransactionType_Deploy
case "DEPLOY_ACCOUNT":
*tt = TransactionType_DeployAccount
case "INVOKE":
Expand Down Expand Up @@ -81,13 +78,6 @@ func (tr DeclareTransactionReceipt) Hash() *felt.Felt {
return tr.TransactionHash
}

// DeployTransactionReceipt Deploy Transaction Receipt
type DeployTransactionReceipt struct {
CommonTransactionReceipt
// ContractAddress The address of the deployed contract
ContractAddress string `json:"contract_address"`
}

// DeployAccountTransactionReceipt Deploy Account Transaction Receipt
type DeployAccountTransactionReceipt struct {
CommonTransactionReceipt
Expand All @@ -102,13 +92,6 @@ func (tr L1HandlerTransactionReceipt) Hash() *felt.Felt {
return tr.TransactionHash
}

// PendingDeployTransactionReceipt Pending Transaction Receipt
type PendingDeployTransactionReceipt struct {
PendingCommonTransactionReceiptProperties
// ContractAddress The address of the deployed contract
ContractAddress *felt.Felt `json:"contract_address"`
}

// PendingCommonTransactionReceiptProperties Pending Transaction Receipt
type PendingCommonTransactionReceiptProperties struct {
// TransactionHash The hash identifying the transaction
Expand Down Expand Up @@ -176,12 +159,8 @@ func unmarshalTransactionReceipt(t interface{}) (TransactionReceipt, error) {
var txn DeclareTransactionReceipt
remarshal(casted, &txn)
return txn, nil
case TransactionType_Deploy:
var txn DeployTransactionReceipt
remarshal(casted, &txn)
return txn, nil
case TransactionType_DeployAccount:
var txn DeployTransactionReceipt
var txn DeployAccountTransactionReceipt
remarshal(casted, &txn)
return txn, nil
case TransactionType_Invoke:
Expand Down
2 changes: 1 addition & 1 deletion rpc/types_transaction_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type AddDeclareTransactionResponse struct {
}

// AddDeployTransactionResponse provides the output for AddDeployTransaction.
type AddDeployTransactionResponse struct {
type AddDeployAccountTransactionResponse struct {
TransactionHash *felt.Felt `json:"transaction_hash"`
ContractAddress *felt.Felt `json:"contract_address"`
}
Expand Down
14 changes: 2 additions & 12 deletions rpc/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,9 @@ func (provider *Provider) AddDeclareTransaction(ctx context.Context, declareTran
return &result, nil
}

// AddDeployTransaction allows to declare a class and instantiate the
// associated contract in one command. This function will be deprecated and
// replaced by AddDeclareTransaction to declare a class, followed by
// AddInvokeTransaction to instantiate the contract. For now, it remains the only
// way to deploy an account without being charged for it.
func (provider *Provider) AddDeployTransaction(ctx context.Context, deployTransaction BroadcastedDeployTxn) (*AddDeployTransactionResponse, error) {
var result AddDeployTransactionResponse
return &result, errors.New("AddDeployTransaction was removed, UDC should be used instead")
}

// AddDeployAccountTransaction manages the DEPLOY_ACCOUNT syscall
func (provider *Provider) AddDeployAccountTransaction(ctx context.Context, deployAccountTransaction BroadcastedDeployAccountTransaction) (*AddDeployTransactionResponse, error) {
var result AddDeployTransactionResponse
func (provider *Provider) AddDeployAccountTransaction(ctx context.Context, deployAccountTransaction BroadcastedDeployAccountTransaction) (*AddDeployAccountTransactionResponse, error) {
var result AddDeployAccountTransactionResponse
if err := do(ctx, provider.c, "starknet_addDeployAccountTransaction", &result, deployAccountTransaction); err != nil {
if strings.Contains(err.Error(), "Class hash not found") {
return nil, ErrClassHashNotFound
Expand Down

0 comments on commit a645a4a

Please sign in to comment.