mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
cli/rpc: test-invoke deployment script to get the system fee value
Fix #1134.
This commit is contained in:
parent
17ea6411a2
commit
0819583413
2 changed files with 11 additions and 8 deletions
|
@ -654,12 +654,17 @@ func contractDeploy(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
txScript, sysfee, err := request.CreateDeploymentScript(nefFile.Script, m)
|
||||
txScript, err := request.CreateDeploymentScript(nefFile.Script, m)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to create deployment script: %v", err), 1)
|
||||
}
|
||||
// It doesn't require any cosigners.
|
||||
invRes, err := c.InvokeScript(hex.EncodeToString(txScript), nil)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to test-invoke deployment script: %v", err), 1)
|
||||
}
|
||||
|
||||
txHash, err := c.SignAndPushInvocationTx(txScript, acc, sysfee, gas)
|
||||
txHash, err := c.SignAndPushInvocationTx(txScript, acc, invRes.GasConsumed, gas)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to push invocation tx: %v", err), 1)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
|
@ -16,18 +15,17 @@ import (
|
|||
)
|
||||
|
||||
// CreateDeploymentScript returns a script that deploys given smart contract
|
||||
// with its metadata and system fee require for this.
|
||||
func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, int64, error) {
|
||||
// with its metadata.
|
||||
func CreateDeploymentScript(avm []byte, manif *manifest.Manifest) ([]byte, error) {
|
||||
script := io.NewBufBinWriter()
|
||||
rawManifest, err := manif.MarshalJSON()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
return nil, err
|
||||
}
|
||||
emit.Bytes(script.BinWriter, rawManifest)
|
||||
emit.Bytes(script.BinWriter, avm)
|
||||
emit.Syscall(script.BinWriter, "System.Contract.Create")
|
||||
sysfee := int64(core.StoragePrice * (len(avm) + len(rawManifest)))
|
||||
return script.Bytes(), sysfee, nil
|
||||
return script.Bytes(), nil
|
||||
}
|
||||
|
||||
// expandArrayIntoScript pushes all FuncParam parameters from the given array
|
||||
|
|
Loading…
Reference in a new issue