mirror of
https://github.com/status-im/status-lib.git
synced 2025-01-11 13:04:26 +00:00
refactor: ensure the settings are being accessed via backend (#68)
This commit is contained in:
parent
cf2a43f9b3
commit
e29ba9c9fa
@ -7,6 +7,7 @@ import json_serialization
|
||||
import tables
|
||||
import strformat
|
||||
import statusgo_backend/core
|
||||
import statusgo_backend/settings as status_settings
|
||||
import ./types/[transaction, setting, rpc_response, network_type, network]
|
||||
import utils
|
||||
import statusgo_backend/wallet
|
||||
@ -19,7 +20,6 @@ import eth/contracts
|
||||
import eth/transactions as eth_transactions
|
||||
import chronicles, libp2p/[multihash, multicodec, cid]
|
||||
|
||||
import ./settings as status_settings
|
||||
import ./wallet as status_wallet
|
||||
|
||||
const domain* = ".stateofus.eth"
|
||||
@ -380,7 +380,7 @@ proc validateEnsName*(ens: string, isStatus: bool, usernames: seq[string]): stri
|
||||
if ownerAddr == "" and isStatus:
|
||||
result = "available"
|
||||
else:
|
||||
let userPubKey = status_settings.getSetting2[string](Setting.PublicKey, "0x0")
|
||||
let userPubKey = status_settings.getSetting[string](Setting.PublicKey, "0x0")
|
||||
let userWallet = status_wallet.getWalletAccounts()[0].address
|
||||
let ens_pubkey = pubkey(ens)
|
||||
if ownerAddr != "":
|
||||
|
@ -1,8 +1,5 @@
|
||||
import json, json_serialization
|
||||
|
||||
import
|
||||
sugar, sequtils, strutils, atomics
|
||||
|
||||
import statusgo_backend/settings as statusgo_backend_settings
|
||||
import ../eventemitter
|
||||
import ./types/[fleet, network_type, setting, rpc_response]
|
||||
@ -24,13 +21,6 @@ proc getSetting*[T](self: SettingsModel, name: Setting, defaultValue: T, useCach
|
||||
proc getSetting*[T](self: SettingsModel, name: Setting, useCached: bool = true): T =
|
||||
result = statusgo_backend_settings.getSetting[T](name, useCached)
|
||||
|
||||
# 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)
|
||||
|
||||
proc getSetting2*[T](name: Setting, useCached: bool = true): T =
|
||||
result = statusgo_backend_settings.getSetting[T](name, useCached)
|
||||
|
||||
proc getCurrentNetworkDetails*(self: SettingsModel): NetworkDetails =
|
||||
result = statusgo_backend_settings.getCurrentNetworkDetails()
|
||||
|
||||
@ -49,11 +39,8 @@ proc saveMailserver*(self: SettingsModel, name, enode: string) =
|
||||
proc getFleet*(self: SettingsModel): Fleet =
|
||||
result = statusgo_backend_settings.getFleet()
|
||||
|
||||
proc getCurrentNetwork*(): NetworkType =
|
||||
result = statusgo_backend_settings.getCurrentNetwork()
|
||||
|
||||
proc getCurrentNetwork*(self: SettingsModel): NetworkType =
|
||||
result = getCurrentNetwork()
|
||||
result = statusgo_backend_settings.getCurrentNetwork()
|
||||
|
||||
proc setWakuVersion*(self: SettingsModel, newVersion: int) =
|
||||
statusgo_backend_settings.setWakuVersion(newVersion)
|
||||
|
@ -3,14 +3,13 @@ import
|
||||
|
||||
import
|
||||
json_serialization, chronicles, uuids
|
||||
from status_go import nil
|
||||
|
||||
import
|
||||
./core, ./accounts/constants, ../utils
|
||||
|
||||
import ../types/[setting, network_type, fleet, rpc_response]
|
||||
|
||||
from status_go import nil
|
||||
|
||||
var
|
||||
settings {.threadvar.}: JsonNode
|
||||
settingsInited {.threadvar.}: bool
|
||||
@ -30,9 +29,6 @@ proc saveSetting*(key: Setting, value: string | JsonNode | bool): StatusGoError
|
||||
except Exception as e:
|
||||
error "Error saving setting", key=key, value=value, msg=e.msg
|
||||
|
||||
proc getWeb3ClientVersion*(): string =
|
||||
parseJson(callPrivateRPC("web3_clientVersion"))["result"].getStr
|
||||
|
||||
proc getSettings*(useCached: bool = true, keepSensitiveData: bool = false): JsonNode =
|
||||
let cacheIsDirty = (not settingsInited) or dirty.load
|
||||
if useCached and (not cacheIsDirty) and (not keepSensitiveData):
|
||||
@ -65,6 +61,9 @@ proc getSetting*[T](name: Setting, defaultValue: T, useCached: bool = true): T =
|
||||
proc getSetting*[T](name: Setting, useCached: bool = true): T =
|
||||
result = getSetting(name, default(type(T)), useCached)
|
||||
|
||||
proc getWeb3ClientVersion*(): string =
|
||||
parseJson(callPrivateRPC("web3_clientVersion"))["result"].getStr
|
||||
|
||||
proc getCurrentNetwork*(): NetworkType =
|
||||
case getSetting[string](Setting.Networks_CurrentNetwork, constants.DEFAULT_NETWORK_NAME):
|
||||
of "mainnet_rpc":
|
||||
@ -100,7 +99,6 @@ proc getPinnedMailserver*(): string =
|
||||
result = pinnedMailservers{fleet}.getStr()
|
||||
info "getPinnedMailserver", topics="mailserver-interaction", fleet, result
|
||||
|
||||
|
||||
proc pinMailserver*(enode: string = "") =
|
||||
let pinnedMailservers = getSetting[JsonNode](Setting.PinnedMailservers, %*{})
|
||||
let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD)
|
||||
@ -109,7 +107,6 @@ proc pinMailserver*(enode: string = "") =
|
||||
let response = saveSetting(Setting.PinnedMailservers, pinnedMailservers)
|
||||
info "pinMailserver", topics="mailserver-interaction", enode, response
|
||||
|
||||
|
||||
proc saveMailserver*(name, enode: string) =
|
||||
let fleet = getSetting[string](Setting.Fleet, $Fleet.PROD)
|
||||
let id = $genUUID()
|
||||
@ -124,13 +121,12 @@ proc saveMailserver*(name, enode: string) =
|
||||
let result = response.parseJSON()["result"]
|
||||
info "saveMailserver", topics="mailserver-interaction", rpc_method="mailservers_addMailserver", id, name, enode, fleet, response
|
||||
|
||||
|
||||
proc getMailservers*():JsonNode =
|
||||
proc getMailservers*(): JsonNode =
|
||||
let response = callPrivateRPC("mailservers_getMailservers")
|
||||
result = response.parseJSON()["result"]
|
||||
info "getMailservers", topics="mailserver-interaction", rpc_method="mailservers_getMailservers", response
|
||||
|
||||
proc getNodeConfig*():JsonNode =
|
||||
proc getNodeConfig*(): JsonNode =
|
||||
result = status_go.getNodeConfig().parseJSON()
|
||||
|
||||
# setting correct values in json
|
||||
|
Loading…
x
Reference in New Issue
Block a user