refactor: do not cache the mnemonic in settings
This commit is contained in:
parent
bd9e1619fa
commit
22a86b939f
|
@ -23,18 +23,21 @@ proc saveSetting*(key: Setting, value: string | JsonNode): StatusGoError =
|
||||||
proc getWeb3ClientVersion*(): string =
|
proc getWeb3ClientVersion*(): string =
|
||||||
parseJson(callPrivateRPC("web3_clientVersion"))["result"].getStr
|
parseJson(callPrivateRPC("web3_clientVersion"))["result"].getStr
|
||||||
|
|
||||||
proc getSettings*(useCached: bool = true): JsonNode =
|
proc getSettings*(useCached: bool = true, keepSensitiveData: bool = false): JsonNode =
|
||||||
{.gcsafe.}:
|
{.gcsafe.}:
|
||||||
withLock settingsLock:
|
withLock settingsLock:
|
||||||
if useCached and not dirty:
|
if useCached and not dirty and not keepSensitiveData:
|
||||||
result = settings
|
result = settings
|
||||||
else:
|
else:
|
||||||
settings = callPrivateRPC("settings_getSettings").parseJSON()["result"]
|
result = callPrivateRPC("settings_getSettings").parseJSON()["result"]
|
||||||
|
if (keepSensitiveData):
|
||||||
|
return
|
||||||
dirty = false
|
dirty = false
|
||||||
result = settings
|
delete(result, "mnemonic")
|
||||||
|
settings = result
|
||||||
|
|
||||||
proc getSetting*[T](name: Setting, defaultValue: T, useCached: bool = true): T =
|
proc getSetting*[T](name: Setting, defaultValue: T, useCached: bool = true): T =
|
||||||
let settings: JsonNode = getSettings(useCached)
|
let settings: JsonNode = getSettings(useCached, $name == "mnemonic")
|
||||||
if not settings.contains($name) or settings{$name}.isEmpty():
|
if not settings.contains($name) or settings{$name}.isEmpty():
|
||||||
return defaultValue
|
return defaultValue
|
||||||
result = Json.decode($settings{$name}, T)
|
result = Json.decode($settings{$name}, T)
|
||||||
|
|
Loading…
Reference in New Issue