Mirror Wallet changes in TokenaryWallet

This commit is contained in:
Ivan Grachev 2022-04-30 00:11:48 +03:00
parent 17cd7b9878
commit 76130c3d40
2 changed files with 22 additions and 0 deletions

View File

@ -43,6 +43,22 @@ public final class Wallet: Hashable, Equatable {
return account
}
/// Returns the account for a specific coin and derivation.
///
/// - Parameters:
/// - password: wallet encryption password
/// - coin: coin type
/// - derivation: derivation, a specific or default
/// - Returns: the account
/// - Throws: `KeyStore.Error.invalidPassword` if the password is incorrect.
public func getAccount(password: String, coin: CoinType, derivation: Derivation) throws -> Account {
let wallet = key.wallet(password: Data(password.utf8))
guard let account = key.accountForCoinDerivation(coin: coin, derivation: derivation, wallet: wallet) else {
throw KeyStore.Error.invalidPassword
}
return account
}
/// Returns the accounts for a specific coins.
///
/// - Parameters:

View File

@ -24,6 +24,12 @@ final class TokenaryWallet: Hashable, Equatable {
return account
}
func getAccount(password: String, coin: CoinType, derivation: Derivation) throws -> Account {
let wallet = key.wallet(password: Data(password.utf8))
guard let account = key.accountForCoinDerivation(coin: coin, derivation: derivation, wallet: wallet) else { throw KeyStore.Error.invalidPassword }
return account
}
func getAccounts(password: String, coins: [CoinType]) throws -> [Account] {
guard let wallet = key.wallet(password: Data(password.utf8)) else { throw KeyStore.Error.invalidPassword }
return coins.compactMap({ key.accountForCoin(coin: $0, wallet: wallet) })