update sdk

This commit is contained in:
rhuairahrighairigh 2018-06-16 22:34:07 +01:00
parent e27cbab60b
commit a2d4299b99
9 changed files with 664 additions and 447 deletions

1
.gitignore vendored
View File

@ -13,7 +13,6 @@
# Exclude build files # Exclude build files
vendor vendor
build
# Exclude text editor files # Exclude text editor files
*.sublime-project *.sublime-project

503
Gopkg.lock generated Normal file
View File

@ -0,0 +1,503 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
name = "github.com/bgentry/speakeasy"
packages = ["."]
revision = "4aabc24848ce5fd31929f7d1e4ea74d3709c14cd"
version = "v0.1.0"
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcd"
packages = ["btcec"]
revision = "86fed781132ac890ee03e906e4ecd5d6fa180c64"
[[projects]]
branch = "master"
name = "github.com/btcsuite/btcutil"
packages = ["bech32"]
revision = "d4cc87b860166d00d6b5b9e0d3b3d71d6088d4d4"
[[projects]]
name = "github.com/cosmos/cosmos-sdk"
packages = [
"baseapp",
"client",
"client/context",
"client/keys",
"client/lcd",
"client/rpc",
"client/tx",
"cmd/gaia/app",
"server",
"store",
"tests",
"types",
"version",
"wire",
"x/auth",
"x/auth/client/cli",
"x/auth/client/rest",
"x/bank",
"x/bank/client",
"x/bank/client/cli",
"x/bank/client/rest",
"x/ibc",
"x/ibc/client/cli",
"x/ibc/client/rest",
"x/slashing",
"x/stake",
"x/stake/client/cli",
"x/stake/client/rest"
]
revision = "c6711810a86f09457481a8dadae899681a9d77ab"
version = "v0.19.0"
[[projects]]
name = "github.com/davecgh/go-spew"
packages = ["spew"]
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
version = "v1.1.0"
[[projects]]
branch = "master"
name = "github.com/ebuchman/fail-test"
packages = ["."]
revision = "95f809107225be108efcf10a3509e4ea6ceef3c4"
[[projects]]
name = "github.com/fsnotify/fsnotify"
packages = ["."]
revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9"
version = "v1.4.7"
[[projects]]
name = "github.com/go-kit/kit"
packages = [
"log",
"log/level",
"log/term"
]
revision = "4dc7be5d2d12881735283bcab7352178e190fc71"
version = "v0.6.0"
[[projects]]
name = "github.com/go-logfmt/logfmt"
packages = ["."]
revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5"
version = "v0.3.0"
[[projects]]
name = "github.com/go-stack/stack"
packages = ["."]
revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc"
version = "v1.7.0"
[[projects]]
name = "github.com/gogo/protobuf"
packages = [
"gogoproto",
"jsonpb",
"proto",
"protoc-gen-gogo/descriptor",
"sortkeys",
"types"
]
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
version = "v1.0.0"
[[projects]]
name = "github.com/golang/protobuf"
packages = [
"proto",
"ptypes",
"ptypes/any",
"ptypes/duration",
"ptypes/timestamp"
]
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
version = "v1.0.0"
[[projects]]
branch = "master"
name = "github.com/golang/snappy"
packages = ["."]
revision = "2e65f85255dbc3072edf28d6b5b8efc472979f5a"
[[projects]]
name = "github.com/gorilla/context"
packages = ["."]
revision = "08b5f424b9271eedf6f9f0ce86cb9396ed337a42"
version = "v1.1.1"
[[projects]]
name = "github.com/gorilla/mux"
packages = ["."]
revision = "e3702bed27f0d39777b0b37b664b6280e8ef8fbf"
version = "v1.6.2"
[[projects]]
name = "github.com/gorilla/websocket"
packages = ["."]
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
version = "v1.2.0"
[[projects]]
branch = "master"
name = "github.com/hashicorp/hcl"
packages = [
".",
"hcl/ast",
"hcl/parser",
"hcl/printer",
"hcl/scanner",
"hcl/strconv",
"hcl/token",
"json/parser",
"json/scanner",
"json/token"
]
revision = "ef8a98b0bbce4a65b5aa4c368430a80ddc533168"
[[projects]]
branch = "master"
name = "github.com/howeyc/crc16"
packages = ["."]
revision = "2b2a61e366a66d3efb279e46176e7291001e0354"
[[projects]]
name = "github.com/inconshreveable/mousetrap"
packages = ["."]
revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"
version = "v1.0"
[[projects]]
branch = "master"
name = "github.com/jmhodges/levigo"
packages = ["."]
revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9"
[[projects]]
branch = "master"
name = "github.com/kr/logfmt"
packages = ["."]
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"
[[projects]]
name = "github.com/magiconair/properties"
packages = ["."]
revision = "c2353362d570a7bfa228149c62842019201cfb71"
version = "v1.8.0"
[[projects]]
name = "github.com/mattn/go-isatty"
packages = ["."]
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
version = "v0.0.3"
[[projects]]
branch = "master"
name = "github.com/mitchellh/mapstructure"
packages = ["."]
revision = "bb74f1db0675b241733089d5a1faa5dd8b0ef57b"
[[projects]]
name = "github.com/pelletier/go-toml"
packages = ["."]
revision = "c01d1270ff3e442a8a57cddc1c92dc1138598194"
version = "v1.2.0"
[[projects]]
name = "github.com/pkg/errors"
packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
[[projects]]
name = "github.com/pmezard/go-difflib"
packages = ["difflib"]
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
version = "v1.0.0"
[[projects]]
branch = "master"
name = "github.com/rcrowley/go-metrics"
packages = ["."]
revision = "e2704e165165ec55d062f5919b4b29494e9fa790"
[[projects]]
name = "github.com/spf13/afero"
packages = [
".",
"mem"
]
revision = "787d034dfe70e44075ccc060d346146ef53270ad"
version = "v1.1.1"
[[projects]]
name = "github.com/spf13/cast"
packages = ["."]
revision = "8965335b8c7107321228e3e3702cab9832751bac"
version = "v1.2.0"
[[projects]]
name = "github.com/spf13/cobra"
packages = ["."]
revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385"
version = "v0.0.3"
[[projects]]
branch = "master"
name = "github.com/spf13/jwalterweatherman"
packages = ["."]
revision = "7c0cea34c8ece3fbeb2b27ab9b59511d360fb394"
[[projects]]
name = "github.com/spf13/pflag"
packages = ["."]
revision = "583c0c0531f06d5278b7d917446061adc344b5cd"
version = "v1.0.1"
[[projects]]
name = "github.com/spf13/viper"
packages = ["."]
revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736"
version = "v1.0.2"
[[projects]]
name = "github.com/stretchr/testify"
packages = [
"assert",
"require"
]
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
version = "v1.2.2"
[[projects]]
branch = "master"
name = "github.com/syndtr/goleveldb"
packages = [
"leveldb",
"leveldb/cache",
"leveldb/comparer",
"leveldb/errors",
"leveldb/filter",
"leveldb/iterator",
"leveldb/journal",
"leveldb/memdb",
"leveldb/opt",
"leveldb/storage",
"leveldb/table",
"leveldb/util"
]
revision = "e2150783cd35f5b607daca48afd8c57ec54cc995"
[[projects]]
name = "github.com/tendermint/abci"
packages = [
"client",
"example/code",
"example/kvstore",
"server",
"types"
]
revision = "ebee2fe114020aa49c70bbbae50b7079fc7e7b90"
version = "v0.11.0"
[[projects]]
branch = "master"
name = "github.com/tendermint/ed25519"
packages = [
".",
"edwards25519",
"extra25519"
]
revision = "d8387025d2b9d158cf4efb07e7ebf814bcce2057"
[[projects]]
name = "github.com/tendermint/go-amino"
packages = ["."]
revision = "ed62928576cfcaf887209dc96142cd79cdfff389"
version = "0.9.9"
[[projects]]
name = "github.com/tendermint/go-crypto"
packages = [
".",
"keys",
"keys/bcrypt",
"keys/words",
"keys/words/wordlist"
]
revision = "915416979bf70efa4bcbf1c6cd5d64c5fff9fc19"
version = "v0.6.2"
[[projects]]
name = "github.com/tendermint/iavl"
packages = [
".",
"sha256truncated"
]
revision = "c9206995e8f948e99927f5084a88a7e94ca256da"
version = "v0.8.0-rc0"
[[projects]]
name = "github.com/tendermint/tendermint"
packages = [
"blockchain",
"cmd/tendermint/commands",
"config",
"consensus",
"consensus/types",
"evidence",
"libs/events",
"libs/pubsub",
"libs/pubsub/query",
"lite",
"lite/client",
"lite/errors",
"lite/files",
"lite/proxy",
"mempool",
"node",
"p2p",
"p2p/conn",
"p2p/pex",
"p2p/upnp",
"privval",
"proxy",
"rpc/client",
"rpc/core",
"rpc/core/types",
"rpc/grpc",
"rpc/lib",
"rpc/lib/client",
"rpc/lib/server",
"rpc/lib/types",
"state",
"state/txindex",
"state/txindex/kv",
"state/txindex/null",
"types",
"version"
]
revision = "27bd1deabe4ba6a2d9b463b8f3e3f1e31b993e61"
version = "v0.20.0"
[[projects]]
name = "github.com/tendermint/tmlibs"
packages = [
"autofile",
"bech32",
"cli",
"cli/flags",
"clist",
"common",
"db",
"flowrate",
"log",
"merkle",
"merkle/tmhash"
]
revision = "0c98d10b4ffbd87978d79c160e835b3d3df241ec"
[[projects]]
branch = "master"
name = "golang.org/x/crypto"
packages = [
"blowfish",
"curve25519",
"internal/subtle",
"nacl/box",
"nacl/secretbox",
"openpgp/armor",
"openpgp/errors",
"poly1305",
"ripemd160",
"salsa20/salsa"
]
revision = "a8fb68e7206f8c78be19b432c58eb52a6aa34462"
[[projects]]
branch = "master"
name = "golang.org/x/net"
packages = [
"context",
"http/httpguts",
"http2",
"http2/hpack",
"idna",
"internal/timeseries",
"trace"
]
revision = "db08ff08e8622530d9ed3a0e8ac279f6d4c02196"
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["unix"]
revision = "6c888cc515d3ed83fc103cf1d84468aad274b0a7"
[[projects]]
name = "golang.org/x/text"
packages = [
"collate",
"collate/build",
"internal/colltab",
"internal/gen",
"internal/tag",
"internal/triegen",
"internal/ucd",
"language",
"secure/bidirule",
"transform",
"unicode/bidi",
"unicode/cldr",
"unicode/norm",
"unicode/rangetable"
]
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0"
[[projects]]
name = "google.golang.org/genproto"
packages = ["googleapis/rpc/status"]
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
[[projects]]
name = "google.golang.org/grpc"
packages = [
".",
"balancer",
"codes",
"connectivity",
"credentials",
"grpclb/grpc_lb_v1/messages",
"grpclog",
"internal",
"keepalive",
"metadata",
"naming",
"peer",
"resolver",
"stats",
"status",
"tap",
"transport"
]
revision = "5b3c4e850e90a4cf6a20ebd46c8b32a0a3afcb9e"
version = "v1.7.5"
[[projects]]
name = "gopkg.in/yaml.v2"
packages = ["."]
revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183"
version = "v2.2.1"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "ffb18db87921d091119ab0ab7fa8daaeb76c646d5dbd6796724ff1e8dc41e044"
solver-name = "gps-cdcl"
solver-version = 1

