/
genesis.go
54 lines (45 loc) · 1.59 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/peggyjv/sommelier/v7/x/pubsub/types"
)
// InitGenesis initializes the module's state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k Keeper, gs types.GenesisState) {
k.SetParams(ctx, gs.Params)
for _, publisher := range gs.Publishers {
k.SetPublisher(ctx, *publisher)
}
for _, subscriber := range gs.Subscribers {
addr, err := sdk.AccAddressFromBech32(subscriber.Address)
if err != nil {
panic(fmt.Errorf("invalid subscriber address in genesis state: %s", err.Error()))
}
k.SetSubscriber(ctx, addr, *subscriber)
}
for _, publisherIntent := range gs.PublisherIntents {
k.SetPublisherIntent(ctx, *publisherIntent)
}
for _, subscriberIntent := range gs.SubscriberIntents {
addr, err := sdk.AccAddressFromBech32(subscriberIntent.SubscriberAddress)
if err != nil {
panic(fmt.Errorf("invalid subscriber address in genesis state: %s", err.Error()))
}
k.SetSubscriberIntent(ctx, addr, *subscriberIntent)
}
for _, defaultSubscription := range gs.DefaultSubscriptions {
k.SetDefaultSubscription(ctx, *defaultSubscription)
}
}
// ExportGenesis returns the module's exported genesis.
func ExportGenesis(ctx sdk.Context, k Keeper) types.GenesisState {
return types.GenesisState{
Params: k.GetParams(ctx),
Publishers: k.GetPublishers(ctx),
Subscribers: k.GetSubscribers(ctx),
PublisherIntents: k.GetPublisherIntents(ctx),
SubscriberIntents: k.GetSubscriberIntents(ctx),
DefaultSubscriptions: k.GetDefaultSubscriptions(ctx),
}
}