forked from cerc-io/laconicd
Setup and integrate bond module into the chain (#2)
* Add common message types and update proto gen script * Update proto gen script to generate pulsar proto code * Upgrade direct deps * Populate params and genesis files * Setup keeper files * Setup module files with depinject and autocli * Add placeholder keeper methods * Integrate bond module into the chain
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// InitGenesis initializes the module state from a genesis state.
|
||||
func (k *Keeper) InitGenesis(ctx sdk.Context, data *bond.GenesisState) error {
|
||||
k.SetParams(ctx, data.Params)
|
||||
|
||||
for _, bond := range data.Bonds {
|
||||
k.SaveBond(ctx, bond)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExportGenesis exports the module state to a genesis state.
|
||||
func (k *Keeper) ExportGenesis(ctx sdk.Context) (*bond.GenesisState, error) {
|
||||
params := k.GetParams(ctx)
|
||||
bonds := k.ListBonds(ctx)
|
||||
|
||||
return &bond.GenesisState{Params: params, Bonds: bonds}, nil
|
||||
}
|
||||
+51
-9
@@ -1,23 +1,65 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/address"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
"git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// TODO: Add genesis.go?
|
||||
|
||||
type Keeper struct {
|
||||
cdc codec.BinaryCodec
|
||||
addressCodec address.Codec
|
||||
// Store keys
|
||||
storeKey storetypes.StoreKey
|
||||
|
||||
// TODO: state management
|
||||
// Codecs
|
||||
cdc codec.BinaryCodec
|
||||
|
||||
// TODO: Later: add bond usage keepers
|
||||
// External keepers
|
||||
// accountKeeper auth.AccountKeeper
|
||||
// bankKeeper bank.Keeper
|
||||
|
||||
// Track bond usage in other cosmos-sdk modules (more like a usage tracker).
|
||||
// usageKeepers []types.BondUsageKeeper
|
||||
|
||||
// paramSubspace paramtypes.Subspace
|
||||
}
|
||||
|
||||
// NewKeeper creates a new Keeper instance
|
||||
// TODO: Implement
|
||||
func NewKeeper(cdc codec.BinaryCodec, addressCodec address.Codec) Keeper {
|
||||
return Keeper{}
|
||||
// NewKeeper creates new instances of the bond Keeper
|
||||
func NewKeeper(
|
||||
cdc codec.BinaryCodec,
|
||||
// accountKeeper auth.AccountKeeper,
|
||||
// bankKeeper bank.Keeper,
|
||||
// usageKeepers []types.BondUsageKeeper,
|
||||
storeKey storetypes.StoreKey,
|
||||
// ps paramtypes.Subspace,
|
||||
) Keeper {
|
||||
// set KeyTable if it has not already been set
|
||||
// if !ps.HasKeyTable() {
|
||||
// ps = ps.WithKeyTable(types.ParamKeyTable())
|
||||
// }
|
||||
|
||||
return Keeper{
|
||||
// accountKeeper: accountKeeper,
|
||||
// bankKeeper: bankKeeper,
|
||||
storeKey: storeKey,
|
||||
cdc: cdc,
|
||||
// usageKeepers: usageKeepers,
|
||||
// paramSubspace: ps,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add keeper methods
|
||||
|
||||
// SaveBond - saves a bond to the store.
|
||||
func (k Keeper) SaveBond(ctx sdk.Context, bond *bond.Bond) {
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
// ListBonds - get all bonds.
|
||||
func (k Keeper) ListBonds(ctx sdk.Context) []*bond.Bond {
|
||||
// TODO: Implement
|
||||
var bonds []*bond.Bond
|
||||
return bonds
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// GetMaxBondAmount max bond amount
|
||||
func (k Keeper) GetMaxBondAmount(ctx sdk.Context) (res sdk.Coin) {
|
||||
// TODO: Implement
|
||||
return sdk.Coin{}
|
||||
}
|
||||
|
||||
// GetParams - Get all parameter as types.Params.
|
||||
func (k Keeper) GetParams(ctx sdk.Context) (params bond.Params) {
|
||||
getMaxBondAmount := k.GetMaxBondAmount(ctx)
|
||||
return bond.Params{MaxBondAmount: getMaxBondAmount}
|
||||
}
|
||||
|
||||
// SetParams - set the params.
|
||||
func (k Keeper) SetParams(ctx sdk.Context, params bond.Params) {
|
||||
// TODO: Implement
|
||||
}
|
||||
Reference in New Issue
Block a user