60
Gopkg.toml Normal file
View File

@ -0,0 +1,60 @@
# [[constraint]]
# name = "github.com/bgentry/speakeasy"
# version = "~0.1.0"
# [[constraint]]
# name = "github.com/golang/protobuf"
# version = "~1.0.0"
# [[constraint]]
# name = "github.com/mattn/go-isatty"
# version = "~0.0.3"
# [[constraint]]
# name = "github.com/pkg/errors"
# version = "~0.8.0"
[[constraint]]
name = "github.com/spf13/cobra"
version = "~0.0.1"
# [[constraint]]
# name = "github.com/spf13/viper"
# version = "~1.0.0"
[[constraint]]
name = "github.com/stretchr/testify"
version = "~1.2.1"
[[constraint]]
name = "github.com/tendermint/abci"
version = "=0.11.0"
[[constraint]]
name = "github.com/tendermint/go-crypto"
version = "~0.6.2"
# [[constraint]]
# name = "github.com/tendermint/go-amino"
# version = "=0.9.9"
# [[constraint]]
# name = "github.com/tendermint/iavl"
# version = "0.8.0-rc0"
# [[constraint]]
# name = "github.com/tendermint/tendermint"
# version = "=0.20.0"
[[override]]
name = "github.com/tendermint/tmlibs"
revision = "0c98d10b4ffbd87978d79c160e835b3d3df241ec"
# this got updated and broke, so locked to an old working commit ...
[[override]]
name = "google.golang.org/genproto"
revision = "7fd901a49ba6a7f87732eb344f6e3c5b19d1b200"
[prune]
go-tests = true
unused-packages = true

