35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package supply
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
autypes "github.com/cosmos/cosmos-sdk/x/auth"
|
|
"github.com/cosmos/cosmos-sdk/x/supply/internal/types"
|
|
)
|
|
|
|
// InitGenesis sets supply information for genesis.
|
|
func InitGenesis(ctx sdk.Context, keeper Keeper, ak types.AccountKeeper, data GenesisState) {
|
|
// manually set the total supply based on accounts if not provided
|
|
if data.Supply.Total.Empty() {
|
|
var totalSupply sdk.Coins
|
|
ak.IterateAccounts(ctx,
|
|
func(acc autypes.Account) (stop bool) {
|
|
totalSupply = totalSupply.Add(acc.GetCoins())
|
|
return false
|
|
},
|
|
)
|
|
data.Supply.Total = totalSupply
|
|
}
|
|
keeper.SetSupply(ctx, data.Supply)
|
|
}
|
|
|
|
// ExportGenesis returns a GenesisState for a given context and keeper.
|
|
func ExportGenesis(ctx sdk.Context, keeper Keeper) GenesisState {
|
|
return NewGenesisState(keeper.GetSupply(ctx))
|
|
}
|
|
|
|
// ValidateGenesis performs basic validation of supply genesis data returning an
|
|
// error for any failed validation criteria.
|
|
func ValidateGenesis(data GenesisState) error {
|
|
return data.Supply.ValidateBasic()
|
|
}
|