rpc: make generic SignAndPushInvocationTx out of DeployContract
SignAndPushInvocationTx() is gonna be used for more than just deploying contracts.
This commit is contained in:
parent
65332f5e7f
commit
8a5ac12df8
2 changed files with 13 additions and 11 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue