Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update x/genutil to match module spec #4757

Merged
merged 8 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ tags:
- abci
- rest
- cli
- modules
1 change: 1 addition & 0 deletions .pending/improvements/modules/_4751-update-genutil
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4751 update `x/genutils` to match module spec
2 changes: 1 addition & 1 deletion x/genaccounts/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package genaccounts

import (
types "github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
"github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion x/genaccounts/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
types "github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
"github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
)

// InitGenesis initializes accounts and deliver genesis transactions
Expand Down
2 changes: 1 addition & 1 deletion x/genaccounts/internal/types/codec.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genaccounts
package types

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down
2 changes: 1 addition & 1 deletion x/genaccounts/internal/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genaccounts
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
2 changes: 1 addition & 1 deletion x/genaccounts/internal/types/genesis_account.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genaccounts
package types

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion x/genaccounts/internal/types/genesis_account_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genaccounts
package types

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion x/genaccounts/internal/types/genesis_state.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genaccounts
package types

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion x/genaccounts/internal/types/genesis_state_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genaccounts
package types

import (
"testing"
Expand Down
2 changes: 1 addition & 1 deletion x/genaccounts/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
types "github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
"github.com/cosmos/cosmos-sdk/x/genaccounts/internal/types"
)

var (
Expand Down
36 changes: 36 additions & 0 deletions x/genutil/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/x/genutil/types
package genutil

import (
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)

const (
ModuleName = types.ModuleName
)

var (
// functions aliases
NewGenesisState = types.NewGenesisState
NewGenesisStateFromStdTx = types.NewGenesisStateFromStdTx
NewInitConfig = types.NewInitConfig
GetGenesisStateFromAppState = types.GetGenesisStateFromAppState
SetGenesisStateInAppState = types.SetGenesisStateInAppState
GenesisStateFromGenDoc = types.GenesisStateFromGenDoc
GenesisStateFromGenFile = types.GenesisStateFromGenFile
ValidateGenesis = types.ValidateGenesis

// variable aliases
ModuleCdc = types.ModuleCdc
)

type (
GenesisState = types.GenesisState
AppMap = types.AppMap
MigrationCallback = types.MigrationCallback
MigrationMap = types.MigrationMap
InitConfig = types.InitConfig
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
)
3 changes: 2 additions & 1 deletion x/genutil/client/cli/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genutil"
types "github.com/cosmos/cosmos-sdk/x/genutil/types"
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
)

const flagGenTxDir = "gentx-dir"

