Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal v0.44 app, without deleting unupgraded packages #1029

Merged
merged 56 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
bdabd2c
remove migrations
rhuairahrighairidh Oct 19, 2021
038d711
remove incentive module
rhuairahrighairidh Oct 19, 2021
e92cc43
remove swap module
rhuairahrighairidh Oct 19, 2021
1450f06
remove committee module
rhuairahrighairidh Oct 19, 2021
63c9326
remove hard module
rhuairahrighairidh Oct 19, 2021
deb4e1e
remove bep3 module
rhuairahrighairidh Oct 19, 2021
03aa355
remove kavadist module
rhuairahrighairidh Oct 19, 2021
45b3833
remove cdp module
rhuairahrighairidh Oct 19, 2021
a797d65
remove issuance module
rhuairahrighairidh Oct 19, 2021
3fc21ac
remove auction module
rhuairahrighairidh Oct 19, 2021
65dce3a
remove pricefeed module
rhuairahrighairidh Oct 19, 2021
fb02168
remove validator-vesting module
rhuairahrighairidh Oct 19, 2021
b47c320
remove unused rest test spike
rhuairahrighairidh Oct 19, 2021
e742d84
remove missed module imports from antehandler
rhuairahrighairidh Oct 19, 2021
deaf002
app - remove alias from imports
rhuairahrighairidh Oct 19, 2021
e7f61bf
update cosmos-sdk version in go.mod
rhuairahrighairidh Oct 19, 2021
d01d1c1
app - replace supply module
rhuairahrighairidh Oct 19, 2021
a6d34dd
app - add vesting modulea
rhuairahrighairidh Oct 19, 2021
0a8b4d1
app - replace codec
rhuairahrighairidh Oct 19, 2021
94a9707
app - remove upgrade, remove antehandler
rhuairahrighairidh Oct 19, 2021
b7eba95
app - remove features until NewApp runs
rhuairahrighairidh Oct 20, 2021
09722ea
delete cmd, cli_test, migration cmd
rhuairahrighairidh Oct 20, 2021
e3c72ca
add new app binary
rhuairahrighairidh Oct 20, 2021
36e22f9
add rough copy of gaia cmds
rhuairahrighairidh Oct 20, 2021
5986f07
read from flags/config and create new app
rhuairahrighairidh Oct 20, 2021
e04a790
remove out of date contrib files
rhuairahrighairidh Oct 20, 2021
7ab71e9
add sdk config and other tweaks to get app running
rhuairahrighairidh Oct 20, 2021
49f2727
code tidying and checks against old kava and gaia
rhuairahrighairidh Oct 20, 2021
c829030
add modules packages back in
rhuairahrighairidh Oct 21, 2021
0cc924f
set go mod to ignore modules
rhuairahrighairidh Oct 21, 2021
8aea9c4
add ante package back in
rhuairahrighairidh Oct 21, 2021
e7119b9
set go mod to ignore ante
rhuairahrighairidh Oct 21, 2021
e5724e3
add cmd packages back in
rhuairahrighairidh Oct 21, 2021
6594432
set go mod to ignore cmd
rhuairahrighairidh Oct 21, 2021
6d66008
add migrate package back in
rhuairahrighairidh Oct 21, 2021
73a3d4c
set go mod to ignore migrate
rhuairahrighairidh Oct 21, 2021
a5df7f5
add app files back in, but ignored
rhuairahrighairidh Oct 21, 2021
1a1e978
revert commented out params file
rhuairahrighairidh Oct 21, 2021
567b7e9
add cli_test package back in
rhuairahrighairidh Oct 21, 2021
17d2107
set go mod to ignore cli_test
rhuairahrighairidh Oct 21, 2021
453ed88
remove unused makefile entry
rhuairahrighairidh Oct 21, 2021
b2635a9
add upgrade todo to go.mod
rhuairahrighairidh Oct 21, 2021
c05e705
update to go 1.16
rhuairahrighairidh Oct 21, 2021
e5494b8
fix CI
rhuairahrighairidh Oct 21, 2021
ad913f2
update replace directive for v0.44.x and run go mod tidy; removes
nddeluca Oct 21, 2021
4aa5df1
add ldflag for tendermint version, as tendermint now sets the version at
nddeluca Oct 22, 2021
313ee8c
add todo for settings version map in upgrade keeper
nddeluca Oct 22, 2021
9d938fc
upgrade antehandler package
rhuairahrighairidh Oct 25, 2021
94e8877
upgrade TestApp, add antehandler to app
rhuairahrighairidh Oct 25, 2021
0d6d145
register rest and grpc gateway routes
rhuairahrighairidh Oct 26, 2021
8898199
resolve TODO about funding community pool
rhuairahrighairidh Oct 26, 2021
8645874
move test methods to TestApp
rhuairahrighairidh Oct 26, 2021
dd6a95b
decouple default data dir configuration from app
rhuairahrighairidh Oct 26, 2021
b777597
refactor NewTestApp
rhuairahrighairidh Oct 26, 2021
b2e3fcb
remove ineffective cmd formatting
rhuairahrighairidh Oct 26, 2021
18a2266
move test helper for more accesibility
rhuairahrighairidh Oct 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add cmd packages back in
  • Loading branch information
