2022-04-05 07:09:27 +00:00
|
|
|
package nameservice
|
|
|
|
|
|
|
|
import (
|
2022-04-08 07:33:58 +00:00
|
|
|
"time"
|
|
|
|
|
2022-09-07 06:36:11 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/nameservice/keeper"
|
|
|
|
"github.com/cerc-io/laconicd/x/nameservice/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/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.
|
2022-04-08 07:33:58 +00:00
|
|
|
expiryTime, err := time.Parse(time.RFC3339, record.ExpiryTime)
|
2022-04-14 03:56:12 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if expiryTime.After(ctx.BlockTime()) {
|
|
|
|
keeper.InsertRecordExpiryQueue(ctx, record)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2022-10-17 06:47:56 +00:00
|
|
|
// Only import authorities that are marked active.
|
2022-04-05 07:09:27 +00:00
|
|
|
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)
|
2022-10-17 07:15:01 +00:00
|
|
|
authorityEntries := []types.AuthorityEntry{}
|
2022-10-18 06:44:29 +00:00
|
|
|
// #nosec G705
|
2022-04-05 07:09:27 +00:00
|
|
|
for name, record := range authorities {
|
|
|
|
authorityEntries = append(authorityEntries, types.AuthorityEntry{
|
|
|
|
Name: name,
|
2022-10-17 11:03:31 +00:00
|
|
|
Entry: &record, //nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
names := keeper.ListNameRecords(ctx)
|
|
|
|
|
|
|
|
return types.GenesisState{
|
|
|
|
Params: params,
|
|
|
|
Records: records,
|
|
|
|
Authorities: authorityEntries,
|
|
|
|
Names: names,
|
|
|
|
}
|
|
|
|
}
|