refactor: node config
This commit is contained in:
parent
d8053f5291
commit
f4da94af6a
|
@ -74,12 +74,9 @@ QtObject:
|
|||
notify = receivedMessage
|
||||
|
||||
proc setWakuBloomFilterMode*(self: NodeView, bloomFilterMode: bool) {.slot.} =
|
||||
discard self.status.settings.saveSetting(Setting.WakuBloomFilterMode, bloomFilterMode)
|
||||
var fleetStr = self.status.settings.getSetting[:string](Setting.Fleet)
|
||||
let fleet = if fleetStr == "": Fleet.PROD else: parseEnum[Fleet](fleetStr)
|
||||
let installationId = self.status.settings.getSetting[:string](Setting.InstallationId)
|
||||
let updatedNodeConfig = self.status.accounts.getNodeConfig(self.status.fleet.config, installationId, $self.status.settings.getCurrentNetwork(), fleet, bloomFilterMode)
|
||||
discard self.status.settings.saveSetting(Setting.NodeConfig, updatedNodeConfig)
|
||||
let statusGoResult = self.status.settings.setBloomFilterMode(bloomFilterMode)
|
||||
if statusGoResult.error != "":
|
||||
error "Error saving updated node config", msg=statusGoResult.error
|
||||
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
|
||||
|
||||
proc init*(self: NodeView) {.slot.} =
|
||||
|
|
|
@ -25,11 +25,11 @@ QtObject:
|
|||
self.fleetChanged($self.status.settings.getFleet())
|
||||
|
||||
proc setFleet*(self: Fleets, newFleet: string) {.slot.} =
|
||||
discard self.status.settings.saveSetting(Setting.Fleet, newFleet)
|
||||
let fleet = parseEnum[Fleet](newFleet)
|
||||
let installationId = self.status.settings.getSetting[:string](Setting.InstallationId)
|
||||
let updatedNodeConfig = self.status.accounts.getNodeConfig(self.status.fleet.config, installationId, $self.status.settings.getCurrentNetwork(), fleet)
|
||||
discard self.status.settings.saveSetting(Setting.NodeConfig, updatedNodeConfig)
|
||||
let statusGoResult = self.status.settings.setFleet(self.status.fleet.config, fleet)
|
||||
if statusGoResult.error != "":
|
||||
error "Error saving updated node config", msg=statusGoResult.error
|
||||
|
||||
let isWakuV2 = if fleet == WakuV2Prod or fleet == WakuV2Test: true else: false
|
||||
# Updating waku version because it makes no sense for some fleets to run under wakuv1 or v2 config
|
||||
if isWakuV2:
|
||||
|
|
|
@ -63,40 +63,16 @@ proc generateIdenticon*(self: AccountModel, publicKey: string): string =
|
|||
result = generateIdenticon(publicKey)
|
||||
|
||||
proc changeNetwork*(self: AccountModel, fleetConfig: FleetConfig, network: string) =
|
||||
|
||||
# 1. update current network setting
|
||||
var statusGoResult = status_settings.saveSetting(Setting.Networks_CurrentNetwork, network)
|
||||
if statusGoResult.error != "":
|
||||
error "Error saving current network setting", msg=statusGoResult.error
|
||||
|
||||
# 2. update node config setting
|
||||
let installationId = status_settings.getSetting[string](Setting.InstallationId)
|
||||
|
||||
let networks = getSetting[JsonNode](Setting.Networks_Networks)
|
||||
let networkData = networks.getElems().find((n:JsonNode) => n["id"].getStr() == network)
|
||||
|
||||
let updatedNodeConfig = status_accounts.getNodeConfig(fleetConfig, installationId, networkData)
|
||||
|
||||
updatedNodeConfig["KeyStoreDir"] = newJString("./keystore")
|
||||
updatedNodeConfig["LogFile"] = newJString("./geth.log")
|
||||
updatedNodeConfig["ShhextConfig"]["BackupDisabledDataDir"] = newJString("./")
|
||||
|
||||
statusGoResult = status_settings.saveSetting(Setting.NodeConfig, updatedNodeConfig)
|
||||
var statusGoResult = status_settings.setNetwork(network)
|
||||
if statusGoResult.error != "":
|
||||
error "Error saving updated node config", msg=statusGoResult.error
|
||||
|
||||
# 3. remove all installed sticker packs (pack ids do not match across networks)
|
||||
# remove all installed sticker packs (pack ids do not match across networks)
|
||||
statusGoResult = status_settings.saveSetting(Setting.Stickers_PacksInstalled, %* {})
|
||||
if statusGoResult.error != "":
|
||||
error "Error removing all installed sticker packs", msg=statusGoResult.error
|
||||
|
||||
# 4. remove all recent stickers (pack ids do not match across networks)
|
||||
# remove all recent stickers (pack ids do not match across networks)
|
||||
statusGoResult = status_settings.saveSetting(Setting.Stickers_Recent, %* {})
|
||||
if statusGoResult.error != "":
|
||||
error "Error removing all recent stickers", msg=statusGoResult.error
|
||||
|
||||
proc getNodeConfig*(self: AccountModel, fleetConfig: FleetConfig, installationId: string, networkConfig: JsonNode, fleet: Fleet = Fleet.PROD, bloomFilterMode = false): JsonNode =
|
||||
result = status_accounts.getNodeConfig(fleetConfig, installationId, networkConfig, fleet, bloomFilterMode)
|
||||
|
||||
proc getNodeConfig*(self: AccountModel, fleetConfig: FleetConfig, installationId: string, currentNetwork: string = DEFAULT_NETWORK_NAME, fleet: Fleet = Fleet.PROD, bloomFilterMode = false): JsonNode =
|
||||
result = status_accounts.getNodeConfig(fleetConfig, installationId, currentNetwork, fleet, bloomFilterMode)
|
||||
|
|
|
@ -13,15 +13,14 @@ proc getNetworkConfig(currentNetwork: string): JsonNode =
|
|||
result = constants.DEFAULT_NETWORKS.first("id", currentNetwork)
|
||||
|
||||
|
||||
proc getNodeConfig*(fleetConfig: FleetConfig, installationId: string, networkConfig: JsonNode, fleet: Fleet = Fleet.PROD, bloomFilterMode = false, useDefaultConfig: bool = false): JsonNode =
|
||||
proc getDefaultNodeConfig*(fleetConfig: FleetConfig, installationId: string): JsonNode =
|
||||
let networkConfig = getNetworkConfig(constants.DEFAULT_NETWORK_NAME)
|
||||
let upstreamUrl = networkConfig["config"]["UpstreamConfig"]["URL"]
|
||||
let fleet = Fleet.PROD
|
||||
|
||||
var newDataDir = networkConfig["config"]["DataDir"].getStr
|
||||
newDataDir.removeSuffix("_rpc")
|
||||
|
||||
if useDefaultConfig:
|
||||
result = constants.NODE_CONFIG.copy()
|
||||
else:
|
||||
result = getNodeConfig().parseJSON()
|
||||
result = constants.NODE_CONFIG.copy()
|
||||
result["ClusterConfig"]["Fleet"] = newJString($fleet)
|
||||
result["ClusterConfig"]["BootNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Bootnodes)
|
||||
result["ClusterConfig"]["TrustedMailServers"] = %* fleetConfig.getNodes(fleet, FleetNodes.Mailservers)
|
||||
|
@ -29,7 +28,6 @@ proc getNodeConfig*(fleetConfig: FleetConfig, installationId: string, networkCon
|
|||
result["ClusterConfig"]["RendezvousNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Rendezvous)
|
||||
result["ClusterConfig"]["WakuNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Waku)
|
||||
result["ClusterConfig"]["WakuStoreNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Waku)
|
||||
|
||||
result["NetworkId"] = networkConfig["config"]["NetworkId"]
|
||||
result["DataDir"] = newDataDir.newJString()
|
||||
result["UpstreamConfig"]["Enabled"] = networkConfig["config"]["UpstreamConfig"]["Enabled"]
|
||||
|
@ -38,11 +36,7 @@ proc getNodeConfig*(fleetConfig: FleetConfig, installationId: string, networkCon
|
|||
|
||||
# TODO: commented since it's not necessary (we do the connections thru C bindings). Enable it thru an option once status-nodes are able to be configured in desktop
|
||||
# result["ListenAddr"] = if existsEnv("STATUS_PORT"): newJString("0.0.0.0:" & $getEnv("STATUS_PORT")) else: newJString("0.0.0.0:30305")
|
||||
result["WakuConfig"]["BloomFilterMode"] = newJBool(bloomFilterMode)
|
||||
|
||||
proc getNodeConfig*(fleetConfig: FleetConfig, installationId: string, currentNetwork: string = constants.DEFAULT_NETWORK_NAME, fleet: Fleet = Fleet.PROD, bloomFilterMode = false, useDefaultConfig: bool = false): JsonNode =
|
||||
let networkConfig = getNetworkConfig(currentNetwork)
|
||||
result = getNodeConfig(fleetConfig, installationId, networkConfig, fleet, bloomFilterMode, useDefaultConfig)
|
||||
|
||||
proc hashPassword*(password: string): string =
|
||||
result = "0x" & $keccak_256.digest(password)
|
||||
|
@ -194,7 +188,7 @@ proc setupAccount*(fleetConfig: FleetConfig, account: GeneratedAccount, password
|
|||
let accountData = getAccountData(account)
|
||||
let installationId = $genUUID()
|
||||
var settingsJSON = getAccountSettings(account, constants.DEFAULT_NETWORKS, installationId)
|
||||
var nodeConfig = getNodeConfig(fleetConfig, installationId, constants.DEFAULT_NETWORK_NAME, Fleet.PROD, false, true)
|
||||
var nodeConfig = getDefaultNodeConfig(fleetConfig, installationId)
|
||||
result = saveAccountAndLogin(account, $accountData, password, $nodeConfig, $settingsJSON)
|
||||
|
||||
except StatusGoException as e:
|
||||
|
|
|
@ -8,7 +8,7 @@ import
|
|||
./core, ../types, ../signals/types as statusgo_types, ./accounts/constants,
|
||||
../utils
|
||||
|
||||
from status_go import getNodeConfig
|
||||
from status_go import nil
|
||||
|
||||
var
|
||||
settings {.threadvar.}: JsonNode
|
||||
|
@ -115,8 +115,22 @@ proc getMailservers*():JsonNode =
|
|||
let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD)
|
||||
result = callPrivateRPC("mailservers_getMailservers").parseJSON()["result"]
|
||||
|
||||
proc getNodeConfig*():JsonNode =
|
||||
result = status_go.getNodeConfig().parseJSON()
|
||||
|
||||
# setting correct values in json
|
||||
let currNetwork = getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME)
|
||||
let networks = getSetting[JsonNode](Setting.Networks_Networks)
|
||||
let networkConfig = networks.getElems().find((n:JsonNode) => n["id"].getStr() == currNetwork)
|
||||
var newDataDir = networkConfig["config"]["DataDir"].getStr
|
||||
newDataDir.removeSuffix("_rpc")
|
||||
result["DataDir"] = newDataDir.newJString()
|
||||
result["KeyStoreDir"] = newJString("./keystore")
|
||||
result["LogFile"] = newJString("./geth.log")
|
||||
result["ShhextConfig"]["BackupDisabledDataDir"] = newJString("./")
|
||||
|
||||
proc getWakuVersion*():int =
|
||||
let nodeConfig = getNodeConfig().parseJSON()
|
||||
let nodeConfig = getNodeConfig()
|
||||
if nodeConfig["WakuConfig"]["Enabled"].getBool():
|
||||
return 1
|
||||
if nodeConfig["WakuV2Config"]["Enabled"].getBool():
|
||||
|
@ -124,10 +138,7 @@ proc getWakuVersion*():int =
|
|||
return 0
|
||||
|
||||
proc setWakuVersion*(newVersion: int) =
|
||||
let nodeConfig = getNodeConfig().parseJSON()
|
||||
nodeConfig["KeyStoreDir"] = newJString("./keystore")
|
||||
nodeConfig["LogFile"] = newJString("./geth.log")
|
||||
nodeConfig["ShhextConfig"]["BackupDisabledDataDir"] = newJString("./")
|
||||
let nodeConfig = getNodeConfig()
|
||||
if newVersion == 1:
|
||||
nodeConfig["WakuConfig"]["Enabled"] = newJBool(true)
|
||||
nodeConfig["WakuV2Config"]["Enabled"] = newJBool(false)
|
||||
|
@ -140,3 +151,49 @@ proc setWakuVersion*(newVersion: int) =
|
|||
nodeConfig["Rendezvous"] = newJBool(false)
|
||||
discard saveSetting(Setting.NodeConfig, nodeConfig)
|
||||
|
||||
proc setNetwork*(network: string): StatusGoError =
|
||||
let statusGoResult = saveSetting(Setting.Networks_CurrentNetwork, network)
|
||||
if statusGoResult.error != "":
|
||||
return statusGoResult
|
||||
|
||||
let networks = getSetting[JsonNode](Setting.Networks_Networks)
|
||||
let networkConfig = networks.getElems().find((n:JsonNode) => n["id"].getStr() == network)
|
||||
|
||||
var nodeConfig = getNodeConfig()
|
||||
let upstreamUrl = networkConfig["config"]["UpstreamConfig"]["URL"]
|
||||
var newDataDir = networkConfig["config"]["DataDir"].getStr
|
||||
newDataDir.removeSuffix("_rpc")
|
||||
|
||||
nodeConfig["NetworkId"] = networkConfig["config"]["NetworkId"]
|
||||
nodeConfig["DataDir"] = newDataDir.newJString()
|
||||
nodeConfig["UpstreamConfig"]["Enabled"] = networkConfig["config"]["UpstreamConfig"]["Enabled"]
|
||||
nodeConfig["UpstreamConfig"]["URL"] = upstreamUrl
|
||||
|
||||
return saveSetting(Setting.NodeConfig, nodeConfig)
|
||||
|
||||
proc setBloomFilterMode*(bloomFilterMode: bool): StatusGoError =
|
||||
let statusGoResult = saveSetting(Setting.WakuBloomFilterMode, bloomFilterMode)
|
||||
if statusGoResult.error != "":
|
||||
return statusGoResult
|
||||
|
||||
var nodeConfig = getNodeConfig()
|
||||
nodeConfig["WakuConfig"]["BloomFilterMode"] = newJBool(bloomFilterMode)
|
||||
|
||||
return saveSetting(Setting.NodeConfig, nodeConfig)
|
||||
|
||||
proc setFleet*(fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =
|
||||
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"]["WakuNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Waku)
|
||||
nodeConfig["ClusterConfig"]["WakuStoreNodes"] = %* fleetConfig.getNodes(fleet, FleetNodes.Waku)
|
||||
|
||||
return saveSetting(Setting.NodeConfig, nodeConfig)
|
||||
|
||||
|
|
|
@ -59,4 +59,13 @@ proc getCurrentNetwork*(self: SettingsModel): Network =
|
|||
result = getCurrentNetwork()
|
||||
|
||||
proc setWakuVersion*(self: SettingsModel, newVersion: int) =
|
||||
libstatus_settings.setWakuVersion(newVersion)
|
||||
libstatus_settings.setWakuVersion(newVersion)
|
||||
|
||||
proc setBloomFilterMode*(self: SettingsModel, bloomFilterMode: bool): StatusGoError =
|
||||
libstatus_settings.setBloomFilterMode(bloomFilterMode)
|
||||
|
||||
proc setFleet*(self: SettingsModel, fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =
|
||||
libstatus_settings.setFleet(fleetConfig, fleet)
|
||||
|
||||
proc getNodeConfig*(self: SettingsModel): JsonNode =
|
||||
libstatus_settings.getNodeConfig()
|
||||
|
|
Loading…
Reference in New Issue