Skip to content

Commit

Permalink
feat: upgrade to v0.52.0 beta (#163)
Browse files Browse the repository at this point in the history
* feat: upgrade to v0.52.0-beta.1

* disclaimer
  • Loading branch information
julienrbrt authored Oct 3, 2024
1 parent 4628e03 commit 480981a
Show file tree
Hide file tree
Showing 14 changed files with 485 additions and 708 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
go-version: "1.21"
go-version: "1.23"
check-latest: true
env:
GOOS: ${{ matrix.targetos }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"
check-latest: true
cache: true
cache-dependency-path: go.sum
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ It uses the least modules possible and is intended to be used as a starting poin

`Minid` uses the **latest** version of the [Cosmos-SDK](https://github.com/cosmos/cosmos-sdk).

> This is an example module for the v0.52.x Cosmos SDK. Looking for the v0.50.x example? Check the [v0.50.x](https://github.com/cosmosregistry/chain-minimal/tree/v0.50.x) branch.
## How to use

In addition to learn how to build a chain thanks to `minid`, you can as well directly run `minid`.
Expand Down
54 changes: 18 additions & 36 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ import (
_ "embed"
"io"

dbm "github.com/cosmos/cosmos-db"

"cosmossdk.io/core/appconfig"
"cosmossdk.io/core/registry"
corestore "cosmossdk.io/core/store"
"cosmossdk.io/depinject"
"cosmossdk.io/depinject/appconfig"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"

_ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects
clienthelpers "cosmossdk.io/client/v2/helpers"
_ "cosmossdk.io/x/accounts" // import for side-effects
_ "cosmossdk.io/x/bank" // import for side-effects
_ "cosmossdk.io/x/consensus" // import for side-effects
_ "cosmossdk.io/x/distribution" // import for side-effects
distrkeeper "cosmossdk.io/x/distribution/keeper"
_ "cosmossdk.io/x/mint" // import for side-effects
_ "cosmossdk.io/x/staking" // import for side-effects
stakingkeeper "cosmossdk.io/x/staking/keeper"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -22,23 +32,8 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/types/module"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
consensuskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
_ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/mint" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
)

// DefaultNodeHome default home directories for the application daemon
Expand All @@ -57,17 +52,14 @@ var (
// capabilities aren't needed for testing.
type MiniApp struct {
*runtime.App
legacyAmino *codec.LegacyAmino
legacyAmino registry.AminoRegistrar
appCodec codec.Codec
txConfig client.TxConfig
interfaceRegistry codectypes.InterfaceRegistry

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
DistrKeeper distrkeeper.Keeper
ConsensusParamsKeeper consensuskeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
DistrKeeper distrkeeper.Keeper

// simulation manager
sm *module.SimulationManager
Expand All @@ -86,20 +78,13 @@ func init() {
func AppConfig() depinject.Config {
return depinject.Configs(
appconfig.LoadYAML(AppConfigYAML),
depinject.Supply(
&appv1alpha1.Config{}, // hack until https://github.com/cosmos/cosmos-sdk/pull/21042
// supply custom module basics
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
},
),
)
}

// NewMiniApp returns a reference to an initialized MiniApp.
func NewMiniApp(
logger log.Logger,
db dbm.DB,
db corestore.KVStoreWithBatch,
traceStore io.Writer,
loadLatest bool,
appOpts servertypes.AppOptions,
Expand All @@ -123,11 +108,8 @@ func NewMiniApp(
&app.legacyAmino,
&app.txConfig,
&app.interfaceRegistry,
&app.AccountKeeper,
&app.BankKeeper,
&app.StakingKeeper,
&app.DistrKeeper,
&app.ConsensusParamsKeeper,
); err != nil {
return nil, err
}
Expand All @@ -154,7 +136,7 @@ func NewMiniApp(
}

// LegacyAmino returns MiniApp's amino codec.
func (app *MiniApp) LegacyAmino() *codec.LegacyAmino {
func (app *MiniApp) LegacyAmino() registry.AminoRegistrar {
return app.legacyAmino
}

Expand Down
8 changes: 7 additions & 1 deletion app/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ modules:
end_blockers: [staking]
# NOTE: The genutils module must occur after staking so that pools are properly initialized with tokens from genesis accounts.
# NOTE: The genutils module must also occur after auth so that it can access the params from auth.
init_genesis: [auth, bank, distribution, staking, genutil]
init_genesis:
[consensus, accounts, auth, bank, distribution, staking, genutil]
override_store_keys:
- module_name: auth
kv_store_key: acc
- module_name: accounts
kv_store_key: _accounts
- name: accounts
config:
"@type": cosmos.accounts.module.v1.Module
- name: auth
config:
"@type": cosmos.auth.module.v1.Module
Expand Down
42 changes: 2 additions & 40 deletions app/params/config.go → app/config.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
package params
package app

import (
"cosmossdk.io/errors"
"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const (
CoinUnit = "mini"

DefaultBondDenom = CoinUnit

// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address.
Bech32PrefixAccAddr = "mini"
)
Expand All @@ -32,38 +23,9 @@ var (
)

func init() {
SetAddressPrefixes()
RegisterDenoms()
}

func RegisterDenoms() {
err := sdk.RegisterDenom(CoinUnit, math.LegacyOneDec())
if err != nil {
panic(err)
}
}

func SetAddressPrefixes() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)

// This is copied from the cosmos sdk v0.43.0-beta1
// source: https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-beta1/types/address.go#L141
config.SetAddressVerifier(func(bytes []byte) error {
if len(bytes) == 0 {
return errors.Wrap(sdkerrors.ErrUnknownAddress, "addresses cannot be empty")
}

if len(bytes) > address.MaxAddrLen {
return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address max length is %d, got %d", address.MaxAddrLen, len(bytes))
}

if len(bytes) != 20 && len(bytes) != 32 {
return errors.Wrapf(sdkerrors.ErrUnknownAddress, "address length must be 20 or 32 bytes, got %d", len(bytes))
}

return nil
})
config.Seal()
}
Loading

0 comments on commit 480981a

Please sign in to comment.