rhuairahrighairidh committed Oct 21, 2021
commit e5724e3060b909d046e77c5f7f4c494ecb1d023c
112 changes: 112 additions & 0 deletions cmd/kvcli/cmd_keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package main

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/kava-labs/kava/app"
)

/*
NOTE TO FUTURE IMPLEMENTERS
This monkey patches the sdk `keys` command, therefore needs to be reviewed on any sdk updates.

The patch adds support for using kava's legacy bip44 coin type to the cli.
Coin types are used to create a bip44 derivation path, which is used as a mapping from mnemonic to private key.

In cosmos-sdk v0.38.3, all private keys are stored without reference to the mnemonic or bip44 derivation path, except ledger keys.
Ledger keys are just references to a private key on a ledger device. They contain the bip44 derivation path.
To patch the cli, we only need to modify:
- when new ledger references are created
- anything to do with converting a mnemonic to a private key.

These only happen in `kvcli keys add` cmd.
For private key generation, use a --legacy-hd-path flag to enable old coin type.
The current cosmos ledger app (v1.5.3) only supports the legacy coin type. So we only need to ensure ledger reference creation doesn't use the new coin type.

Signing txs:
- with local keys
- the stored the priv key is used to sign, mnemonics or bip44 paths not involved
- with ledger
- the stored bip44 path is used to instruct the ledger which key to sign with
*/

const flagLegacyHDPath = "legacy-hd-path"
const flagHDPath = "hd-path" // this is copied from keys add cmd because it's not exported

// getModifiedKeysCmd returns the standard cosmos-sdk/client/keys cmd but modified to support new and old bip44 coin types supported by kava.
func getModifiedKeysCmd() *cobra.Command {
keysCmd := keys.Commands()
for _, c := range keysCmd.Commands() {
if c.Name() == "add" {
monkeyPatchCmdKeysAdd(c)
}
if c.Name() == "parse" {
monkeyPatchCmdKeysParse(c)
}
}
return keysCmd
}

func monkeyPatchCmdKeysParse(keysParseCmd *cobra.Command) {

// replace the run function with a wrapped version that sets the old coin type in the global config
oldRun := keysParseCmd.RunE
keysParseCmd.RunE = func(cmd *cobra.Command, args []string) error {

sdk.GetConfig().Seal()
return oldRun(cmd, args)
}
}

// monkeyPatchCmdKeysAdd modifies the `keys add` command to use the old bip44 coin type when a flag is passed.
func monkeyPatchCmdKeysAdd(keysAddCmd *cobra.Command) {
// add flag
keysAddCmd.Flags().Bool(flagLegacyHDPath, false, fmt.Sprintf("Use the old bip44 coin type (%d) to derive addresses from mnemonics.", sdk.CoinType))

// replace description
keysAddCmd.Long = fmt.Sprintf(`Derive a new private key and encrypt to disk.
Optionally specify a BIP39 mnemonic, a BIP39 passphrase to further secure the mnemonic,
and BIP44 account/index numbers to derive a specific key. The key will be stored under the given name
and encrypted with the given password.

NOTE: This cli defaults to Kava's BIP44 coin type %d. Use the --%s flag to use the old one (%d).

The flag --recover allows one to recover a key from a seed passphrase.
If run with --dry-run, a key would be generated (or recovered) but not stored to the
local keystore.
Use the --pubkey flag to add arbitrary public keys to the keystore for constructing
multisig transactions.

You can add a multisig key by passing the list of key names you want the public
key to be composed of to the --multisig flag and the minimum number of signatures
required through --multisig-threshold. The keys are sorted by address, unless
the flag --nosort is set.
`, app.Bip44CoinType, flagLegacyHDPath, sdk.CoinType)

// replace the run function with a wrapped version that sets the old coin type in the global config
oldRun := keysAddCmd.RunE
keysAddCmd.RunE = func(cmd *cobra.Command, args []string) error {

if !viper.GetBool(flagLegacyHDPath) && viper.GetBool(flags.FlagUseLedger) {
return fmt.Errorf("cosmos ledger app only supports legacy bip44 coin type, must use --%s flag when adding ledger key", flagLegacyHDPath)
}
if viper.GetBool(flagLegacyHDPath) && viper.IsSet(flagHDPath) {
return fmt.Errorf("cannot use a custom hd path (--%s) and legacy bip44 coin type (--%s) at the same time", flagHDPath, flagLegacyHDPath)
}
if viper.GetBool(flagLegacyHDPath) {
preExistingCoinType := sdk.GetConfig().GetCoinType()
sdk.GetConfig().SetCoinType(sdk.CoinType) // set old coin type
err := oldRun(cmd, args)
sdk.GetConfig().SetCoinType(preExistingCoinType) // revert to pre-existing coin type
return err
}
return oldRun(cmd, args)
}
}
171 changes: 171 additions & 0 deletions cmd/kvcli/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package main