// CollectGenTxsCmd - return the cobra command to collect genesis transactions
func CollectGenTxsCmd(ctx *server.Context, cdc *codec.Codec,
genAccIterator genutil.GenesisAccountsIterator, defaultNodeHome string) *cobra.Command {
genAccIterator types.GenesisAccountsIterator, defaultNodeHome string) *cobra.Command {

cmd := &cobra.Command{
Use: "collect-gentxs",
Expand Down
3 changes: 2 additions & 1 deletion x/genutil/client/cli/gentx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/genutil"
types "github.com/cosmos/cosmos-sdk/x/genutil/types"
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
)

// helpers for message building gen-tx command
Expand All @@ -41,7 +42,7 @@ type StakingMsgBuildingHelpers interface {
// GenTxCmd builds the application's gentx command.
// nolint: errcheck
func GenTxCmd(ctx *server.Context, cdc *codec.Codec, mbm module.BasicManager, smbh StakingMsgBuildingHelpers,
genAccIterator genutil.GenesisAccountsIterator, defaultNodeHome, defaultCLIHome string) *cobra.Command {
genAccIterator types.GenesisAccountsIterator, defaultNodeHome, defaultCLIHome string) *cobra.Command {

ipDefault, _ := server.ExternalIP()
fsCreateValidator, flagNodeID, flagPubKey, flagAmount, defaultsDesc := smbh.CreateValidatorMsgHelpers(ipDefault)
Expand Down
22 changes: 0 additions & 22 deletions x/genutil/codec.go

This file was deleted.

62 changes: 12 additions & 50 deletions x/genutil/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,20 @@ import (
"strings"

cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/staking"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// common config options for init
type InitConfig struct {
ChainID string
GenTxsDir string
Name string
NodeID string
ValPubKey crypto.PubKey
}

// NewInitConfig creates a new InitConfig object
func NewInitConfig(chainID, genTxsDir, name, nodeID string, valPubKey crypto.PubKey) InitConfig {
return InitConfig{
ChainID: chainID,
GenTxsDir: genTxsDir,
Name: name,
NodeID: nodeID,
ValPubKey: valPubKey,
}
}

// get the genesis app state from the config
// GenAppStateFromConfig gets the genesis app state from the config
func GenAppStateFromConfig(cdc *codec.Codec, config *cfg.Config,
initCfg InitConfig, genDoc tmtypes.GenesisDoc,
genAccIterator GenesisAccountsIterator,
genAccIterator types.GenesisAccountsIterator,
) (appState json.RawMessage, err error) {

// process genesis transactions, else create default genesis.json
Expand Down Expand Up @@ -83,30 +64,11 @@ func GenAppStateFromConfig(cdc *codec.Codec, config *cfg.Config,
return appState, err
}

// Set the genesis transactions int the app genesis state
func SetGenTxsInAppGenesisState(cdc *codec.Codec, appGenesisState map[string]json.RawMessage,
genTxs []auth.StdTx) (map[string]json.RawMessage, error) {

genesisState := GetGenesisStateFromAppState(cdc, appGenesisState)
// convert all the GenTxs to JSON
var genTxsBz []json.RawMessage
for _, genTx := range genTxs {
txBz, err := cdc.MarshalJSON(genTx)
if err != nil {
return appGenesisState, err
}
genTxsBz = append(genTxsBz, txBz)
}

genesisState.GenTxs = genTxsBz
return SetGenesisStateInAppState(cdc, appGenesisState, genesisState), nil
}

// CollectStdTxs processes and validates application's genesis StdTxs and returns
// the list of appGenTxs, and persistent peers required to generate genesis.json.
func CollectStdTxs(cdc *codec.Codec, moniker, genTxsDir string,
genDoc tmtypes.GenesisDoc, genAccIterator GenesisAccountsIterator,
) (appGenTxs []auth.StdTx, persistentPeers string, err error) {
genDoc tmtypes.GenesisDoc, genAccIterator types.GenesisAccountsIterator,
) (appGenTxs []authtypes.StdTx, persistentPeers string, err error) {

var fos []os.FileInfo
fos, err = ioutil.ReadDir(genTxsDir)
Expand All @@ -121,9 +83,9 @@ func CollectStdTxs(cdc *codec.Codec, moniker, genTxsDir string,
return appGenTxs, persistentPeers, err
}

addrMap := make(map[string]auth.Account)
addrMap := make(map[string]authexported.Account)
genAccIterator.IterateGenesisAccounts(cdc, appState,
func(acc auth.Account) (stop bool) {
func(acc authexported.Account) (stop bool) {
addrMap[acc.GetAddress().String()] = acc
return false
},
Expand All @@ -143,7 +105,7 @@ func CollectStdTxs(cdc *codec.Codec, moniker, genTxsDir string,
if jsonRawTx, err = ioutil.ReadFile(filename); err != nil {
return appGenTxs, persistentPeers, err
}
var genStdTx auth.StdTx
var genStdTx authtypes.StdTx
if err = cdc.UnmarshalJSON(jsonRawTx, &genStdTx); err != nil {
return appGenTxs, persistentPeers, err
}
Expand All @@ -166,7 +128,7 @@ func CollectStdTxs(cdc *codec.Codec, moniker, genTxsDir string,
}

// TODO abstract out staking message validation back to staking
msg := msgs[0].(staking.MsgCreateValidator)
msg := msgs[0].(stakingtypes.MsgCreateValidator)
// validate delegator and validator addresses and funds against the accounts in the state
delAddr := msg.DelegatorAddress.String()
valAddr := sdk.AccAddress(msg.ValidatorAddress).String()
Expand Down
32 changes: 0 additions & 32 deletions x/genutil/expected.go

This file was deleted.

5 changes: 3 additions & 2 deletions x/genutil/init.go → x/genutil/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)

// initialize accounts and deliver genesis transactions
func InitGenesis(ctx sdk.Context, cdc *codec.Codec, stakingKeeper StakingKeeper,
// InitGenesis - initialize accounts and deliver genesis transactions
func InitGenesis(ctx sdk.Context, cdc *codec.Codec, stakingKeeper types.StakingKeeper,
deliverTx deliverTxfn, genesisState GenesisState) []abci.ValidatorUpdate {

var validators []abci.ValidatorUpdate
Expand Down
47 changes: 0 additions & 47 deletions x/genutil/genesis_state_test.go

This file was deleted.

Loading