Commit 9cf65ea3 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Added method to get an account by name

parent f3647040
...@@ -125,6 +125,23 @@ namespace Breeze.Wallet ...@@ -125,6 +125,23 @@ namespace Breeze.Wallet
var index = unusedAccounts.Min(a => a.Index); var index = unusedAccounts.Min(a => a.Index);
return unusedAccounts.Single(a => a.Index == index); return unusedAccounts.Single(a => a.Index == index);
} }
/// <summary>
/// Gets the account matching the name passed as a parameter.
/// </summary>
/// <param name="accountName">The name of the account to get.</param>
/// <returns></returns>
/// <exception cref="System.Exception"></exception>
public HdAccount GetAccountByName(string accountName)
{
// get the account
HdAccount account = this.Accounts.SingleOrDefault(a => a.Name == accountName);
if (account == null)
{
throw new Exception($"No account with name {accountName} could be found.");
}
return account;
}
} }
/// <summary> /// <summary>
...@@ -257,7 +274,7 @@ namespace Breeze.Wallet ...@@ -257,7 +274,7 @@ namespace Breeze.Wallet
{ {
var addresses = this.ExternalAddresses.Concat(this.InternalAddresses); var addresses = this.ExternalAddresses.Concat(this.InternalAddresses);
return addresses.SelectMany(a => a.Transactions.Where(t => t.Id == id)); return addresses.SelectMany(a => a.Transactions.Where(t => t.Id == id));
} }
} }
/// <summary> /// <summary>
......
...@@ -203,18 +203,14 @@ namespace Breeze.Wallet ...@@ -203,18 +203,14 @@ namespace Breeze.Wallet
return newAccount; return newAccount;
} }
/// <inheritdoc /> /// <inheritdoc />
public string GetUnusedAddress(string walletName, CoinType coinType, string accountName) public string GetUnusedAddress(string walletName, CoinType coinType, string accountName)
{ {
Wallet wallet = this.GetWalletByName(walletName); Wallet wallet = this.GetWalletByName(walletName);
// get the account // get the account
HdAccount account = wallet.AccountsRoot.Single(a => a.CoinType == coinType).Accounts.SingleOrDefault(a => a.Name == accountName); HdAccount account = wallet.AccountsRoot.Single(a => a.CoinType == coinType).GetAccountByName(accountName);
if (account == null)
{
throw new Exception($"No account with name {accountName} could be found.");
}
// validate address creation // validate address creation
if (account.ExternalAddresses.Any()) if (account.ExternalAddresses.Any())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment