Skip to content

Commit

Permalink
Update cosmos to 0.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau committed Dec 4, 2018
1 parent d73a152 commit d4ebba2
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 111 deletions.
9 changes: 5 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ func NewCyberdApp(
app.cdc, dbKeys.stake,
dbKeys.tStake, app.coinKeeper,
app.paramsKeeper.Subspace(stake.DefaultParamspace),
app.RegisterCodespace(stake.DefaultCodespace),
stake.DefaultCodespace,
)
app.slashingKeeper = slashing.NewKeeper(
app.cdc,
dbKeys.slashing,
&stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace),
app.RegisterCodespace(slashing.DefaultCodespace),
slashing.DefaultCodespace,
)
app.memStorage = &InMemoryStorage{}

Expand All @@ -164,7 +164,7 @@ func NewCyberdApp(
app.SetAnteHandler(auth.NewAnteHandler(app.accountKeeper, app.feeCollectionKeeper))

// mount the multistore and load the latest state
app.MountStoresIAVL(dbKeys.main, dbKeys.acc, dbKeys.cidIndex, dbKeys.links, dbKeys.rank, dbKeys.stake,
app.MountStores(dbKeys.main, dbKeys.acc, dbKeys.cidIndex, dbKeys.links, dbKeys.rank, dbKeys.stake,
dbKeys.slashing, dbKeys.params)
app.MountStoresTransient(dbKeys.tParams, dbKeys.tStake)
err := app.LoadLatestVersion(dbKeys.main)
Expand Down Expand Up @@ -294,9 +294,10 @@ func (app *CyberdApp) EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock) abci.R
app.memStorage.UpdateRank(newRank)
app.mainStorage.StoreAppHash(ctx, hash[:])

validatorUpdates := stake.EndBlocker(ctx, app.stakeKeeper)
validatorUpdates, tags := stake.EndBlocker(ctx, app.stakeKeeper)
return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Tags: tags,
}
}

Expand Down
30 changes: 7 additions & 23 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/cybercongress/cyberd/app/coin"
"github.com/pkg/errors"
tmtypes "github.com/tendermint/tendermint/types"
"io/ioutil"
Expand All @@ -18,13 +18,6 @@ import (
"strings"
)

var (
// bonded tokens given to genesis validators/accounts
freeFermionVal = int64(100)
freeFermionsAcc = sdk.NewInt(150)
bondDenom = "CBD"
)

// State to Unmarshal
type GenesisState struct {
Accounts []GenesisAccount `json:"accounts"`
Expand All @@ -48,8 +41,8 @@ type GenesisAccount struct {
Name string `json:"name"`
Address sdk.AccAddress `json:"address"`
Coins sdk.Coins `json:"coins"`
Sequence int64 `json:"sequence_number"`
AccountNumber int64 `json:"account_number"`
Sequence uint64 `json:"sequence_number"`
AccountNumber uint64 `json:"account_number"`
}

func NewGenesisAccount(acc *auth.BaseAccount) GenesisAccount {
Expand Down Expand Up @@ -80,14 +73,6 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) {
}
}

// get app init parameters for server init command
func CyberdAppInit() server.AppInit {

return server.AppInit{
AppGenState: CyberdAppGenStateJSON,
}
}

// Create the core parameters for genesis initialization for cyberd
// note that the pubkey input is this machines pubkey
func CyberdAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []json.RawMessage) (
Expand Down Expand Up @@ -115,16 +100,15 @@ func CyberdAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []
}
if _, ok := msgs[0].(stake.MsgCreateValidator); !ok {
return genesisState, fmt.Errorf(
"Genesis transaction %v does not contain a MsgCreateValidator", i)
"genesis transaction %v does not contain a MsgCreateValidator", i)
}
}

