Commit 1d842329 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Added syncing of the transactions with the wallet.

Final commit waiting on a new nuget package for the full node.
parent 79f14616
...@@ -18,11 +18,12 @@ namespace Breeze.Deamon ...@@ -18,11 +18,12 @@ namespace Breeze.Deamon
// configure Full Node // configure Full Node
Logs.Configure(new LoggerFactory().AddConsole(LogLevel.Trace, false)); Logs.Configure(new LoggerFactory().AddConsole(LogLevel.Trace, false));
NodeSettings nodeSettings = NodeSettings.FromArguments(args); NodeSettings nodeSettings = NodeSettings.FromArguments(args);
var node = (FullNode)new FullNodeBuilder() var node = (FullNode)new FullNodeBuilder()
.UseNodeSettings(nodeSettings) .UseNodeSettings(nodeSettings)
.UseWallet() .UseWallet()
.UseBlockNotification() .UseBlockNotification()
.UseTransactionNotification()
.UseApi() .UseApi()
.Build(); .Build();
......
using NBitcoin;
using Stratis.Bitcoin;
using Breeze.Wallet.Wrappers;
namespace Breeze.Wallet.Notifications
{
/// <summary>
/// Observer that receives notifications about the arrival of new <see cref="Transaction"/>s.
/// </summary>
public class TransactionObserver : SignalObserver<Transaction>
{
private readonly ITrackerWrapper trackerWrapper;
public TransactionObserver(ITrackerWrapper trackerWrapper)
{
this.trackerWrapper = trackerWrapper;
}
/// <summary>
/// Manages what happens when a new transaction is received.
/// </summary>
/// <param name="transaction">The new transaction</param>
protected override void OnNextCore(Transaction transaction)
{
this.trackerWrapper.NotifyAboutTransaction(transaction);
}
}
}
using Stratis.Bitcoin;
using System;
using NBitcoin;
namespace Breeze.Wallet.Notifications
{
/// <summary>
/// Manages the subscription of the transaction observer to the transaction signaler.
/// </summary>
public class TransactionSubscriber
{
private readonly ISignaler<Transaction> signaler;
private readonly TransactionObserver observer;
public TransactionSubscriber(ISignaler<Transaction> signaler, TransactionObserver observer)
{
this.signaler = signaler;
this.observer = observer;
}
/// <summary>
/// Subscribes the transaction observer to the transaction signaler.
/// </summary>
/// <returns>An <see cref="IDisposable"/></returns>
public IDisposable Subscribe()
{
return this.signaler.Subscribe(this.observer);
}
}
}
...@@ -26,6 +26,8 @@ namespace Breeze.Wallet ...@@ -26,6 +26,8 @@ namespace Breeze.Wallet
{ {
BlockSubscriber sub = new BlockSubscriber(signals.Blocks, new BlockObserver(chain, trackerWrapper)); BlockSubscriber sub = new BlockSubscriber(signals.Blocks, new BlockObserver(chain, trackerWrapper));
sub.Subscribe(); sub.Subscribe();
TransactionSubscriber txSub = new TransactionSubscriber(signals.Transactions, new TransactionObserver(trackerWrapper));
txSub.Subscribe();
} }
} }
......
...@@ -6,6 +6,8 @@ namespace Breeze.Wallet.Wrappers ...@@ -6,6 +6,8 @@ namespace Breeze.Wallet.Wrappers
{ {
void NotifyAboutBlock(int height, Block block); void NotifyAboutBlock(int height, Block block);
uint256 GetLastProcessedBlock(); void NotifyAboutTransaction(Transaction transaction);
uint256 GetLastProcessedBlock();
} }
} }
...@@ -13,8 +13,8 @@ namespace Breeze.Wallet.Wrappers ...@@ -13,8 +13,8 @@ namespace Breeze.Wallet.Wrappers
{ {
this.tracker = new Tracker(network); this.tracker = new Tracker(network);
} }
/// <summary> /// <summary>
/// Get the hash of the last block that has been succesfully processed. /// Get the hash of the last block that has been succesfully processed.
/// </summary> /// </summary>
/// <returns>The hash of the block</returns> /// <returns>The hash of the block</returns>
...@@ -27,7 +27,15 @@ namespace Breeze.Wallet.Wrappers ...@@ -27,7 +27,15 @@ namespace Breeze.Wallet.Wrappers
public void NotifyAboutBlock(int height, Block block) public void NotifyAboutBlock(int height, Block block)
{ {
this.tracker.AddOrReplaceBlock(new Height(height), block); this.tracker.AddOrReplaceBlock(new Height(height), block);
Console.WriteLine($"height: {height}, block hash: {block.Header.GetHash()}"); Console.WriteLine($"block notification: height: {height}, block hash: {block.Header.GetHash()}");
} }
public void NotifyAboutTransaction(Transaction transaction)
{
// TODO what should the height be? is it necessary?
this.tracker.ProcessTransaction(new SmartTransaction(transaction, new Height(0)));
Console.WriteLine($"transaction notification: tx hash {transaction.GetHash()}");
}
} }
} }
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