Skip to content

Commit

Permalink
Merge PR cosmos#5600: Migrate x/staking to Protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Feb 6, 2020
1 parent ae9af02 commit ca483bf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
16 changes: 4 additions & 12 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
Expand Down Expand Up @@ -79,16 +78,6 @@ var (
}
)

// MakeCodec - custom tx codec
func MakeCodec() *codec.Codec {
var cdc = codec.New()
ModuleBasics.RegisterCodec(cdc)
vesting.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
return cdc
}

// Verify app interface at compile time
var _ App = (*SimApp)(nil)

Expand Down Expand Up @@ -135,6 +124,9 @@ func NewSimApp(
invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp),
) *SimApp {

appCodec := NewAppCodec()

// TODO: Remove cdc in favor of appCodec once all modules are migrated.
cdc := MakeCodec()

bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...)
Expand Down Expand Up @@ -180,7 +172,7 @@ func NewSimApp(
app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
)
stakingKeeper := staking.NewKeeper(
app.cdc, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
appCodec.Staking, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
)
app.MintKeeper = mint.NewKeeper(
app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
Expand Down
40 changes: 40 additions & 0 deletions codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package simapp

import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
"github.com/cosmos/cosmos-sdk/x/staking"
)

// AppCodec defines the application-level codec. This codec contains all the
// required module-specific codecs that are to be provided upon initialization.
type AppCodec struct {
amino *codec.Codec

Staking *staking.Codec
}

func NewAppCodec() *AppCodec {
amino := MakeCodec()

return &AppCodec{
amino: amino,
Staking: staking.NewCodec(amino),
}
}

// MakeCodec creates and returns a reference to an Amino codec that has all the
// necessary types and interfaces registered. This codec is provided to all the
// modules the application depends on.
//
// NOTE: This codec will be deprecated in favor of AppCodec once all modules are
// migrated.
func MakeCodec() *codec.Codec {
var cdc = codec.New()
ModuleBasics.RegisterCodec(cdc)
vesting.RegisterCodec(cdc)
sdk.RegisterCodec(cdc)
codec.RegisterCrypto(cdc)
return cdc
}

0 comments on commit ca483bf

Please sign in to comment.