mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-24 14:35:47 +00:00
* used this to pass tests * made the MockMqttMonitor a global object so that it can be easily mocked * removed MockMqttMonitor from the app/keeper initialization * adjusted test cases to register "active machines" to the mqttmonitor Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
35 lines
829 B
Go
35 lines
829 B
Go
package monitor
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/planetmint/planetmint-go/config"
|
|
"github.com/syndtr/goleveldb/leveldb"
|
|
)
|
|
|
|
type MQTTMonitorClientI interface {
|
|
AddParticipant(address string, lastSeenTS int64) (err error)
|
|
SelectPoPParticipantsOutOfActiveActors() (challenger string, challengee string, err error)
|
|
SetContext(ctx sdk.Context)
|
|
Start() (err error)
|
|
}
|
|
|
|
var MqttMonitorInstance MQTTMonitorClientI
|
|
|
|
func LazyMqttMonitorLoader(homeDir string) {
|
|
if MqttMonitorInstance != nil {
|
|
return
|
|
}
|
|
if homeDir == "" {
|
|
homeDir = "./"
|
|
}
|
|
aciveActorsDB, err := leveldb.OpenFile(homeDir+"activeActors.db", nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
MqttMonitorInstance = NewMqttMonitorService(aciveActorsDB, *config.GetConfig())
|
|
err = MqttMonitorInstance.Start()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|