2020-03-02 12:39:02 +00:00
|
|
|
package wallet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2020-06-17 21:15:13 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/options"
|
2020-10-02 13:13:17 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/cli/paramcontext"
|
2020-03-02 12:39:02 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newMultisigCommands() []cli.Command {
|
2020-06-17 21:15:13 +00:00
|
|
|
signFlags := []cli.Flag{
|
|
|
|
walletPathFlag,
|
|
|
|
outFlag,
|
|
|
|
inFlag,
|
|
|
|
cli.StringFlag{
|
2020-09-28 15:43:53 +00:00
|
|
|
Name: "address, a",
|
2020-06-17 21:15:13 +00:00
|
|
|
Usage: "Address to use",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
signFlags = append(signFlags, options.RPC...)
|
2020-03-02 12:39:02 +00:00
|
|
|
return []cli.Command{
|
|
|
|
{
|
|
|
|
Name: "sign",
|
|
|
|
Usage: "sign a transaction",
|
2020-09-28 15:43:53 +00:00
|
|
|
UsageText: "multisig sign --wallet <path> --address <address> --in <file.in> --out <file.out>",
|
2020-03-02 12:39:02 +00:00
|
|
|
Action: signMultisig,
|
2020-06-17 21:15:13 +00:00
|
|
|
Flags: signFlags,
|
2020-03-02 12:39:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func signMultisig(ctx *cli.Context) error {
|
2020-06-25 15:46:24 +00:00
|
|
|
wall, err := openWallet(ctx.String("wallet"))
|
2020-03-02 12:39:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
defer wall.Close()
|
|
|
|
|
2020-10-02 13:13:17 +00:00
|
|
|
c, err := paramcontext.Read(ctx.String("in"))
|
2020-03-02 12:39:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
2020-09-28 15:43:53 +00:00
|
|
|
addr := ctx.String("address")
|
2020-03-02 12:39:02 +00:00
|
|
|
sh, err := address.StringToUint160(addr)
|
|
|
|
if err != nil {
|
2020-08-06 16:09:57 +00:00
|
|
|
return cli.NewExitError(fmt.Errorf("invalid address: %w", err), 1)
|
2020-03-02 12:39:02 +00:00
|
|
|
}
|
2020-08-28 09:11:19 +00:00
|
|
|
acc, err := getDecryptedAccount(ctx, wall, sh)
|
2020-08-07 09:34:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
2020-03-02 12:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tx, ok := c.Verifiable.(*transaction.Transaction)
|
|
|
|
if !ok {
|
|
|
|
return cli.NewExitError("verifiable item is not a transaction", 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
priv := acc.PrivateKey()
|
|
|
|
sign := priv.Sign(tx.GetSignedPart())
|
|
|
|
if err := c.AddSignature(acc.Contract, priv.PublicKey(), sign); err != nil {
|
2020-08-06 16:09:57 +00:00
|
|
|
return cli.NewExitError(fmt.Errorf("can't add signature: %w", err), 1)
|
2020-10-02 06:40:41 +00:00
|
|
|
}
|
|
|
|
if out := ctx.String("out"); out != "" {
|
2020-10-02 13:13:17 +00:00
|
|
|
if err := paramcontext.Save(c, out); err != nil {
|
2020-10-02 06:40:41 +00:00
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
2020-03-02 12:39:02 +00:00
|
|
|
}
|
2020-06-17 21:15:13 +00:00
|
|
|
if len(ctx.String(options.RPCEndpointFlag)) != 0 {
|
2020-03-02 12:39:02 +00:00
|
|
|
w, err := c.GetWitness(acc.Contract)
|
|
|
|
if err != nil {
|
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
|
|
|
tx.Scripts = append(tx.Scripts, *w)
|
|
|
|
|
2020-06-17 21:15:13 +00:00
|
|
|
gctx, cancel := options.GetTimeoutContext(ctx)
|
2020-03-02 12:39:02 +00:00
|
|
|
defer cancel()
|
|
|
|
|
2020-06-17 21:15:13 +00:00
|
|
|
c, err := options.GetRPCClient(gctx, ctx)
|
2020-03-02 12:39:02 +00:00
|
|
|
if err != nil {
|
2020-11-03 11:08:59 +00:00
|
|
|
return cli.NewExitError(err, 1)
|
2020-06-17 21:15:13 +00:00
|
|
|
}
|
2020-07-21 07:31:45 +00:00
|
|
|
res, err := c.SendRawTransaction(tx)
|
|
|
|
if err != nil {
|
2020-03-02 12:39:02 +00:00
|
|
|
return cli.NewExitError(err, 1)
|
|
|
|
}
|
2020-08-28 09:11:19 +00:00
|
|
|
fmt.Fprintln(ctx.App.Writer, res.StringLE())
|
2020-07-21 07:31:45 +00:00
|
|
|
return nil
|
2020-03-02 12:39:02 +00:00
|
|
|
}
|
|
|
|
|
2020-08-28 09:11:19 +00:00
|
|
|
fmt.Fprintln(ctx.App.Writer, tx.Hash().StringLE())
|
2020-03-02 12:39:02 +00:00
|
|
|
return nil
|
|
|
|
}
|