View File

@ -2,5 +2,5 @@
## Installation ## Installation
go install ./cmd/kavad go install ./cmd/kvd
go install ./cmd/kavacli go install ./cmd/kvcli

View File

@ -26,8 +26,8 @@ import (
// rootCmd is the entry point for this binary // rootCmd is the entry point for this binary
var ( var (
rootCmd = &cobra.Command{ rootCmd = &cobra.Command{
Use: "basecli", Use: "kvcli",
Short: "Basecoin light-client", Short: "Kava Light-Client",
} }
) )
@ -59,8 +59,8 @@ func main() {
bankcmd.SendTxCmd(cdc), bankcmd.SendTxCmd(cdc),
ibccmd.IBCTransferCmd(cdc), ibccmd.IBCTransferCmd(cdc),
ibccmd.IBCRelayCmd(cdc), ibccmd.IBCRelayCmd(cdc),
stakecmd.GetCmdDeclareCandidacy(cdc), stakecmd.GetCmdCreateValidator(cdc),
stakecmd.GetCmdEditCandidacy(cdc), stakecmd.GetCmdEditValidator(cdc),
stakecmd.GetCmdDelegate(cdc), stakecmd.GetCmdDelegate(cdc),
stakecmd.GetCmdUnbond(cdc), stakecmd.GetCmdUnbond(cdc),
)...) )...)
@ -75,9 +75,6 @@ func main() {
) )
// prepare and add flags // prepare and add flags
executor := cli.PrepareMainCmd(rootCmd, "BC", os.ExpandEnv("$HOME/.basecli")) executor := cli.PrepareMainCmd(rootCmd, "KV", os.ExpandEnv("$HOME/.kvcli"))
executor.Execute() executor.Execute()
} }
func Blarg() {
45}

View File

