From 8a5ac12df85da4041cc77003ed24d08ab6c968b6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 29 Nov 2019 17:59:07 +0300 Subject: [PATCH] rpc: make generic SignAndPushInvocationTx out of DeployContract SignAndPushInvocationTx() is gonna be used for more than just deploying contracts. --- cli/smartcontract/smart_contract.go | 9 +++++++-- pkg/rpc/rpc.go | 15 ++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index e3f8cd2b2..4b7c2877c 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -503,9 +503,14 @@ func contractDeploy(ctx *cli.Context) error { return cli.NewExitError(err, 1) } - txHash, err := client.DeployContract(avm, &conf.Contract, wif, gas) + txScript, err := rpc.CreateDeploymentScript(avm, &conf.Contract) if err != nil { - return cli.NewExitError(fmt.Errorf("failed to deploy: %v", err), 1) + return cli.NewExitError(fmt.Errorf("failed to create deployment script: %v", err), 1) + } + + txHash, err := client.SignAndPushInvocationTx(txScript, wif, gas) + if err != nil { + return cli.NewExitError(fmt.Errorf("failed to push invocation tx: %v", err), 1) } fmt.Printf("Sent deployment transaction %s for contract %s\n", txHash.ReverseString(), hash.Hash160(avm).ReverseString()) return nil diff --git a/pkg/rpc/rpc.go b/pkg/rpc/rpc.go index 6995c74d7..be9143085 100644 --- a/pkg/rpc/rpc.go +++ b/pkg/rpc/rpc.go @@ -153,20 +153,17 @@ func (c *Client) SendToAddress(asset util.Uint256, address string, amount util.F return response, nil } -// DeployContract deploys given contract to the blockchain using given wif to -// sign the transaction and spending the amount of gas specified. It returns -// a hash of the deployment transaction and an error. -func (c *Client) DeployContract(avm []byte, contract *ContractDetails, wif *keys.WIF, gas util.Fixed8) (util.Uint256, error) { +// SignAndPushInvocationTx signs and pushes given script as an invocation +// transaction using given wif to sign it and spending the amount of gas +// specified. It returns a hash of the invocation transaction and an error. +func (c *Client) SignAndPushInvocationTx(script []byte, wif *keys.WIF, gas util.Fixed8) (util.Uint256, error) { var txHash util.Uint256 + var err error gasIDB, _ := hex.DecodeString("602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7") gasID, _ := util.Uint256DecodeReverseBytes(gasIDB) - txScript, err := CreateDeploymentScript(avm, contract) - if err != nil { - return txHash, errors.Wrap(err, "failed creating deployment script") - } - tx := transaction.NewInvocationTX(txScript, gas) + tx := transaction.NewInvocationTX(script, gas) fromAddress := wif.PrivateKey.Address()