Commit a425df19 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Added getting transactions from the Mempool.

parents fe62fc98 1d842329
......@@ -18,11 +18,12 @@ namespace Breeze.Deamon
// configure Full Node
Logs.Configure(new LoggerFactory().AddConsole(LogLevel.Trace, false));
NodeSettings nodeSettings = NodeSettings.FromArguments(args);
var node = (FullNode)new FullNodeBuilder()
var node = (FullNode)new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseWallet()
.UseBlockNotification()
.UseTransactionNotification()
.UseApi()
.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
{
BlockSubscriber sub = new BlockSubscriber(signals.Blocks, new BlockObserver(chain, trackerWrapper));
sub.Subscribe();
TransactionSubscriber txSub = new TransactionSubscriber(signals.Transactions, new TransactionObserver(trackerWrapper));
txSub.Subscribe();
}
}
......
......@@ -6,6 +6,8 @@ namespace Breeze.Wallet.Wrappers
{
void NotifyAboutBlock(int height, Block block);
uint256 GetLastProcessedBlock();
void NotifyAboutTransaction(Transaction transaction);
uint256 GetLastProcessedBlock();
}
}
......@@ -5,27 +5,35 @@ namespace Breeze.Wallet.Wrappers
{
public class TrackerWrapper : ITrackerWrapper
{
// private readonly Tracker tracker;
// private readonly Tracker tracker;
public TrackerWrapper(Network network)
{
//this.tracker = new Tracker(network);
}
/// <summary>
/// Get the hash of the last block that has been succesfully processed.
/// </summary>
/// <returns>The hash of the block</returns>
public uint256 GetLastProcessedBlock()
{
// TODO use Tracker.BestHeight. Genesis hash for now.
return uint256.Parse("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
}
/// <summary>
/// Get the hash of the last block that has been succesfully processed.
/// </summary>
/// <returns>The hash of the block</returns>
public uint256 GetLastProcessedBlock()
{
// TODO use Tracker.BestHeight. Genesis hash for now.
return uint256.Parse("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f");
}
public void NotifyAboutBlock(int height, Block block)
{
// this.tracker.AddOrReplaceBlock(new Height(height), block);
Console.WriteLine($"block notification: height: {height}, block hash: {block.Header.GetHash()}");
}
public void NotifyAboutBlock(int height, Block block)
public void NotifyAboutTransaction(Transaction transaction)
{
//this.tracker.AddOrReplaceBlock(new Height(height), block);
Console.WriteLine($"height: {height}, block hash: {block.Header.GetHash()}");
// 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