Commit 6334754e authored by Sergei Zubov's avatar Sergei Zubov

Modify processing of genesis block in wallet

Processing genesis block in wallet at every wallet initialization is
unnecessary, doing it only at synchronizing from first block is enough.
parent 2d4e72d3
......@@ -28,9 +28,10 @@ namespace Stratis.Bitcoin.Features.Wallet
.DependOn<RPCFeature>()
.FeatureServices(services =>
{
services.AddSingleton<IWalletSyncManager, WalletSyncManager>();
services.AddSingleton<IWalletSyncManager, DeStreamWalletSyncManager>();
services.AddSingleton<IWalletTransactionHandler, WalletTransactionHandler>();
services.AddSingleton<IWalletManager, DeStreamWalletManager>();
services.AddSingleton<IDeStreamWalletManager, DeStreamWalletManager>();
services.AddSingleton<IWalletManager>(p => p.GetService<IDeStreamWalletManager>());
services.AddSingleton<IWalletFeePolicy, WalletFeePolicy>();
services.AddSingleton<WalletController>();
services.AddSingleton<WalletRPCController>();
......
using System;
using System.Linq;
using System.Linq;
using Microsoft.Extensions.Logging;
using NBitcoin;
using Stratis.Bitcoin.Configuration;
......@@ -8,8 +7,8 @@ using Stratis.Bitcoin.Utilities;
namespace Stratis.Bitcoin.Features.Wallet
{
/// <inheritdoc />
public class DeStreamWalletManager : WalletManager
/// <inheritdoc cref="WalletManager" />
public class DeStreamWalletManager : WalletManager, IDeStreamWalletManager
{
public DeStreamWalletManager(ILoggerFactory loggerFactory, Network network, ConcurrentChain chain,
NodeSettings settings, WalletSettings walletSettings,
......@@ -21,16 +20,6 @@ namespace Stratis.Bitcoin.Features.Wallet
{
}
public ConcurrentChain chain { get; set; }
/// <inheritdoc />
public override void Start()
{
base.Start();
this.ProcessGenesisBlock();
}
/// <inheritdoc />
public override Wallet LoadWallet(string password, string name)
{
......@@ -38,29 +27,14 @@ namespace Stratis.Bitcoin.Features.Wallet
this.LoadKeysLookupLock();
this.ProcessGenesisBlock();
return result;
}
/// <inheritdoc />
public override Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime,
string passphrase = null)
{
Wallet result = base.RecoverWallet(password, name, mnemonic, creationTime, passphrase);
this.ProcessGenesisBlock();
return result;
}
/// <summary>
/// Processes genesis block
/// </summary>
private void ProcessGenesisBlock()
public void ProcessGenesisBlock()
{
foreach (var transactionWithOutput in this.network.GetGenesis().Transactions.SelectMany(p =>
p.Outputs.Select(q => new { Transaction = p, Output = q }).Where(q =>
p.Outputs.Select(q => new {Transaction = p, Output = q}).Where(q =>
this.keysLookup.TryGetValue(q.Output.ScriptPubKey, out HdAddress _))))
{
this.AddTransactionToWallet(transactionWithOutput.Transaction, transactionWithOutput.Output, 0,
......
using Microsoft.Extensions.Logging;
using NBitcoin;
using Stratis.Bitcoin.Features.BlockStore;
using Stratis.Bitcoin.Features.Wallet.Interfaces;
using Stratis.Bitcoin.Utilities;
namespace Stratis.Bitcoin.Features.Wallet
{
public class DeStreamWalletSyncManager : WalletSyncManager
{
private readonly IDeStreamWalletManager _deStreamWalletManager;
public DeStreamWalletSyncManager(ILoggerFactory loggerFactory, IDeStreamWalletManager walletManager,
ConcurrentChain chain, Network network, IBlockStoreCache blockStoreCache, StoreSettings storeSettings,
INodeLifetime nodeLifetime) : base(loggerFactory, walletManager, chain, network, blockStoreCache,
storeSettings, nodeLifetime)
{
this._deStreamWalletManager = walletManager;
}
public override void SyncFromHeight(int height)
{
base.SyncFromHeight(height);
// Wallet's initial state - height 0 and no blocks processed,
// but there may be transactions at height 0.
// This function is called with next unprocessed block height,
// so, processing of genesis block is required on height = 1.
if (height > 1) return;
this._deStreamWalletManager.ProcessGenesisBlock();
this.logger.LogTrace("Genesis block processed");
}
}
}
\ No newline at end of file
namespace Stratis.Bitcoin.Features.Wallet.Interfaces
{
public interface IDeStreamWalletManager : IWalletManager
{
/// <summary>
/// Processes genesis block
/// </summary>
void ProcessGenesisBlock();
}
}
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Stratis Bitcoin Features Wallet</Description>
<AssemblyTitle>Stratis.Bitcoin.Features.Wallet</AssemblyTitle>
......@@ -14,10 +13,9 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.1.12-beta</Version>
<Version>1.1.12-beta</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Stratis.Bitcoin.Features.Wallet\**" />
<EmbeddedResource Remove="Stratis.Bitcoin.Features.Wallet\**" />
......@@ -32,7 +30,6 @@
<PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NBitcoin\NBitcoin.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin.Features.BlockStore\Stratis.Bitcoin.Features.BlockStore.csproj" />
......@@ -40,14 +37,12 @@
<ProjectReference Include="..\Stratis.Bitcoin.Features.RPC\Stratis.Bitcoin.Features.RPC.csproj" />
<ProjectReference Include="..\Stratis.Bitcoin\Stratis.Bitcoin.csproj" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>$(DefineConstants);NETCORE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;IDE0008;</NoWarn>
<DocumentationFile></DocumentationFile>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -149,7 +149,7 @@ namespace Stratis.Bitcoin.Features.Wallet
this.logger.LogTrace("(-)");
}
public virtual void Start()
public void Start()
{
this.logger.LogTrace("()");
......@@ -284,7 +284,7 @@ namespace Stratis.Bitcoin.Features.Wallet
}
/// <inheritdoc />
public virtual Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime, string passphrase = null)
public Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime, string passphrase = null)
{
Guard.NotEmpty(password, nameof(password));
Guard.NotEmpty(name, nameof(name));
......
......@@ -19,7 +19,7 @@ namespace Stratis.Bitcoin.Features.Wallet
protected readonly CoinType coinType;
/// <summary>Instance logger.</summary>
private readonly ILogger logger;
protected readonly ILogger logger;
private readonly IBlockStoreCache blockStoreCache;
......
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