status-lib/status/settings.nim

71 lines
2.8 KiB
Nim
Raw Normal View History

2021-09-08 18:05:39 +00:00
import json, json_serialization
import
sugar, sequtils, strutils, atomics
import statusgo_backend/settings as statusgo_backend_settings
2021-09-08 18:05:39 +00:00
import ../eventemitter
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 =
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 =
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 =
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 =
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 =
result = statusgo_backend_settings.getSetting[T](name, useCached)
2021-09-08 18:05:39 +00:00
proc getCurrentNetworkDetails*(self: SettingsModel): NetworkDetails =
result = statusgo_backend_settings.getCurrentNetworkDetails()
2021-09-08 18:05:39 +00:00
proc getMailservers*(self: SettingsModel):JsonNode =
result = statusgo_backend_settings.getMailservers()
2021-09-08 18:05:39 +00:00
proc getPinnedMailserver*(self: SettingsModel): string =
result = statusgo_backend_settings.getPinnedMailserver()
2021-09-08 18:05:39 +00:00
proc pinMailserver*(self: SettingsModel, enode: string = "") =
statusgo_backend_settings.pinMailserver(enode)
2021-09-08 18:05:39 +00:00
proc saveMailserver*(self: SettingsModel, name, enode: string) =
statusgo_backend_settings.saveMailserver(name, enode)
2021-09-08 18:05:39 +00:00
proc getFleet*(self: SettingsModel): Fleet =
result = statusgo_backend_settings.getFleet()
2021-09-08 18:05:39 +00:00
proc getCurrentNetwork*(): NetworkType =
result = statusgo_backend_settings.getCurrentNetwork()
2021-09-08 18:05:39 +00:00
proc getCurrentNetwork*(self: SettingsModel): NetworkType =
2021-09-08 18:05:39 +00:00
result = getCurrentNetwork()
proc setWakuVersion*(self: SettingsModel, newVersion: int) =
statusgo_backend_settings.setWakuVersion(newVersion)
2021-09-08 18:05:39 +00:00
proc setBloomFilterMode*(self: SettingsModel, bloomFilterMode: bool): StatusGoError =
statusgo_backend_settings.setBloomFilterMode(bloomFilterMode)
2021-09-08 18:05:39 +00:00
proc setFleet*(self: SettingsModel, fleetConfig: FleetConfig, fleet: Fleet): StatusGoError =
statusgo_backend_settings.setFleet(fleetConfig, fleet)
2021-09-08 18:05:39 +00:00
proc getNodeConfig*(self: SettingsModel): JsonNode =
statusgo_backend_settings.getNodeConfig()
2021-09-08 18:05:39 +00:00
proc setBloomLevel*(self: SettingsModel, bloomFilterMode: bool, fullNode: bool): StatusGoError =
statusgo_backend_settings.setBloomLevel(bloomFilterMode, fullNode)