feat: move create accounts to status-go
This commit is contained in:
parent
047c4f0839
commit
6915c19c84
|
@ -189,33 +189,7 @@ method getWalletAccount*(self: Service, accountIndex: int): WalletAccountDto =
|
||||||
method getCurrencyBalance*(self: Service): float64 =
|
method getCurrencyBalance*(self: Service): float64 =
|
||||||
return self.getWalletAccounts().map(a => a.getCurrencyBalance()).foldl(a + b, 0.0)
|
return self.getWalletAccounts().map(a => a.getCurrencyBalance()).foldl(a + b, 0.0)
|
||||||
|
|
||||||
method getDefaultAccount(self: Service): string =
|
method addNewAccountToLocalStore(self: Service) =
|
||||||
return status_go_eth.getAccounts().result[0].getStr
|
|
||||||
|
|
||||||
method saveAccount(
|
|
||||||
self: Service,
|
|
||||||
address: string,
|
|
||||||
name: string,
|
|
||||||
password: string,
|
|
||||||
color: string,
|
|
||||||
accountType: string,
|
|
||||||
isADerivedAccount = true,
|
|
||||||
walletIndex: int = 0,
|
|
||||||
id: string = "",
|
|
||||||
publicKey: string = "",
|
|
||||||
): string =
|
|
||||||
try:
|
|
||||||
status_go_accounts.saveAccount(
|
|
||||||
address,
|
|
||||||
name,
|
|
||||||
password,
|
|
||||||
color,
|
|
||||||
accountType,
|
|
||||||
isADerivedAccount = true,
|
|
||||||
walletIndex,
|
|
||||||
id,
|
|
||||||
publicKey,
|
|
||||||
)
|
|
||||||
let accounts = fetchAccounts()
|
let accounts = fetchAccounts()
|
||||||
let prices = self.fetchPrices()
|
let prices = self.fetchPrices()
|
||||||
|
|
||||||
|
@ -229,90 +203,60 @@ method saveAccount(
|
||||||
newAccount.tokens = self.buildTokens(newAccount, prices, balances{newAccount.address})
|
newAccount.tokens = self.buildTokens(newAccount, prices, balances{newAccount.address})
|
||||||
self.accounts[newAccount.address] = newAccount
|
self.accounts[newAccount.address] = newAccount
|
||||||
self.events.emit("walletAccount/accountSaved", AccountSaved(account: newAccount))
|
self.events.emit("walletAccount/accountSaved", AccountSaved(account: newAccount))
|
||||||
except Exception as e:
|
|
||||||
return fmt"Error adding new account: {e.msg}"
|
|
||||||
|
|
||||||
method generateNewAccount*(self: Service, password: string, accountName: string, color: string): string =
|
method generateNewAccount*(self: Service, password: string, accountName: string, color: string): string =
|
||||||
let
|
try:
|
||||||
setting = self.settingService.getSetting()
|
discard status_go_accounts.generateAccount(
|
||||||
walletRootAddress = setting.walletRootAddress
|
|
||||||
walletIndex = setting.latestDerivedPath + 1
|
|
||||||
defaultAccount = self.getDefaultAccount()
|
|
||||||
isPasswordOk = status_go_accounts.verifyAccountPassword(defaultAccount, password, KEYSTOREDIR)
|
|
||||||
|
|
||||||
if not isPasswordOk:
|
|
||||||
return "Error generating new account: invalid password"
|
|
||||||
|
|
||||||
let accountResponse = status_go_accounts.loadAccount(walletRootAddress, password)
|
|
||||||
let accountId = accountResponse.result{"id"}.getStr
|
|
||||||
let path = "m/" & $walletIndex
|
|
||||||
let deriveResponse = status_go_accounts.deriveAccounts(accountId, @[path])
|
|
||||||
let errMsg = self.saveAccount(
|
|
||||||
deriveResponse.result[path]{"address"}.getStr,
|
|
||||||
accountName,
|
|
||||||
password,
|
password,
|
||||||
|
accountName,
|
||||||
color,
|
color,
|
||||||
status_go_accounts.GENERATED,
|
|
||||||
true,
|
|
||||||
walletIndex,
|
|
||||||
accountId,
|
|
||||||
deriveResponse.result[path]{"publicKey"}.getStr
|
|
||||||
)
|
)
|
||||||
if errMsg != "":
|
except Exception as e:
|
||||||
return errMsg
|
return fmt"Error generating new account: {e.msg}"
|
||||||
|
|
||||||
discard self.settingService.saveSetting("latest-derived-path", walletIndex)
|
self.addNewAccountToLocalStore()
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
method addAccountsFromPrivateKey*(self: Service, privateKey: string, password: string, accountName: string, color: string): string =
|
method addAccountsFromPrivateKey*(self: Service, privateKey: string, password: string, accountName: string, color: string): string =
|
||||||
let
|
try:
|
||||||
accountResponse = status_go_accounts.multiAccountImportPrivateKey(privateKey)
|
discard status_go_accounts.addAccountWithPrivateKey(
|
||||||
defaultAccount = self.getDefaultAccount()
|
privateKey,
|
||||||
isPasswordOk = status_go_accounts.verifyAccountPassword(defaultAccount, password, KEYSTOREDIR)
|
|
||||||
|
|
||||||
if not isPasswordOk:
|
|
||||||
return "Error generating new account: invalid password"
|
|
||||||
|
|
||||||
return self.saveAccount(
|
|
||||||
accountResponse.result{"address"}.getStr,
|
|
||||||
accountName,
|
|
||||||
password,
|
password,
|
||||||
color,
|
|
||||||
status_go_accounts.KEY,
|
|
||||||
false,
|
|
||||||
0,
|
|
||||||
accountResponse.result{"accountId"}.getStr,
|
|
||||||
accountResponse.result{"publicKey"}.getStr,
|
|
||||||
)
|
|
||||||
|
|
||||||
method addAccountsFromSeed*(self: Service, seedPhrase: string, password: string, accountName: string, color: string): string =
|
|
||||||
let mnemonic = replace(seedPhrase, ',', ' ')
|
|
||||||
let paths = @[PATH_WALLET_ROOT, PATH_EIP_1581, PATH_WHISPER, PATH_DEFAULT_WALLET]
|
|
||||||
let accountResponse = status_go_accounts.multiAccountImportMnemonic(mnemonic)
|
|
||||||
let accountId = accountResponse.result{"id"}.getStr
|
|
||||||
let deriveResponse = status_go_accounts.deriveAccounts(accountId, paths)
|
|
||||||
|
|
||||||
let
|
|
||||||
defaultAccount = self.getDefaultAccount()
|
|
||||||
isPasswordOk = status_go_accounts.verifyAccountPassword(defaultAccount, password, KEYSTOREDIR)
|
|
||||||
|
|
||||||
if not isPasswordOk:
|
|
||||||
return "Error generating new account: invalid password"
|
|
||||||
|
|
||||||
return self.saveAccount(
|
|
||||||
deriveResponse.result[PATH_DEFAULT_WALLET]{"address"}.getStr,
|
|
||||||
accountName,
|
accountName,
|
||||||
password,
|
|
||||||
color,
|
color,
|
||||||
status_go_accounts.SEED,
|
|
||||||
true,
|
|
||||||
0,
|
|
||||||
accountId,
|
|
||||||
deriveResponse.result[PATH_DEFAULT_WALLET]{"publicKey"}.getStr
|
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
return fmt"Error adding account with private key: {e.msg}"
|
||||||
|
|
||||||
|
self.addNewAccountToLocalStore()
|
||||||
|
return ""
|
||||||
|
|
||||||
|
method addAccountsFromSeed*(self: Service, mnemonic: string, password: string, accountName: string, color: string): string =
|
||||||
|
try:
|
||||||
|
discard status_go_accounts.addAccountWithMnemonic(
|
||||||
|
mnemonic,
|
||||||
|
password,
|
||||||
|
accountName,
|
||||||
|
color,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
return fmt"Error adding account with mnemonic: {e.msg}"
|
||||||
|
|
||||||
|
self.addNewAccountToLocalStore()
|
||||||
|
return ""
|
||||||
|
|
||||||
method addWatchOnlyAccount*(self: Service, address: string, accountName: string, color: string): string =
|
method addWatchOnlyAccount*(self: Service, address: string, accountName: string, color: string): string =
|
||||||
return self.saveAccount(address, accountName, "", color, status_go_accounts.WATCH, false)
|
try:
|
||||||
|
discard status_go_accounts.addAccountWatch(
|
||||||
|
address,
|
||||||
|
accountName,
|
||||||
|
color,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
return fmt"Error adding account with mnemonic: {e.msg}"
|
||||||
|
|
||||||
|
self.addNewAccountToLocalStore()
|
||||||
|
return ""
|
||||||
|
|
||||||
method deleteAccount*(self: Service, address: string) =
|
method deleteAccount*(self: Service, address: string) =
|
||||||
discard status_go_accounts.deleteAccount(address)
|
discard status_go_accounts.deleteAccount(address)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 40a908e528938d2fe156631690c9c1b10a69ab52
|
Subproject commit 7413bbde00a015fe5fca37846448135f1b43b2cf
|
Loading…
Reference in New Issue