Skip to content

Commit

Permalink
fix: fix action module and simapp
Browse files Browse the repository at this point in the history
  • Loading branch information
dadamu committed Jun 25, 2024
1 parent fefcdec commit 4494450
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 38 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ module github.com/forbole/callisto/v4

go 1.21

toolchain go1.22.3

require (
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.0
cosmossdk.io/x/evidence v0.1.1
Expand Down Expand Up @@ -41,7 +40,6 @@ require (
cosmossdk.io/core v0.11.0 // indirect
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/4meepo/tagalign v1.3.3 // indirect
Expand Down
28 changes: 16 additions & 12 deletions modules/actions/module.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package actions

import (
"fmt"

"github.com/cosmos/cosmos-sdk/codec"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/forbole/juno/v6/modules"
"github.com/forbole/juno/v6/node"
"github.com/forbole/juno/v6/node/builder"
nodeconfig "github.com/forbole/juno/v6/node/config"
"github.com/forbole/juno/v6/types/config"
"github.com/rs/zerolog/log"

modulestypes "github.com/forbole/callisto/v4/modules/types"
)
Expand All @@ -27,7 +30,7 @@ type Module struct {
sources *modulestypes.Sources
}

func NewModule(cfg config.Config, cdc codec.Codec) *Module {
func NewModule(cfg config.Config, cdc codec.Codec, sources *modulestypes.Sources) *Module {
bz, err := cfg.GetBytes()
if err != nil {
panic(err)
Expand All @@ -43,22 +46,23 @@ func NewModule(cfg config.Config, cdc codec.Codec) *Module {
nodeCfg = nodeconfig.NewConfig(nodeconfig.TypeRemote, actionsCfg.Node)
}

// Build the node
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
junoNode, err := builder.BuildNode(nodeCfg, txConfig, cdc)
if err != nil {
panic(err)
}
var node node.Node
if cfg.Node.Type == nodeconfig.TypeLocal {
log.Err(fmt.Errorf("local node is not supported for actions module"))
} else {
// Build the node
txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes)
junoNode, err := builder.BuildNode(nodeCfg, txConfig, cdc)
if err != nil {
panic(err)
}

// Build the sources
sources, err := modulestypes.BuildSources(nodeCfg, cdc)
if err != nil {
panic(err)
node = junoNode
}

return &Module{
cfg: actionsCfg,
node: junoNode,
node: node,
sources: sources,
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (r *Registrar) BuildModules(ctx registrar.Context) jmodules.Modules {
panic(err)
}

actionsModule := actions.NewModule(ctx.JunoConfig, r.cdc)
actionsModule := actions.NewModule(ctx.JunoConfig, r.cdc, sources)
authModule := auth.NewModule(r.parser, r.cdc, db)
bankModule := bank.NewModule(r.parser, sources.BankSource, r.cdc, db)
consensusModule := consensus.NewModule(db)
Expand Down
16 changes: 4 additions & 12 deletions modules/types/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
Expand All @@ -23,6 +24,7 @@ import (
localbanksource "github.com/forbole/callisto/v4/modules/bank/source/local"
remotebanksource "github.com/forbole/callisto/v4/modules/bank/source/remote"
distrsource "github.com/forbole/callisto/v4/modules/distribution/source"
localdistrsource "github.com/forbole/callisto/v4/modules/distribution/source/local"
remotedistrsource "github.com/forbole/callisto/v4/modules/distribution/source/remote"
govsource "github.com/forbole/callisto/v4/modules/gov/source"
localgovsource "github.com/forbole/callisto/v4/modules/gov/source/local"
Expand Down Expand Up @@ -69,8 +71,8 @@ func buildLocalSources(cfg *local.Details, cdc codec.Codec) (*Sources, error) {
app := simapp.NewSimApp(cdc)

sources := &Sources{
BankSource: localbanksource.NewSource(source, banktypes.QueryServer(app.BankKeeper)),
// DistrSource: localdistrsource.NewSource(source, distrtypes.QueryServer(app.DistrKeeper)),
BankSource: localbanksource.NewSource(source, banktypes.QueryServer(app.BankKeeper)),
DistrSource: localdistrsource.NewSource(source, distrkeeper.NewQuerier(app.DistrKeeper)),
GovSource: localgovsource.NewSource(source, govkeeper.NewQueryServer(&app.GovKeeper)),
MintSource: localmintsource.NewSource(source, mintkeeper.NewQueryServerImpl(app.MintKeeper)),
SlashingSource: localslashingsource.NewSource(source, slashingtypes.QueryServer(app.SlashingKeeper)),
Expand All @@ -83,16 +85,6 @@ func buildLocalSources(cfg *local.Details, cdc codec.Codec) (*Sources, error) {
return nil, err
}

err = source.MountTransientStores(app, "tkeys")
if err != nil {
return nil, err
}

err = source.MountMemoryStores(app, "memKeys")
if err != nil {
return nil, err
}

err = source.InitStores()
if err != nil {
return nil, err
Expand Down
46 changes: 36 additions & 10 deletions utils/simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package simapp
import (
storetypes "cosmossdk.io/store/types"

"cosmossdk.io/log"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -12,27 +13,37 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

var maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
}

type SimApp struct {
// keys to access the substores
keys map[string]*storetypes.KVStoreKey
tkeys map[string]*storetypes.TransientStoreKey
keys map[string]*storetypes.KVStoreKey

// keepers
BankKeeper bankkeeper.BaseKeeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
}

Expand All @@ -44,26 +55,41 @@ func NewSimApp(cdc codec.Codec) *SimApp {
minttypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
distrtypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)

app := &SimApp{
keys: keys,
tkeys: tkeys,
keys: keys,
}

accountKeeper := authkeeper.NewAccountKeeper(cdc, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, nil, authcodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String())
accountKeeper := authkeeper.NewAccountKeeper(cdc, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.GetConfig().GetBech32AccountAddrPrefix(), authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.BankKeeper = bankkeeper.NewBaseKeeper(
cdc,
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
accountKeeper,
nil,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
log.NewNopLogger(),
)
app.DistrKeeper = distrkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), accountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.StakingKeeper = stakingkeeper.NewKeeper(
cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr),
cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
)

app.MintKeeper = mintkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, accountKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.SlashingKeeper = slashingkeeper.NewKeeper(
cdc, nil, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.StakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.SlashingKeeper.Hooks()),
govConfig := govtypes.DefaultConfig()
govKeeper := govkeeper.NewKeeper(
cdc, runtime.NewKVStoreService(keys[govtypes.StoreKey]), accountKeeper, app.BankKeeper,
app.StakingKeeper, app.DistrKeeper, nil, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.GovKeeper = *govKeeper

return app
}

0 comments on commit 4494450

Please sign in to comment.