-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
87 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
EXPLORER_DEBUG=ME_DEBUG | ||
APP_BASE_COIN=ME_BASE_COIN | ||
CENTRIFUGO_LINK=ME_EXTENDER_WS_ADDRESS | ||
CENTRIFUGO_BLOCK_CHANNEL=ME_EXTENDER_WS_CHANNEL_BLOCKS | ||
DB_HOST=ME_DB_HOST | ||
DB_PORT=ME_DB_PORT | ||
DB_POOL_SIZE=ME_DB_POOL_SIZE | ||
DB_NAME=ME_DB_NAME | ||
DB_USER=ME_DB_USER | ||
DB_PASSWORD=ME_DB_PASSWORD | ||
EXPLORER_PORT=ME_SRV_PORT | ||
MARKET_HOST=ME_MARKET_HOST | ||
EXPLORER_DEBUG= | ||
APP_BASE_COIN= | ||
CENTRIFUGO_LINK= | ||
CENTRIFUGO_BLOCK_CHANNEL= | ||
DB_HOST= | ||
DB_PORT= | ||
DB_POOL_SIZE= | ||
DB_NAME= | ||
DB_USER= | ||
DB_PASSWORD= | ||
EXPLORER_PORT= | ||
MARKET_HOST= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ws | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/MinterTeam/minter-explorer-api/v2/blocks" | ||
"github.com/MinterTeam/minter-explorer-api/v2/helpers" | ||
"github.com/centrifugal/centrifuge-go" | ||
) | ||
|
||
type BlocksChannelHandler struct { | ||
Subscribers []NewBlockSubscriber | ||
} | ||
|
||
type NewBlockSubscriber interface { | ||
OnNewBlock(blocks.Resource) | ||
} | ||
|
||
// Constructor for blocks event channel handler | ||
func NewBlocksChannelHandler() *BlocksChannelHandler { | ||
return &BlocksChannelHandler{ | ||
Subscribers: make([]NewBlockSubscriber, 0), | ||
} | ||
} | ||
|
||
// Add new subscriber for channel | ||
func (b *BlocksChannelHandler) AddSubscriber(sub NewBlockSubscriber) { | ||
b.Subscribers = append(b.Subscribers, sub) | ||
} | ||
|
||
// Handle new block from ws and publish him to all subscribers | ||
func (b *BlocksChannelHandler) OnPublish(sub *centrifuge.Subscription, e centrifuge.PublishEvent) { | ||
var block blocks.Resource | ||
err := json.Unmarshal(e.Data, &block) | ||
helpers.CheckErr(err) | ||
|
||
for _, sub := range b.Subscribers { | ||
go sub.OnNewBlock(block) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters