Merge pull request #7 from Kava-Labs/update-to-0.24.2

Update to 0.24.2
This commit is contained in:
Ruaridh 2018-09-20 11:04:16 -04:00 committed by GitHub
commit 7dd47f074a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 175 additions and 201 deletions

85
Gopkg.lock generated
View File

@ -2,7 +2,6 @@
[[projects]]
branch = "master"
digest = "1:09a7f74eb6bb3c0f14d8926610c87f569c5cff68e978d30e9a3540aeb626fdf0"
name = "github.com/bartekn/go-bip39"
packages = ["."]
@ -49,7 +48,7 @@
revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4"
[[projects]]
digest = "1:bb617355120eed649354b41a20d1745b2feb994e4da1a97591259143ad65375a"
digest = "1:7f6e80c9a48014e57211353a9a82d12088f9dc85f564b6a70674bbc1d5abc34e"
name = "github.com/cosmos/cosmos-sdk"
packages = [
"baseapp",
@ -58,6 +57,7 @@
"client/keys",
"client/rpc",
"client/tx",
"client/utils",
"crypto",
"crypto/keys",
"crypto/keys/bcrypt",
@ -71,12 +71,12 @@
"wire",
"x/auth",
"x/auth/client/cli",
"x/auth/client/context",
"x/bank",
"x/bank/client",
"x/bank/client/cli",
"x/gov",
"x/ibc",
"x/mock",
"x/params",
"x/slashing",
"x/slashing/client/cli",
"x/stake",
@ -86,8 +86,8 @@
"x/stake/types",
]
pruneopts = "UT"
revision = "23e3d5ac12145c02fcb4b4767d7dfccad782aee5"
version = "v0.23.1"
revision = "1c38c70468ec721e3a555ba2f3bf5f9da31f0cc9"
version = "v0.24.2"
[[projects]]
digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39"
@ -437,14 +437,6 @@
pruneopts = "UT"
revision = "c4c61651e9e37fa117f53c5a906d3b63090d8445"
[[projects]]
digest = "1:8b7ca9e3745cb049a65364d3adbbab63e98d3c43c83cb101cb450c8dac3c3492"
name = "github.com/tendermint/abci"
packages = ["types"]
pruneopts = "UT"
revision = "68592f4d8ee34e97db94b7a7976b1309efdb7eb9"
version = "v0.10.0"
[[projects]]
branch = "master"
digest = "1:087aaa7920e5d0bf79586feb57ce01c35c830396ab4392798112e8aae8c47722"
@ -458,23 +450,12 @@
revision = "d8387025d2b9d158cf4efb07e7ebf814bcce2057"
[[projects]]
digest = "1:e9113641c839c21d8eaeb2c907c7276af1eddeed988df8322168c56b7e06e0e1"
digest = "1:e0a2a4be1e20c305badc2b0a7a9ab7fef6da500763bec23ab81df3b5f9eec9ee"
name = "github.com/tendermint/go-amino"
packages = ["."]
pruneopts = "UT"
revision = "2106ca61d91029c931fd54968c2bb02dc96b1412"
version = "0.10.1"
[[projects]]
digest = "1:82f70bfe58f1a55601d469b928aec5b10b1d85710e6adde40dfea8d9adba939d"
name = "github.com/tendermint/go-crypto"
packages = [
".",
"tmhash",
]
pruneopts = "UT"
revision = "6a6b591a3d7592a04b46af95451cb5be3b114f76"
version = "v0.9.0"
revision = "a8328986c1608950fa5d3d1c0472cccc4f8fc02c"
version = "v0.12.0-rc0"
[[projects]]
digest = "1:d4a15d404afbf591e8be16fcda7f5ac87948d5c7531f9d909fd84cc730ab16e2"
@ -485,7 +466,7 @@
version = "v0.9.2"
[[projects]]
digest = "1:eb0f8bee357e6c28c9ad5fa074545b5085d0dcf580ba0e7024ab8c3285a5c815"
digest = "1:4f15e95fe3888cc75dd34f407d6394cbc7fd3ff24920851b92b295f6a8b556e6"
name = "github.com/tendermint/tendermint"
packages = [
"abci/client",
@ -548,35 +529,26 @@
"version",
]
pruneopts = "UT"
revision = "d542d2c3945116697f60451e6a407082c41c3cc9"
version = "v0.22.8"
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:5bd938386bd1f61a581bf8cd6ff2b7b2f79c542929176db4ceb44965440dae07"
digest = "1:4dcb0dd65feecb068ce23a234d1a07c7868a1e39f52a6defcae0bb371d03abf6"
name = "github.com/zondax/ledger-goclient"
packages = ["."]
pruneopts = "UT"
revision = "39ba4728c137c75718a21f9b4b3280fa31b9139b"
revision = "4296ee5701e945f9b3a7dbe51f402e0b9be57259"
[[projects]]
branch = "master"
digest = "1:65a21a9e051d54eb6a3f70c659a765f706a998d9287c302269f4ed8054b2a852"
digest = "1:7a71fffde456d746c52f9cd09c50b034533a3180fb1f6320abb149f2ccc579e5"
name = "golang.org/x/crypto"
packages = [
"blowfish",
"chacha20poly1305",
"curve25519",
"hkdf",
"internal/chacha20",
"internal/subtle",
"nacl/box",
"nacl/secretbox",
@ -608,9 +580,12 @@
[[projects]]
branch = "master"
digest = "1:0316a8ad208917f1d141b077e278980fd5e4594f3a85f835dacbf24d85798252"
digest = "1:4bd75b1a219bc590b05c976bbebf47f4e993314ebb5c7cbf2efe05a09a184d54"
name = "golang.org/x/sys"
packages = ["unix"]
packages = [
"cpu",
"unix",
]
pruneopts = "UT"
revision = "4e1fef5609515ec7a2cee7b5de30ba6d9b438cbf"
@ -693,9 +668,11 @@
input-imports = [
"github.com/cosmos/cosmos-sdk/baseapp",
"github.com/cosmos/cosmos-sdk/client",
"github.com/cosmos/cosmos-sdk/client/context",
"github.com/cosmos/cosmos-sdk/client/keys",
"github.com/cosmos/cosmos-sdk/client/rpc",
"github.com/cosmos/cosmos-sdk/client/tx",
"github.com/cosmos/cosmos-sdk/client/utils",
"github.com/cosmos/cosmos-sdk/server",
"github.com/cosmos/cosmos-sdk/server/config",
"github.com/cosmos/cosmos-sdk/types",
@ -703,30 +680,28 @@
"github.com/cosmos/cosmos-sdk/wire",
"github.com/cosmos/cosmos-sdk/x/auth",
"github.com/cosmos/cosmos-sdk/x/auth/client/cli",
"github.com/cosmos/cosmos-sdk/x/auth/client/context",
"github.com/cosmos/cosmos-sdk/x/bank",
"github.com/cosmos/cosmos-sdk/x/bank/client/cli",
"github.com/cosmos/cosmos-sdk/x/gov",
"github.com/cosmos/cosmos-sdk/x/ibc",
"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/pkg/errors",
"github.com/spf13/cobra",
"github.com/spf13/pflag",
"github.com/spf13/viper",
"github.com/stretchr/testify/assert",
"github.com/stretchr/testify/require",
"github.com/tendermint/abci/types",
"github.com/tendermint/go-crypto",
"github.com/tendermint/tendermint/abci/types",
"github.com/tendermint/tendermint/crypto",
"github.com/tendermint/tendermint/crypto/ed25519",
"github.com/tendermint/tendermint/libs/cli",
"github.com/tendermint/tendermint/libs/common",
"github.com/tendermint/tendermint/libs/db",
"github.com/tendermint/tendermint/libs/log",
"github.com/tendermint/tendermint/types",
"github.com/tendermint/tmlibs/db",
"github.com/tendermint/tmlibs/log",
]
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -1,6 +1,6 @@
[[constraint]]
name = "github.com/cosmos/cosmos-sdk"
version="=0.23.1"
version="=0.24.2"
# Copied from cosmos-sdk, constraints switched to overrides
@ -35,7 +35,7 @@
[[override]]
name = "github.com/tendermint/go-amino"
version = "=0.10.1"
version = "=v0.12.0-rc0"
[[override]]
name = "github.com/tendermint/iavl"
@ -43,16 +43,17 @@
[[override]]
name = "github.com/tendermint/tendermint"
version = "=v0.22.8"
version = "=v0.23.1-rc0"
[[override]]
name = "github.com/bartekn/go-bip39"
branch = "master"
revision = "a05967ea095d81c8fe4833776774cfaff8e5036c"
[[override]]
name = "github.com/zondax/ledger-goclient"
revision = "39ba4728c137c75718a21f9b4b3280fa31b9139b"
revision = "4296ee5701e945f9b3a7dbe51f402e0b9be57259"
[prune]
go-tests = true
unused-packages = true

View File

@ -16,11 +16,10 @@ 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"
paychancmd "github.com/kava-labs/kava/internal/x/paychan/client/cli"
"github.com/kava-labs/kava/internal/app"
//"github.com/kava-labs/kava/internal/lcd"
@ -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"
@ -41,25 +40,23 @@ type KavaApp struct {
cdc *wire.Codec
// keys to access the substores
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
//keyIBC *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
keySlashing *sdk.KVStoreKey
//keyGov *sdk.KVStoreKey
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
keySlashing *sdk.KVStoreKey
keyFeeCollection *sdk.KVStoreKey
keyParams *sdk.KVStoreKey
tkeyParams *sdk.TransientStoreKey
keyPaychan *sdk.KVStoreKey
// keepers
accountMapper auth.AccountMapper
feeCollectionKeeper auth.FeeCollectionKeeper
coinKeeper bank.Keeper
stakeKeeper stake.Keeper
slashingKeeper slashing.Keeper
paramsKeeper params.Keeper
paychanKeeper paychan.Keeper
//ibcMapper ibc.Mapper
stakeKeeper stake.Keeper
slashingKeeper slashing.Keeper
//govKeeper gov.Keeper
}
// Creates a new KavaApp.
@ -69,49 +66,46 @@ 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
var app = &KavaApp{
BaseApp: bApp,
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"),
BaseApp: bApp,
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyStake: sdk.NewKVStoreKey("stake"),
keySlashing: sdk.NewKVStoreKey("slashing"),
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/cosmos/cosmos-sdk/client"
"github.com/spf13/pflag"
"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"
@ -19,6 +21,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/stake"
)
const defaultPassword = "password"
var (
// Tokens given to genesis validators and accounts
numStartingTokensValidators = int64(1000)
@ -61,7 +65,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 +90,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)

View File

@ -3,6 +3,7 @@ package cli
import (
"fmt"
"io/ioutil"
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -10,9 +11,11 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/utils"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authctx "github.com/cosmos/cosmos-sdk/x/auth/client/context"
"github.com/kava-labs/kava/internal/x/paychan"
)
@ -31,13 +34,15 @@ func CreateChannelCmd(cdc *wire.Codec) *cobra.Command {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// TODO is this needed for channelID
// ctx.PrintResponse = true
// Create a tx and cli "contexts": structs populated with info from common flags.
txCtx := authctx.NewTxContextFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
// Get sender adress
sender, err := ctx.GetFromAddress()
// Get sender address
sender, err := cliCtx.GetFromAddress()
if err != nil {
return err
}
@ -67,11 +72,7 @@ func CreateChannelCmd(cdc *wire.Codec) *cobra.Command {
}
// Build and sign the transaction, then broadcast to the blockchain
err = ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, []sdk.Msg{msg}, cdc)
if err != nil {
return err
}
return nil
return utils.SendTx(txCtx, cliCtx, []sdk.Msg{msg})
},
}
cmd.Flags().String(flagTo, "", "Recipient address of the payment channel.")
@ -92,8 +93,11 @@ func GeneratePaymentCmd(cdc *wire.Codec) *cobra.Command {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// Create a cli "context": struct populated with info from common flags.
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
// Get the paychan id
id := paychan.ChannelID(viper.GetInt64(flagId)) // TODO make this default to pulling id from chain
@ -121,8 +125,8 @@ func GeneratePaymentCmd(cdc *wire.Codec) *cobra.Command {
if err != nil {
return err
}
name := ctx.FromAddressName
passphrase, err := ctx.GetPassphraseFromStdin(name)
name := cliCtx.FromAddressName
passphrase, err := keys.GetPassphrase(cliCtx.FromAddressName)
if err != nil {
return err
}
@ -169,8 +173,11 @@ func VerifyPaymentCmd(cdc *wire.Codec, paychanStoreName string) *cobra.Command {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper()
// Create a cli "context": struct populated with info from common flags.
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
// read in update
bz, err := ioutil.ReadFile(viper.GetString(flagPaymentFile))
@ -183,7 +190,7 @@ func VerifyPaymentCmd(cdc *wire.Codec, paychanStoreName string) *cobra.Command {
cdc.UnmarshalJSON(bz, &update)
// get the channel from the node
res, err := ctx.QueryStore(paychan.GetChannelKey(update.ChannelID), paychanStoreName)
res, err := cliCtx.QueryStore(paychan.GetChannelKey(update.ChannelID), paychanStoreName)
if len(res) == 0 || err != nil {
return errors.Errorf("channel with ID '%d' does not exist", update.ChannelID)
}
@ -218,12 +225,15 @@ func SubmitPaymentCmd(cdc *wire.Codec) *cobra.Command {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper().WithDecoder(authcmd.GetAccountDecoder(cdc))
// ctx.PrintResponse = true TODO is this needed for channelID
// Create a tx and cli "contexts": structs populated with info from common flags.
txCtx := authctx.NewTxContextFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
// Get sender adress
submitter, err := ctx.GetFromAddress()
// Get sender address
submitter, err := cliCtx.GetFromAddress()
if err != nil {
return err
}
@ -248,11 +258,7 @@ func SubmitPaymentCmd(cdc *wire.Codec) *cobra.Command {
}
// Build and sign the transaction, then broadcast to the blockchain
err = ctx.EnsureSignBuildBroadcast(ctx.FromAddressName, []sdk.Msg{msg}, cdc)
if err != nil {
return err
}
return nil
return utils.SendTx(txCtx, cliCtx, []sdk.Msg{msg})
},
}
cmd.Flags().String(flagPaymentFile, "payment.json", "File to read the payment from.")
@ -268,14 +274,17 @@ func GetChannelCmd(cdc *wire.Codec, paychanStoreName string) *cobra.Command {
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// Create a "client context" stuct populated with info from common flags
ctx := context.NewCoreContextFromViper()
// Create a cli "context": struct populated with info from common flags.
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithLogger(os.Stdout).
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
// Get channel ID
id := paychan.ChannelID(viper.GetInt64(flagId))
// Get the channel from the node
res, err := ctx.QueryStore(paychan.GetChannelKey(id), paychanStoreName)
res, err := cliCtx.QueryStore(paychan.GetChannelKey(id), paychanStoreName)
if len(res) == 0 || err != nil {
return errors.Errorf("channel with ID '%d' does not exist", id)
}
@ -291,11 +300,11 @@ func GetChannelCmd(cdc *wire.Codec, paychanStoreName string) *cobra.Command {
fmt.Println(string(jsonChannel))
// Get any submitted updates from the node
res, err = ctx.QueryStore(paychan.GetSubmittedUpdateKey(id), paychanStoreName)
res, err = cliCtx.QueryStore(paychan.GetSubmittedUpdateKey(id), paychanStoreName)
if err != nil {
return err
}
// Print out the submited update if it exsits
// Print out the submitted update if it exists
if len(res) != 0 {
var submittedUpdate paychan.SubmittedUpdate
cdc.MustUnmarshalBinary(res, &submittedUpdate)

View File

@ -1,9 +1,10 @@
package paychan
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"testing"
)
func TestEndBlocker(t *testing.T) {
@ -14,7 +15,7 @@ func TestEndBlocker(t *testing.T) {
ctx, _, channelKeeper, addrs, _, _, _ := createMockApp(accountSeeds)
sender := addrs[0]
receiver := addrs[1]
coins := sdk.Coins{sdk.NewCoin("KVA", 10)}
coins := sdk.Coins{sdk.NewInt64Coin("KVA", 10)}
// create new channel
channelID := ChannelID(0) // should be 0 as first channel
@ -26,11 +27,10 @@ func TestEndBlocker(t *testing.T) {
channelKeeper.setChannel(ctx, channel)
// create closing update and submittedUpdate
payout := Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}
payout := Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}
update := Update{
ChannelID: channelID,
Payout: payout,
//Sigs: [1]crypto.Signature{},
}
sUpdate := SubmittedUpdate{
Update: update,

View File

@ -30,7 +30,7 @@ func TestKeeper(t *testing.T) {
"HappyPath",
addrs[senderAccountIndex],
addrs[receiverAccountIndex],
sdk.Coins{sdk.NewCoin("KVA", 10)},
sdk.Coins{sdk.NewInt64Coin("KVA", 10)},
true,
false,
},
@ -38,7 +38,7 @@ func TestKeeper(t *testing.T) {
"NilAddress",
sdk.AccAddress{},
sdk.AccAddress{},
sdk.Coins{sdk.NewCoin("KVA", 10)},
sdk.Coins{sdk.NewInt64Coin("KVA", 10)},
false,
true,
},
@ -54,7 +54,7 @@ func TestKeeper(t *testing.T) {
"NegativeCoins",
addrs[senderAccountIndex],
addrs[receiverAccountIndex],
sdk.Coins{sdk.NewCoin("KVA", -57)},
sdk.Coins{sdk.NewInt64Coin("KVA", -57)},
false,
true,
},
@ -126,7 +126,7 @@ func TestKeeper(t *testing.T) {
)
ctx, coinKeeper, channelKeeper, addrs, pubKeys, privKeys, genAccFunding := createMockApp(accountSeeds)
coins := sdk.Coins{sdk.NewCoin("KVA", 10)}
coins := sdk.Coins{sdk.NewInt64Coin("KVA", 10)}
// create new channel
channelID := ChannelID(0) // should be 0 as first channel
@ -138,7 +138,7 @@ func TestKeeper(t *testing.T) {
channelKeeper.setChannel(ctx, channel)
// create closing update
payout := Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}
payout := Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}
update := Update{
ChannelID: channelID,
Payout: payout,
@ -200,14 +200,14 @@ func TestKeeper(t *testing.T) {
{
"HappyPath",
true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
"sameAsSubmited",
false,
},
{
"NoChannel",
false,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
"empty",
true,
},
@ -221,35 +221,35 @@ func TestKeeper(t *testing.T) {
{
"NegativeCoins",
true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", -5)}, sdk.Coins{sdk.NewCoin("KVA", 15)}}, senderAccountIndex, senderAccountIndex},
testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", -5)}, sdk.Coins{sdk.NewInt64Coin("KVA", 15)}}, senderAccountIndex, senderAccountIndex},
"empty",
true,
},
{
"TooManyCoins",
true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 100)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 100)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, senderAccountIndex, senderAccountIndex},
"empty",
true,
},
{
"WrongSignature",
true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, senderAccountIndex, otherAccountIndex},
testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, senderAccountIndex, otherAccountIndex},
"empty",
true,
},
{
"WrongPubKey",
true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, otherAccountIndex, senderAccountIndex},
testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, otherAccountIndex, senderAccountIndex},
"empty",
true,
},
{
"ReceiverSigned",
true,
testUpdate{chanID, Payout{sdk.Coins{sdk.NewCoin("KVA", 3)}, sdk.Coins{sdk.NewCoin("KVA", 7)}}, receiverAccountIndex, receiverAccountIndex},
testUpdate{chanID, Payout{sdk.Coins{sdk.NewInt64Coin("KVA", 3)}, sdk.Coins{sdk.NewInt64Coin("KVA", 7)}}, receiverAccountIndex, receiverAccountIndex},
"empty",
true,
},
@ -266,7 +266,7 @@ func TestKeeper(t *testing.T) {
channel := Channel{
ID: chanID, // should be 0 as first channel
Participants: [2]sdk.AccAddress{addrs[senderAccountIndex], addrs[receiverAccountIndex]},
Coins: sdk.Coins{sdk.NewCoin("KVA", 10)},
Coins: sdk.Coins{sdk.NewInt64Coin("KVA", 10)},
}
channelKeeper.setChannel(ctx, channel)
}

View File

@ -27,7 +27,7 @@ func createMockApp(accountSeeds []string) (sdk.Context, bank.Keeper, Keeper, []s
mApp.CompleteSetup([]*sdk.KVStoreKey{keyChannel})
// create some accounts
genAccFunding := sdk.Coins{sdk.NewCoin("KVA", 1000)}
genAccFunding := sdk.Coins{sdk.NewInt64Coin("KVA", 1000)}
genAccs, addrs, pubKeys, privKeys := createTestGenAccounts(accountSeeds, genAccFunding)
// initialize the app with these accounts

View File

@ -61,7 +61,7 @@ func (p Payout) Sum() sdk.Coins {
type UpdateSignature struct {
PubKey crypto.PubKey
CryptoSignature crypto.Signature
CryptoSignature []byte
}
// An update that has been submitted to the blockchain, but not yet acted on.

View File

@ -28,18 +28,18 @@ func TestSubmittedUpdatesQueue(t *testing.T) {
func TestPayout(t *testing.T) {
t.Run("IsNotNegative", func(t *testing.T) {
p := Payout{sdk.Coins{sdk.NewCoin("USD", 4), sdk.NewCoin("GBP", 0)}, sdk.Coins{sdk.NewCoin("USD", 129879234), sdk.NewCoin("GBP", 1)}}
p := Payout{sdk.Coins{sdk.NewInt64Coin("USD", 4), sdk.NewInt64Coin("GBP", 0)}, sdk.Coins{sdk.NewInt64Coin("USD", 129879234), sdk.NewInt64Coin("GBP", 1)}}
assert.True(t, p.IsNotNegative())
p = Payout{sdk.Coins{sdk.NewCoin("USD", -4), sdk.NewCoin("GBP", 0)}, sdk.Coins{sdk.NewCoin("USD", 129879234), sdk.NewCoin("GBP", 1)}}
p = Payout{sdk.Coins{sdk.NewInt64Coin("USD", -4), sdk.NewInt64Coin("GBP", 0)}, sdk.Coins{sdk.NewInt64Coin("USD", 129879234), sdk.NewInt64Coin("GBP", 1)}}
assert.False(t, p.IsNotNegative())
})
t.Run("Sum", func(t *testing.T) {
p := Payout{
sdk.Coins{sdk.NewCoin("EUR", 1), sdk.NewCoin("USD", -5)},
sdk.Coins{sdk.NewCoin("EUR", 1), sdk.NewCoin("USD", 100), sdk.NewCoin("GBP", 1)},
sdk.Coins{sdk.NewInt64Coin("EUR", 1), sdk.NewInt64Coin("USD", -5)},
sdk.Coins{sdk.NewInt64Coin("EUR", 1), sdk.NewInt64Coin("USD", 100), sdk.NewInt64Coin("GBP", 1)},
}
expected := sdk.Coins{sdk.NewCoin("EUR", 2), sdk.NewCoin("GBP", 1), sdk.NewCoin("USD", 95)}
expected := sdk.Coins{sdk.NewInt64Coin("EUR", 2), sdk.NewInt64Coin("GBP", 1), sdk.NewInt64Coin("USD", 95)}
assert.Equal(t, expected, p.Sum())
})
}