cli: allow to send multisig deploy/invoke tx

It allows to invoke native contracts as committee
from CLI in privnet, e.g. to set new oracle nodes.

Also don't require `out` flag in `multisig sign`
if tx is to be pushed.
This commit is contained in:
Evgenii Stratonikov 2020-10-02 16:13:17 +03:00
parent 0dcf42ac24
commit 897c9198f8
5 changed files with 108 additions and 46 deletions

View file

@ -1,25 +1,20 @@
package wallet
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"strings"
"github.com/nspcc-dev/neo-go/cli/flags"
"github.com/nspcc-dev/neo-go/cli/options"
"github.com/nspcc-dev/neo-go/cli/paramcontext"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/context"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/urfave/cli"
)
// validUntilBlockIncrement is the number of extra blocks to add to an exported transaction
const validUntilBlockIncrement = 50
var (
neoToken = wallet.NewToken(client.NeoContractHash, "NEO", "neo", 0)
gasToken = wallet.NewToken(client.GasContractHash, "GAS", "gas", 8)
@ -474,18 +469,8 @@ func signAndSendTransfer(ctx *cli.Context, c *client.Client, acc *wallet.Account
}
if outFile := ctx.String("out"); outFile != "" {
// avoid fast transaction expiration
tx.ValidUntilBlock += validUntilBlockIncrement
priv := acc.PrivateKey()
pub := priv.PublicKey()
sign := priv.Sign(tx.GetSignedPart())
scCtx := context.NewParameterContext("Neo.Core.ContractTransaction", tx)
if err := scCtx.AddSignature(acc.Contract, pub, sign); err != nil {
return cli.NewExitError(fmt.Errorf("can't add signature: %w", err), 1)
} else if data, err := json.Marshal(scCtx); err != nil {
return cli.NewExitError(fmt.Errorf("can't marshal tx to JSON: %w", err), 1)
} else if err := ioutil.WriteFile(outFile, data, 0644); err != nil {
return cli.NewExitError(fmt.Errorf("can't write tx to file: %w", err), 1)
if err := paramcontext.InitAndSave(tx, acc, outFile); err != nil {
return cli.NewExitError(err, 1)
}
} else {
_ = acc.SignTx(tx)