for _, acc := range genesisState.Accounts {
// create the genesis account, give'm few steaks and a buncha token with there name
for _, coin := range acc.Coins {
if coin.Denom == bondDenom {
for _, c := range acc.Coins {
if c.Denom == coin.CBD {
stakeData.Pool.LooseTokens = stakeData.Pool.LooseTokens.
Add(sdk.NewDecFromInt(coin.Amount)) // increase the supply
Add(sdk.NewDecFromInt(c.Amount)) // increase the supply
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func NewLinksHandler(cis CidIndexStorage, ls LinksStorage, imms *InMemoryStorage
link := cbd.NewLink(fromCidNumber, toCidNumber, accNumber)

if ls.IsLinkExist(ctx, link) {
return sdk.Result{Code: cbd.LinkAlreadyExistsCode()}
return sdk.Result{Code: cbd.CodeLinkAlreadyExist, Codespace: cbd.CodespaceCbd}
}

if !ctx.IsCheckTx() {
imms.AddLink(link)
}

return sdk.Result{Code: sdk.ABCICodeOK}
return sdk.Result{Code: cbd.CodeOK, Codespace: cbd.CodespaceCbd}
}
}

Expand Down
10 changes: 1 addition & 9 deletions app/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,5 @@ func (app *CyberdApp) Account(address sdk.AccAddress) auth.Account {
if acc != nil {
return acc
}

// no acc in chain, assume new one, so balance 0 and seq 0
// acc number -1 is for addresses not in chain
return &auth.BaseAccount{
Address: address,
Sequence: 0,
Coins: make(sdk.Coins, 0),
AccountNumber: -1,
}
return nil
}
13 changes: 3 additions & 10 deletions app/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
CodeCidNotFound sdk.CodeType = 3

// Code space
CodespaceCBD sdk.CodespaceType = 42
CodespaceCbd sdk.CodespaceType = "cyberd"
)

func codeToDefaultMsg(code sdk.CodeType) string {
Expand All @@ -29,22 +29,15 @@ func codeToDefaultMsg(code sdk.CodeType) string {
}
}

//----------------------------------------
// Code constructors

func LinkAlreadyExistsCode() sdk.ABCICodeType {
return sdk.ToABCICode(CodespaceCBD, CodeLinkAlreadyExist)
}

//----------------------------------------
// Error constructors

func ErrInvalidCid() sdk.Error {
return newError(CodespaceCBD, CodeInvalidCid)
return newError(CodespaceCbd, CodeInvalidCid)
}

func ErrCidNotFound() sdk.Error {
return newError(CodespaceCBD, CodeCidNotFound)
return newError(CodespaceCbd, CodeCidNotFound)
}

func newError(codespace sdk.CodespaceType, code sdk.CodeType) sdk.Error {
Expand Down
6 changes: 3 additions & 3 deletions claim/context/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type ClaimContext struct {
CliContext cli.CLIContext
ipClaims map[string]int
Mtx *sync.Mutex
Sequence *int64
AccountNumber int64
Sequence *uint64
AccountNumber uint64
}

func NewClaimContext() (ClaimContext, error) {
Expand All @@ -35,7 +35,7 @@ func NewClaimContext() (ClaimContext, error) {

cliCtx := newCLIContext(name, chainId, viper.GetString(common.FlagNode)).
WithCodec(cdc).
WithAccountDecoder(app.GetAccountDecoder(cdc))
WithAccountDecoder(cdc)

address, err := types.AccAddressFromBech32(viper.GetString(common.FlagAddress))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cyberd/init/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ following delegation and commission default parameters:
w.Close()

prepareFlagsForTxSign()
signCmd := authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc))
signCmd := authcmd.GetSignCommand(cdc)
if w, err = prepareOutputFile(config.RootDir, nodeID); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cyberd/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func displayInfo(cdc *codec.Codec, info printInfo) error {

// get cmd to initialize all files for tendermint and application
// nolint
func InitCmd(ctx *server.Context, cdc *codec.Codec, appInit server.AppInit) *cobra.Command {
func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Initialize private validator, p2p, genesis, and application configuration files",
Expand Down
3 changes: 1 addition & 2 deletions cyberd/init/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ var (
const nodeDirPerm = 0755

// get cmd to initialize all files for tendermint testnet and application
func TestnetFilesCmd(ctx *server.Context, cdc *codec.Codec,
appInit server.AppInit) *cobra.Command {
func TestnetFilesCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {

cmd := &cobra.Command{
Use: "testnet",
Expand Down
14 changes: 8 additions & 6 deletions cyberd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ func main() {
app.SetPrefix()
ctx := server.NewDefaultContext()

cobra.EnableCommandSorting = false
rootCmd := &cobra.Command{
Use: "cyberd",
Short: "Cyberd Daemon (server)",
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}

appInit := app.CyberdAppInit()

rootCmd.AddCommand(initCyberd.InitCmd(ctx, cdc, appInit))
rootCmd.AddCommand(initCyberd.InitCmd(ctx, cdc))
rootCmd.AddCommand(initCyberd.GenerateAccountCmd())
rootCmd.AddCommand(initCyberd.CollectGenTxsCmd(ctx, cdc))
rootCmd.AddCommand(initCyberd.TestnetFilesCmd(ctx, cdc, server.AppInit{}))
rootCmd.AddCommand(initCyberd.TestnetFilesCmd(ctx, cdc))
rootCmd.AddCommand(initCyberd.GenTxCmd(ctx, cdc))
rootCmd.AddCommand(initCyberd.AddGenesisAccountCmd(ctx, cdc))
server.AddCommands(ctx, cdc, rootCmd, appInit, newApp, exportAppStateAndTMValidators)
server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)

for _, c := range rootCmd.Commands() {
if c.Use == "start" {
Expand Down Expand Up @@ -74,7 +73,10 @@ func newApp(logger log.Logger, db dbm.DB, storeTracer io.Writer) abci.Applicatio
return cyberdApp
}

func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, storeTracer io.Writer) (json.RawMessage, []tmtypes.GenesisValidator, error) {
func exportAppStateAndTMValidators(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool,
) (json.RawMessage, []tmtypes.GenesisValidator, error) {

capp := app.NewCyberdApp(logger, db, rank.CPU)
return capp.ExportAppStateAndValidators()
}
3 changes: 1 addition & 2 deletions cyberdcli/commands/linktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"
cbd "github.com/cybercongress/cyberd/app/types"
. "github.com/cybercongress/cyberd/cyberdcli/util"
Expand All @@ -28,7 +27,7 @@ func LinkTxCmd(cdc *codec.Codec) *cobra.Command {
txCtx := authtxb.NewTxBuilderFromCLI().WithCodec(cdc)
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(authcmd.GetAccountDecoder(cdc))
WithAccountDecoder(cdc)

if err := cliCtx.EnsureAccountExists(); err != nil {
return err
Expand Down
Loading

0 comments on commit d4ebba2

Please sign in to comment.