Skip to content

Commit

Permalink
Merge branch 'cudos-dev' into cudos-master
Browse files Browse the repository at this point in the history
  • Loading branch information
kstoykov committed Jan 17, 2022
2 parents 1427143 + b164546 commit 83f85e0
Show file tree
Hide file tree
Showing 88 changed files with 3,493 additions and 1,254 deletions.
79 changes: 44 additions & 35 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

appparams "cudos.org/cudos-node/app/params"
"cudos.org/cudos-node/x/admin"
adminkeeper "cudos.org/cudos-node/x/admin/keeper"
admintypes "cudos.org/cudos-node/x/admin/types"
appparams "github.com/CudoVentures/cudos-node/app/params"
"github.com/CudoVentures/cudos-node/x/admin"
adminkeeper "github.com/CudoVentures/cudos-node/x/admin/keeper"
admintypes "github.com/CudoVentures/cudos-node/x/admin/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
"github.com/cosmos/cosmos-sdk/client/rpc"
Expand Down Expand Up @@ -84,19 +84,20 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/modules/core"
ibcclient "github.com/cosmos/ibc-go/modules/core/02-client"
ibcclientclient "github.com/cosmos/ibc-go/modules/core/02-client/client"
ibcclienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types"
porttypes "github.com/cosmos/ibc-go/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/modules/core/keeper"
tmjson "github.com/tendermint/tendermint/libs/json"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

// this line is used by starport scaffolding # stargate/app/moduleImport
"cudos.org/cudos-node/x/cudoMint"
cudoMintkeeper "cudos.org/cudos-node/x/cudoMint/keeper"
cudoMinttypes "cudos.org/cudos-node/x/cudoMint/types"
nftmodule "cudos.org/cudos-node/x/nft"
nftmodulekeeper "cudos.org/cudos-node/x/nft/keeper"
nftmoduletypes "cudos.org/cudos-node/x/nft/types"
"github.com/CudoVentures/cudos-node/x/cudoMint"
cudoMintkeeper "github.com/CudoVentures/cudos-node/x/cudoMint/keeper"
cudoMinttypes "github.com/CudoVentures/cudos-node/x/cudoMint/types"
nftmodule "github.com/CudoVentures/cudos-node/x/nft"
nftmodulekeeper "github.com/CudoVentures/cudos-node/x/nft/keeper"
nftmoduletypes "github.com/CudoVentures/cudos-node/x/nft/types"

"github.com/althea-net/cosmos-gravity-bridge/module/x/gravity"
gravitykeeper "github.com/althea-net/cosmos-gravity-bridge/module/x/gravity/keeper"
Expand All @@ -114,7 +115,7 @@ var (
ProposalsEnabled = "false"
// If set to non-empty string it must be comma-separated list of values that are all a subset
// of "EnableAllProposals" (takes precedence over ProposalsEnabled)
// https://cudos.org/cudos-node/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
// https://github.com/CudoVentures/cudos-node/blob/02a54d33ff2c064f3539ae12d75d027d9c665f05/x/wasm/internal/types/proposal.go#L28-L34
EnableSpecificProposals = ""
)

Expand Down Expand Up @@ -152,6 +153,7 @@ var (
distr.AppModuleBasic{},
gov.NewAppModuleBasic(
paramsclient.ProposalHandler, distrclient.ProposalHandler, upgradeclient.ProposalHandler, upgradeclient.CancelProposalHandler,
ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler,
),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
Expand Down Expand Up @@ -260,7 +262,8 @@ type App struct {
NftKeeper nftmodulekeeper.Keeper

// the module manager
mm *module.Manager
mm *module.Manager
configurator module.Configurator
}

// New returns a reference to an initialized Gaia.
Expand Down Expand Up @@ -318,6 +321,7 @@ func New(
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedWasmKeeper := app.CapabilityKeeper.ScopeToModule(wasm.ModuleName)
app.CapabilityKeeper.Seal()

// add keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -345,6 +349,8 @@ func New(
)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)

