update main app

This commit is contained in:
rhuairahrighairigh 2018-09-19 15:22:16 -04:00
parent 05b0e743ef
commit 482c1646e1
4 changed files with 104 additions and 72 deletions

44
Gopkg.lock generated
View File

@ -224,6 +224,14 @@
pruneopts = "UT"
revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168"
[[projects]]
branch = "master"
digest = "1:2dbfffce77b67ce945b23c3a24396c19f346cd68e9e6a3b84ab2c1f599804110"
name = "github.com/howeyc/crc16"
packages = ["."]
pruneopts = "UT"
revision = "2b2a61e366a66d3efb279e46176e7291001e0354"
[[projects]]
digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be"
name = "github.com/inconshreveable/mousetrap"
@ -240,6 +248,14 @@
pruneopts = "UT"
revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9"
[[projects]]
digest = "1:1846bcae1759ffcd35d50a2a63950df5c5d7cb27f475e7624e2c4f2c8926d4e9"
name = "github.com/kava-labs/cosmos-sdk"
packages = ["client"]
pruneopts = "UT"
revision = "187be1a5df81de1fd71da9053102d3a4868ec979"
version = "v0.17.2"
[[projects]]
branch = "master"
digest = "1:a64e323dc06b73892e5bb5d040ced475c4645d456038333883f58934abbf6f72"
@ -457,6 +473,20 @@
revision = "a8328986c1608950fa5d3d1c0472cccc4f8fc02c"
version = "v0.12.0-rc0"
[[projects]]
digest = "1:541edf51e3081be6d1b4799b7ff69531462feddd86be0270d8e7e821476ffaea"
name = "github.com/tendermint/go-crypto"
packages = [
".",
"keys",
"keys/bcrypt",
"keys/words",
"keys/words/wordlist",
]
pruneopts = "UT"
revision = "915416979bf70efa4bcbf1c6cd5d64c5fff9fc19"
version = "v0.6.2"
[[projects]]
digest = "1:d4a15d404afbf591e8be16fcda7f5ac87948d5c7531f9d909fd84cc730ab16e2"
name = "github.com/tendermint/iavl"
@ -532,6 +562,18 @@
revision = "81df19e68ab1519399fccf0cab81cb75bf9d782e"
version = "v0.23.1-rc0"
[[projects]]
digest = "1:68921ddf468c0db04496dc49cc67948f1727a74520b1f1f06100bce5c65fa08b"
name = "github.com/tendermint/tmlibs"
packages = [
"common",
"db",
"log",
]
pruneopts = "UT"
revision = "692f1d86a6e2c0efa698fd1e4541b68c74ffaf38"
version = "v0.8.4"
[[projects]]
digest = "1:4dcb0dd65feecb068ce23a234d1a07c7868a1e39f52a6defcae0bb371d03abf6"
name = "github.com/zondax/ledger-goclient"
@ -682,10 +724,12 @@
"github.com/cosmos/cosmos-sdk/x/bank",
"github.com/cosmos/cosmos-sdk/x/bank/client/cli",
"github.com/cosmos/cosmos-sdk/x/mock",
"github.com/cosmos/cosmos-sdk/x/params",
"github.com/cosmos/cosmos-sdk/x/slashing",
"github.com/cosmos/cosmos-sdk/x/slashing/client/cli",
"github.com/cosmos/cosmos-sdk/x/stake",
"github.com/cosmos/cosmos-sdk/x/stake/client/cli",
"github.com/kava-labs/cosmos-sdk/client",
"github.com/pkg/errors",
"github.com/spf13/cobra",
"github.com/spf13/pflag",

View File

