Skip to content

Commit

Permalink
Problem (fix crypto-org-chain#269 crypto-org-chain#200): denom conver…
Browse files Browse the repository at this point in the history
…sion in cosmos-sdk is not used

Solution:
- update to cosmos-sdk master
- use sdk.ParseCoinsNormalized
- cleanup unused code
- re-organize code to minimize diff between app/app.go and
  simapp/app.go, cmd/chain-maind/app/app.go and simapp/simd/cmd/root.go
- disable line length linter(lll), to keep it consistent with cosmos-sdk
- one can still use the derivation of mkShell to work with remote shell
  • Loading branch information
yihuang committed Nov 19, 2020
1 parent 07c2477 commit 1c8c5d3
Show file tree
Hide file tree
Showing 36 changed files with 231 additions and 2,722 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ linters:
- govet
- ineffassign
- interfacer
- lll
- misspell
# - maligned
- nakedret
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ make-proto:
###############################################################################
# nix installation: https://nixos.org/download.html
nix-integration-test: check-network make-proto
nix run -f ./. ci-env -c run-integration-tests
nix run -f ./. run-integration-tests -c run-integration-tests

nix-build-%: check-network check-os
@if [ -e ~/.nix/remote-build-env ]; then \
Expand Down
87 changes: 38 additions & 49 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package app

import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"

Expand All @@ -18,8 +18,10 @@ import (
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand All @@ -35,8 +37,6 @@ import (
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/core"

"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -58,6 +58,7 @@ import (
transfer "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer"
ibctransferkeeper "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/keeper"
ibctransfertypes "github.com/cosmos/cosmos-sdk/x/ibc/applications/transfer/types"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/core"
ibcclient "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client"
porttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/05-port/types"
ibchost "github.com/cosmos/cosmos-sdk/x/ibc/core/24-host"
Expand All @@ -81,46 +82,36 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
appparams "github.com/crypto-com/chain-main/app/params"
chainbank "github.com/crypto-com/chain-main/x/bank"
"github.com/crypto-com/chain-main/x/chainmain"
chainmainkeeper "github.com/crypto-com/chain-main/x/chainmain/keeper"
chainmaintypes "github.com/crypto-com/chain-main/x/chainmain/types"
chaingov "github.com/crypto-com/chain-main/x/gov"
chainstaking "github.com/crypto-com/chain-main/x/staking"
supply "github.com/crypto-com/chain-main/x/supply"
supplykeeper "github.com/crypto-com/chain-main/x/supply/keeper"
supplytypes "github.com/crypto-com/chain-main/x/supply/types"

appconfig "github.com/crypto-com/chain-main/config"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)

const appName = "chain-maind"

var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome = func(appName string) string {
return os.ExpandEnv("$HOME/.chain-maind")
}

// DefaultCoinParser converts coin denominations
DefaultCoinParser = NewSDKCoinParser(appconfig.BaseCoinUnit, appconfig.CoinToBaseUnitMuls)
DefaultNodeHome string

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
genutil.AppModuleBasic{},
chainbank.NewAppModuleBasic(DefaultCoinParser),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
chainstaking.NewAppModuleBasic(DefaultCoinParser),
staking.AppModuleBasic{},
mint.AppModuleBasic{},
distr.AppModuleBasic{},
chaingov.NewAppModuleBasic(
DefaultCoinParser,
paramsclient.ProposalHandler, distrclient.ProposalHandler,
upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
),
params.AppModuleBasic{},
slashing.AppModuleBasic{},
Expand All @@ -130,7 +121,7 @@ var (
transfer.AppModuleBasic{},
vesting.AppModuleBasic{},
supply.AppModuleBasic{},
chainmain.NewAppModuleBasicWithCoinParser(DefaultCoinParser),
chainmain.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -160,10 +151,7 @@ var (
// capabilities aren't needed for testing.
type ChainApp struct {
*baseapp.BaseApp

appName string

cdc *codec.LegacyAmino
legacyAmino *codec.LegacyAmino
appCodec codec.Marshaler
interfaceRegistry types.InterfaceRegistry

Expand Down Expand Up @@ -202,16 +190,25 @@ type ChainApp struct {
sm *module.SimulationManager
}

func init() {
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}

DefaultNodeHome = filepath.Join(userHomeDir, fmt.Sprintf(".%s", appName))
}

// New returns a reference to an initialized Chain.
func New(
appName string, logger log.Logger, db dbm.DB,
traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest bool, skipUpgradeHeights map[int64]bool,
homePath string, invCheckPeriod uint, encodingConfig appparams.EncodingConfig,
baseAppOptions ...func(*baseapp.BaseApp),
appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp),
) *ChainApp {

// TODO: Remove cdc in favor of appCodec once all modules are migrated.
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
Expand All @@ -231,8 +228,7 @@ func New(

app := &ChainApp{
BaseApp: bApp,
appName: appName,
cdc: cdc,
legacyAmino: legacyAmino,
appCodec: appCodec,
interfaceRegistry: interfaceRegistry,
invCheckPeriod: invCheckPeriod,
Expand All @@ -241,26 +237,23 @@ func New(
memKeys: memKeys,
}

app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

// set the BaseApp's parameter store
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))

// add capability keeper and ScopeToModule for ibc module
app.CapabilityKeeper = capabilitykeeper.NewKeeper(
appCodec, keys[capabilitytypes.StoreKey],
memKeys[capabilitytypes.MemStoreKey],
)
app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms,
)
app.BankKeeper = chainmainkeeper.NewBankKeeperWrapper(bankkeeper.NewBaseKeeper(
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedAddrs(),
))
)
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)
Expand Down Expand Up @@ -291,7 +284,7 @@ func New(

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, scopedIBCKeeper,
)

// register the proposal types
Expand All @@ -317,7 +310,6 @@ func New(
// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
// ibcRouter.AddRoute(ibcmock.ModuleName, mockModule)
app.IBCKeeper.SetRouter(ibcRouter)

// create evidence keeper with router
Expand All @@ -329,7 +321,6 @@ func New(

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.

app.mm = module.NewManager(
genutil.NewAppModule(
app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx,
Expand All @@ -349,7 +340,7 @@ func New(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
chainmain.NewAppModule(appCodec, app.chainmainKeeper, DefaultCoinParser),
chainmain.NewAppModule(appCodec, app.chainmainKeeper),
supply.NewAppModule(appCodec, app.SupplyKeeper),
)

Expand All @@ -369,8 +360,7 @@ func New(
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
app.mm.SetOrderInitGenesis(
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName,
stakingtypes.ModuleName,
capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName,
slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName,
ibchost.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, ibctransfertypes.ModuleName,
chainmaintypes.ModuleName, supplytypes.ModuleName,
Expand Down Expand Up @@ -494,7 +484,7 @@ func (app *ChainApp) BlockedAddrs() map[string]bool {
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *ChainApp) LegacyAmino() *codec.LegacyAmino {
return app.cdc
return app.legacyAmino
}

// AppCodec returns Chain's app codec.
Expand Down Expand Up @@ -590,9 +580,7 @@ func GetMaccPerms() map[string][]string {
}

// initParamsKeeper init params keeper and its subspaces
func initParamsKeeper(
appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey,
) paramskeeper.Keeper {
func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)

paramsKeeper.Subspace(authtypes.ModuleName)
Expand All @@ -603,6 +591,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(slashingtypes.ModuleName)
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibchost.ModuleName)

return paramsKeeper
}
86 changes: 0 additions & 86 deletions app/coins.go

This file was deleted.

Loading

0 comments on commit 1c8c5d3

Please sign in to comment.