rebase, add account command

This commit is contained in:
Kevin Davis 2019-10-03 15:13:38 -04:00
parent cadb7baf2b
commit 54b9cf167f
8 changed files with 117 additions and 38 deletions

View File

@ -3,26 +3,33 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
"github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/cli"
"github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported" authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/genutil" "github.com/cosmos/cosmos-sdk/x/genutil"
) )
const ( const (
flagClientHome = "home-client" flagClientHome = "home-client"
flagVestingStart = "vesting-start-time" flagVestingStart = "vesting-start-time"
flagVestingEnd = "vesting-end-time" flagVestingEnd = "vesting-end-time"
flagVestingAmt = "vesting-amount" flagVestingAmt = "vesting-amount"
flagVestingPeriodsFile = "vesting-periods-file"
flagValidatorVestingFile = "validator-vesting-file"
) )
// AddGenesisAccountCmd returns an add-genesis-account cobra Command. // AddGenesisAccountCmd returns an add-genesis-account cobra Command.
@ -33,11 +40,17 @@ func AddGenesisAccountCmd(
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]", Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
Short: "Add a genesis account to genesis.json", Short: "Add a genesis account to genesis.json",
Long: `Add a genesis account to genesis.json. The provided account must specify Long: strings.TrimSpace(
fmt.Sprintf(`Add a genesis account to genesis.json. The provided account must specify
the account address or key name and a list of initial coins. If a key name is given, the account address or key name and a list of initial coins. If a key name is given,
the address will be looked up in the local Keybase. The list of initial tokens must the address will be looked up in the local Keybase. The list of initial tokens must
contain valid denominations. Accounts may optionally be supplied with vesting parameters. contain valid denominations. Accounts may optionally be supplied with vesting parameters.
`, If the account is a periodic or validator vesting account, vesting periods must be suppleid
via a JSON file using the 'vesting-periods-file' flag or 'validator-vesting-file' flag,
respectively.
Example:
%s add-genesis-account <account-name> <amount> --vesting-amount <amount> --vesting-end-time <unix-timestamp> --vesting-start-time <unix-timestamp> --vesting-periods <path/to/vesting.json>`, version.ClientName),
),
Args: cobra.ExactArgs(2), Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error { RunE: func(_ *cobra.Command, args []string) error {
config := ctx.Config config := ctx.Config
@ -70,22 +83,43 @@ func AddGenesisAccountCmd(
if err != nil { if err != nil {
return fmt.Errorf("failed to parse vesting amount: %w", err) return fmt.Errorf("failed to parse vesting amount: %w", err)
} }
vestingPeriodsFile := viper.GetString(flagVestingPeriodsFile)
validatorVestingFile := viper.GetString(flagValidatorVestingFile)
if vestingPeriodsFile != "" && validatorVestingFile != "" {
return errors.New("Cannot specify both vesting-periods-file and validator-vesting-file")
}
// create concrete account type based on input parameters // create concrete account type based on input parameters
var genAccount authexported.GenesisAccount var genAccount authexported.GenesisAccount
baseAccount := auth.NewBaseAccount(addr, coins.Sort(), nil, 0, 0) baseAccount := auth.NewBaseAccount(addr, coins.Sort(), nil, 0, 0)
if !vestingAmt.IsZero() { if !vestingAmt.IsZero() {
baseVestingAccount := auth.NewBaseVestingAccount( baseVestingAccount := vesting.NewBaseVestingAccount(
baseAccount, vestingAmt.Sort(), sdk.Coins{}, sdk.Coins{}, vestingEnd, baseAccount, vestingAmt.Sort(), vestingEnd,
) )
switch { switch {
case vestingPeriodsFile != "":
vestingPeriodsJSON, err := ParsePeriodicVestingJSON(cdc, vestingPeriodsFile)
if err != nil {
return fmt.Errorf("failed to parse periodic vesting account json file: %w", err)
}
genAccount = vesting.NewPeriodicVestingAccountRaw(baseVestingAccount, vestingStart, vestingPeriodsJSON.Periods)
case validatorVestingFile != "":
validatorVestingJSON, err := ParseValidatorVestingJSON(cdc, validatorVestingFile)
if err != nil {
return fmt.Errorf("failed to parse validator vesting account json file: %w", err)
}
consAddr, err := sdk.ConsAddressFromHex(validatorVestingJSON.ValidatorAddress)
if err != nil {
return fmt.Errorf("failed to convert validator address to bytes: %w", err)
}
genAccount = validatorvesting.NewValidatorVestingAccountRaw(baseVestingAccount, vestingStart, validatorVestingJSON.Periods, consAddr, validatorVestingJSON.ReturnAddress, validatorVestingJSON.SigningThreshold)
case vestingStart != 0 && vestingEnd != 0: case vestingStart != 0 && vestingEnd != 0:
genAccount = auth.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart) genAccount = vesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart)
case vestingEnd != 0: case vestingEnd != 0:
genAccount = auth.NewDelayedVestingAccountRaw(baseVestingAccount) genAccount = vesting.NewDelayedVestingAccountRaw(baseVestingAccount)
default: default:
return errors.New("invalid vesting parameters; must supply start and end time or end time") return errors.New("invalid vesting parameters; must supply start and end time or end time")
@ -136,6 +170,52 @@ func AddGenesisAccountCmd(
cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts") cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts")
cmd.Flags().Uint64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts") cmd.Flags().Uint64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts")
cmd.Flags().Uint64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts") cmd.Flags().Uint64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts")
cmd.Flags().String(flagVestingPeriodsFile, "", "path to file where periodic vesting schedule is specified")
cmd.Flags().String(flagValidatorVestingFile, "", "path to file where validator vesting schedule is specified")
return cmd return cmd
} }
// ValidatorVestingJSON input json for validator-vesting-file flag
type ValidatorVestingJSON struct {
Periods vesting.Periods `json:"periods" yaml:"periods"`
ValidatorAddress string `json:"validator_address" yaml:"validator_address"`
SigningThreshold int64 `json:"signing_threshold" yaml:"signing_threshold"`
ReturnAddress sdk.AccAddress `json:"return_address,omitempty" yaml:"return_address,omitempty"`
}
// PeriodicVestingJSON input json for vesting-periods-file flag
type PeriodicVestingJSON struct {
Periods vesting.Periods `json:"periods" yaml:"periods"`
}
// ParsePeriodicVestingJSON reads and parses ParsePeriodicVestingJSON from the file
func ParsePeriodicVestingJSON(cdc *codec.Codec, inputFile string) (PeriodicVestingJSON, error) {
periodsInput := PeriodicVestingJSON{}
content, err := ioutil.ReadFile(inputFile)
if err != nil {
return periodsInput, err
}
if err := cdc.UnmarshalJSON(content, &periodsInput); err != nil {
return periodsInput, err
}
return periodsInput, nil
}
// ParseValidatorVestingJSON reads and parses ParseValidatorVestingJSON from the file
func ParseValidatorVestingJSON(cdc *codec.Codec, inputFile string) (ValidatorVestingJSON, error) {
validatorVestingInput := ValidatorVestingJSON{}
content, err := ioutil.ReadFile(inputFile)
if err != nil {
return validatorVestingInput, err
}
if err := cdc.UnmarshalJSON(content, &validatorVestingInput); err != nil {
return validatorVestingInput, err
}
return validatorVestingInput, nil
}

4
go.mod
View File

@ -9,9 +9,9 @@ require (
github.com/spf13/viper v1.4.0 github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
github.com/tendermint/go-amino v0.15.0 github.com/tendermint/go-amino v0.15.0
github.com/tendermint/tendermint v0.32.3 github.com/tendermint/tendermint v0.32.5
github.com/tendermint/tm-db v0.2.0 github.com/tendermint/tm-db v0.2.0
gopkg.in/yaml.v2 v2.2.2 gopkg.in/yaml.v2 v2.2.3
) )
replace github.com/cosmos/cosmos-sdk => ../../cosmos/cosmos-sdk replace github.com/cosmos/cosmos-sdk => ../../cosmos/cosmos-sdk

