From 0819583413f5f06891ff4742ba4fcd1319628ad3 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 2 Jul 2020 16:22:49 +0300 Subject: [PATCH] cli/rpc: test-invoke deployment script to get the system fee value Fix #1134. --- cli/smartcontract/smart_contract.go | 9 +++++++-- pkg/rpc/request/txBuilder.go | 10 ++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/smartcontract/smart_contract.go b/cli/smartcontract/smart_contract.go index 292c6649c..69c0c4b47 100644 --- a/cli/smartcontract/smart_contract.go +++ b/cli/smartcontract/smart_contract.go @@ -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) } diff --git a/pkg/rpc/request/txBuilder.go b/pkg/rpc/request/txBuilder.go index 953ef7287..f8db67de2 100644 --- a/pkg/rpc/request/txBuilder.go +++ b/pkg/rpc/request/txBuilder.go @@ -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