@@ -4,8 +4,10 @@ import (
4
4
"context"
5
5
"fmt"
6
6
7
+ "cosmossdk.io/core/event"
7
8
"cosmossdk.io/core/header"
8
9
"cosmossdk.io/core/store"
10
+ "cosmossdk.io/core/transaction"
9
11
)
10
12
11
13
var (
@@ -105,6 +107,18 @@ func (g *GenesisKVStoreService) OpenKVStore(ctx context.Context) store.KVStore {
105
107
return readonlyKVStore {state }
106
108
}
107
109
110
+ type readonlyKVStore struct {
111
+ store.Reader
112
+ }
113
+
114
+ func (r readonlyKVStore ) Set (key , value []byte ) error {
115
+ panic ("tried to call Set on a readonly store" )
116
+ }
117
+
118
+ func (r readonlyKVStore ) Delete (key []byte ) error {
119
+ panic ("tried to call Delete on a readonly store" )
120
+ }
121
+
108
122
// GenesisHeaderService is a header.Service implementation that is used during
109
123
// genesis initialization. It wraps an inner execution context header.Service.
110
124
type GenesisHeaderService struct {
@@ -123,20 +137,46 @@ func (g *GenesisHeaderService) HeaderInfo(ctx context.Context) header.Info {
123
137
124
138
// NewGenesisHeaderService creates a new GenesisHeaderService.
125
139
// - executionService is the header.Service to use when the genesis context is not active.
126
- func NewGenesisHeaderService (executionService header.Service ) * GenesisHeaderService {
140
+ func NewGenesisHeaderService (executionService header.Service ) header. Service {
127
141
return & GenesisHeaderService {
128
142
executionService : executionService ,
129
143
}
130
144
}
131
145
132
- type readonlyKVStore struct {
133
- store.Reader
146
+ // GenesisEventService is an event.Service implementation that is used during
147
+ // genesis initialization. It wraps an inner execution context event.Service.
148
+ // During genesis initialization, it returns a blackHoleEventManager into which
149
+ // events enter and disappear completely.
150
+ type GenesisEventService struct {
151
+ executionService event.Service
134
152
}
135
153
136
- func (r readonlyKVStore ) Set (key , value []byte ) error {
137
- panic ("tried to call Set on a readonly store" )
154
+ // NewGenesisEventService creates a new GenesisEventService.
155
+ // - executionService is the event.Service to use when the genesis context is not active.
156
+ func NewGenesisEventService (executionService event.Service ) event.Service {
157
+ return & GenesisEventService {
158
+ executionService : executionService ,
159
+ }
138
160
}
139
161
140
- func (r readonlyKVStore ) Delete (key []byte ) error {
141
- panic ("tried to call Delete on a readonly store" )
162
+ func (g * GenesisEventService ) EventManager (ctx context.Context ) event.Manager {
163
+ v := ctx .Value (genesisContextKey )
164
+ if v == nil {
165
+ return g .executionService .EventManager (ctx )
166
+ }
167
+ return & blackHoleEventManager {}
168
+ }
169
+
170
+ var _ event.Manager = (* blackHoleEventManager )(nil )
171
+
172
+ // blackHoleEventManager is an event.Manager that does nothing.
173
+ // It is used during genesis initialization, genesis events are not emitted.
174
+ type blackHoleEventManager struct {}
175
+
176
+ func (b * blackHoleEventManager ) Emit (_ transaction.Msg ) error {
177
+ return nil
178
+ }
179
+
180
+ func (b * blackHoleEventManager ) EmitKV (_ string , _ ... event.Attribute ) error {
181
+ return nil
142
182
}
0 commit comments