Commit 049e63f6 authored by Dan Gershony's avatar Dan Gershony Committed by GitHub

Merge pull request #104 from bokobza/master

Added watch only wallet for use in tumble bit
parents 9a873237 569d7dac
......@@ -18,6 +18,7 @@ using Stratis.Bitcoin.Miner;
using Stratis.Bitcoin.Notifications;
using Stratis.Bitcoin.Utilities;
using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.WatchOnlyWallet;
namespace Breeze.Daemon
{
......@@ -90,6 +91,7 @@ namespace Breeze.Daemon
{
tumblerAddress = tumblerAddress.Replace("-tumbler-uri=", string.Empty);
fullNodeBuilder.UseTumbleBit(new Uri(tumblerAddress));
fullNodeBuilder.UseWatchOnlyWallet();
}
var node = fullNodeBuilder.Build();
......
......@@ -14,10 +14,6 @@ namespace Breeze.TumbleBit.Client
return null;
}
public void Track(Script scriptPubkey)
{
}
public bool Broadcast(Transaction tx)
{
return true;
......
......@@ -99,7 +99,7 @@ namespace Breeze.TumbleBit.Client
// Tracker.AddressCreated(cycle.Start, TransactionType.ClientEscrow, escrowTxOut.ScriptPubKey, correlation);
// Tracker.TransactionCreated(cycle.Start, TransactionType.ClientEscrow, clientEscrowTx.GetHash(), correlation);
services.Track(escrowTxOut.ScriptPubKey);
this.watchOnlyWalletManager.Watch(escrowTxOut.ScriptPubKey);
var redeemDestination = this.OriginWallet.GetAccountsByCoinType(this.coinType).First().GetFirstUnusedReceivingAddress().ScriptPubKey;// Services.WalletService.GenerateAddress().ScriptPubKey;
var redeemTx = session.SolverClientSession.CreateRedeemTransaction(feeRate, redeemDestination);
......@@ -147,7 +147,7 @@ namespace Breeze.TumbleBit.Client
var tumblerInformation = await this.BobClient.OpenChannelAsync(bobEscrowInformation);
session.PromiseClientSession = session.ClientChannelNegotiation.ReceiveTumblerEscrowedCoin(tumblerInformation);
//Tell to the block explorer we need to track that address (for checking if it is confirmed in payment phase)
services.Track(session.PromiseClientSession.EscrowedCoin.ScriptPubKey);
this.watchOnlyWalletManager.Watch(session.PromiseClientSession.EscrowedCoin.ScriptPubKey);
//Tracker.AddressCreated(cycle.Start, TransactionType.TumblerEscrow, PromiseClientSession.EscrowedCoin.ScriptPubKey, correlation);
//Tracker.TransactionCreated(cycle.Start, TransactionType.TumblerEscrow, PromiseClientSession.EscrowedCoin.Outpoint.Hash, correlation);
......@@ -195,7 +195,7 @@ namespace Breeze.TumbleBit.Client
var offerRedeemAddress = this.OriginWallet.GetAccountsByCoinType(this.coinType).First().GetFirstUnusedReceivingAddress(); // Services.WalletService.GenerateAddress($"Cycle {cycle.Start} Tumbler Redeem").ScriptPubKey);
var offerRedeem = session.SolverClientSession.CreateOfferRedeemTransaction(feeRate, offerRedeemAddress.ScriptPubKey);
//May need to find solution in the fulfillment transaction
services.Track(offerRedeem.PreviousScriptPubKey);
this.watchOnlyWalletManager.Watch(offerRedeem.PreviousScriptPubKey);
//Tracker.AddressCreated(cycle.Start, TransactionType.ClientOfferRedeem, offerRedeemAddress.ScriptPubKey, correlation);
services.TrustedBroadcast(cycle.Start, TransactionType.ClientOfferRedeem, correlation, offerRedeem);
logger.LogInformation("Offer redeem " + offerRedeem.Transaction.GetHash() + " locked until " + offerRedeem.Transaction.LockTime.Height);
......
......@@ -6,6 +6,7 @@ using NBitcoin;
using NTumbleBit.ClassicTumbler;
using Stratis.Bitcoin;
using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.WatchOnlyWallet;
namespace Breeze.TumbleBit.Client
{
......@@ -17,6 +18,7 @@ namespace Breeze.TumbleBit.Client
{
private ITumblerService tumblerService;
private readonly IWalletManager walletManager;
private readonly IWatchOnlyWalletManager watchOnlyWalletManager;
private readonly ILogger logger;
private readonly Signals signals;
private readonly ConcurrentChain chain;
......@@ -26,15 +28,16 @@ namespace Breeze.TumbleBit.Client
private ClassicTumblerParameters TumblerParameters { get; set; }
public TumbleBitManager(ILoggerFactory loggerFactory, IWalletManager walletManager, ConcurrentChain chain, Network network, Signals signals)
public TumbleBitManager(ILoggerFactory loggerFactory, IWalletManager walletManager, IWatchOnlyWalletManager watchOnlyWalletManager, ConcurrentChain chain, Network network, Signals signals)
{
this.walletManager = walletManager;
this.watchOnlyWalletManager = watchOnlyWalletManager;
this.chain = chain;
this.signals = signals;
this.network = network;
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.tumblingState = new TumblingState(loggerFactory, this.chain, this.walletManager, this.network);
this.tumblingState = new TumblingState(loggerFactory, this.chain, this.walletManager, this.watchOnlyWalletManager, this.network);
}
/// <inheritdoc />
......
......@@ -10,6 +10,7 @@ using NTumbleBit.ClassicTumbler;
using NTumbleBit.PuzzlePromise;
using NTumbleBit.PuzzleSolver;
using Stratis.Bitcoin.Wallet;
using Stratis.Bitcoin.WatchOnlyWallet;
namespace Breeze.TumbleBit.Client
{
......@@ -20,6 +21,7 @@ namespace Breeze.TumbleBit.Client
private readonly ILogger logger;
private readonly ConcurrentChain chain;
private readonly IWalletManager walletManager;
private readonly IWatchOnlyWalletManager watchOnlyWalletManager;
private readonly CoinType coinType;
[JsonProperty("tumblerParameters")]
......@@ -60,11 +62,13 @@ namespace Breeze.TumbleBit.Client
public TumblingState(ILoggerFactory loggerFactory,
ConcurrentChain chain,
IWalletManager walletManager,
IWatchOnlyWalletManager watchOnlyWalletManager,
Network network)
{
this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.chain = chain;
this.walletManager = walletManager;
this.watchOnlyWalletManager = watchOnlyWalletManager;
this.coinType = (CoinType)network.Consensus.CoinType;
}
......
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