Commit ad73f92c authored by Dan Gershony's avatar Dan Gershony

Chcking for segwit activation and adding the behaviour to drop nodes when behind

parent 6b0d5f4d
using Stratis.Bitcoin.Builder.Feature; using Stratis.Bitcoin.Builder.Feature;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using NBitcoin;
using NBitcoin.Protocol;
using Stratis.Bitcoin.Builder; using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Connection;
using Stratis.Bitcoin.Consensus;
using Stratis.Bitcoin.Consensus.Deployments;
using Stratis.Bitcoin.Wallet; using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Controllers; using Stratis.Bitcoin.Wallet.Controllers;
...@@ -10,17 +15,30 @@ namespace Breeze.Wallet ...@@ -10,17 +15,30 @@ namespace Breeze.Wallet
{ {
private readonly IWalletSyncManager walletSyncManager; private readonly IWalletSyncManager walletSyncManager;
private readonly IWalletManager walletManager; private readonly IWalletManager walletManager;
private readonly IConnectionManager connectionManager;
private readonly ConcurrentChain chain;
private readonly NodeDeployments nodeDeployments;
public LightWalletFeature(IWalletSyncManager walletSyncManager, IWalletManager walletManager) public LightWalletFeature(IWalletSyncManager walletSyncManager, IWalletManager walletManager, IConnectionManager connectionManager,
ConcurrentChain chain, NodeDeployments nodeDeployments)
{ {
this.walletSyncManager = walletSyncManager; this.walletSyncManager = walletSyncManager;
this.walletManager = walletManager; this.walletManager = walletManager;
this.connectionManager = connectionManager;
this.chain = chain;
this.nodeDeployments = nodeDeployments;
} }
public override void Start() public override void Start()
{ {
this.connectionManager.Parameters.TemplateBehaviors.Add(new DropNodesBehaviour(this.chain, this.connectionManager));
this.walletManager.Initialize(); this.walletManager.Initialize();
this.walletSyncManager.Initialize(); this.walletSyncManager.Initialize();
var flags = this.nodeDeployments.GetFlags(this.walletSyncManager.WalletTip);
if (flags.ScriptFlags.HasFlag(ScriptVerify.Witness))
this.connectionManager.AddDiscoveredNodesRequirement(NodeServices.NODE_WITNESS);
} }
public override void Stop() public override void Stop()
...@@ -36,8 +54,8 @@ namespace Breeze.Wallet ...@@ -36,8 +54,8 @@ namespace Breeze.Wallet
fullNodeBuilder.ConfigureFeature(features => fullNodeBuilder.ConfigureFeature(features =>
{ {
features features
.AddFeature<LightWalletFeature>() .AddFeature<LightWalletFeature>()
.FeatureServices(services => .FeatureServices(services =>
{ {
services.AddSingleton<IWalletSyncManager, LightWalletSyncManager>(); services.AddSingleton<IWalletSyncManager, LightWalletSyncManager>();
services.AddSingleton<IWalletManager, WalletManager>(); services.AddSingleton<IWalletManager, WalletManager>();
......
...@@ -23,6 +23,8 @@ namespace Breeze.Wallet ...@@ -23,6 +23,8 @@ namespace Breeze.Wallet
private ChainedBlock walletTip; private ChainedBlock walletTip;
public ChainedBlock WalletTip => this.walletTip;
public LightWalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network, public LightWalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network,
BlockNotification blockNotification, Signals signals) BlockNotification blockNotification, Signals signals)
{ {
......
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