Commit 9efd15c0 authored by Dan Gershony's avatar Dan Gershony

merge

parents 7ea016a3 bb43fb28
...@@ -27,10 +27,11 @@ namespace Breeze.Daemon ...@@ -27,10 +27,11 @@ namespace Breeze.Daemon
{ {
IFullNodeBuilder fullNodeBuilder = null; IFullNodeBuilder fullNodeBuilder = null;
// configure logging
Logs.Configure(Logs.GetLoggerFactory(args));
if (args.Contains("stratis")) if (args.Contains("stratis"))
{ {
// configure Full Node
Logs.Configure(Logs.GetLoggerFactory(args));
if (NodeSettings.PrintHelp(args, Network.StratisMain)) if (NodeSettings.PrintHelp(args, Network.StratisMain))
return; return;
......
{ {
"profiles": { "profiles": {
"Breeze.Daemon Main": { "Breeze.Daemon Main": {
"commandName": "Project" "commandName": "Project",
"commandLineArgs": "light"
}, },
"Breeze.Daemon TestNet": { "Breeze.Daemon TestNet": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "-testnet -tumbler-uri=http://localhost:5050" "commandLineArgs": "-testnet -tumbler-uri=http://localhost:5050 light -debug"
}, },
"StratisTest": { "StratisTest": {
"commandName": "Project", "commandName": "Project",
"commandLineArgs": "stratis -testnet -datadir=I:\\\\stratistestnet" "commandLineArgs": "stratis -testnet"
} }
} }
} }
\ No newline at end of file
using Stratis.Bitcoin.Builder.Feature; using Stratis.Bitcoin.Builder.Feature;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Stratis.Bitcoin.Builder; using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Logging;
using Microsoft.Extensions.Logging;
using Serilog;
using Stratis.Bitcoin.Wallet; using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Controllers; using Stratis.Bitcoin.Wallet.Controllers;
...@@ -11,16 +8,16 @@ namespace Breeze.Wallet ...@@ -11,16 +8,16 @@ namespace Breeze.Wallet
{ {
public class LightWalletFeature : FullNodeFeature public class LightWalletFeature : FullNodeFeature
{ {
private readonly LightWalletSyncManager lightWalletSyncManager; private readonly IWalletSyncManager walletSyncManager;
public LightWalletFeature(LightWalletSyncManager lightWalletSyncManager) public LightWalletFeature(IWalletSyncManager walletSyncManager)
{ {
this.lightWalletSyncManager = lightWalletSyncManager; this.walletSyncManager = walletSyncManager;
} }
public override void Start() public override void Start()
{ {
this.lightWalletSyncManager.Initialize(); this.walletSyncManager.Initialize();
} }
public override void Stop() public override void Stop()
......
...@@ -8,32 +8,46 @@ using Stratis.Bitcoin; ...@@ -8,32 +8,46 @@ using Stratis.Bitcoin;
using Stratis.Bitcoin.Notifications; using Stratis.Bitcoin.Notifications;
using Stratis.Bitcoin.Utilities; using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Wallet; using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.Wallet.Notifications;
namespace Breeze.Wallet namespace Breeze.Wallet
{ {
public class LightWalletSyncManager : WalletSyncManager public class LightWalletSyncManager : IWalletSyncManager
{ {
private readonly WalletManager walletManager; private readonly WalletManager walletManager;
private readonly ConcurrentChain chain; private readonly ConcurrentChain chain;
private readonly BlockNotification blockNotification; private readonly BlockNotification blockNotification;
private readonly CoinType coinType; private readonly CoinType coinType;
private readonly ILogger logger; private readonly ILogger logger;
private readonly Signals signals;
public LightWalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network, public LightWalletSyncManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network,
BlockNotification blockNotification):base(loggerFactory, walletManager, chain, network) BlockNotification blockNotification, Signals signals)// :base(loggerFactory, walletManager, chain, network)
{ {
this.walletManager = walletManager as WalletManager;
this.chain = chain;
this.signals = signals;
this.blockNotification = blockNotification; this.blockNotification = blockNotification;
this.coinType = (CoinType)network.Consensus.CoinType;
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Initialize() public async Task Initialize()
{ {
// get the chain headers. This needs to be up-to-date before we really do anything // get the chain headers. This needs to be up-to-date before we really do anything
this.WaitForChainDownloadAsync().GetAwaiter().GetResult(); await this.WaitForChainDownloadAsync();
// subscribe to receiving blocks and transactions
BlockSubscriber sub = new BlockSubscriber(this.signals.Blocks, new BlockObserver(this.chain, this));
sub.Subscribe();
TransactionSubscriber txSub = new TransactionSubscriber(this.signals.Transactions, new TransactionObserver(this));
txSub.Subscribe();
// start syncing blocks // start syncing blocks
var bestHeightForSyncing = this.FindBestHeightForSyncing(); var bestHeightForSyncing = this.FindBestHeightForSyncing();
this.SyncFrom(bestHeightForSyncing); this.SyncFrom(bestHeightForSyncing);
this.logger.LogInformation($"Tracker initialized. Syncing from {bestHeightForSyncing}.");
} }
private int FindBestHeightForSyncing() private int FindBestHeightForSyncing()
...@@ -75,7 +89,7 @@ namespace Breeze.Wallet ...@@ -75,7 +89,7 @@ namespace Breeze.Wallet
} }
/// <inheritdoc /> /// <inheritdoc />
public override void SyncFrom(DateTime date) public void SyncFrom(DateTime date)
{ {
int blockSyncStart = this.chain.GetHeightAtTime(date); int blockSyncStart = this.chain.GetHeightAtTime(date);
...@@ -84,9 +98,22 @@ namespace Breeze.Wallet ...@@ -84,9 +98,22 @@ namespace Breeze.Wallet
} }
/// <inheritdoc /> /// <inheritdoc />
public override void SyncFrom(int height) public void SyncFrom(int height)
{ {
this.blockNotification.SyncFrom(this.chain.GetBlock(height).HashBlock); this.blockNotification.SyncFrom(this.chain.GetBlock(height).HashBlock);
} }
public void ProcessBlock(Block block)
{
var hash = block.Header.GetHash();
var height = this.chain.GetBlock(hash).Height;
this.walletManager.ProcessBlock(height, block);
}
public void ProcessTransaction(Transaction transaction)
{
this.walletManager.ProcessTransaction(transaction);
}
} }
} }
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