laconicd-deprecated/x/nameservice/genesis.go
Sai Kumar 95dde36e1c
Migrating the nameservice module from dxns (#2)
* WIP: migrating the nameservice module

* WIP: migrating the nameservice module from dxns to ethermint

* refactor: move the proto package version from `v1` to `v1beta1` for vulcanize modules

* refactor: added bond module dependency to nameserivce module

* feat: added auction module dependency to nameservice module

* refactor: refactored the nameservice module

* refactor: add human-readable attributes output to cli nameservice `list`

* fix: fix the sub names authority storing issue

* refactor: removed legacyCodec from nameservice

* fix: fix the responses for `authority-expiry` and `records-expiry` commands query result

* refactor: sort the imports in app

* refactor: removed json encoder and decoder
2021-10-06 11:35:51 +05:30

72 lines
2.0 KiB
Go

package nameservice
import (
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tharsis/ethermint/x/nameservice/keeper"
"github.com/tharsis/ethermint/x/nameservice/types"
)
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data types.GenesisState) []abci.ValidatorUpdate {
keeper.SetParams(ctx, data.Params)
for _, record := range data.Records {
keeper.PutRecord(ctx, record)
// Add to record expiry queue if expiry time is in the future.
if record.ExpiryTime.After(ctx.BlockTime()) {
keeper.InsertRecordExpiryQueue(ctx, record)
}
// Note: Bond genesis runs first, so bonds will already be present.
if record.BondId != "" {
keeper.AddBondToRecordIndexEntry(ctx, record.BondId, record.Id)
}
}
for _, authority := range data.Authorities {
//Only import authorities that are marked active.
if authority.Entry.Status == types.AuthorityActive {
keeper.SetNameAuthority(ctx, authority.Name, authority.Entry)
// Add authority name to expiry queue.
keeper.InsertAuthorityExpiryQueue(ctx, authority.Name, authority.Entry.ExpiryTime)
// Note: Bond genesis runs first, so bonds will already be present.
if authority.Entry.BondId != "" {
keeper.AddBondToAuthorityIndexEntry(ctx, authority.Entry.BondId, authority.Name)
}
}
}
for _, nameEntry := range data.Names {
keeper.SetNameRecord(ctx, nameEntry.Name, nameEntry.Entry.Latest.Id)
}
return []abci.ValidatorUpdate{}
}
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) types.GenesisState {
params := keeper.GetParams(ctx)
records := keeper.ListRecords(ctx)
authorities := keeper.ListNameAuthorityRecords(ctx)
var authorityEntries []types.AuthorityEntry
for name, record := range authorities {
authorityEntries = append(authorityEntries, types.AuthorityEntry{
Name: name,
Entry: &record,
})
}
names := keeper.ListNameRecords(ctx)
return types.GenesisState{
Params: params,
Records: records,
Authorities: authorityEntries,
Names: names,
}
}