2019-01-16 09:30:57 -08:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2019-05-18 16:06:08 -07:00
|
|
|
"strings"
|
2019-01-16 09:30:57 -08:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2021-02-24 11:56:10 -08:00
|
|
|
"github.com/spf13/viper"
|
2019-06-05 16:26:17 -07:00
|
|
|
|
2020-06-01 05:46:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
2019-06-05 16:26:17 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
2020-07-29 15:33:42 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/tx"
|
2020-03-25 08:20:36 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
2020-09-18 02:40:39 -07:00
|
|
|
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
2020-06-04 03:38:24 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/types/multisig"
|
2020-01-22 09:54:56 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2021-02-24 11:56:10 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/errors"
|
2020-07-29 15:33:42 -07:00
|
|
|
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
|
2019-05-18 16:06:08 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
2020-06-01 05:46:03 -07:00
|
|
|
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
2021-07-06 03:04:54 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
2020-07-29 15:33:42 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/signing"
|
2019-01-16 09:30:57 -08:00
|
|
|
)
|
|
|
|
|
2021-07-06 03:04:54 -07:00
|
|
|
// BroadcastReq defines a tx broadcasting request.
|
|
|
|
type BroadcastReq struct {
|
|
|
|
Tx legacytx.StdTx `json:"tx" yaml:"tx"`
|
|
|
|
Mode string `json:"mode" yaml:"mode"`
|
|
|
|
}
|
|
|
|
|
2019-01-16 09:30:57 -08:00
|
|
|
// GetSignCommand returns the sign command
|
2020-07-14 11:37:14 -07:00
|
|
|
func GetMultiSignCommand() *cobra.Command {
|
2019-01-16 09:30:57 -08:00
|
|
|
cmd := &cobra.Command{
|
2019-02-06 16:15:37 -08:00
|
|
|
Use: "multisign [file] [name] [[signature]...]",
|
2019-01-16 09:30:57 -08:00
|
|
|
Short: "Generate multisig signatures for transactions generated offline",
|
2019-05-18 16:06:08 -07:00
|
|
|
Long: strings.TrimSpace(
|
|
|
|
fmt.Sprintf(`Sign transactions created with the --generate-only flag that require multisig signatures.
|
2019-01-16 09:30:57 -08:00
|
|
|
|
2021-02-27 01:39:08 -08:00
|
|
|
Read one or more signatures from one or more [signature] file, generate a multisig signature compliant to the
|
|
|
|
multisig key [name], and attach the key name to the transaction read from [file].
|
2019-01-16 09:30:57 -08:00
|
|
|
|
2019-05-18 16:06:08 -07:00
|
|
|
Example:
|
2021-02-24 11:56:10 -08:00
|
|
|
$ %s tx multisign transaction.json k1k2k3 k1sig.json k2sig.json k3sig.json
|
2019-01-16 09:30:57 -08:00
|
|
|
|
2021-02-27 01:39:08 -08:00
|
|
|
If --signature-only flag is on, output a JSON representation
|
|
|
|
of only the generated signature.
|
2019-01-16 09:30:57 -08:00
|
|
|
|
2021-02-27 01:39:08 -08:00
|
|
|
If the --offline flag is on, the client will not reach out to an external node.
|
|
|
|
Account number or sequence number lookups are not performed so you must
|
|
|
|
set these parameters manually.
|
2021-02-24 11:56:10 -08:00
|
|
|
|
2021-02-27 01:39:08 -08:00
|
|
|
The current multisig implementation defaults to amino-json sign mode.
|
|
|
|
The SIGN_MODE_DIRECT sign mode is not supported.'
|
2019-01-16 09:30:57 -08:00
|
|
|
`,
|
2020-07-07 08:40:46 -07:00
|
|
|
version.AppName,
|
2019-05-18 16:06:08 -07:00
|
|
|
),
|
|
|
|
),
|
2020-07-14 11:37:14 -07:00
|
|
|
RunE: makeMultiSignCmd(),
|
2019-01-16 09:30:57 -08:00
|
|
|
Args: cobra.MinimumNArgs(3),
|
|
|
|
}
|
2019-05-18 16:06:08 -07:00
|
|
|
|
2019-01-16 09:30:57 -08:00
|
|
|
cmd.Flags().Bool(flagSigOnly, false, "Print only the generated signature, then exit")
|
2021-02-27 01:39:08 -08:00
|
|
|
cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT")
|
|
|
|
cmd.Flags().Bool(flagAmino, false, "Generate Amino-encoded JSON suitable for submitting to the txs REST endpoint")
|
2020-07-11 01:13:46 -07:00
|
|
|
flags.AddTxFlagsToCmd(cmd)
|
2020-07-14 11:37:14 -07:00
|
|
|
cmd.Flags().String(flags.FlagChainID, "", "network chain ID")
|
2019-01-16 09:30:57 -08:00
|
|
|
|
2020-07-11 01:13:46 -07:00
|
|
|
return cmd
|
2019-01-16 09:30:57 -08:00
|
|
|
}
|
|
|
|
|
2020-12-14 13:44:15 -08:00
|
|
|
func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) {
|
2019-01-16 09:30:57 -08:00
|
|
|
return func(cmd *cobra.Command, args []string) (err error) {
|
2020-12-14 14:09:51 -08:00
|
|
|
clientCtx, err := client.GetClientTxContext(cmd)
|
2020-07-29 15:33:42 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
parsedTx, err := authclient.ReadTxFromFile(clientCtx, args[0])
|
2019-01-16 09:30:57 -08:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-29 15:33:42 -07:00
|
|
|
txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags())
|
|
|
|
if txFactory.SignMode() == signingtypes.SignMode_SIGN_MODE_UNSPECIFIED {
|
2021-04-06 16:33:54 -07:00
|
|
|
txFactory = txFactory.WithSignMode(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
|
2020-07-29 15:33:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
txCfg := clientCtx.TxConfig
|
|
|
|
txBuilder, err := txCfg.WrapTxBuilder(parsedTx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-09-20 05:02:15 -07:00
|
|
|
k, err := getMultisigRecord(clientCtx, args[1])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pubKey, err := k.GetPubKey()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := k.GetAddress()
|
2019-01-16 09:30:57 -08:00
|
|
|
if err != nil {
|
2021-02-24 11:56:10 -08:00
|
|
|
return err
|
2019-01-16 09:30:57 -08:00
|
|
|
}
|
|
|
|
|
2021-09-20 05:02:15 -07:00
|
|
|
multisigPub := pubKey.(*kmultisig.LegacyAminoPubKey)
|
2019-01-16 09:30:57 -08:00
|
|
|
multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys))
|
2020-06-01 05:46:03 -07:00
|
|
|
if !clientCtx.Offline {
|
2021-09-20 05:02:15 -07:00
|
|
|
accnum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, addr)
|
2019-01-16 09:30:57 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-29 15:33:42 -07:00
|
|
|
txFactory = txFactory.WithAccountNumber(accnum).WithSequence(seq)
|
2019-01-16 09:30:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// read each signature and add it to the multisig if valid
|
|
|
|
for i := 2; i < len(args); i++ {
|
2020-07-29 15:33:42 -07:00
|
|
|
sigs, err := unmarshalSignatureJSON(clientCtx, args[i])
|
2019-01-16 09:30:57 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-29 01:10:04 -07:00
|
|
|
if txFactory.ChainID() == "" {
|
|
|
|
return fmt.Errorf("set the chain id with either the --chain-id flag or config file")
|
|
|
|
}
|
|
|
|
|
2021-12-08 03:43:15 -08:00
|
|
|
for _, sig := range sigs {
|
2021-10-18 03:32:43 -07:00
|
|
|
signingData := signing.SignerData{
|
|
|
|
Address: sdk.AccAddress(sig.PubKey.Address()).String(),
|
|
|
|
ChainID: txFactory.ChainID(),
|
|
|
|
AccountNumber: txFactory.AccountNumber(),
|
|
|
|
Sequence: txFactory.Sequence(),
|
2021-12-08 03:43:15 -08:00
|
|
|
PubKey: sig.PubKey,
|
2021-10-18 03:32:43 -07:00
|
|
|
}
|
2020-06-12 11:13:20 -07:00
|
|
|
|
2020-07-29 15:33:42 -07:00
|
|
|
err = signing.VerifySignature(sig.PubKey, signingData, sig.Data, txCfg.SignModeHandler(), txBuilder.GetTx())
|
|
|
|
if err != nil {
|
2021-02-19 07:23:52 -08:00
|
|
|
addr, _ := sdk.AccAddressFromHex(sig.PubKey.Address().String())
|
|
|
|
return fmt.Errorf("couldn't verify signature for address %s", addr)
|
2020-07-29 15:33:42 -07:00
|
|
|
}
|
2020-06-12 11:13:20 -07:00
|
|
|
|
2020-09-18 02:40:39 -07:00
|
|
|
if err := multisig.AddSignatureV2(multisigSig, sig, multisigPub.GetPubKeys()); err != nil {
|
2020-07-29 15:33:42 -07:00
|
|
|
return err
|
|
|
|
}
|
2019-03-19 09:52:43 -07:00
|
|
|
}
|
2019-01-16 09:30:57 -08:00
|
|
|
}
|
|
|
|
|
2020-07-29 15:33:42 -07:00
|
|
|
sigV2 := signingtypes.SignatureV2{
|
2020-08-21 07:20:47 -07:00
|
|
|
PubKey: multisigPub,
|
|
|
|
Data: multisigSig,
|
|
|
|
Sequence: txFactory.Sequence(),
|
2020-07-29 15:33:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
err = txBuilder.SetSignatures(sigV2)
|
2020-06-12 11:13:20 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-06 07:23:32 -07:00
|
|
|
sigOnly, _ := cmd.Flags().GetBool(flagSigOnly)
|
2020-06-30 13:59:21 -07:00
|
|
|
|
2020-10-15 08:12:35 -07:00
|
|
|
aminoJSON, _ := cmd.Flags().GetBool(flagAmino)
|
|
|
|
|
|
|
|
var json []byte
|
|
|
|
|
|
|
|
if aminoJSON {
|
|
|
|
stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBuilder.GetTx())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-06 03:04:54 -07:00
|
|
|
req := BroadcastReq{
|
2020-10-15 08:12:35 -07:00
|
|
|
Tx: stdTx,
|
|
|
|
Mode: "block|sync|async",
|
|
|
|
}
|
|
|
|
|
|
|
|
json, _ = clientCtx.LegacyAmino.MarshalJSON(req)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
json, err = marshalSignatureJSON(txCfg, txBuilder, sigOnly)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-01-16 09:30:57 -08:00
|
|
|
}
|
|
|
|
|
2020-07-06 07:23:32 -07:00
|
|
|
outputDoc, _ := cmd.Flags().GetString(flags.FlagOutputDocument)
|
|
|
|
if outputDoc == "" {
|
2020-07-14 11:37:14 -07:00
|
|
|
cmd.Printf("%s\n", json)
|
2019-01-16 09:30:57 -08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-06 07:23:32 -07:00
|
|
|
fp, err := os.OpenFile(outputDoc, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
2019-01-16 09:30:57 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-14 13:44:15 -08:00
|
|
|
defer func() {
|
|
|
|
err2 := fp.Close()
|
|
|
|
if err == nil {
|
|
|
|
err = err2
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
err = clientCtx.PrintBytes(json)
|
|
|
|
|
|
|
|
return
|
2019-01-16 09:30:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-24 11:56:10 -08:00
|
|
|
func GetMultiSignBatchCmd() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "multisign-batch [file] [name] [[signature-file]...]",
|
|
|
|
Short: "Assemble multisig transactions in batch from batch signatures",
|
|
|
|
Long: strings.TrimSpace(
|
|
|
|
fmt.Sprintf(`Assemble a batch of multisig transactions generated by batch sign command.
|
|
|
|
|
2021-02-27 01:39:08 -08:00
|
|
|
Read one or more signatures from one or more [signature] file, generate a multisig signature compliant to the
|
|
|
|
multisig key [name], and attach the key name to the transaction read from [file].
|
2021-02-24 11:56:10 -08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
$ %s tx multisign-batch transactions.json multisigk1k2k3 k1sigs.json k2sigs.json k3sig.json
|
|
|
|
|
2021-02-27 01:39:08 -08:00
|
|
|
The current multisig implementation defaults to amino-json sign mode.
|
|
|
|
The SIGN_MODE_DIRECT sign mode is not supported.'
|
2021-02-24 11:56:10 -08:00
|
|
|
`, version.AppName,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
PreRun: preSignCmd,
|
|
|
|
RunE: makeBatchMultisignCmd(),
|
|
|
|
Args: cobra.MinimumNArgs(3),
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Flags().Bool(flagNoAutoIncrement, false, "disable sequence auto increment")
|
|
|
|
cmd.Flags().String(
|
|
|
|
flagMultisig, "",
|
2021-02-27 01:39:08 -08:00
|
|
|
"Address of the multisig account that the transaction signs on behalf of",
|
2021-02-24 11:56:10 -08:00
|
|
|
)
|
2021-03-15 05:18:46 -07:00
|
|
|
cmd.Flags().String(flags.FlagOutputDocument, "", "The document is written to the given file instead of STDOUT")
|
2021-02-24 11:56:10 -08:00
|
|
|
flags.AddTxFlagsToCmd(cmd)
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error {
|
|
|
|
return func(cmd *cobra.Command, args []string) (err error) {
|
|
|
|
var clientCtx client.Context
|
|
|
|
|
|
|
|
clientCtx, err = client.GetClientTxContext(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
txCfg := clientCtx.TxConfig
|
|
|
|
txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags())
|
|
|
|
if txFactory.SignMode() == signingtypes.SignMode_SIGN_MODE_UNSPECIFIED {
|
2021-04-06 16:33:54 -07:00
|
|
|
txFactory = txFactory.WithSignMode(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
|
2021-02-24 11:56:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
var infile = os.Stdin
|
|
|
|
if args[0] != "-" {
|
|
|
|
infile, err = os.Open(args[0])
|
|
|
|
defer func() {
|
|
|
|
err2 := infile.Close()
|
|
|
|
if err == nil {
|
|
|
|
err = err2
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("couldn't open %s: %w", args[0], err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scanner := authclient.NewBatchScanner(txCfg, infile)
|
|
|
|
|
2021-09-20 05:02:15 -07:00
|
|
|
k, err := getMultisigRecord(clientCtx, args[1])
|
2021-02-24 11:56:10 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var signatureBatch [][]signingtypes.SignatureV2
|
|
|
|
for i := 2; i < len(args); i++ {
|
|
|
|
sigs, err := readSignaturesFromFile(clientCtx, args[i])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
signatureBatch = append(signatureBatch, sigs)
|
|
|
|
}
|
|
|
|
|
2021-09-20 05:02:15 -07:00
|
|
|
addr, err := k.GetAddress()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-24 11:56:10 -08:00
|
|
|
if !clientCtx.Offline {
|
2021-09-20 05:02:15 -07:00
|
|
|
accnum, seq, err := clientCtx.AccountRetriever.GetAccountNumberSequence(clientCtx, addr)
|
2021-02-24 11:56:10 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
txFactory = txFactory.WithAccountNumber(accnum).WithSequence(seq)
|
|
|
|
}
|
|
|
|
|
2021-03-15 05:18:46 -07:00
|
|
|
// prepare output document
|
|
|
|
closeFunc, err := setOutputFile(cmd)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer closeFunc()
|
|
|
|
clientCtx.WithOutput(cmd.OutOrStdout())
|
|
|
|
|
2021-02-24 11:56:10 -08:00
|
|
|
for i := 0; scanner.Scan(); i++ {
|
|
|
|
txBldr, err := txCfg.WrapTxBuilder(scanner.Tx())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-09-20 05:02:15 -07:00
|
|
|
pubKey, err := k.GetPubKey()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
multisigPub := pubKey.(*kmultisig.LegacyAminoPubKey)
|
2021-02-24 11:56:10 -08:00
|
|
|
multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys))
|
|
|
|
signingData := signing.SignerData{
|
2021-10-18 03:32:43 -07:00
|
|
|
Address: sdk.AccAddress(pubKey.Address()).String(),
|
2021-02-24 11:56:10 -08:00
|
|
|
ChainID: txFactory.ChainID(),
|
|
|
|
AccountNumber: txFactory.AccountNumber(),
|
|
|
|
Sequence: txFactory.Sequence(),
|
2021-12-08 03:43:15 -08:00
|
|
|
PubKey: pubKey,
|
2021-02-24 11:56:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, sig := range signatureBatch {
|
|
|
|
err = signing.VerifySignature(sig[i].PubKey, signingData, sig[i].Data, txCfg.SignModeHandler(), txBldr.GetTx())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("couldn't verify signature: %w %v", err, sig)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := multisig.AddSignatureV2(multisigSig, sig[i], multisigPub.GetPubKeys()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sigV2 := signingtypes.SignatureV2{
|
|
|
|
PubKey: multisigPub,
|
|
|
|
Data: multisigSig,
|
|
|
|
Sequence: txFactory.Sequence(),
|
|
|
|
}
|
|
|
|
|
|
|
|
err = txBldr.SetSignatures(sigV2)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sigOnly, _ := cmd.Flags().GetBool(flagSigOnly)
|
|
|
|
aminoJSON, _ := cmd.Flags().GetBool(flagAmino)
|
|
|
|
|
|
|
|
var json []byte
|
|
|
|
|
|
|
|
if aminoJSON {
|
|
|
|
stdTx, err := tx.ConvertTxToStdTx(clientCtx.LegacyAmino, txBldr.GetTx())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-06 03:04:54 -07:00
|
|
|
req := BroadcastReq{
|
2021-02-24 11:56:10 -08:00
|
|
|
Tx: stdTx,
|
|
|
|
Mode: "block|sync|async",
|
|
|
|
}
|
|
|
|
|
|
|
|
json, _ = clientCtx.LegacyAmino.MarshalJSON(req)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
json, err = marshalSignatureJSON(txCfg, txBldr, sigOnly)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = clientCtx.PrintString(fmt.Sprintf("%s\n", json))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if viper.GetBool(flagNoAutoIncrement) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
sequence := txFactory.Sequence() + 1
|
|
|
|
txFactory = txFactory.WithSequence(sequence)
|
|
|
|
}
|
|
|
|
|
2021-03-15 05:18:46 -07:00
|
|
|
return scanner.UnmarshalErr()
|
2021-02-24 11:56:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-29 15:33:42 -07:00
|
|
|
func unmarshalSignatureJSON(clientCtx client.Context, filename string) (sigs []signingtypes.SignatureV2, err error) {
|
2019-01-16 09:30:57 -08:00
|
|
|
var bytes []byte
|
2021-10-13 00:38:22 -07:00
|
|
|
if bytes, err = os.ReadFile(filename); err != nil {
|
2019-01-16 09:30:57 -08:00
|
|
|
return
|
|
|
|
}
|
2020-07-29 15:33:42 -07:00
|
|
|
return clientCtx.TxConfig.UnmarshalSignatureJSON(bytes)
|
2019-01-16 09:30:57 -08:00
|
|
|
}
|
2021-02-24 11:56:10 -08:00
|
|
|
|
|
|
|
func readSignaturesFromFile(ctx client.Context, filename string) (sigs []signingtypes.SignatureV2, err error) {
|
2021-10-13 00:38:22 -07:00
|
|
|
bz, err := os.ReadFile(filename)
|
2021-02-24 11:56:10 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
newString := strings.TrimSuffix(string(bz), "\n")
|
|
|
|
lines := strings.Split(newString, "\n")
|
|
|
|
|
|
|
|
for _, bz := range lines {
|
|
|
|
sig, err := ctx.TxConfig.UnmarshalSignatureJSON([]byte(bz))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
sigs = append(sigs, sig...)
|
|
|
|
}
|
|
|
|
return sigs, nil
|
|
|
|
}
|
|
|
|
|
2021-09-20 05:02:15 -07:00
|
|
|
func getMultisigRecord(clientCtx client.Context, name string) (*keyring.Record, error) {
|
2021-02-24 11:56:10 -08:00
|
|
|
kb := clientCtx.Keyring
|
2021-09-20 05:02:15 -07:00
|
|
|
multisigRecord, err := kb.Key(name)
|
2021-02-24 11:56:10 -08:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "error getting keybase multisig account")
|
|
|
|
}
|
|
|
|
|
2021-09-20 05:02:15 -07:00
|
|
|
return multisigRecord, nil
|
2021-02-24 11:56:10 -08:00
|
|
|
}
|