Add cli support for register/update ibc
This commit is contained in:
parent
746ae28eaa
commit
de537c34ac
|
@ -67,6 +67,9 @@ func main() {
|
||||||
coincmd.SendTxCmd,
|
coincmd.SendTxCmd,
|
||||||
// this enables creating roles
|
// this enables creating roles
|
||||||
rolecmd.CreateRoleTxCmd,
|
rolecmd.CreateRoleTxCmd,
|
||||||
|
// these are for handling ibc
|
||||||
|
ibccmd.RegisterChainTxCmd,
|
||||||
|
ibccmd.UpdateChainTxCmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Set up the various commands to use
|
// Set up the various commands to use
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/tendermint/basecoin/client/commands"
|
||||||
|
txcmd "github.com/tendermint/basecoin/client/commands/txs"
|
||||||
|
"github.com/tendermint/basecoin/modules/ibc"
|
||||||
|
"github.com/tendermint/light-client/certifiers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RegisterChainTxCmd is CLI command to register a new chain for ibc
|
||||||
|
var RegisterChainTxCmd = &cobra.Command{
|
||||||
|
Use: "ibc-register",
|
||||||
|
Short: "Register a new chain",
|
||||||
|
RunE: commands.RequireInit(registerChainTxCmd),
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateChainTxCmd is CLI command to update the header for an ibc chain
|
||||||
|
var UpdateChainTxCmd = &cobra.Command{
|
||||||
|
Use: "ibc-update",
|
||||||
|
Short: "Add new header to an existing chain",
|
||||||
|
RunE: commands.RequireInit(updateChainTxCmd),
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: post packet (query and all that jazz)
|
||||||
|
|
||||||
|
// TODO: relay!
|
||||||
|
|
||||||
|
//nolint
|
||||||
|
const (
|
||||||
|
FlagSeed = "seed"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
fs1 := RegisterChainTxCmd.Flags()
|
||||||
|
fs1.String(FlagSeed, "", "Filename with a seed file")
|
||||||
|
|
||||||
|
fs2 := UpdateChainTxCmd.Flags()
|
||||||
|
fs2.String(FlagSeed, "", "Filename with a seed file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func registerChainTxCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
seed, err := readSeed()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tx := ibc.RegisterChainTx{seed}.Wrap()
|
||||||
|
return txcmd.DoTx(tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateChainTxCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
seed, err := readSeed()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tx := ibc.UpdateChainTx{seed}.Wrap()
|
||||||
|
return txcmd.DoTx(tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func readSeed() (seed certifiers.Seed, err error) {
|
||||||
|
name := viper.GetString(FlagSeed)
|
||||||
|
if name == "" {
|
||||||
|
return seed, errors.New("You must specify a seed file")
|
||||||
|
}
|
||||||
|
|
||||||
|
var f *os.File
|
||||||
|
f, err = os.Open(name)
|
||||||
|
if err != nil {
|
||||||
|
return seed, errors.Wrap(err, "Cannot read seed file")
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
// read the file as json into a seed
|
||||||
|
j := json.NewDecoder(f)
|
||||||
|
err = j.Decode(&seed)
|
||||||
|
err = errors.Wrap(err, "Invalid seed file")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// func readCreateRoleTxFlags() (tx basecoin.Tx, err error) {
|
||||||
|
// role, err := parseRole(viper.GetString(FlagRole))
|
||||||
|
// if err != nil {
|
||||||
|
// return tx, err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// sigs := viper.GetInt(FlagMinSigs)
|
||||||
|
// if sigs < 1 {
|
||||||
|
// return tx, errors.Errorf("--%s must be at least 1", FlagMinSigs)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// signers, err := commands.ParseActors(viper.GetString(FlagMembers))
|
||||||
|
// if err != nil {
|
||||||
|
// return tx, err
|
||||||
|
// }
|
||||||
|
// if len(signers) == 0 {
|
||||||
|
// return tx, errors.New("must specify at least one member")
|
||||||
|
// }
|
||||||
|
|
||||||
|
// tx = roles.NewCreateRoleTx(role, uint32(sigs), signers)
|
||||||
|
// return tx, nil
|
||||||
|
// }
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/tendermint/basecoin/modules/roles"
|
"github.com/tendermint/basecoin/modules/roles"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateRoleTxCmd is CLI command to send tokens between basecoin accounts
|
// CreateRoleTxCmd is CLI command to create a new role
|
||||||
var CreateRoleTxCmd = &cobra.Command{
|
var CreateRoleTxCmd = &cobra.Command{
|
||||||
Use: "create-role",
|
Use: "create-role",
|
||||||
Short: "Create a new role",
|
Short: "Create a new role",
|
||||||
|
@ -32,7 +32,7 @@ func init() {
|
||||||
flags.Int(FlagMinSigs, 0, "Minimum number of signatures needed to assume this role")
|
flags.Int(FlagMinSigs, 0, "Minimum number of signatures needed to assume this role")
|
||||||
}
|
}
|
||||||
|
|
||||||
// createRoleTxCmd is an example of how to make a tx
|
// createRoleTxCmd creates a basic role tx and then wraps, signs, and posts it
|
||||||
func createRoleTxCmd(cmd *cobra.Command, args []string) error {
|
func createRoleTxCmd(cmd *cobra.Command, args []string) error {
|
||||||
tx, err := readCreateRoleTxFlags()
|
tx, err := readCreateRoleTxFlags()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue