-
Notifications
You must be signed in to change notification settings - Fork 29
/
genesis.go
37 lines (32 loc) · 892 Bytes
/
genesis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package bonds
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ixofoundation/ixo-blockchain/x/bonds/internal/types"
)
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) {
// Initialise bonds
for _, b := range data.Bonds {
keeper.SetBond(ctx, b.BondDid, b)
keeper.SetBondDid(ctx, b.Token, b.BondDid)
}
// Initialise batches
for _, b := range data.Batches {
keeper.SetBatch(ctx, b.BondDid, b)
}
}
func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
// Export bonds and batches
var bonds []types.Bond
var batches []types.Batch
iterator := k.GetBondIterator(ctx)
for ; iterator.Valid(); iterator.Next() {
bond := k.MustGetBondByKey(ctx, iterator.Key())
batch := k.MustGetBatch(ctx, bond.BondDid)
bonds = append(bonds, bond)
batches = append(batches, batch)
}
return GenesisState{
Bonds: bonds,
Batches: batches,
}
}