feat(service): wire EventBus into BlockchainService
BlockchainService now has an EventBus that emits: - EventBlockNew on every synced block (with hash) - EventAlias when a block contains an alias registration Chain's BlockCallback → EventBus.Emit → subscribers. Ready for core/stream SSEBroker integration. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
8a4a9c0cb7
commit
cd2f4ff092
1 changed files with 10 additions and 0 deletions
10
service.go
10
service.go
|
|
@ -36,6 +36,7 @@ type BlockchainService struct {
|
|||
chain *chain.Chain
|
||||
store *store.Store
|
||||
daemon *daemon.Server
|
||||
events *EventBus
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
|
|
@ -76,6 +77,15 @@ func (s *BlockchainService) start() core.Result {
|
|||
}
|
||||
s.store = st
|
||||
s.chain = chain.New(st)
|
||||
s.events = NewEventBus()
|
||||
|
||||
// Wire block events
|
||||
s.chain.SetBlockCallback(func(height uint64, hash string, aliasName string) {
|
||||
s.events.Emit(Event{Type: EventBlockNew, Height: height, Data: hash})
|
||||
if aliasName != "" {
|
||||
s.events.Emit(Event{Type: EventAlias, Height: height, Data: aliasName})
|
||||
}
|
||||
})
|
||||
|
||||
cfg, forks := resolveConfig(s.opts.Testnet, &s.opts.Seed)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue