Commit 135a3452 authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Merge pull request #44 from bokobza/feature/build-transaction

Feature/build transaction
parents 823f271e d520c752
...@@ -295,4 +295,4 @@ Thumbs.db ...@@ -295,4 +295,4 @@ Thumbs.db
# DNX # DNX
project.lock.json project.lock.json
/Breeze/src/Breeze.Deamon/Wallets /Breeze/src/Breeze.Daemon/Wallets
...@@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Breeze.Api.Tests", "src\Bre ...@@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Breeze.Api.Tests", "src\Bre
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Breeze.Wallet", "src\Breeze.Wallet\Breeze.Wallet.csproj", "{D16CD478-9D1E-4C69-91AD-43539E94A215}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Breeze.Wallet", "src\Breeze.Wallet\Breeze.Wallet.csproj", "{D16CD478-9D1E-4C69-91AD-43539E94A215}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Breeze.Deamon", "src\Breeze.Deamon\Breeze.Deamon.csproj", "{1B598E33-667F-496D-BC0D-88276E8E7632}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Breeze.Daemon", "src\Breeze.Daemon\Breeze.Daemon.csproj", "{1B598E33-667F-496D-BC0D-88276E8E7632}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>..\\Breeze.Deamon\\bin\\Debug\\netcoreapp1.0\\Breeze.Api.xml</DocumentationFile> <DocumentationFile>..\\Breeze.Daemon\\bin\\Debug\\netcoreapp1.0\\Breeze.Api.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework> <TargetFramework>netcoreapp1.0</TargetFramework>
<AssemblyName>Breeze.Deamon</AssemblyName> <AssemblyName>Breeze.Daemon</AssemblyName>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<PackageId>Breeze.Deamon</PackageId> <PackageId>Breeze.Daemon</PackageId>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion> <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback> <PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
......
...@@ -9,7 +9,7 @@ using Stratis.Bitcoin.Logging; ...@@ -9,7 +9,7 @@ using Stratis.Bitcoin.Logging;
using Breeze.Wallet; using Breeze.Wallet;
using Stratis.Bitcoin.Notifications; using Stratis.Bitcoin.Notifications;
namespace Breeze.Deamon namespace Breeze.Daemon
{ {
public class Program public class Program
{ {
......
...@@ -7,7 +7,7 @@ using System.Runtime.InteropServices; ...@@ -7,7 +7,7 @@ using System.Runtime.InteropServices;
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Breeze.Deamon")] [assembly: AssemblyProduct("Breeze.Daemon")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
// Setting ComVisible to false makes the types in this assembly not visible // Setting ComVisible to false makes the types in this assembly not visible
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>..\\Breeze.Deamon\\bin\\Debug\\netcoreapp1.0\\Breeze.Wallet.xml</DocumentationFile> <DocumentationFile>..\\Breeze.Daemon\\bin\\Debug\\netcoreapp1.0\\Breeze.Wallet.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
......
...@@ -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>
...@@ -219,7 +246,18 @@ namespace Breeze.Wallet ...@@ -219,7 +246,18 @@ namespace Breeze.Wallet
// gets the used address with the highest index // gets the used address with the highest index
var index = usedAddresses.Max(a => a.Index); var index = usedAddresses.Max(a => a.Index);
return usedAddresses.Single(a => a.Index == index); return usedAddresses.Single(a => a.Index == index);
} }
/// <summary>
/// Gets a collection of transactions by id.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns></returns>
public IEnumerable<TransactionData> GetTransactionsById(uint256 id)
{
var addresses = this.ExternalAddresses.Concat(this.InternalAddresses);
return addresses.SelectMany(a => a.Transactions.Where(t => t.Id == id));
}
} }
/// <summary> /// <summary>
...@@ -232,14 +270,7 @@ namespace Breeze.Wallet ...@@ -232,14 +270,7 @@ namespace Breeze.Wallet
/// </summary> /// </summary>
[JsonProperty(PropertyName = "index")] [JsonProperty(PropertyName = "index")]
public int Index { get; set; } public int Index { get; set; }
/// <summary>
/// Gets or sets the creation time.
/// </summary>
[JsonProperty(PropertyName = "creationTime")]
[JsonConverter(typeof(DateTimeOffsetConverter))]
public DateTimeOffset CreationTime { get; set; }
/// <summary> /// <summary>
/// The script pub key for this address. /// The script pub key for this address.
/// </summary> /// </summary>
...@@ -284,6 +315,13 @@ namespace Breeze.Wallet ...@@ -284,6 +315,13 @@ namespace Breeze.Wallet
[JsonConverter(typeof(UInt256JsonConverter))] [JsonConverter(typeof(UInt256JsonConverter))]
public uint256 Id { get; set; } public uint256 Id { get; set; }
/// <summary>
/// The id of the transaction in which the output referenced in this transaction is spent.
/// </summary>
[JsonProperty(PropertyName = "spentIn", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(UInt256JsonConverter))]
public uint256 SpentInTransaction { get; set; }
/// <summary> /// <summary>
/// The transaction amount. /// The transaction amount.
/// </summary> /// </summary>
......
This diff is collapsed.
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