refactor: necessary changes due to moving fleet config to the desktop app

This commit doesn't remove fleet configuration completely but it's more like
a step before the final one.
This commit is contained in:
Sale Djenic 2021-11-23 14:33:29 +01:00 committed by saledjenic
parent e1ba033633
commit 1f07ce9a8f
4 changed files with 23 additions and 25 deletions

View File

@ -62,7 +62,7 @@ proc generateAlias*(self: AccountModel, publicKey: string): string =
proc generateIdenticon*(self: AccountModel, publicKey: string): string =
result = generateIdenticon(publicKey)
proc changeNetwork*(self: AccountModel, fleetConfig: FleetConfig, network: string) =
proc changeNetwork*(self: AccountModel, network: string) =
var statusGoResult = status_settings.setNetwork(network)
if statusGoResult.error != "":
error "Error saving updated node config", msg=statusGoResult.error

View File

@ -1,4 +1,4 @@
import json, json_serialization
import json, json_serialization, strutils
import statusgo_backend/settings as statusgo_backend_settings
import ../eventemitter
@ -36,8 +36,8 @@ proc pinMailserver*(self: SettingsModel, enode: string = "") =
proc saveMailserver*(self: SettingsModel, name, enode: string) =
statusgo_backend_settings.saveMailserver(name, enode)
proc getFleet*(self: SettingsModel): Fleet =
result = statusgo_backend_settings.getFleet()
proc getFleet*(self: SettingsModel): string =
statusgo_backend_settings.getFleet()
proc getCurrentNetwork*(self: SettingsModel): NetworkType =
result = statusgo_backend_settings.getCurrentNetwork()
@ -51,7 +51,7 @@ proc getWakuVersion*(self: SettingsModel): int =
proc setBloomFilterMode*(self: SettingsModel, bloomFilterMode: bool): StatusGoError =
statusgo_backend_settings.setBloomFilterMode(bloomFilterMode)
proc setFleet*(self: SettingsModel, fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =
proc setFleet*(self: SettingsModel, fleetConfig: FleetConfig, fleet: string): StatusGoError =
statusgo_backend_settings.setFleet(fleetConfig, fleet)
proc setV2LightMode*(self: SettingsModel, enabled: bool): StatusGoError =

View File

@ -9,12 +9,11 @@ import ./keycard
import ../backends/backend
export chat, accounts, node, messages, contacts, profile, network, permissions, fleet, eventemitter
export chat, accounts, node, messages, contacts, profile, network, permissions, eventemitter
type Status* = ref object
backend*: Backend
events*: EventEmitter
fleet*: FleetModel
chat*: ChatModel
messages*: MessagesModel
accounts*: AccountModel
@ -31,11 +30,10 @@ type Status* = ref object
provider*: ProviderModel
keycard*: KeycardModel
proc newStatusInstance*(fleetConfig: string, backendName: string = "statusgo"): Status =
proc newStatusInstanceInternal(backendName: string = "statusgo"): Status =
result = Status()
result.backend = newBackend(backendName)
result.events = createEventEmitter()
result.fleet = fleet.newFleetModel(fleetConfig)
result.chat = chat.newChatModel(result.events)
result.accounts = accounts.newAccountModel(result.events)
result.wallet = wallet.newWalletModel(result.events)
@ -95,8 +93,8 @@ proc getBloomFilterBitsSet*(self: Status): int {.exportc, dynlib.} =
# exported correctly
proc newStatusInstance*(fleetConfig: cstring): Status {.exportc, dynlib.} =
newStatusInstance($fleetConfig)
proc newStatusInstance*(): Status {.exportc, dynlib.} =
newStatusInstanceInternal()
proc initNode*(self: Status, statusGoDir, keystoreDir: cstring) {.exportc, dynlib.} =
self.initNode($statusGoDir, $keystoreDir)

View File

@ -89,9 +89,8 @@ proc getCurrentNetworkDetails*(): NetworkDetails =
proc getLinkPreviewWhitelist*(): JsonNode =
result = callPrivateRPC("getLinkPreviewWhitelist".prefix, %* []).parseJSON()["result"]
proc getFleet*(): Fleet =
let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD)
result = parseEnum[Fleet](fleet)
proc getFleet*(): string =
result = getSetting[string](Setting.Fleet, $Fleet.PROD)
proc getPinnedMailserver*(): string =
let pinnedMailservers = getSetting[JsonNode](Setting.PinnedMailservers, %*{})
@ -203,20 +202,21 @@ proc setBloomLevel*(bloomFilterMode: bool, fullNode: bool): StatusGoError =
nodeConfig["WakuConfig"]["LightClient"] = newJBool(not fullNode)
return saveSetting(Setting.NodeConfig, nodeConfig)
proc setFleet*(fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =
let statusGoResult = saveSetting(Setting.Fleet, $fleet)
proc setFleet*(fleetConfig: FleetConfig, fleet: string): StatusGoError =
let fleetType = parseEnum[Fleet](fleet)
let statusGoResult = saveSetting(Setting.Fleet, fleet)
if statusGoResult.error != "":
return statusGoResult
var nodeConfig = getNodeConfig()
nodeConfig["ClusterConfig"]["Fleet"] = newJString($fleet)
nodeConfig["ClusterConfig"]["BootNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Bootnodes)
nodeConfig["ClusterConfig"]["TrustedMailServers"] = %* fleetConfig.getNodes(fleet, FleetNodes.Mailservers)
nodeConfig["ClusterConfig"]["StaticNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Whisper)
nodeConfig["ClusterConfig"]["RendezvousNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Rendezvous)
nodeConfig["ClusterConfig"]["RelayNodes"] = %* @["enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.waku.nodes.status.im"]
nodeConfig["ClusterConfig"]["StoreNodes"] = %* @["enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.waku.nodes.status.im"]
nodeConfig["ClusterConfig"]["FilterNodes"] = %* @["enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.waku.nodes.status.im"]
nodeConfig["ClusterConfig"]["LightpushNodes"] = %* @["enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.waku.nodes.status.im"]
nodeConfig["ClusterConfig"]["Fleet"] = newJString(fleet)
nodeConfig["ClusterConfig"]["BootNodes"] = %* fleetConfig.getNodes(fleetType, FleetNodes.Bootnodes)
nodeConfig["ClusterConfig"]["TrustedMailServers"] = %* fleetConfig.getNodes(fleetType, FleetNodes.Mailservers)
nodeConfig["ClusterConfig"]["StaticNodes"] = %* fleetConfig.getNodes(fleetType, FleetNodes.Whisper)
nodeConfig["ClusterConfig"]["RendezvousNodes"] = %* fleetConfig.getNodes(fleetType, FleetNodes.Rendezvous)
nodeConfig["ClusterConfig"]["RelayNodes"] = %* @["enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev"]
nodeConfig["ClusterConfig"]["StoreNodes"] = %* @["enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev"]
nodeConfig["ClusterConfig"]["FilterNodes"] = %* @["enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev"]
nodeConfig["ClusterConfig"]["LightpushNodes"] = %* @["enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev"]
#TODO: in the meantime we're using the go-waku test fleet for rendezvous.
# once we have a prod fleet this code needs to be updated