2021-09-08 18:05:39 +00:00
|
|
|
import json, json_serialization
|
|
|
|
|
|
|
|
import
|
|
|
|
sugar, sequtils, strutils, atomics
|
|
|
|
|
2021-09-11 21:50:36 +00:00
|
|
|
import statusgo_backend/settings as statusgo_backend_settings
|
2021-09-08 18:05:39 +00:00
|
|
|
import ../eventemitter
|
2021-09-09 21:36:28 +00:00
|
|
|
import ./types/[fleet, network_type, setting, rpc_response]
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
SettingsModel* = ref object
|
|
|
|
events*: EventEmitter
|
|
|
|
|
|
|
|
proc newSettingsModel*(events: EventEmitter): SettingsModel =
|
|
|
|
result = SettingsModel()
|
|
|
|
result.events = events
|
|
|
|
|
|
|
|
proc saveSetting*(self: SettingsModel, key: Setting, value: string | JsonNode | bool): StatusGoError =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.saveSetting(key, value)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getSetting*[T](self: SettingsModel, name: Setting, defaultValue: T, useCached: bool = true): T =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getSetting(name, defaultValue, useCached)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getSetting*[T](self: SettingsModel, name: Setting, useCached: bool = true): T =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getSetting[T](name, useCached)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
# TODO: name with a 2 due to namespace conflicts that need to be addressed in subsquent PRs
|
|
|
|
proc getSetting2*[T](name: Setting, defaultValue: T, useCached: bool = true): T =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getSetting(name, defaultValue, useCached)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getSetting2*[T](name: Setting, useCached: bool = true): T =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getSetting[T](name, useCached)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getCurrentNetworkDetails*(self: SettingsModel): NetworkDetails =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getCurrentNetworkDetails()
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getMailservers*(self: SettingsModel):JsonNode =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getMailservers()
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getPinnedMailserver*(self: SettingsModel): string =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getPinnedMailserver()
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc pinMailserver*(self: SettingsModel, enode: string = "") =
|
2021-09-11 21:50:36 +00:00
|
|
|
statusgo_backend_settings.pinMailserver(enode)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc saveMailserver*(self: SettingsModel, name, enode: string) =
|
2021-09-11 21:50:36 +00:00
|
|
|
statusgo_backend_settings.saveMailserver(name, enode)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getFleet*(self: SettingsModel): Fleet =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getFleet()
|
2021-09-08 18:05:39 +00:00
|
|
|
|
2021-09-09 21:36:28 +00:00
|
|
|
proc getCurrentNetwork*(): NetworkType =
|
2021-09-11 21:50:36 +00:00
|
|
|
result = statusgo_backend_settings.getCurrentNetwork()
|
2021-09-08 18:05:39 +00:00
|
|
|
|
2021-09-09 21:36:28 +00:00
|
|
|
proc getCurrentNetwork*(self: SettingsModel): NetworkType =
|
2021-09-08 18:05:39 +00:00
|
|
|
result = getCurrentNetwork()
|
|
|
|
|
|
|
|
proc setWakuVersion*(self: SettingsModel, newVersion: int) =
|
2021-09-11 21:50:36 +00:00
|
|
|
statusgo_backend_settings.setWakuVersion(newVersion)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc setBloomFilterMode*(self: SettingsModel, bloomFilterMode: bool): StatusGoError =
|
2021-09-11 21:50:36 +00:00
|
|
|
statusgo_backend_settings.setBloomFilterMode(bloomFilterMode)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc setFleet*(self: SettingsModel, fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =
|
2021-09-11 21:50:36 +00:00
|
|
|
statusgo_backend_settings.setFleet(fleetConfig, fleet)
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc getNodeConfig*(self: SettingsModel): JsonNode =
|
2021-09-11 21:50:36 +00:00
|
|
|
statusgo_backend_settings.getNodeConfig()
|
2021-09-08 18:05:39 +00:00
|
|
|
|
|
|
|
proc setBloomLevel*(self: SettingsModel, bloomFilterMode: bool, fullNode: bool): StatusGoError =
|
2021-09-11 21:50:36 +00:00
|
|
|
statusgo_backend_settings.setBloomLevel(bloomFilterMode, fullNode)
|