@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/cli" "github.com/tendermint/tmlibs/cli"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tmlibs/log"
@ -20,26 +21,26 @@ func main() {
ctx := server.NewDefaultContext() ctx := server.NewDefaultContext()
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: "kavad", Use: "kvd",
Short: "Kava Daemon", Short: "Kava Daemon",
PersistentPreRunE: server.PersistentPreRunEFn(ctx), PersistentPreRunE: server.PersistentPreRunEFn(ctx),
} }
server.AddCommands(ctx, cdc, rootCmd, server.DefaultAppInit, server.AddCommands(ctx, cdc, rootCmd, server.DefaultAppInit,
server.ConstructAppCreator(newApp, "kava"), server.ConstructAppCreator(newApp, "kava"),
server.ConstructAppExporter(exportAppState, "kava")) server.ConstructAppExporter(exportAppStateAndTMValidators, "kava"))
// prepare and add flags // prepare and add flags
rootDir := os.ExpandEnv("$HOME/.kavad") rootDir := os.ExpandEnv("$HOME/.kvd")
executor := cli.PrepareBaseCmd(rootCmd, "KV", rootDir) executor := cli.PrepareBaseCmd(rootCmd, "KV", rootDir)
executor.Execute() executor.Execute()
} }
func newApp(logger log.Logger, db dbm.DB) abci.Application { func newApp(logger log.Logger, db dbm.DB) abci.Application {
return app.NewBasecoinApp(logger, db) return app.NewKavaApp(logger, db)
} }
func exportAppState(logger log.Logger, db dbm.DB) (json.RawMessage, error) { func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB) (json.RawMessage, []tmtypes.GenesisValidator, error) {
bapp := app.NewBasecoinApp(logger, db) bapp := app.NewKavaApp(logger, db)
return bapp.ExportAppStateJSON() return bapp.ExportAppStateAndValidators()
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
tmtypes "github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common" cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tmlibs/log"
@ -14,46 +15,51 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/ibc" "github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake" "github.com/cosmos/cosmos-sdk/x/stake"
"github.com/kava-labs/kava/internal/types" "github.com/kava-labs/kava/internal/types"
) )
const ( const (
appName = "BasecoinApp" appName = "KavaApp"
) )
// Extended ABCI application // Extended ABCI application
type BasecoinApp struct { type KavaApp struct {
*bam.BaseApp *bam.BaseApp
cdc *wire.Codec cdc *wire.Codec
// keys to access the substores // keys to access the substores
keyMain *sdk.KVStoreKey keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey keyAccount *sdk.KVStoreKey
keyIBC *sdk.KVStoreKey keyIBC *sdk.KVStoreKey
keyStake *sdk.KVStoreKey keyStake *sdk.KVStoreKey
keySlashing *sdk.KVStoreKey
// Manage getting and setting accounts // Manage getting and setting accounts
accountMapper sdk.AccountMapper accountMapper auth.AccountMapper
coinKeeper bank.Keeper feeCollectionKeeper auth.FeeCollectionKeeper
ibcMapper ibc.Mapper coinKeeper bank.Keeper
stakeKeeper stake.Keeper ibcMapper ibc.Mapper
stakeKeeper stake.Keeper
slashingKeeper slashing.Keeper
} }
func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp { func NewKavaApp(logger log.Logger, db dbm.DB) *KavaApp {
// Create app-level codec for txs and accounts. // Create app-level codec for txs and accounts.
var cdc = MakeCodec() var cdc = MakeCodec()
// Create your application object. // Create your application object.
var app = &BasecoinApp{ var app = &KavaApp{
BaseApp: bam.NewBaseApp(appName, cdc, logger, db), BaseApp: bam.NewBaseApp(appName, cdc, logger, db),
cdc: cdc, cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"), keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"), keyAccount: sdk.NewKVStoreKey("acc"),
keyIBC: sdk.NewKVStoreKey("ibc"), keyIBC: sdk.NewKVStoreKey("ibc"),
keyStake: sdk.NewKVStoreKey("stake"), keyStake: sdk.NewKVStoreKey("stake"),
keySlashing: sdk.NewKVStoreKey("slashing"),
} }
// Define the accountMapper. // Define the accountMapper.
@ -67,17 +73,21 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp {
app.coinKeeper = bank.NewKeeper(app.accountMapper) app.coinKeeper = bank.NewKeeper(app.accountMapper)
app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace)) app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace))
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace)) 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))
// register message routes // register message routes
app.Router(). app.Router().
AddRoute("auth", auth.NewHandler(app.accountMapper)).
AddRoute("bank", bank.NewHandler(app.coinKeeper)). AddRoute("bank", bank.NewHandler(app.coinKeeper)).
AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)). AddRoute("ibc", ibc.NewHandler(app.ibcMapper, app.coinKeeper)).
AddRoute("stake", stake.NewHandler(app.stakeKeeper)) AddRoute("stake", stake.NewHandler(app.stakeKeeper))
// Initialize BaseApp. // Initialize BaseApp.
app.SetInitChainer(app.initChainer) app.SetInitChainer(app.initChainer)
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake) app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, auth.BurnFeeHandler)) app.SetEndBlocker(app.EndBlocker)
app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper))
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake, app.keySlashing)
err := app.LoadLatestVersion(app.keyMain) err := app.LoadLatestVersion(app.keyMain)
if err != nil { if err != nil {
cmn.Exit(err.Error()) cmn.Exit(err.Error())
@ -92,16 +102,35 @@ func MakeCodec() *wire.Codec {
sdk.RegisterWire(cdc) // Register Msgs sdk.RegisterWire(cdc) // Register Msgs
bank.RegisterWire(cdc) bank.RegisterWire(cdc)
stake.RegisterWire(cdc) stake.RegisterWire(cdc)
slashing.RegisterWire(cdc)
ibc.RegisterWire(cdc) ibc.RegisterWire(cdc)
// register custom AppAccount // register custom AppAccount
cdc.RegisterInterface((*sdk.Account)(nil), nil) cdc.RegisterInterface((*auth.Account)(nil), nil)
cdc.RegisterConcrete(&types.AppAccount{}, "kava/Account", nil) cdc.RegisterConcrete(&types.AppAccount{}, "basecoin/Account", nil)
return cdc return cdc
} }
// application updates every end block
func (app *KavaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
tags := slashing.BeginBlocker(ctx, req, app.slashingKeeper)
return abci.ResponseBeginBlock{
Tags: tags.ToKVPairs(),
}
}
// application updates every end block
func (app *KavaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
}
}
// Custom logic for basecoin initialization // Custom logic for basecoin initialization
func (app *BasecoinApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { func (app *KavaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
stateJSON := req.AppStateBytes stateJSON := req.AppStateBytes
genesisState := new(types.GenesisState) genesisState := new(types.GenesisState)
@ -117,18 +146,23 @@ func (app *BasecoinApp) initChainer(ctx sdk.Context, req abci.RequestInitChain)
panic(err) // TODO https://github.com/cosmos/cosmos-sdk/issues/468 panic(err) // TODO https://github.com/cosmos/cosmos-sdk/issues/468
// return sdk.ErrGenesisParse("").TraceCause(err, "") // return sdk.ErrGenesisParse("").TraceCause(err, "")
} }
acc.AccountNumber = app.accountMapper.GetNextAccountNumber(ctx)
app.accountMapper.SetAccount(ctx, acc) app.accountMapper.SetAccount(ctx, acc)
} }
// load the initial stake information
stake.InitGenesis(ctx, app.stakeKeeper, genesisState.StakeData)
return abci.ResponseInitChain{} return abci.ResponseInitChain{}
} }
// Custom logic for state export // Custom logic for state export
func (app *BasecoinApp) ExportAppStateJSON() (appState json.RawMessage, err error) { func (app *KavaApp) ExportAppStateAndValidators() (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
ctx := app.NewContext(true, abci.Header{}) ctx := app.NewContext(true, abci.Header{})
// iterate to get the accounts // iterate to get the accounts
accounts := []*types.GenesisAccount{} accounts := []*types.GenesisAccount{}
appendAccount := func(acc sdk.Account) (stop bool) { appendAccount := func(acc auth.Account) (stop bool) {
account := &types.GenesisAccount{ account := &types.GenesisAccount{
Address: acc.GetAddress(), Address: acc.GetAddress(),
Coins: acc.GetCoins(), Coins: acc.GetCoins(),
@ -141,5 +175,10 @@ func (app *BasecoinApp) ExportAppStateJSON() (appState json.RawMessage, err erro
genState := types.GenesisState{ genState := types.GenesisState{
Accounts: accounts, Accounts: accounts,
} }
return wire.MarshalJSONIndent(app.cdc, genState) appState, err = wire.MarshalJSONIndent(app.cdc, genState)
if err != nil {
return nil, nil, err
}
validators = stake.WriteValidators(ctx, app.stakeKeeper)
return appState, validators, err
} }

View File

@ -1,19 +1,17 @@
package app package app
import ( import (
"encoding/json"
"fmt"
"os" "os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/examples/basecoin/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/stake"
"github.com/cosmos/cosmos-sdk/x/ibc" "github.com/kava-labs/kava/internal/types"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
crypto "github.com/tendermint/go-crypto" crypto "github.com/tendermint/go-crypto"
@ -21,99 +19,25 @@ import (
"github.com/tendermint/tmlibs/log" "github.com/tendermint/tmlibs/log"
) )
// Construct some global addrs and txs for tests. func setGenesis(bapp *KavaApp, accs ...auth.BaseAccount) error {
var (
chainID = "" // TODO
accName = "foobart"
priv1 = crypto.GenPrivKeyEd25519()
addr1 = priv1.PubKey().Address()
priv2 = crypto.GenPrivKeyEd25519()
addr2 = priv2.PubKey().Address()
addr3 = crypto.GenPrivKeyEd25519().PubKey().Address()
priv4 = crypto.GenPrivKeyEd25519()
addr4 = priv4.PubKey().Address()
coins = sdk.Coins{{"foocoin", 10}}
halfCoins = sdk.Coins{{"foocoin", 5}}
manyCoins = sdk.Coins{{"foocoin", 1}, {"barcoin", 1}}
fee = sdk.StdFee{
sdk.Coins{{"foocoin", 0}},
0,
}
sendMsg1 = bank.MsgSend{
Inputs: []bank.Input{bank.NewInput(addr1, coins)},
Outputs: []bank.Output{bank.NewOutput(addr2, coins)},
}
sendMsg2 = bank.MsgSend{
Inputs: []bank.Input{bank.NewInput(addr1, coins)},
Outputs: []bank.Output{
bank.NewOutput(addr2, halfCoins),
bank.NewOutput(addr3, halfCoins),
},
}
sendMsg3 = bank.MsgSend{
Inputs: []bank.Input{
bank.NewInput(addr1, coins),
bank.NewInput(addr4, coins),
},
Outputs: []bank.Output{
bank.NewOutput(addr2, coins),
bank.NewOutput(addr3, coins),
},
}
sendMsg4 = bank.MsgSend{
Inputs: []bank.Input{
bank.NewInput(addr2, coins),
},
Outputs: []bank.Output{
bank.NewOutput(addr1, coins),
},
}
sendMsg5 = bank.MsgSend{
Inputs: []bank.Input{
bank.NewInput(addr1, manyCoins),
},
Outputs: []bank.Output{
bank.NewOutput(addr2, manyCoins),
},
}
)
func loggerAndDB() (log.Logger, dbm.DB) {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
db := dbm.NewMemDB()
return logger, db
}
func newBasecoinApp() *BasecoinApp {
logger, db := loggerAndDB()
return NewBasecoinApp(logger, db)
}
func setGenesisAccounts(bapp *BasecoinApp, accs ...auth.BaseAccount) error {
genaccs := make([]*types.GenesisAccount, len(accs)) genaccs := make([]*types.GenesisAccount, len(accs))
for i, acc := range accs { for i, acc := range accs {
genaccs[i] = types.NewGenesisAccount(&types.AppAccount{acc, accName}) genaccs[i] = types.NewGenesisAccount(&types.AppAccount{acc, "foobart"})
} }
genesisState := types.GenesisState{ genesisState := types.GenesisState{
Accounts: genaccs, Accounts: genaccs,
StakeData: stake.DefaultGenesisState(),
} }
stateBytes, err := json.MarshalIndent(genesisState, "", "\t") stateBytes, err := wire.MarshalJSONIndent(bapp.cdc, genesisState)
if err != nil { if err != nil {
return err return err
} }
// Initialize the chain // Initialize the chain
vals := []abci.Validator{} vals := []abci.Validator{}
bapp.InitChain(abci.RequestInitChain{vals, stateBytes}) bapp.InitChain(abci.RequestInitChain{Validators: vals, AppStateBytes: stateBytes})
bapp.Commit() bapp.Commit()
return nil return nil
@ -121,66 +45,10 @@ func setGenesisAccounts(bapp *BasecoinApp, accs ...auth.BaseAccount) error {
//_______________________________________________________________________ //_______________________________________________________________________
func TestMsgs(t *testing.T) {
bapp := newBasecoinApp()
msgs := []struct {
msg sdk.Msg
}{
{sendMsg1},
}
for i, m := range msgs {
// Run a CheckDeliver
SignCheckDeliver(t, bapp, m.msg, []int64{int64(i)}, false, priv1)
}
}
func TestSortGenesis(t *testing.T) {
logger, db := loggerAndDB()
bapp := NewBasecoinApp(logger, db)
// Note the order: the coins are unsorted!
coinDenom1, coinDenom2 := "foocoin", "barcoin"
genState := fmt.Sprintf(`{
"accounts": [{
"address": "%s",
"coins": [
{
"denom": "%s",
"amount": 10
},
{
"denom": "%s",
"amount": 20
}
]
}]
}`, addr1.String(), coinDenom1, coinDenom2)
// Initialize the chain
vals := []abci.Validator{}
bapp.InitChain(abci.RequestInitChain{vals, []byte(genState)})
bapp.Commit()
// Unsorted coins means invalid
err := sendMsg5.ValidateBasic()
require.Equal(t, sdk.CodeInvalidCoins, err.Code(), err.ABCILog())
// Sort coins, should be valid
sendMsg5.Inputs[0].Coins.Sort()
sendMsg5.Outputs[0].Coins.Sort()
err = sendMsg5.ValidateBasic()
require.Nil(t, err)
// Ensure we can send
SignCheckDeliver(t, bapp, sendMsg5, []int64{0}, true, priv1)
}
func TestGenesis(t *testing.T) { func TestGenesis(t *testing.T) {
logger, db := loggerAndDB() logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
bapp := NewBasecoinApp(logger, db) db := dbm.NewMemDB()
bapp := NewKavaApp(logger, db)
// Construct some genesis bytes to reflect basecoin/types/AppAccount // Construct some genesis bytes to reflect basecoin/types/AppAccount
pk := crypto.GenPrivKeyEd25519().PubKey() pk := crypto.GenPrivKeyEd25519().PubKey()
@ -193,8 +61,8 @@ func TestGenesis(t *testing.T) {
} }
acc := &types.AppAccount{baseAcc, "foobart"} acc := &types.AppAccount{baseAcc, "foobart"}
err = setGenesisAccounts(bapp, baseAcc) err = setGenesis(bapp, baseAcc)
assert.Nil(t, err) require.Nil(t, err)
// A checkTx context // A checkTx context
ctx := bapp.BaseApp.NewContext(true, abci.Header{}) ctx := bapp.BaseApp.NewContext(true, abci.Header{})
@ -202,260 +70,8 @@ func TestGenesis(t *testing.T) {
assert.Equal(t, acc, res1) assert.Equal(t, acc, res1)
// reload app and ensure the account is still there // reload app and ensure the account is still there
bapp = NewBasecoinApp(logger, db) bapp = NewKavaApp(logger, db)
ctx = bapp.BaseApp.NewContext(true, abci.Header{}) ctx = bapp.BaseApp.NewContext(true, abci.Header{})
res1 = bapp.accountMapper.GetAccount(ctx, baseAcc.Address) res1 = bapp.accountMapper.GetAccount(ctx, baseAcc.Address)
assert.Equal(t, acc, res1) assert.Equal(t, acc, res1)
} }
func TestMsgSendWithAccounts(t *testing.T) {
bapp := newBasecoinApp()
// Construct some genesis bytes to reflect basecoin/types/AppAccount
// Give 77 foocoin to the first key
coins, err := sdk.ParseCoins("77foocoin")
require.Nil(t, err)
baseAcc := auth.BaseAccount{
Address: addr1,
Coins: coins,
}
// Construct genesis state
err = setGenesisAccounts(bapp, baseAcc)
assert.Nil(t, err)
// A checkTx context (true)
ctxCheck := bapp.BaseApp.NewContext(true, abci.Header{})
res1 := bapp.accountMapper.GetAccount(ctxCheck, addr1)
assert.Equal(t, baseAcc, res1.(*types.AppAccount).BaseAccount)
// Run a CheckDeliver
SignCheckDeliver(t, bapp, sendMsg1, []int64{0}, true, priv1)
// Check balances
CheckBalance(t, bapp, addr1, "67foocoin")
CheckBalance(t, bapp, addr2, "10foocoin")
// Delivering again should cause replay error
SignCheckDeliver(t, bapp, sendMsg1, []int64{0}, false, priv1)
// bumping the txnonce number without resigning should be an auth error
tx := genTx(sendMsg1, []int64{0}, priv1)
tx.Signatures[0].Sequence = 1
res := bapp.Deliver(tx)
assert.Equal(t, sdk.ToABCICode(sdk.CodespaceRoot, sdk.CodeUnauthorized), res.Code, res.Log)
// resigning the tx with the bumped sequence should work
SignCheckDeliver(t, bapp, sendMsg1, []int64{1}, true, priv1)
}
func TestMsgSendMultipleOut(t *testing.T) {
bapp := newBasecoinApp()
genCoins, err := sdk.ParseCoins("42foocoin")
require.Nil(t, err)
acc1 := auth.BaseAccount{
Address: addr1,
Coins: genCoins,
}
acc2 := auth.BaseAccount{
Address: addr2,
Coins: genCoins,
}
err = setGenesisAccounts(bapp, acc1, acc2)
assert.Nil(t, err)
// Simulate a Block
SignCheckDeliver(t, bapp, sendMsg2, []int64{0}, true, priv1)
// Check balances
CheckBalance(t, bapp, addr1, "32foocoin")
CheckBalance(t, bapp, addr2, "47foocoin")
CheckBalance(t, bapp, addr3, "5foocoin")
}
func TestSengMsgMultipleInOut(t *testing.T) {
bapp := newBasecoinApp()
genCoins, err := sdk.ParseCoins("42foocoin")
require.Nil(t, err)
acc1 := auth.BaseAccount{
Address: addr1,
Coins: genCoins,
}
acc2 := auth.BaseAccount{
Address: addr2,
Coins: genCoins,
}
acc4 := auth.BaseAccount{
Address: addr4,
Coins: genCoins,
}
err = setGenesisAccounts(bapp, acc1, acc2, acc4)
assert.Nil(t, err)
// CheckDeliver
SignCheckDeliver(t, bapp, sendMsg3, []int64{0, 0}, true, priv1, priv4)
// Check balances
CheckBalance(t, bapp, addr1, "32foocoin")
CheckBalance(t, bapp, addr4, "32foocoin")
CheckBalance(t, bapp, addr2, "52foocoin")
CheckBalance(t, bapp, addr3, "10foocoin")
}
func TestMsgSendDependent(t *testing.T) {
bapp := newBasecoinApp()
genCoins, err := sdk.ParseCoins("42foocoin")
require.Nil(t, err)
acc1 := auth.BaseAccount{
Address: addr1,
Coins: genCoins,
}
err = setGenesisAccounts(bapp, acc1)
assert.Nil(t, err)
// CheckDeliver
SignCheckDeliver(t, bapp, sendMsg1, []int64{0}, true, priv1)
// Check balances
CheckBalance(t, bapp, addr1, "32foocoin")
CheckBalance(t, bapp, addr2, "10foocoin")
// Simulate a Block
SignCheckDeliver(t, bapp, sendMsg4, []int64{0}, true, priv2)
// Check balances
CheckBalance(t, bapp, addr1, "42foocoin")
}
func TestMsgQuiz(t *testing.T) {
bapp := newBasecoinApp()
// Construct genesis state
// Construct some genesis bytes to reflect basecoin/types/AppAccount
baseAcc := auth.BaseAccount{
Address: addr1,
Coins: nil,
}
acc1 := &types.AppAccount{baseAcc, "foobart"}
// Construct genesis state
genesisState := map[string]interface{}{
"accounts": []*types.GenesisAccount{
types.NewGenesisAccount(acc1),
},
}
stateBytes, err := json.MarshalIndent(genesisState, "", "\t")
require.Nil(t, err)
// Initialize the chain (nil)
vals := []abci.Validator{}
bapp.InitChain(abci.RequestInitChain{vals, stateBytes})
bapp.Commit()
// A checkTx context (true)
ctxCheck := bapp.BaseApp.NewContext(true, abci.Header{})
res1 := bapp.accountMapper.GetAccount(ctxCheck, addr1)
assert.Equal(t, acc1, res1)
}
func TestIBCMsgs(t *testing.T) {
bapp := newBasecoinApp()
sourceChain := "source-chain"
destChain := "dest-chain"
baseAcc := auth.BaseAccount{
Address: addr1,
Coins: coins,
}
acc1 := &types.AppAccount{baseAcc, "foobart"}
err := setGenesisAccounts(bapp, baseAcc)
assert.Nil(t, err)
// A checkTx context (true)
ctxCheck := bapp.BaseApp.NewContext(true, abci.Header{})
res1 := bapp.accountMapper.GetAccount(ctxCheck, addr1)
assert.Equal(t, acc1, res1)
packet := ibc.IBCPacket{
SrcAddr: addr1,
DestAddr: addr1,
Coins: coins,
SrcChain: sourceChain,
DestChain: destChain,
}
transferMsg := ibc.IBCTransferMsg{
IBCPacket: packet,
}
receiveMsg := ibc.IBCReceiveMsg{
IBCPacket: packet,
Relayer: addr1,
Sequence: 0,
}
SignCheckDeliver(t, bapp, transferMsg, []int64{0}, true, priv1)
CheckBalance(t, bapp, addr1, "")
SignCheckDeliver(t, bapp, transferMsg, []int64{1}, false, priv1)
SignCheckDeliver(t, bapp, receiveMsg, []int64{2}, true, priv1)
CheckBalance(t, bapp, addr1, "10foocoin")
SignCheckDeliver(t, bapp, receiveMsg, []int64{3}, false, priv1)
}
func genTx(msg sdk.Msg, seq []int64, priv ...crypto.PrivKeyEd25519) sdk.StdTx {
sigs := make([]sdk.StdSignature, len(priv))
for i, p := range priv {
sigs[i] = sdk.StdSignature{
PubKey: p.PubKey(),
Signature: p.Sign(sdk.StdSignBytes(chainID, seq, fee, msg)),
Sequence: seq[i],
}
}
return sdk.NewStdTx(msg, fee, sigs)
}
func SignCheckDeliver(t *testing.T, bapp *BasecoinApp, msg sdk.Msg, seq []int64, expPass bool, priv ...crypto.PrivKeyEd25519) {
// Sign the tx
tx := genTx(msg, seq, priv...)
// Run a Check
res := bapp.Check(tx)
if expPass {
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
} else {
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
}
// Simulate a Block
bapp.BeginBlock(abci.RequestBeginBlock{})
res = bapp.Deliver(tx)
if expPass {
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
} else {
require.NotEqual(t, sdk.ABCICodeOK, res.Code, res.Log)
}
bapp.EndBlock(abci.RequestEndBlock{})
//bapp.Commit()
}
func CheckBalance(t *testing.T, bapp *BasecoinApp, addr sdk.Address, balExpected string) {
ctxDeliver := bapp.BaseApp.NewContext(false, abci.Header{})
res2 := bapp.accountMapper.GetAccount(ctxDeliver, addr)
assert.Equal(t, balExpected, fmt.Sprintf("%v", res2.GetCoins()))
}

View File

@ -4,9 +4,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/stake"
) )
var _ sdk.Account = (*AppAccount)(nil) var _ auth.Account = (*AppAccount)(nil)
// Custom extensions for this application. This is just an example of // Custom extensions for this application. This is just an example of
// extending auth.BaseAccount with custom fields. // extending auth.BaseAccount with custom fields.
@ -23,8 +24,8 @@ func (acc AppAccount) GetName() string { return acc.Name }
func (acc *AppAccount) SetName(name string) { acc.Name = name } func (acc *AppAccount) SetName(name string) { acc.Name = name }
// Get the AccountDecoder function for the custom AppAccount // Get the AccountDecoder function for the custom AppAccount
func GetAccountDecoder(cdc *wire.Codec) sdk.AccountDecoder { func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder {
return func(accBytes []byte) (res sdk.Account, err error) { return func(accBytes []byte) (res auth.Account, err error) {
if len(accBytes) == 0 { if len(accBytes) == 0 {
return nil, sdk.ErrTxDecode("accBytes are empty") return nil, sdk.ErrTxDecode("accBytes are empty")
} }
@ -41,7 +42,8 @@ func GetAccountDecoder(cdc *wire.Codec) sdk.AccountDecoder {
// State to Unmarshal // State to Unmarshal
type GenesisState struct { type GenesisState struct {
Accounts []*GenesisAccount `json:"accounts"` Accounts []*GenesisAccount `json:"accounts"`
StakeData stake.GenesisState `json:"stake"`
} }
// GenesisAccount doesn't need pubkey or sequence // GenesisAccount doesn't need pubkey or sequence