Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Blockcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Networks.SeniorBl
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Networks.RoyalSportsCity", "Networks\Blockcore.Networks.RoyalSportsCity\Blockcore.Networks.RoyalSportsCity.csproj", "{D176C98F-E2EF-49C6-B073-32F08889BD27}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Consensus.Host", "Features\Blockcore.Features.Consensus.Host\Blockcore.Features.Consensus.Host.csproj", "{83A17E7D-FC7F-4F7D-A22F-C94E9A70DAEF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.MemoryPool.Host", "Features\Blockcore.Features.MemoryPool.Host\Blockcore.Features.MemoryPool.Host.csproj", "{A54A4DB3-C1D9-4C5F-A636-FE448AA36174}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Wallet.Host", "Features\Blockcore.Features.Wallet.Host\Blockcore.Features.Wallet.Host.csproj", "{77E48C55-353E-4E51-A904-A021C961FA81}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blockcore.Features.BlockStore.Host", "Features\Blockcore.Features.BlockStore.Host\Blockcore.Features.BlockStore.Host.csproj", "{2D445BEF-2578-4A5A-99AA-7EB9E90A37A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blockcore.Features.Miner.Host", "Features\Blockcore.Features.Miner.Host\Blockcore.Features.Miner.Host.csproj", "{C887B83D-815C-4CFF-BA8E-4EB148C7F488}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -404,6 +414,26 @@ Global
{D176C98F-E2EF-49C6-B073-32F08889BD27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D176C98F-E2EF-49C6-B073-32F08889BD27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D176C98F-E2EF-49C6-B073-32F08889BD27}.Release|Any CPU.Build.0 = Release|Any CPU
{83A17E7D-FC7F-4F7D-A22F-C94E9A70DAEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83A17E7D-FC7F-4F7D-A22F-C94E9A70DAEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83A17E7D-FC7F-4F7D-A22F-C94E9A70DAEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83A17E7D-FC7F-4F7D-A22F-C94E9A70DAEF}.Release|Any CPU.Build.0 = Release|Any CPU
{A54A4DB3-C1D9-4C5F-A636-FE448AA36174}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A54A4DB3-C1D9-4C5F-A636-FE448AA36174}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A54A4DB3-C1D9-4C5F-A636-FE448AA36174}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A54A4DB3-C1D9-4C5F-A636-FE448AA36174}.Release|Any CPU.Build.0 = Release|Any CPU
{77E48C55-353E-4E51-A904-A021C961FA81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77E48C55-353E-4E51-A904-A021C961FA81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77E48C55-353E-4E51-A904-A021C961FA81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77E48C55-353E-4E51-A904-A021C961FA81}.Release|Any CPU.Build.0 = Release|Any CPU
{2D445BEF-2578-4A5A-99AA-7EB9E90A37A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D445BEF-2578-4A5A-99AA-7EB9E90A37A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D445BEF-2578-4A5A-99AA-7EB9E90A37A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D445BEF-2578-4A5A-99AA-7EB9E90A37A2}.Release|Any CPU.Build.0 = Release|Any CPU
{C887B83D-815C-4CFF-BA8E-4EB148C7F488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C887B83D-815C-4CFF-BA8E-4EB148C7F488}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C887B83D-815C-4CFF-BA8E-4EB148C7F488}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C887B83D-815C-4CFF-BA8E-4EB148C7F488}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -472,6 +502,11 @@ Global
{2834DEF2-0CF7-4012-A73D-07F06256CC75} = {3B56C02B-4468-4268-B797-851562789FCC}
{9C962CB5-A11B-47F1-A5D3-2AD2215CF100} = {3B56C02B-4468-4268-B797-851562789FCC}
{D176C98F-E2EF-49C6-B073-32F08889BD27} = {3B56C02B-4468-4268-B797-851562789FCC}
{83A17E7D-FC7F-4F7D-A22F-C94E9A70DAEF} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{A54A4DB3-C1D9-4C5F-A636-FE448AA36174} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{77E48C55-353E-4E51-A904-A021C961FA81} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{2D445BEF-2578-4A5A-99AA-7EB9E90A37A2} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
{C887B83D-815C-4CFF-BA8E-4EB148C7F488} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6C780ABA-5872-4B83-AD3F-A5BD423AD907}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public IActionResult GetAddressesBalances(string addresses, int minConfirmations

this.logger.LogDebug("Asking data for {0} addresses.", addressesArray.Length);

AddressBalancesResult result = this.addressIndexer.GetAddressBalances(addressesArray, minConfirmations);
AddressIndexing.AddressBalancesResult result = this.addressIndexer.GetAddressBalances(addressesArray, minConfirmations);

this.logger.LogDebug("Sending data for {0} addresses.", result.Balances.Count);

Expand All @@ -221,7 +221,7 @@ public IActionResult GetVerboseAddressesBalancesData(string addresses)

this.logger.LogDebug("Asking data for {0} addresses.", addressesArray.Length);

VerboseAddressBalancesResult result = this.addressIndexer.GetAddressIndexerState(addressesArray);
AddressIndexing.VerboseAddressBalancesResult result = this.addressIndexer.GetAddressIndexerState(addressesArray);

return this.Json(result);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Blockcore Features BlockStore Host</Description>
<AssemblyTitle>Blockcore.Features.BlockStore.Host</AssemblyTitle>
<AssemblyName>Blockcore.Features.BlockStore.Host</AssemblyName>
<PackageId>Blockcore.Features.BlockStore.Host</PackageId>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Blockcore</Authors>
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.3.310801">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
<ProjectReference Include="..\Blockcore.Features.BlockStore\Blockcore.Features.BlockStore.csproj" />
<ProjectReference Include="..\Blockcore.Features.RPC\Blockcore.Features.RPC.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;IDE0008;</NoWarn>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using System.Collections.Generic;
using Blockcore.Utilities.JsonConverters;
using LiteDB;
using NBitcoin;
using Newtonsoft.Json;

namespace Blockcore.Features.BlockStore.AddressIndexing
{
/// <summary>
/// A class that contains a list of balances per address as requested.
/// <para>
/// Should the request fail the <see cref="Reason"/> will be populated.
/// </para>
/// </summary>
public sealed class AddressBalancesResult
{
public AddressBalancesResult()
{
this.Balances = new List<AddressBalanceResult>();
}

public List<AddressBalanceResult> Balances { get; set; }

[JsonProperty("reason")]
public string Reason { get; private set; }

public static AddressBalancesResult RequestFailed(string reason)
{
return new AddressBalancesResult() { Reason = reason };
}
}

/// <summary>
/// A class that contains the balance for a given address.
/// </summary>
public sealed class AddressBalanceResult
{
public AddressBalanceResult() { }

public AddressBalanceResult(string address, Money balance)
{
this.Address = address;
this.Balance = balance;
}

[JsonProperty("address")]
public string Address { get; set; }

[JsonProperty("balance")]
[JsonConverter(typeof(MoneyJsonConverter))]
public Money Balance { get; set; }
}

/// <summary>
/// A class that contains a list of balances data per address as requested.
/// <para>Should the request fail the <see cref="Reason"/> will be populated.</para>
/// </summary>
public sealed class VerboseAddressBalancesResult
{
private VerboseAddressBalancesResult()
{
this.BalancesData = new List<AddressIndexerData>();
}

public VerboseAddressBalancesResult(int consensusTipHeight) : this()
{
this.ConsensusTipHeight = consensusTipHeight;
}

public List<AddressIndexerData> BalancesData { get; set; }

public int ConsensusTipHeight { get; set; }

[JsonProperty("reason")]
public string Reason { get; private set; }

public static VerboseAddressBalancesResult RequestFailed(string reason)
{
return new VerboseAddressBalancesResult() { Reason = reason };
}
}

public class AddressIndexerData
{
[BsonId]
public string Address { get; set; }

public List<AddressBalanceChange> BalanceChanges { get; set; }
}

public class AddressBalanceChange
{
/// <summary><c>true</c> if there was a deposit to an address, <c>false</c> if it was a withdrawal.</summary>
public bool Deposited { get; set; }

public long Satoshi { get; set; }

/// <summary>Height of a block in which operation was confirmed.</summary>
public int BalanceChangedHeight { get; set; }

/// <inheritdoc />
public override string ToString()
{
return $"{nameof(this.Deposited)}:{this.Deposited}, {nameof(this.Satoshi)}:{this.Satoshi}, {nameof(this.BalanceChangedHeight)}:{this.BalanceChangedHeight}";
}
}

public static class AddressBalanceChangeExtensions
{
public static long CalculateBalance(this IEnumerable<AddressBalanceChange> balanceChanges)
{
long balance = 0;

foreach (AddressBalanceChange change in balanceChanges)
{
if (change.Deposited)
balance += change.Satoshi;
else
balance -= change.Satoshi;
}

return balance;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Blockcore.Controllers.Models;
using Blockcore.Utilities;
using LiteDB;
using Microsoft.Extensions.Logging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Blockcore.Consensus.BlockInfo;
using Blockcore.Consensus.Chain;
using Blockcore.Consensus.TransactionInfo;
using Blockcore.Controllers.Models;
using Blockcore.Interfaces;
using Blockcore.Networks;
using Blockcore.Utilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
<ProjectReference Include="..\Blockcore.Features.RPC\Blockcore.Features.RPC.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
<ProjectReference Include="..\Blockcore.Features.Wallet.Host\Blockcore.Features.Wallet.Host.csproj" />
<ProjectReference Include="..\Blockcore.Features.Wallet\Blockcore.Features.Wallet.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Blockcore Features Consensus Host</Description>
<AssemblyTitle>Blockcore.Features.Consensus.Host</AssemblyTitle>
<AssemblyName>Blockcore.Features.Consensus.Host</AssemblyName>
<PackageId>Blockcore.Features.Consensus.Host</PackageId>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Blockcore</Authors>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
<ProjectReference Include="..\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
<ProjectReference Include="..\Blockcore.Features.NodeHost\Blockcore.Features.NodeHost.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;IDE0008;</NoWarn>
<DocumentationFile></DocumentationFile>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Blockcore Features MemoryPool Host</Description>
<AssemblyTitle>Blockcore.Features.MemoryPool.Host</AssemblyTitle>
<AssemblyName>Blockcore.Features.MemoryPool.Host</AssemblyName>
<PackageId>Blockcore.Features.MemoryPool.Host</PackageId>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<ApplicationIcon />
<OutputTypeEx>library</OutputTypeEx>
<StartupObject />
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Blockcore.Features.Consensus\Blockcore.Features.Consensus.csproj" />
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
<ProjectReference Include="..\Blockcore.Features.MemoryPool\Blockcore.Features.MemoryPool.csproj" />
<ProjectReference Include="..\Blockcore.Features.NodeHost\Blockcore.Features.NodeHost.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputType>Library</OutputType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;IDE0008;</NoWarn>
<DocumentationFile></DocumentationFile>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<Description>Blockcore Features Miner Host</Description>
<AssemblyTitle>Blockcore.Features.Miner.Host</AssemblyTitle>
<AssemblyName>Blockcore.Features.Miner.Host</AssemblyName>
<PackageId>Blockcore.Features.Miner.Host</PackageId>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Blockcore.Features.Miner\**" />
<EmbeddedResource Remove="Blockcore.Features.Miner\**" />
<None Remove="Blockcore.Features.Miner\**" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Blockcore.Features.MemoryPool\Blockcore.Features.MemoryPool.csproj" />
<ProjectReference Include="..\Blockcore.Features.Miner\Blockcore.Features.Miner.csproj" />
<ProjectReference Include="..\Blockcore.Features.NodeHost\Blockcore.Features.NodeHost.csproj" />
<ProjectReference Include="..\Blockcore.Features.RPC\Blockcore.Features.RPC.csproj" />
<ProjectReference Include="..\Blockcore.Features.Wallet\Blockcore.Features.Wallet.csproj" />
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;IDE0008;</NoWarn>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.3.310801">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>
</Project>
Loading