mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-15 17:16:26 +00:00
fix(@general): user status go service to migrate account
This commit is contained in:
parent
451e650b09
commit
db3722cd4f
@ -290,8 +290,6 @@ proc start*(self: AppController) =
|
||||
self.startupModule.load()
|
||||
|
||||
proc load(self: AppController) =
|
||||
self.accountsService.deleteExtraKeyStoreFile()
|
||||
|
||||
self.notificationsManager.init()
|
||||
|
||||
self.settingsService.init()
|
||||
|
@ -1,5 +1,4 @@
|
||||
import os, json, sequtils, strutils, uuids
|
||||
>>>>>>> 8b5de1363 (fix(@general): keystore management)
|
||||
import json_serialization, chronicles
|
||||
import times as times
|
||||
|
||||
@ -7,6 +6,7 @@ import ./dto/accounts as dto_accounts
|
||||
import ./dto/generated_accounts as dto_generated_accounts
|
||||
import ../../../backend/accounts as status_account
|
||||
import ../../../backend/general as status_general
|
||||
import ../../../backend/core as status_core
|
||||
|
||||
import ../../../app/core/fleets/fleet_configuration
|
||||
import ../../common/[account_constants, network_constants, utils, string_utils]
|
||||
@ -50,49 +50,6 @@ proc getImportedAccount*(self: Service): GeneratedAccountDto =
|
||||
proc isFirstTimeAccountLogin*(self: Service): bool =
|
||||
return self.isFirstTimeAccountLogin
|
||||
|
||||
# Remove extra copied keystore that are not needed (can be remove 1st jan 2023)
|
||||
proc deleteExtraKeyStoreFile*(self: Service) =
|
||||
let accounts = status_account.getAccounts().result
|
||||
var deleteCandidates: seq[string] = @[]
|
||||
for path in walkFiles(self.keyStoreDir & "*"):
|
||||
var found = false
|
||||
for account in accounts.getElems():
|
||||
let address = account{"address"}.getStr.replace("0x", "")
|
||||
if path.endsWith(address):
|
||||
found = true
|
||||
break
|
||||
|
||||
if not found:
|
||||
deleteCandidates.add(path)
|
||||
|
||||
if len(deleteCandidates) == 2:
|
||||
return
|
||||
|
||||
let tz = times.utc()
|
||||
let tf = times.initTimeFormat("yyyy-mm-dd'T'HH-mm-ss")
|
||||
proc extractTime(path: string): DateTime =
|
||||
return os.extractFilename(path).split("--")[1].split(".")[0].parse(tf, tz)
|
||||
|
||||
let interval = times.initDuration(seconds = 2)
|
||||
var toDelete: seq[string] = @[]
|
||||
for a in deleteCandidates:
|
||||
let aTime = extractTime(a)
|
||||
var found = false
|
||||
for b in deleteCandidates:
|
||||
let bTime = extractTime(b)
|
||||
|
||||
if aTime - bTime < interval:
|
||||
found = true
|
||||
break
|
||||
|
||||
if found:
|
||||
continue
|
||||
|
||||
toDelete.add(a)
|
||||
|
||||
for path in toDelete:
|
||||
os.removeFile(path)
|
||||
|
||||
proc setKeyStoreDir(self: Service, key: string) =
|
||||
self.keyStoreDir = joinPath(main_constants.ROOTKEYSTOREDIR, key) & main_constants.sep
|
||||
discard status_general.initKeystore(self.keyStoreDir)
|
||||
@ -381,12 +338,12 @@ proc login*(self: Service, account: AccountDto, password: string): string =
|
||||
elif(img.imgType == "large"):
|
||||
largeImage = img.uri
|
||||
|
||||
# Copy old keystore file to new dir, this code can be remove 1st jan 2023
|
||||
let keyStoreDir = joinPath(main_constants.ROOTKEYSTOREDIR, account.keyUid) & main_constants.sep
|
||||
if not dirExists(self.keyStoreDir):
|
||||
os.createDir(self.keyStoreDir)
|
||||
for path in walkFiles(main_constants.ROOTKEYSTOREDIR & "*"):
|
||||
os.copyFile(path, self.keyStoreDir & os.extractFilename(path))
|
||||
if not dirExists(keyStoreDir):
|
||||
os.createDir(keyStoreDir)
|
||||
status_core.migrateKeyStoreDir($ %* {
|
||||
"key-uid": account.keyUid
|
||||
}, password, main_constants.ROOTKEYSTOREDIR, keyStoreDir)
|
||||
|
||||
self.setKeyStoreDir(account.keyUid)
|
||||
# This is moved from `status-lib` here
|
||||
@ -420,8 +377,7 @@ proc login*(self: Service, account: AccountDto, password: string): string =
|
||||
}
|
||||
|
||||
let response = status_account.login(account.name, account.keyUid, hashedPassword, thumbnailImage,
|
||||
largeImage, $nodeCfg)
|
||||
|
||||
largeImage, $nodeCfg)
|
||||
var error = "response doesn't contain \"error\""
|
||||
if(response.result.contains("error")):
|
||||
error = response.result["error"].getStr
|
||||
@ -432,7 +388,7 @@ proc login*(self: Service, account: AccountDto, password: string): string =
|
||||
return error
|
||||
|
||||
except Exception as e:
|
||||
error "error: ", procName="setupAccount", errName = e.name, errDesription = e.msg
|
||||
error "error: ", procName="login", errName = e.name, errDesription = e.msg
|
||||
return e.msg
|
||||
|
||||
proc verifyAccountPassword*(self: Service, account: string, password: string): bool =
|
||||
|
@ -68,4 +68,16 @@ proc sendTransaction*(inputJSON: string, password: string): RpcResponse[JsonNode
|
||||
result = Json.decode(rpcResponseRaw, RpcResponse[JsonNode])
|
||||
except RpcException as e:
|
||||
error "error sending tx", inputJSON, exception=e.msg
|
||||
raise newException(RpcException, e.msg)
|
||||
raise newException(RpcException, e.msg)
|
||||
|
||||
|
||||
proc migrateKeyStoreDir*(account: string, password: string, oldKeystoreDir: string, multiaccountKeystoreDir: string)
|
||||
{.raises: [RpcException, ValueError, Defect, SerializationError].} =
|
||||
try:
|
||||
var hashed_password = "0x" & $keccak_256.digest(password)
|
||||
discard status_go.migrateKeyStoreDir(account, hashed_password, oldKeystoreDir, multiaccountKeystoreDir)
|
||||
except RpcException as e:
|
||||
error "error migrating keystore dir", account, exception=e.msg
|
||||
raise newException(RpcException, e.msg)
|
||||
|
||||
|
@ -56,7 +56,7 @@ let
|
||||
OPENURI* = desktopConfig.uri
|
||||
DATADIR* = baseDir & sep
|
||||
STATUSGODIR* = joinPath(baseDir, "data") & sep
|
||||
ROOTKEYSTOREDIR* = joinPath(baseDir, "data", "keystore") & sep
|
||||
ROOTKEYSTOREDIR* = joinPath(baseDir, "data", "keystore")
|
||||
TMPDIR* = joinPath(baseDir, "tmp") & sep
|
||||
LOGDIR* = joinPath(baseDir, "logs") & sep
|
||||
|
||||
|
2
vendor/status-go
vendored
2
vendor/status-go
vendored
@ -1 +1 @@
|
||||
Subproject commit 55f2900ec2fcb6384b79bd4f55ddc70cdfb0bff0
|
||||
Subproject commit 7227ae1c8ef1f74e180f324185d01f564730af70
|
Loading…
x
Reference in New Issue
Block a user