15
go.sum
View File

@ -6,6 +6,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/Workiva/go-datastructures v1.0.50/go.mod h1:Z+F2Rca0qCsVYDS8z7bAGm8f3UkzuWYS/oBZz5a7VVA=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@ -73,6 +74,8 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/go-kit/kit v0.6.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.6.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0 h1:wDJmvq38kDhkVxi50ni9ykkdUr1PKgqKOoi01fa0Mdk=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA= github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80nA=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
@ -143,8 +146,12 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/libp2p/go-buffer-pool v0.0.1 h1:9Rrn/H46cXjaA2HQ5Y8lyhOS1NhTkZ4yuEs2r3Eechg= github.com/libp2p/go-buffer-pool v0.0.1 h1:9Rrn/H46cXjaA2HQ5Y8lyhOS1NhTkZ4yuEs2r3Eechg=
github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ= github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ=
github.com/libp2p/go-buffer-pool v0.0.2 h1:QNK2iAFa8gjAe1SPz6mHSMuCcjs+X1wlHzeOSqcmlfs=
github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
@ -189,6 +196,8 @@ github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165/go.mod h1:bCqn
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI= github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4= github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa/go.mod h1:oJyF+mSPHbB5mVY2iO9KV3pTt/QbIkGaO8gQ2WrDbP4=
@ -237,6 +246,8 @@ github.com/tendermint/iavl v0.12.4/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJk
github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9mGBww8MPRNPNxnU= github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9mGBww8MPRNPNxnU=
github.com/tendermint/tendermint v0.32.3 h1:GEnWpGQ795h5oTFNbfBLsY0LW/CW2j6p6HtiYNfxsgg= github.com/tendermint/tendermint v0.32.3 h1:GEnWpGQ795h5oTFNbfBLsY0LW/CW2j6p6HtiYNfxsgg=
github.com/tendermint/tendermint v0.32.3/go.mod h1:ZK2c29jl1QRYznIRyRWRDsmm1yvtPzBRT00x4t1JToY= github.com/tendermint/tendermint v0.32.3/go.mod h1:ZK2c29jl1QRYznIRyRWRDsmm1yvtPzBRT00x4t1JToY=
github.com/tendermint/tendermint v0.32.5 h1:2hCLwuzfCKZxXSe/+iMEl+ChJWKJx6g/Wcvq3NMxVN4=
github.com/tendermint/tendermint v0.32.5/go.mod h1:D2+A3pNjY+Po72X0mTfaXorFhiVI8dh/Zg640FGyGtE=
github.com/tendermint/tm-db v0.1.1 h1:G3Xezy3sOk9+ekhjZ/kjArYIs1SmwV+1OUgNkj7RgV0= github.com/tendermint/tm-db v0.1.1 h1:G3Xezy3sOk9+ekhjZ/kjArYIs1SmwV+1OUgNkj7RgV0=
github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw= github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw=
github.com/tendermint/tm-db v0.2.0 h1:rJxgdqn6fIiVJZy4zLpY1qVlyD0TU6vhkT4kEf71TQQ= github.com/tendermint/tm-db v0.2.0 h1:rJxgdqn6fIiVJZy4zLpY1qVlyD0TU6vhkT4kEf71TQQ=
@ -310,6 +321,8 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
google.golang.org/grpc v1.22.0 h1:J0UbZOIrCAl+fpTOf8YLs4dJo8L/owV4LYVtAXQoPkw= google.golang.org/grpc v1.22.0 h1:J0UbZOIrCAl+fpTOf8YLs4dJo8L/owV4LYVtAXQoPkw=
google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.23.1 h1:q4XQuHFC6I28BKZpo6IYyb3mNO+l7lSOxRuYTCiDfXk=
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
@ -323,5 +336,7 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