app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
Expand All @@ -366,10 +372,20 @@ func New(
if err != nil {
panic("error while reading wasm config: " + err.Error())
}

app.NftKeeper = *nftmodulekeeper.NewKeeper(
appCodec,
keys[nftmoduletypes.StoreKey],
keys[nftmoduletypes.MemStoreKey],
)

supportedFeatures := "staking,stargate"
customEncoderOptions := GetCustomMsgEncodersOptions()
customQueryOptions := GetCustomMsgQueryOptions(app.NftKeeper)
wasmOpts := append(customEncoderOptions, customQueryOptions...)

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "staking,stargate"
var wasmOpts []wasm.Option
app.wasmKeeper = wasm.NewKeeper(
appCodec,
keys[wasm.StoreKey],
Expand Down Expand Up @@ -402,7 +418,7 @@ func New(
AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)).
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibchost.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

app.adminKeeper = *adminkeeper.NewKeeper(
appCodec, keys[admintypes.StoreKey], keys[admintypes.MemStoreKey],
Expand Down Expand Up @@ -434,11 +450,6 @@ func New(
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

app.NftKeeper = *nftmodulekeeper.NewKeeper(
appCodec,
keys[nftmoduletypes.StoreKey],
keys[nftmoduletypes.MemStoreKey],
)
nftModule := nftmodule.NewAppModule(appCodec, app.NftKeeper, app.AccountKeeper, app.BankKeeper)

// this line is used by starport scaffolding # stargate/app/keeperDefinition
Expand Down Expand Up @@ -505,8 +516,15 @@ func New(
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
app.mm.SetOrderBeginBlockers(
upgradetypes.ModuleName, minttypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName,
evidencetypes.ModuleName, stakingtypes.ModuleName, ibchost.ModuleName, cudoMinttypes.ModuleName,
capabilitytypes.ModuleName,
upgradetypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
stakingtypes.ModuleName,
ibchost.ModuleName,
cudoMinttypes.ModuleName,
gravitytypes.ModuleName,
)

Expand All @@ -517,6 +535,8 @@ func New(
// NOTE: Capability module must occur first so that it can initialize any capabilities
// so that other modules that want to create or claim capabilities afterwards in InitChain
// can do so safely.
// NOTE: Gravity module must occur before genutils so that the pool are propertly initiallized
// before gextxs
app.mm.SetOrderInitGenesis(
capabilitytypes.ModuleName,
authtypes.ModuleName,
Expand All @@ -528,13 +548,13 @@ func New(
minttypes.ModuleName,
crisistypes.ModuleName,
ibchost.ModuleName,
gravitytypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
wasm.ModuleName,
admintypes.ModuleName,
cudoMinttypes.ModuleName,
gravitytypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
nftmoduletypes.ModuleName,
)
Expand Down Expand Up @@ -572,17 +592,6 @@ func New(
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
}

// Initialize and seal the capability keeper so all persistent capabilities
// are loaded in-memory and prevent any further modules from creating scoped
// sub-keepers.
// This must be done during creation of baseapp rather than in InitChain so
// that in-memory capabilities get regenerated on app restart.
// Note that since this reads from the store, we can only perform it when
// `loadLatest` is set to true.
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
app.CapabilityKeeper.InitMemStore(ctx)
app.CapabilityKeeper.Seal()
}

app.ScopedIBCKeeper = scopedIBCKeeper
Expand Down
2 changes: 1 addition & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app

import (
"cudos.org/cudos-node/app/params"
"github.com/CudoVentures/cudos-node/app/params"
"github.com/cosmos/cosmos-sdk/std"
)

Expand Down
31 changes: 31 additions & 0 deletions app/wasm_custom_bindings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package app

import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmKeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
nftCustomBindings "github.com/CudoVentures/cudos-node/x/nft/custom-bindings"
nftKeeper "github.com/CudoVentures/cudos-node/x/nft/keeper"
)

func GetCustomMsgEncodersOptions() []wasmKeeper.Option {
nftEncodingOptions := wasmKeeper.WithMessageEncoders(nftEncoders())
return []wasm.Option{nftEncodingOptions}
}

func GetCustomMsgQueryOptions(keeper nftKeeper.Keeper) []wasmKeeper.Option {
nftQueryOptions := wasmKeeper.WithQueryPlugins(nftQueryPlugins(keeper))
return []wasm.Option{nftQueryOptions}
}

func nftEncoders() *wasmKeeper.MessageEncoders {
return &wasmKeeper.MessageEncoders{
Custom: nftCustomBindings.EncodeNftMessage(),
}
}

// nftQueryPlugins needs to be registered in test setup to handle custom query callbacks
func nftQueryPlugins(keeper nftKeeper.Keeper) *wasmKeeper.QueryPlugins {
return &wasmKeeper.QueryPlugins{
Custom: nftCustomBindings.PerformCustomNftQuery(keeper),
}
}
43 changes: 38 additions & 5 deletions cmd/cudos-noded/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
"errors"
"fmt"
"io"
"os"
"path/filepath"

"github.com/CosmWasm/wasmd/x/wasm"

"cudos.org/cudos-node/app/params"
"github.com/CudoVentures/cudos-node/app/params"
"github.com/cosmos/cosmos-sdk/snapshots"

"github.com/spf13/cast"
Expand All @@ -18,7 +19,7 @@ import (
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

"cudos.org/cudos-node/app"
"github.com/CudoVentures/cudos-node/app"
gravitycmd "github.com/althea-net/cosmos-gravity-bridge/module/cmd/gravity/cmd"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -36,10 +37,13 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
stakingFlags "github.com/cosmos/cosmos-sdk/x/staking/client/cli"
)

var ChainID string

var minSelfDelegationValueLowerBoundString string = "2000000000000000000000000"

// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
Expand All @@ -56,22 +60,51 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {

rootCmd := &cobra.Command{
Use: app.Name + "d",
Short: "Stargate CosmosHub App",
Short: "Cudos Node App",
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
return err
}

flagMinSelfDelegation := cmd.Flags().Lookup(stakingFlags.FlagMinSelfDelegation)
if flagMinSelfDelegation != nil {
minSelfDelegationValueString, err := cmd.Flags().GetString(stakingFlags.FlagMinSelfDelegation)
if err != nil {
return fmt.Errorf("flag %s is not a valid number", stakingFlags.FlagMinSelfDelegation)
}
minSelfDelegationValueBigInt, ok := sdk.NewIntFromString(minSelfDelegationValueString)
if !ok {
return fmt.Errorf("flag %s is not a valid number", stakingFlags.FlagMinSelfDelegation)
}
minSelfDelegationValueLowerBoundBigInt, _ := sdk.NewIntFromString(minSelfDelegationValueLowerBoundString)
if minSelfDelegationValueBigInt.LT(minSelfDelegationValueLowerBoundBigInt) {
return fmt.Errorf("flag %s must be >= 2 000 000 000 000 000 000 000 000", stakingFlags.FlagMinSelfDelegation)
}
}

return server.InterceptConfigsPreRunHandler(cmd, "", nil)
},
}

initRootCmd(rootCmd, encodingConfig)
overwriteFlagDefaults(rootCmd, map[string]string{
flags.FlagChainID: ChainID,
flags.FlagKeyringBackend: "test",
flags.FlagChainID: ChainID,
flags.FlagKeyringBackend: "os",
stakingFlags.FlagMinSelfDelegation: minSelfDelegationValueLowerBoundString,
})

// flag := rootCmd.Flags().Lookup("long")
// fmt.Println(flag)

// rootCmd.PersistentPreRunE()

// value, err := rootCmd.Flags().GetString(flags.FlagKeyringBackend)
// if err != nil {
// panic(err)
// } else {
// fmt.Printf("Debug %s\n", value)
// }

return rootCmd, encodingConfig
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/cudos-noded/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"os"

"cudos.org/cudos-node/app"
"cudos.org/cudos-node/cmd/cudos-noded/cmd"
"github.com/CudoVentures/cudos-node/app"
"github.com/CudoVentures/cudos-node/cmd/cudos-noded/cmd"
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down
Loading

0 comments on commit 83f85e0

Please sign in to comment.