Commit 1e30455d authored by Jeremy Bokobza's avatar Jeremy Bokobza

better history objects

parent 405ac690
...@@ -198,8 +198,9 @@ namespace Breeze.Wallet.Controllers ...@@ -198,8 +198,9 @@ namespace Breeze.Wallet.Controllers
{ {
WalletHistoryModel model = new WalletHistoryModel { Transactions = new List<TransactionItem>() }; WalletHistoryModel model = new WalletHistoryModel { Transactions = new List<TransactionItem>() };
var accounts = this.walletManager.GetAccountsByCoinType(request.WalletName, request.CoinType).ToList(); // get transactions contained in the wallet
foreach (var address in accounts.SelectMany(a => a.ExternalAddresses).Concat(accounts.SelectMany(a => a.InternalAddresses))) var addresses = this.walletManager.GetHistoryByCoinType(request.WalletName, request.CoinType);
foreach (var address in addresses)
{ {
foreach (var transaction in address.Transactions) foreach (var transaction in address.Transactions)
{ {
...@@ -213,7 +214,7 @@ namespace Breeze.Wallet.Controllers ...@@ -213,7 +214,7 @@ namespace Breeze.Wallet.Controllers
}); });
} }
} }
model.Transactions = model.Transactions.OrderByDescending(t => t.Timestamp).ToList(); model.Transactions = model.Transactions.OrderByDescending(t => t.Timestamp).ToList();
return this.Json(model); return this.Json(model);
} }
......
...@@ -74,7 +74,7 @@ namespace Breeze.Wallet ...@@ -74,7 +74,7 @@ namespace Breeze.Wallet
/// </remarks> /// </remarks>
/// <returns>An unused account.</returns> /// <returns>An unused account.</returns>
HdAccount GetUnusedAccount(Wallet wallet, CoinType coinType, string password); HdAccount GetUnusedAccount(Wallet wallet, CoinType coinType, string password);
/// <summary> /// <summary>
/// Creates a new account. /// Creates a new account.
/// </summary> /// </summary>
...@@ -97,6 +97,22 @@ namespace Breeze.Wallet ...@@ -97,6 +97,22 @@ namespace Breeze.Wallet
/// <returns>An unused address or a newly created address, in Base58 format.</returns> /// <returns>An unused address or a newly created address, in Base58 format.</returns>
string GetUnusedAddress(string walletName, CoinType coinType, string accountName); string GetUnusedAddress(string walletName, CoinType coinType, string accountName);
/// <summary>
/// Gets a collection of addresses containing transactions for this coin.
/// </summary>
/// <param name="walletName">The name of the wallet to get history from.</param>
/// <param name="coinType">Type of the coin.</param>
/// <returns></returns>
IEnumerable<HdAddress> GetHistoryByCoinType(string walletName, CoinType coinType);
/// <summary>
/// Gets a collection of addresses containing transactions for this coin.
/// </summary>
/// <param name="wallet">The wallet to get history from.</param>
/// <param name="coinType">Type of the coin.</param>
/// <returns></returns>
IEnumerable<HdAddress> GetHistoryByCoinType(Wallet wallet, CoinType coinType);
WalletGeneralInfoModel GetGeneralInfo(string walletName); WalletGeneralInfoModel GetGeneralInfo(string walletName);
/// <summary> /// <summary>
...@@ -126,6 +142,6 @@ namespace Breeze.Wallet ...@@ -126,6 +142,6 @@ namespace Breeze.Wallet
/// <param name="transaction">The transaction.</param> /// <param name="transaction">The transaction.</param>
/// <param name="blockHeight">The height of the block this transaction came from. Null if it was not a transaction included in a block.</param> /// <param name="blockHeight">The height of the block this transaction came from. Null if it was not a transaction included in a block.</param>
/// <param name="blockTime">The block time.</param> /// <param name="blockTime">The block time.</param>
void ProcessTransaction(CoinType coinType, NBitcoin.Transaction transaction, int? blockHeight = null, uint? blockTime = null); void ProcessTransaction(CoinType coinType, NBitcoin.Transaction transaction, int? blockHeight = null, uint? blockTime = null);
} }
} }
...@@ -57,6 +57,33 @@ namespace Breeze.Wallet ...@@ -57,6 +57,33 @@ namespace Breeze.Wallet
/// </summary> /// </summary>
[JsonProperty(PropertyName = "accountsRoot")] [JsonProperty(PropertyName = "accountsRoot")]
public IEnumerable<AccountRoot> AccountsRoot { get; set; } public IEnumerable<AccountRoot> AccountsRoot { get; set; }
/// <summary>
/// Gets the type of the accounts by coin.
/// </summary>
/// <param name="coinType">Type of the coin.</param>
/// <returns></returns>
public IEnumerable<HdAccount> GetAccountsByCoinType(CoinType coinType)
{
return this.AccountsRoot.Where(a => a.CoinType == coinType).SelectMany(a => a.Accounts);
}
/// <summary>
/// Gets all the transactions by coin type.
/// </summary>
/// <param name="coinType">Type of the coin.</param>
/// <returns></returns>
public IEnumerable<TransactionData> GetAllTransactionsByCoinType(CoinType coinType)
{
List<TransactionData> result = new List<TransactionData>();
var accounts = this.GetAccountsByCoinType(coinType).ToList();
foreach (var address in accounts.SelectMany(a => a.ExternalAddresses).Concat(accounts.SelectMany(a => a.InternalAddresses)))
{
result.AddRange(address.Transactions);
}
return result;
}
} }
/// <summary> /// <summary>
......
...@@ -242,6 +242,32 @@ namespace Breeze.Wallet ...@@ -242,6 +242,32 @@ namespace Breeze.Wallet
return account.GetFirstUnusedExternalAddress().Address; return account.GetFirstUnusedExternalAddress().Address;
} }
/// <inheritdoc />
public IEnumerable<HdAddress> GetHistoryByCoinType(string walletName, CoinType coinType)
{
Wallet wallet = this.Wallets.SingleOrDefault(w => w.Name == walletName);
if (wallet == null)
{
throw new Exception($"No wallet with name {walletName} could be found.");
}
return this.GetHistoryByCoinType(wallet, coinType);
}
/// <inheritdoc />
public IEnumerable<HdAddress> GetHistoryByCoinType(Wallet wallet, CoinType coinType)
{
var accounts = wallet.GetAccountsByCoinType(coinType).ToList();
foreach (var address in accounts.SelectMany(a => a.ExternalAddresses).Concat(accounts.SelectMany(a => a.InternalAddresses)))
{
if (address.Transactions.Any())
{
yield return address;
}
}
}
/// <summary> /// <summary>
/// Creates a number of addresses in the provided account. /// Creates a number of addresses in the provided account.
/// </summary> /// </summary>
...@@ -301,9 +327,13 @@ namespace Breeze.Wallet ...@@ -301,9 +327,13 @@ namespace Breeze.Wallet
/// <inheritdoc /> /// <inheritdoc />
public IEnumerable<HdAccount> GetAccountsByCoinType(string walletName, CoinType coinType) public IEnumerable<HdAccount> GetAccountsByCoinType(string walletName, CoinType coinType)
{ {
return this.Wallets. Wallet wallet = this.Wallets.SingleOrDefault(w => w.Name == walletName);
SelectMany(w => w.AccountsRoot.Where(a => a.CoinType == coinType)). if (wallet == null)
SelectMany(a => a.Accounts); {
throw new Exception($"No wallet with name {walletName} could be found.");
}
return wallet.GetAccountsByCoinType(coinType);
} }
public WalletBuildTransactionModel BuildTransaction(string password, string address, Money amount, string feeType, bool allowUnconfirmed) public WalletBuildTransactionModel BuildTransaction(string password, string address, Money amount, string feeType, bool allowUnconfirmed)
......
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