View File

@ -11,7 +11,7 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, accountKeeper types.AccountKeep
accounts := accountKeeper.GetAllAccounts(ctx) accounts := accountKeeper.GetAllAccounts(ctx)
for _, a := range accounts { for _, a := range accounts {
vv, ok := a.(ValidatorVestingAccount) vv, ok := a.(*ValidatorVestingAccount)
if ok { if ok {
keeper.SetValidatorVestingAccountKey(ctx, vv.Address) keeper.SetValidatorVestingAccountKey(ctx, vv.Address)
} }

View File

@ -163,6 +163,7 @@ func (k Keeper) HandleVestingDebt(ctx sdk.Context, addr sdk.AccAddress, blockTim
panic(err) panic(err)
} }
} }
vv = k.GetAccountFromAuthKeeper(ctx, addr)
vv.DebtAfterFailedVesting = sdk.NewCoins() vv.DebtAfterFailedVesting = sdk.NewCoins()
k.ak.SetAccount(ctx, vv) k.ak.SetAccount(ctx, vv)
} else { } else {

View File

@ -203,7 +203,6 @@ func TestHandleVestingDebtNoDebt(t *testing.T) {
vva = keeper.GetAccountFromAuthKeeper(ctx, vva.Address) vva = keeper.GetAccountFromAuthKeeper(ctx, vva.Address)
require.Equal(t, origCoins, vva.DelegatedVesting) require.Equal(t, origCoins, vva.DelegatedVesting)
require.Nil(t, vva.DelegatedFree) require.Nil(t, vva.DelegatedFree)
require.Nil(t, vva.GetCoins())
} }