@ -16,8 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
//govcmd "github.com/cosmos/cosmos-sdk/x/gov/client/cli"
//ibccmd "github.com/cosmos/cosmos-sdk/x/ibc/client/cli"
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli"
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli"
paychancmd "github.com/kava-labs/kava/internal/x/paychan/client/cmd"
@ -53,17 +52,6 @@ func main() {
)
tx.AddCommands(tendermintCmd, cdc)
// Add IBC commands
// ibcCmd := &cobra.Command{
// Use: "ibc",
// Short: "Inter-Blockchain Communication subcommands",
// }
// ibcCmd.AddCommand(
// client.PostCommands(
// ibccmd.IBCTransferCmd(cdc),
// ibccmd.IBCRelayCmd(cdc),
// )...)
advancedCmd := &cobra.Command{
Use: "advanced",
Short: "Advanced subcommands",
@ -90,6 +78,10 @@ func main() {
stakecmd.GetCmdQueryValidators("stake", cdc),
stakecmd.GetCmdQueryDelegation("stake", cdc),
stakecmd.GetCmdQueryDelegations("stake", cdc),
stakecmd.GetCmdQueryUnbondingDelegation("stake", cdc),
stakecmd.GetCmdQueryUnbondingDelegations("stake", cdc),
stakecmd.GetCmdQueryRedelegation("stake", cdc),
stakecmd.GetCmdQueryRedelegations("stake", cdc),
slashingcmd.GetCmdQuerySigningInfo("slashing", cdc),
)...)
stakeCmd.AddCommand(
@ -105,27 +97,6 @@ func main() {
stakeCmd,
)
// Add gov commands
// govCmd := &cobra.Command{
// Use: "gov",
// Short: "Governance and voting subcommands",
// }
// govCmd.AddCommand(
// client.GetCommands(
// govcmd.GetCmdQueryProposal("gov", cdc),
// govcmd.GetCmdQueryVote("gov", cdc),
// govcmd.GetCmdQueryVotes("gov", cdc),
// )...)
// govCmd.AddCommand(
// client.PostCommands(
// govcmd.GetCmdSubmitProposal(cdc),
// govcmd.GetCmdDeposit(cdc),
// govcmd.GetCmdVote(cdc),
// )...)
// rootCmd.AddCommand(
// govCmd,
// )
// Add auth and bank commands
rootCmd.AddCommand(
client.GetCommands(

View File

@ -19,8 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
//"github.com/cosmos/cosmos-sdk/x/gov"
//"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/kava-labs/kava/internal/x/paychan"
@ -43,23 +42,21 @@ type KavaApp struct {
// keys to access the substores
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
//keyIBC *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
keySlashing *sdk.KVStoreKey
//keyGov *sdk.KVStoreKey
keyFeeCollection *sdk.KVStoreKey
keyParams *sdk.KVStoreKey
tkeyParams *sdk.TransientStoreKey
keyPaychan *sdk.KVStoreKey
// keepers
accountMapper auth.AccountMapper
feeCollectionKeeper auth.FeeCollectionKeeper
coinKeeper bank.Keeper
paychanKeeper paychan.Keeper
//ibcMapper ibc.Mapper
stakeKeeper stake.Keeper
slashingKeeper slashing.Keeper
//govKeeper gov.Keeper
paramsKeeper params.Keeper
paychanKeeper paychan.Keeper
}
// Creates a new KavaApp.
@ -69,7 +66,7 @@ func NewKavaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
cdc := CreateKavaAppCodec()
// Create a new base app
bApp := bam.NewBaseApp(appName, cdc, logger, db, baseAppOptions...)
bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc) baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
// Create the kava app, extending baseApp
@ -78,40 +75,37 @@ func NewKavaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyPaychan: sdk.NewKVStoreKey("paychan"),
//keyIBC: sdk.NewKVStoreKey("ibc"),
keyStake: sdk.NewKVStoreKey("stake"),
keySlashing: sdk.NewKVStoreKey("slashing"),
//keyGov: sdk.NewKVStoreKey("gov"),
keyFeeCollection: sdk.NewKVStoreKey("fee"),
keyParams: sdk.NewKVStoreKey("params"),
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
keyPaychan: sdk.NewKVStoreKey("paychan"),
}
// Define the accountMapper and base account
app.accountMapper = auth.NewAccountMapper(
cdc,
app.cdc,
app.keyAccount,
auth.ProtoBaseAccount,
)
// Create the keepers
app.coinKeeper = bank.NewKeeper(app.accountMapper)
app.paychanKeeper = paychan.NewKeeper(app.cdc, app.keyPaychan, app.coinKeeper)
//app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams)
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace))
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.RegisterCodespace(slashing.DefaultCodespace))
//app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace))
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection)
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Getter(), app.RegisterCodespace(slashing.DefaultCodespace))
app.paychanKeeper = paychan.NewKeeper(app.cdc, app.keyPaychan, app.coinKeeper)
// Register the message handlers
app.Router().
AddRoute("bank", bank.NewHandler(app.coinKeeper)).
//AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
AddRoute("stake", stake.NewHandler(app.stakeKeeper)).
AddRoute("slashing", slashing.NewHandler(app.slashingKeeper)).
AddRoute("paychan", paychan.NewHandler(app.paychanKeeper))
//AddRoute("gov", gov.NewHandler(app.govKeeper))
// Set func to initialze the chain from appState in genesis file
// Set func to initialize the chain from appState in genesis file
app.SetInitChainer(app.initChainer)
// Set functions that run before and after txs / blocks
@ -120,7 +114,8 @@ func NewKavaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper))
// Mount stores
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyStake, app.keySlashing, app.keyFeeCollection, app.keyPaychan)
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyStake, app.keySlashing, app.keyFeeCollection, app.keyParams, app.keyPaychan)
app.MountStore(app.tkeyParams, sdk.StoreTypeTransient)
err := app.LoadLatestVersion(app.keyMain)
if err != nil {
cmn.Exit(err.Error())
@ -132,11 +127,9 @@ func NewKavaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
func CreateKavaAppCodec() *wire.Codec {
cdc := wire.NewCodec()
paychan.RegisterWire(cdc)
//ibc.RegisterWire(cdc)
bank.RegisterWire(cdc)
stake.RegisterWire(cdc)
slashing.RegisterWire(cdc)
//gov.RegisterWire(cdc)
auth.RegisterWire(cdc)
sdk.RegisterWire(cdc)
wire.RegisterCrypto(cdc)
@ -154,18 +147,18 @@ func (app *KavaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) ab
// The function baseapp runs on receipt of a EndBlock ABCI message
func (app *KavaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
paychan.EndBlocker(ctx, app.paychanKeeper)
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
tags := paychan.EndBlocker(ctx, app.paychanKeeper)
//tags, _ := gov.EndBlocker(ctx, app.govKeeper)
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
app.slashingKeeper.AddValidators(ctx, validatorUpdates)
return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
//Tags: tags,
Tags: tags,
}
}
// Initialzes the app db from the appState in the genesis file. Baseapp runs this on receipt of an InitChain ABCI message
// Initializes the app db from the appState in the genesis file. Baseapp runs this on receipt of an InitChain ABCI message
func (app *KavaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
stateJSON := req.AppStateBytes
@ -183,14 +176,16 @@ func (app *KavaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci
}
// load the initial stake information
err = stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
validators, err := stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
if err != nil {
panic(err)
}
//gov.InitGenesis(ctx, app.govKeeper, gov.DefaultGenesisState())
slashing.InitGenesis(ctx, app.slashingKeeper, genesisState.StakeData)
return abci.ResponseInitChain{}
return abci.ResponseInitChain{
Validators: validators,
}
}
//

View File

@ -6,7 +6,9 @@ package app
import (
"encoding/json"
"errors"
"fmt"
"github.com/kava-labs/cosmos-sdk/client"
"github.com/spf13/pflag"
"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"
@ -19,6 +21,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/stake"
)
const defaultPassword = "password"
var (
// Tokens given to genesis validators and accounts
numStartingTokensValidators = int64(1000)
@ -61,7 +64,7 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) {
}
}
// Create the appInit stuct for server init command
// Create the appInit struct for server init command
func KavaAppInit() server.AppInit {
fsAppGenState := pflag.NewFlagSet("", pflag.ContinueOnError)
fsAppGenTx := pflag.NewFlagSet("", pflag.ContinueOnError)
@ -86,22 +89,41 @@ type KavaGenTx struct {
PubKey string `json:"pub_key"`
}
// Generate a genesis transsction
// Generate a genesis transaction
func KavaAppGenTx(cdc *wire.Codec, pk crypto.PubKey, genTxConfig config.GenTx) (
appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
// Generate address and secret key for the validator
// check a name for the new validator has been specified
if genTxConfig.Name == "" {
return nil, nil, tmtypes.GenesisValidator{}, errors.New("Must specify --name (validator moniker)")
}
var addr sdk.AccAddress
var secret string
addr, secret, err = server.GenerateSaveCoinKey(genTxConfig.CliRoot, genTxConfig.Name, "password", genTxConfig.Overwrite)
// get a new password for the new account
buf := client.BufferStdin()
prompt := fmt.Sprintf("Password for account '%s' (default %s):", genTxConfig.Name, defaultPassword)
keyPass, err := client.GetPassword(prompt, buf)
if err != nil && keyPass != "" {
// An error was returned that either failed to read the password from
// STDIN or the given password is not empty but failed to meet minimum
// length requirements.
return appGenTx, cliPrint, validator, err
}
if keyPass == "" {
keyPass = defaultPassword
}
// generate a new address and secret key
addr, secret, err := server.GenerateSaveCoinKey(
genTxConfig.CliRoot,
genTxConfig.Name,
defaultPassword,
genTxConfig.Overwrite,
)
if err != nil {
return
}
// Create string to print out
// Create message string to print out
mm := map[string]string{"secret": secret}
var bz []byte
bz, err = cdc.MarshalJSON(mm)