Skip to content

Commit 1e6013a

Browse files
Added listtransactions RPC (#159)
* Added WatchOnlyWallet and Notifications This is in preperation for the listtransaction RPC * Added WalletWatchOnly and Notification Tests * Added WalletWatchOnly To Blockcore Solution. * Added listtransactions RPC * Changed include_watchonly to be true by default like 0.20.0 RPC. * Added ability to select account in listtransactions * Remove notifications assembly as it's already in property files
1 parent 5020f38 commit 1e6013a

40 files changed

Lines changed: 1493 additions & 182 deletions

File tree

src/Blockcore.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Node", "Node", "{8820C3A5-7
118118
EndProject
119119
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Node", "Node\Blockcore.Node\Blockcore.Node.csproj", "{D0A183FE-C913-4F8F-92EC-BD4502745140}"
120120
EndProject
121+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Notifications", "Features\Blockcore.Features.Notifications\Blockcore.Features.Notifications.csproj", "{B3D4208F-797A-4893-BC33-BAB77508DFEE}"
122+
EndProject
123+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.Notifications.Tests", "Tests\Blockcore.Features.Notifications.Tests\Blockcore.Features.Notifications.Tests.csproj", "{EADB5247-F704-4B87-8B0E-606730B8517A}"
124+
EndProject
125+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.WalletWatchOnly", "Features\Blockcore.Features.WalletWatchOnly\Blockcore.Features.WalletWatchOnly.csproj", "{F64554A3-EC9A-4DBF-9AD6-25C78176C74E}"
126+
EndProject
127+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blockcore.Features.WalletWatchOnly.Tests", "Tests\Blockcore.Features.WalletWatchOnly.Tests\Blockcore.Features.WalletWatchOnly.Tests.csproj", "{53DA5042-1325-48A0-815A-C586590EC2EB}"
128+
EndProject
121129
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Rutanio", "Rutanio", "{50759380-AF62-11EA-BC6D-7563ABA8C5CA}"
122130
EndProject
123131
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rutanio.Node", "Networks\Rutanio\Rutanio.Node\Rutanio.Node.csproj", "{EECEF785-EC8C-4037-9BF9-1DACABDE0E3D}"
@@ -302,6 +310,22 @@ Global
302310
{D0A183FE-C913-4F8F-92EC-BD4502745140}.Debug|Any CPU.Build.0 = Debug|Any CPU
303311
{D0A183FE-C913-4F8F-92EC-BD4502745140}.Release|Any CPU.ActiveCfg = Release|Any CPU
304312
{D0A183FE-C913-4F8F-92EC-BD4502745140}.Release|Any CPU.Build.0 = Release|Any CPU
313+
{B3D4208F-797A-4893-BC33-BAB77508DFEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
314+
{B3D4208F-797A-4893-BC33-BAB77508DFEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
315+
{B3D4208F-797A-4893-BC33-BAB77508DFEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
316+
{B3D4208F-797A-4893-BC33-BAB77508DFEE}.Release|Any CPU.Build.0 = Release|Any CPU
317+
{EADB5247-F704-4B87-8B0E-606730B8517A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
318+
{EADB5247-F704-4B87-8B0E-606730B8517A}.Debug|Any CPU.Build.0 = Debug|Any CPU
319+
{EADB5247-F704-4B87-8B0E-606730B8517A}.Release|Any CPU.ActiveCfg = Release|Any CPU
320+
{EADB5247-F704-4B87-8B0E-606730B8517A}.Release|Any CPU.Build.0 = Release|Any CPU
321+
{F64554A3-EC9A-4DBF-9AD6-25C78176C74E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
322+
{F64554A3-EC9A-4DBF-9AD6-25C78176C74E}.Debug|Any CPU.Build.0 = Debug|Any CPU
323+
{F64554A3-EC9A-4DBF-9AD6-25C78176C74E}.Release|Any CPU.ActiveCfg = Release|Any CPU
324+
{F64554A3-EC9A-4DBF-9AD6-25C78176C74E}.Release|Any CPU.Build.0 = Release|Any CPU
325+
{53DA5042-1325-48A0-815A-C586590EC2EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
326+
{53DA5042-1325-48A0-815A-C586590EC2EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
327+
{53DA5042-1325-48A0-815A-C586590EC2EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
328+
{53DA5042-1325-48A0-815A-C586590EC2EB}.Release|Any CPU.Build.0 = Release|Any CPU
305329
{EECEF785-EC8C-4037-9BF9-1DACABDE0E3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
306330
{EECEF785-EC8C-4037-9BF9-1DACABDE0E3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
307331
{EECEF785-EC8C-4037-9BF9-1DACABDE0E3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -363,6 +387,10 @@ Global
363387
{36CE71D7-812A-40D7-96B7-8220E8E86643} = {88A9A633-DA22-412B-A04C-2A3405D3E2C8}
364388
{8E17F166-F15A-42F7-9407-06CE2A4AA0AF} = {88A9A633-DA22-412B-A04C-2A3405D3E2C8}
365389
{D0A183FE-C913-4F8F-92EC-BD4502745140} = {8820C3A5-74B4-45AB-B80C-2495DFBA4A2B}
390+
{B3D4208F-797A-4893-BC33-BAB77508DFEE} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
391+
{EADB5247-F704-4B87-8B0E-606730B8517A} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
392+
{F64554A3-EC9A-4DBF-9AD6-25C78176C74E} = {15D29FFD-6142-4DC5-AFFD-10BA0CA55C45}
393+
{53DA5042-1325-48A0-815A-C586590EC2EB} = {EAE139C2-B19C-4905-9117-8A4068ABD3D2}
366394
{EECEF785-EC8C-4037-9BF9-1DACABDE0E3D} = {50759380-AF62-11EA-BC6D-7563ABA8C5CA}
367395
{271E03B3-5DD6-4A16-A54A-1E72AF9B4902} = {50759380-AF62-11EA-BC6D-7563ABA8C5CA}
368396
EndGlobalSection

src/Blockcore/Configuration/Logging/LoggingConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ private static void AddFilters(LogSettings settings = null, DataFolder dataFolde
218218
{
219219
if (!KeyCategories.TryGetValue(key.Trim(), out string category))
220220
{
221-
// Allow direct specification - e.g. "-debug=Stratis.Bitcoin.Miner".
221+
// Allow direct specification - e.g. "-debug=Blockcore.Miner".
222222
category = key.Trim();
223223
}
224224

@@ -276,7 +276,7 @@ public static void ConfigureConsoleFilters(ILoggingBuilder builder, LogSettings
276276
{
277277
if (!KeyCategories.TryGetValue(key.Trim(), out string category))
278278
{
279-
// Allow direct specification - e.g. "-debug=Stratis.Bitcoin.Miner".
279+
// Allow direct specification - e.g. "-debug=Blockcore.Miner".
280280
category = key.Trim();
281281
}
282282

src/Blockcore/Configuration/NodeSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public static void PrintHelp(Network network)
375375
builder.AppendLine($"-conf=<Path> Path to the configuration file. Defaults to {defaults.ConfigurationFile}.");
376376
builder.AppendLine($"-datadir=<Path> Path to the data directory. Defaults to {defaults.DataDir}.");
377377
builder.AppendLine($"-datadirroot=<Path> The path to the root data directory, which holds all node data on the machine. Defaults to 'Blockcore'.");
378-
builder.AppendLine($"-debug[=<string>] Set 'Debug' logging level. Specify what to log via e.g. '-debug=Blockcore.Miner,Stratis.Bitcoin.Wallet'.");
378+
builder.AppendLine($"-debug[=<string>] Set 'Debug' logging level. Specify what to log via e.g. '-debug=Blockcore.Miner,Blockcore.Wallet'.");
379379
builder.AppendLine($"-loglevel=<string> Direct control over the logging level: '-loglevel=trace/debug/info/warn/error/fatal'.");
380380

381381
// Can be overridden in configuration file.

src/External/NBitcoin/ChainIndexer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public virtual IEnumerable<ChainedHeader> EnumerateAfter(ChainedHeader block)
179179
}
180180

181181
/// <summary>
182-
/// TODO: Make this internal when the component moves to Stratis.Bitcoin
182+
/// TODO: Make this internal when the component moves to Blockcore
183183
/// </summary>
184184
public void Add(ChainedHeader addTip)
185185
{
@@ -196,7 +196,7 @@ public void Add(ChainedHeader addTip)
196196
}
197197

198198
/// <summary>
199-
/// TODO: Make this internal when the component moves to Stratis.Bitcoin
199+
/// TODO: Make this internal when the component moves to Blockcore
200200
/// </summary>
201201
public void Remove(ChainedHeader removeTip)
202202
{

src/Features/Blockcore.Features.NodeHost/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ASPNETCORE_ENVIRONMENT": "Development"
1616
}
1717
},
18-
"Stratis.Bitcoin.Api": {
18+
"Blockcore.Api": {
1919
"commandName": "Project",
2020
"launchUrl": "http://localhost:37220/api/values",
2121
"environmentVariables": {
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
using Microsoft.Extensions.Logging;
4+
using NBitcoin;
5+
using Blockcore.AsyncWork;
6+
using Blockcore.Consensus;
7+
using Blockcore.Features.Notifications.Interfaces;
8+
using Blockcore.Signals;
9+
using Blockcore.Utilities;
10+
11+
namespace Blockcore.Features.Notifications
12+
{
13+
// =================================================================
14+
// TODO: This class is broken and the logic needs to be redesigned, this effects light wallet.
15+
// =================================================================
16+
17+
/// <summary>
18+
/// Class used to broadcast about new blocks.
19+
/// </summary>
20+
public class BlockNotification : IBlockNotification
21+
{
22+
/// <summary>The async loop we need to wait upon before we can shut down this manager.</summary>
23+
private IAsyncLoop asyncLoop;
24+
25+
/// <summary>Factory for creating background async loop tasks.</summary>
26+
private readonly IAsyncProvider asyncProvider;
27+
28+
/// <summary>Global application life cycle control - triggers when application shuts down.</summary>
29+
private readonly INodeLifetime nodeLifetime;
30+
31+
private readonly ILogger logger;
32+
33+
private readonly IConsensusManager consensusManager;
34+
private readonly ISignals signals;
35+
36+
private ChainedHeader tip;
37+
38+
public BlockNotification(
39+
ILoggerFactory loggerFactory,
40+
ChainIndexer chainIndexer,
41+
IConsensusManager consensusManager,
42+
ISignals signals,
43+
IAsyncProvider asyncProvider,
44+
INodeLifetime nodeLifetime)
45+
{
46+
Guard.NotNull(loggerFactory, nameof(loggerFactory));
47+
Guard.NotNull(chainIndexer, nameof(chainIndexer));
48+
Guard.NotNull(consensusManager, nameof(consensusManager));
49+
Guard.NotNull(signals, nameof(signals));
50+
Guard.NotNull(asyncProvider, nameof(asyncProvider));
51+
Guard.NotNull(nodeLifetime, nameof(nodeLifetime));
52+
53+
this.ChainIndexer = chainIndexer;
54+
this.consensusManager = consensusManager;
55+
this.signals = signals;
56+
this.asyncProvider = asyncProvider;
57+
this.nodeLifetime = nodeLifetime;
58+
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
59+
}
60+
61+
public ChainIndexer ChainIndexer { get; }
62+
63+
public virtual bool ReSync { get; private set; }
64+
65+
public virtual uint256 StartHash { get; private set; }
66+
67+
/// <inheritdoc/>
68+
public virtual void SyncFrom(uint256 startHash)
69+
{
70+
this.logger.LogDebug("Received request to sync from hash : {0}.", startHash);
71+
72+
// No need to resync the first time this method is called.
73+
if (this.StartHash != null)
74+
{
75+
this.ReSync = true;
76+
77+
ChainedHeader startBlock = this.ChainIndexer.GetHeader(startHash);
78+
if (startBlock != null)
79+
{
80+
// Sets the location of the puller to the block preceding the one we want to receive.
81+
ChainedHeader previousBlock = this.ChainIndexer.GetHeader(startBlock.Height > 0 ? startBlock.Height - 1 : 0);
82+
// this.Puller.SetLocation(previousBlock);
83+
this.tip = previousBlock;
84+
85+
this.logger.LogDebug("Puller location set to block: {0}.", previousBlock);
86+
}
87+
}
88+
89+
this.StartHash = startHash;
90+
}
91+
92+
/// <inheritdoc/>
93+
public void Start()
94+
{
95+
this.asyncLoop = this.asyncProvider.CreateAndRunAsyncLoop("Notify", async token =>
96+
{
97+
await this.Notify(this.nodeLifetime.ApplicationStopping);
98+
},
99+
this.nodeLifetime.ApplicationStopping);
100+
}
101+
102+
/// <inheritdoc/>
103+
public void Stop()
104+
{
105+
if (this.asyncLoop != null)
106+
this.asyncLoop.Dispose();
107+
}
108+
109+
internal Task Notify(CancellationToken token)
110+
{
111+
// Not syncing until the StartHash has been set.
112+
if (this.StartHash == null)
113+
return Task.CompletedTask;
114+
115+
// Not syncing until the chain is downloaded at least up to this block.
116+
ChainedHeader startBlock = this.ChainIndexer.GetHeader(this.StartHash);
117+
if (startBlock == null)
118+
return Task.CompletedTask;
119+
120+
// Sets the location of the puller to the block preceding the one we want to receive.
121+
ChainedHeader previousBlock = this.ChainIndexer.GetHeader(startBlock.Height > 0 ? startBlock.Height - 1 : 0);
122+
// this.Puller.SetLocation(previousBlock);
123+
this.tip = previousBlock;
124+
125+
this.logger.LogDebug("Puller location set to block: {0}.", previousBlock);
126+
127+
// Send notifications for all the following blocks.
128+
while (!this.ReSync)
129+
{
130+
token.ThrowIfCancellationRequested();
131+
132+
//LookaheadResult lookaheadResult = this.Puller.NextBlock(token);
133+
//if (lookaheadResult.Block != null)
134+
//{
135+
// // Broadcast the block to the registered observers.
136+
// this.signals.SignalBlock(lookaheadResult.Block);
137+
// this.tip = this.Chain.GetBlock(lookaheadResult.Block.GetHash());
138+
139+
// continue;
140+
//}
141+
142+
// In reorg we reset the puller to the fork.
143+
// When a reorg happens the puller is pushed back and continues from the current fork.
144+
// Find the location of the fork.
145+
while (this.ChainIndexer.GetHeader(this.tip.HashBlock) == null)
146+
this.tip = this.tip.Previous;
147+
148+
// Set the puller to the fork location.
149+
//this.Puller.SetLocation(this.tip);
150+
}
151+
152+
this.ReSync = false;
153+
154+
return Task.CompletedTask;
155+
}
156+
}
157+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System.Runtime.CompilerServices;
2+
using System.Threading.Tasks;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Logging;
5+
using NBitcoin;
6+
using Blockcore.Base;
7+
using Blockcore.Builder;
8+
using Blockcore.Builder.Feature;
9+
using Blockcore.Connection;
10+
using Blockcore.Consensus;
11+
using Blockcore.Features.Notifications.Controllers;
12+
using Blockcore.Features.Notifications.Interfaces;
13+
using Blockcore.P2P.Peer;
14+
15+
[assembly: InternalsVisibleTo("Blockcore.Features.Notifications.Tests")]
16+
17+
namespace Blockcore.Features.Notifications
18+
{
19+
/// =================================================================
20+
/// TODO: This class is broken and the logic needs to be redesigned, this effects light wallet.
21+
/// =================================================================
22+
/// <summary>
23+
/// Feature enabling the broadcasting of blocks.
24+
/// </summary>
25+
public class BlockNotificationFeature : FullNodeFeature
26+
{
27+
private readonly IBlockNotification blockNotification;
28+
29+
private readonly IConnectionManager connectionManager;
30+
31+
private readonly IConsensusManager consensusManager;
32+
33+
private readonly IChainState chainState;
34+
35+
private readonly ChainIndexer chainIndexer;
36+
37+
private readonly ILoggerFactory loggerFactory;
38+
39+
public BlockNotificationFeature(
40+
IBlockNotification blockNotification,
41+
IConnectionManager connectionManager,
42+
IConsensusManager consensusManager,
43+
IChainState chainState,
44+
ChainIndexer chainIndexer,
45+
ILoggerFactory loggerFactory)
46+
{
47+
this.blockNotification = blockNotification;
48+
this.connectionManager = connectionManager;
49+
this.consensusManager = consensusManager;
50+
this.chainState = chainState;
51+
this.chainIndexer = chainIndexer;
52+
this.loggerFactory = loggerFactory;
53+
}
54+
55+
public override Task InitializeAsync()
56+
{
57+
NetworkPeerConnectionParameters connectionParameters = this.connectionManager.Parameters;
58+
59+
this.blockNotification.Start();
60+
this.chainState.ConsensusTip = this.chainIndexer.Tip;
61+
62+
return Task.CompletedTask;
63+
}
64+
65+
/// <inheritdoc />
66+
public override void Dispose()
67+
{
68+
this.blockNotification.Stop();
69+
}
70+
}
71+
72+
/// <summary>
73+
/// A class providing extension methods for <see cref="IFullNodeBuilder"/>.
74+
/// </summary>
75+
public static class FullNodeBuilderBlockNotificationExtension
76+
{
77+
public static IFullNodeBuilder UseBlockNotification(this IFullNodeBuilder fullNodeBuilder)
78+
{
79+
fullNodeBuilder.ConfigureFeature(features =>
80+
{
81+
features
82+
.AddFeature<BlockNotificationFeature>()
83+
.FeatureServices(services =>
84+
{
85+
services.AddSingleton<IBlockNotification, BlockNotification>();
86+
});
87+
});
88+
89+
return fullNodeBuilder;
90+
}
91+
}
92+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
<PropertyGroup>
3+
<Description>Blockcore Features Notifications</Description>
4+
<AssemblyTitle>Blockcore.Features.Notifications</AssemblyTitle>
5+
<AssemblyName>Blockcore.Features.Notifications</AssemblyName>
6+
<PackageId>Blockcore.Features.Notifications</PackageId>
7+
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.4" />
11+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
12+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.4" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4" />
14+
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.2" />
15+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ProjectReference Include="..\..\External\NBitcoin\NBitcoin.csproj" />
19+
<ProjectReference Include="..\..\Blockcore\Blockcore.csproj" />
20+
</ItemGroup>
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
22+
<NoWarn>1701;1702;1705;IDE0008;</NoWarn>
23+
<DocumentationFile></DocumentationFile>
24+
</PropertyGroup>
25+
</Project>

0 commit comments

Comments
 (0)