View File

@ -43,13 +43,11 @@ type ValidatorVestingAccount struct {
// NewValidatorVestingAccountRaw creates a new ValidatorVestingAccount object from BaseVestingAccount // NewValidatorVestingAccountRaw creates a new ValidatorVestingAccount object from BaseVestingAccount
func NewValidatorVestingAccountRaw(bva *vestingtypes.BaseVestingAccount, func NewValidatorVestingAccountRaw(bva *vestingtypes.BaseVestingAccount,
startTime int64, periods vestingtypes.Periods, validatorAddress sdk.ConsAddress, returnAddress sdk.AccAddress, signingThreshold int64) *ValidatorVestingAccount { startTime int64, periods vestingtypes.Periods, validatorAddress sdk.ConsAddress, returnAddress sdk.AccAddress, signingThreshold int64) *ValidatorVestingAccount {
cva := &vestingtypes.ContinuousVestingAccount{
StartTime: startTime,
BaseVestingAccount: bva,
}
pva := &vestingtypes.PeriodicVestingAccount{ pva := &vestingtypes.PeriodicVestingAccount{
ContinuousVestingAccount: cva, BaseVestingAccount: bva,
VestingPeriods: periods, StartTime: startTime,
VestingPeriods: periods,
} }
var vestingPeriodProgress = make([][]int, len(periods)) var vestingPeriodProgress = make([][]int, len(periods))
for i := range vestingPeriodProgress { for i := range vestingPeriodProgress {
@ -79,13 +77,10 @@ func NewValidatorVestingAccount(baseAcc *authtypes.BaseAccount, startTime int64,
OriginalVesting: baseAcc.Coins, OriginalVesting: baseAcc.Coins,
EndTime: endTime, EndTime: endTime,
} }
cva := &vestingtypes.ContinuousVestingAccount{
StartTime: startTime,
BaseVestingAccount: baseVestingAcc,
}
pva := &vestingtypes.PeriodicVestingAccount{ pva := &vestingtypes.PeriodicVestingAccount{
ContinuousVestingAccount: cva, BaseVestingAccount: baseVestingAcc,
VestingPeriods: periods, StartTime: startTime,
VestingPeriods: periods,
} }
var vestingPeriodProgress = make([][]int, len(periods)) var vestingPeriodProgress = make([][]int, len(periods))
for i := range vestingPeriodProgress { for i := range vestingPeriodProgress {

View File

@ -286,8 +286,6 @@ func TestTrackDelegationValidatorVestingAcc(t *testing.T) {
vva.TrackDelegation(now, origCoins) vva.TrackDelegation(now, origCoins)
require.Equal(t, origCoins, vva.DelegatedVesting) require.Equal(t, origCoins, vva.DelegatedVesting)
require.Nil(t, vva.DelegatedFree) require.Nil(t, vva.DelegatedFree)
require.Nil(t, vva.GetCoins())
require.Nil(t, vva.SpendableCoins(now))
// all periods pass successfully // all periods pass successfully
bacc.SetCoins(origCoins) bacc.SetCoins(origCoins)
@ -299,8 +297,6 @@ func TestTrackDelegationValidatorVestingAcc(t *testing.T) {
// require all delegated coins are free // require all delegated coins are free
require.Equal(t, origCoins, vva.DelegatedFree) require.Equal(t, origCoins, vva.DelegatedFree)
require.Nil(t, vva.DelegatedVesting) require.Nil(t, vva.DelegatedVesting)
require.Nil(t, vva.GetCoins())
require.Nil(t, vva.SpendableCoins(now.Add(48*time.Hour)))
// require the ability to delegate all vesting coins (50%) and all vested coins (50%) // require the ability to delegate all vesting coins (50%) and all vested coins (50%)
bacc.SetCoins(origCoins) bacc.SetCoins(origCoins)
@ -313,7 +309,6 @@ func TestTrackDelegationValidatorVestingAcc(t *testing.T) {
vva.TrackDelegation(now.Add(12*time.Hour), sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) vva.TrackDelegation(now.Add(12*time.Hour), sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)})
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, vva.DelegatedVesting) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, vva.DelegatedVesting)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, vva.DelegatedFree) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, vva.DelegatedFree)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000)}, vva.GetCoins())
// require no modifications when delegation amount is zero or not enough funds // require no modifications when delegation amount is zero or not enough funds
bacc.SetCoins(origCoins) bacc.SetCoins(origCoins)
@ -323,7 +318,6 @@ func TestTrackDelegationValidatorVestingAcc(t *testing.T) {
}) })
require.Nil(t, vva.DelegatedVesting) require.Nil(t, vva.DelegatedVesting)
require.Nil(t, vva.DelegatedFree) require.Nil(t, vva.DelegatedFree)
require.Equal(t, origCoins, vva.GetCoins())
} }
func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
@ -347,7 +341,6 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
vva.TrackUndelegation(origCoins) vva.TrackUndelegation(origCoins)
require.Nil(t, vva.DelegatedFree) require.Nil(t, vva.DelegatedFree)
require.Nil(t, vva.DelegatedVesting) require.Nil(t, vva.DelegatedVesting)
require.Equal(t, origCoins, vva.GetCoins())
// require the ability to delegate all coins after they have successfully vested // require the ability to delegate all coins after they have successfully vested
bacc.SetCoins(origCoins) bacc.SetCoins(origCoins)
@ -359,7 +352,6 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
vva.TrackUndelegation(origCoins) vva.TrackUndelegation(origCoins)
require.Nil(t, vva.DelegatedFree) require.Nil(t, vva.DelegatedFree)
require.Nil(t, vva.DelegatedVesting) require.Nil(t, vva.DelegatedVesting)
require.Equal(t, origCoins, vva.GetCoins())
// require panic and no modifications when attempting to undelegate zero coins // require panic and no modifications when attempting to undelegate zero coins
bacc.SetCoins(origCoins) bacc.SetCoins(origCoins)
@ -369,7 +361,6 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
}) })
require.Nil(t, vva.DelegatedFree) require.Nil(t, vva.DelegatedFree)
require.Nil(t, vva.DelegatedVesting) require.Nil(t, vva.DelegatedVesting)
require.Equal(t, origCoins, vva.GetCoins())
// successfuly vest period 1 and delegate to two validators // successfuly vest period 1 and delegate to two validators
vva = NewValidatorVestingAccount(&bacc, now.Unix(), periods, testConsAddr, nil, 90) vva = NewValidatorVestingAccount(&bacc, now.Unix(), periods, testConsAddr, nil, 90)
@ -381,13 +372,11 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) {
vva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}) vva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)})
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}, vva.DelegatedFree) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}, vva.DelegatedFree)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, vva.DelegatedVesting) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, vva.DelegatedVesting)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 25)}, vva.GetCoins())
// undelegate from the other validator that did not get slashed // undelegate from the other validator that did not get slashed
vva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) vva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)})
require.Nil(t, vva.DelegatedFree) require.Nil(t, vva.DelegatedFree)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}, vva.DelegatedVesting) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 25)}, vva.DelegatedVesting)
require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 75)}, vva.GetCoins())
} }
func TestGenesisAccountValidate(t *testing.T) { func TestGenesisAccountValidate(t *testing.T) {