import (
"fmt"
"os"
"path"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/tendermint/tendermint/libs/cli"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/lcd"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
"github.com/cosmos/cosmos-sdk/x/bank"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"

"github.com/kava-labs/kava/app"
"github.com/kava-labs/kava/migrate/rest_v0_3"
)

func main() {
// Configure cobra to sort commands
cobra.EnableCommandSorting = false

// Instantiate the codec for the command line application
cdc := app.MakeCodec()

// Set the global config
// config is not sealed as the cli supports two coin types for legacy reasons.
config := sdk.GetConfig()
app.SetBech32AddressPrefixes(config)
app.SetBip44CoinType(config)

// TODO: setup keybase, viper object, etc. to be passed into
// the below functions and eliminate global vars, like we do
// with the cdc

rootCmd := &cobra.Command{
Use: "kvcli",
Short: "Command line interface for interacting with kvd",
}

// Add --chain-id to persistent flags and mark it required
rootCmd.PersistentFlags().String(flags.FlagChainID, "", "Chain ID of tendermint node")
rootCmd.PersistentPreRunE = func(_ *cobra.Command, _ []string) error {
return initConfig(rootCmd)
}

// Construct Root Command
rootCmd.AddCommand(
rpc.StatusCommand(),
client.ConfigCmd(app.DefaultCLIHome),
queryCmd(cdc),
txCmd(cdc),
flags.LineBreak,
lcd.ServeCommand(cdc, registerRoutes),
flags.LineBreak,
getModifiedKeysCmd(),
flags.LineBreak,
version.Cmd,
flags.NewCompletionCmd(rootCmd, true),
)

// Add flags and prefix all env exposed with KA
executor := cli.PrepareMainCmd(rootCmd, "KA", app.DefaultCLIHome)

err := executor.Execute()
if err != nil {
fmt.Printf("Failed executing CLI command: %s, exiting...\n", err)
os.Exit(1)
}
}

func queryCmd(cdc *codec.Codec) *cobra.Command {
queryCmd := &cobra.Command{
Use: "query",
Aliases: []string{"q"},
Short: "Querying subcommands",
}

queryCmd.AddCommand(
authcmd.GetAccountCmd(cdc),
flags.LineBreak,
rpc.ValidatorCommand(cdc),
rpc.BlockCommand(),
authcmd.QueryTxsByEventsCmd(cdc),
authcmd.QueryTxCmd(cdc),
flags.LineBreak,
)

// add modules' query commands
app.ModuleBasics.AddQueryCommands(queryCmd, cdc)

return queryCmd
}

func txCmd(cdc *codec.Codec) *cobra.Command {
txCmd := &cobra.Command{
Use: "tx",
Short: "Transactions subcommands",
}

txCmd.AddCommand(
bankcmd.SendTxCmd(cdc),
flags.LineBreak,
authcmd.GetSignCommand(cdc),
authcmd.GetMultiSignCommand(cdc),
flags.LineBreak,
authcmd.GetBroadcastCommand(cdc),
authcmd.GetEncodeCommand(cdc),
authcmd.GetDecodeCommand(cdc),
flags.LineBreak,
)

// add modules' tx commands
app.ModuleBasics.AddTxCommands(txCmd, cdc)

// remove auth and bank commands as they're mounted under the root tx command
var cmdsToRemove []*cobra.Command
for _, cmd := range txCmd.Commands() {
if cmd.Use == auth.ModuleName || cmd.Use == bank.ModuleName {
cmdsToRemove = append(cmdsToRemove, cmd)
}
}
txCmd.RemoveCommand(cmdsToRemove...)

return txCmd
}

// registerRoutes registers the routes from the different modules for the LCD.
func registerRoutes(rs *lcd.RestServer) {
client.RegisterRoutes(rs.CliCtx, rs.Mux)
authrest.RegisterTxRoutes(rs.CliCtx, rs.Mux)
app.ModuleBasics.RegisterRESTRoutes(rs.CliCtx, rs.Mux)
app.RegisterSimulateRoutes(rs.CliCtx, rs.Mux)
// register legacy endpoints compatible with v0.3.x of kava
rest_v0_3.RegisterRoutes(rs.CliCtx, rs.Mux)
}

// initConfig reads in and sets options from a config file (if one exists)
func initConfig(cmd *cobra.Command) error {
home, err := cmd.PersistentFlags().GetString(cli.HomeFlag)
if err != nil {
return err
}
cfgFile := path.Join(home, "config", "config.toml")

if _, err := os.Stat(cfgFile); err == nil {
viper.SetConfigFile(cfgFile)

if err := viper.ReadInConfig(); err != nil {
return err
}
}
if err := viper.BindPFlag(flags.FlagChainID, cmd.PersistentFlags().Lookup(flags.FlagChainID)); err != nil {
return err
}
if err := viper.BindPFlag(cli.EncodingFlag, cmd.PersistentFlags().Lookup(cli.EncodingFlag)); err != nil {
return err
}
return viper.BindPFlag(cli.OutputFlag, cmd.PersistentFlags().Lookup(cli.OutputFlag))
}
Loading