Commit a1e913c0 authored by Jeremy Bokobza's avatar Jeremy Bokobza Committed by GitHub

Merge pull request #101 from bokobza/master

Fee rate for TB
parents d7ff2da1 16d3e3cb
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using NBitcoin;
using NTumbleBit;
using Stratis.Bitcoin.MemoryPool;
namespace Breeze.TumbleBit.Client
{
......@@ -33,7 +34,20 @@ namespace Breeze.TumbleBit.Client
public FeeRate GetFeeRate()
{
return null;
decimal relayFee = MempoolValidator.MinRelayTxFee.FeePerK.ToUnit(MoneyUnit.BTC);
var minimumRate = new FeeRate(Money.Coins(relayFee * 2), 1000); //0.00002000 BTC/kB
var fallbackFeeRate = new FeeRate(Money.Satoshis(50), 1); //0.00050000 BTC/kB
// TODO add real fee estimation
//var rate = _RPCClient.TryEstimateFeeRate(1) ??
// _RPCClient.TryEstimateFeeRate(2) ??
// _RPCClient.TryEstimateFeeRate(3) ??
// FallBackFeeRate;
//if (rate < MinimumFeeRate)
// rate = MinimumFeeRa
return fallbackFeeRate;
}
}
}
......@@ -54,6 +54,8 @@ namespace Breeze.TumbleBit.Client
FeeRate feeRate = null;
switch (phase)
{
// in the registration phase, Bob asks the tumbler for a voucher.
// he cannot open it so he gives it to Alice.
case CyclePhase.Registration:
if (session.ClientChannelNegotiation == null)
{
......@@ -69,6 +71,9 @@ namespace Breeze.TumbleBit.Client
logger.LogInformation("Registration Complete");
}
break;
// in this phase, Alice creates 2 transactions: an escrow transaction and a redeem transaction (in case things don't go as planned)
// on the next phase, she sends the blinded voucher to the tumbler, who doesn't know this voucher is coming from Bob.
// the tumbler signs the voucher and replies with a solution to the voucher.
case CyclePhase.ClientChannelEstablishment:
if (session.ClientChannelNegotiation.Status == TumblerClientSessionStates.WaitingTumblerClientTransactionKey)
{
......@@ -89,16 +94,13 @@ namespace Breeze.TumbleBit.Client
break;
}
session.SolverClientSession = session.ClientChannelNegotiation.SetClientSignedTransaction(clientEscrowTx);
session.SolverClientSession = session.ClientChannelNegotiation.SetClientSignedTransaction(clientEscrowTx);
correlation = GetCorrelation(session.SolverClientSession.EscrowedCoin.ScriptPubKey);
// Tracker.AddressCreated(cycle.Start, TransactionType.ClientEscrow, escrowTxOut.ScriptPubKey, correlation);
// Tracker.TransactionCreated(cycle.Start, TransactionType.ClientEscrow, clientEscrowTx.GetHash(), correlation);
services.Track(escrowTxOut.ScriptPubKey);
var redeemDestination = this.OriginWallet.GetAccountsByCoinType(this.coinType).First().GetFirstUnusedReceivingAddress().ScriptPubKey;// Services.WalletService.GenerateAddress().ScriptPubKey;
var redeemTx = session.SolverClientSession.CreateRedeemTransaction(feeRate, redeemDestination);
......@@ -106,7 +108,6 @@ namespace Breeze.TumbleBit.Client
//redeemTx does not be to be recorded to the tracker, this is TrustedBroadcastService job
services.Broadcast(clientEscrowTx);
services.TrustedBroadcast(cycle.Start, TransactionType.ClientRedeem, correlation, redeemTx);
logger.LogInformation("Client escrow broadcasted " + clientEscrowTx.GetHash());
......@@ -133,6 +134,11 @@ namespace Breeze.TumbleBit.Client
}
}
break;
// in this phase, Bob now opens a channel with the tumbler by sending the unblinded voucher he received from Alice.
// at this point, the tumbler knows that there is an Alice somewhere that wants to tumble with Bob.
// the tumbler then creates a new transaction that spends the money and sends it to Bob.
// but the transaction is locked and Bob doesn't know the signature.
// to prove to Bob that behind the lock there is a signature, the tumbler uses the puzzle promise protocol.
case CyclePhase.TumblerChannelEstablishment:
if (session.ClientChannelNegotiation != null && session.ClientChannelNegotiation.Status == TumblerClientSessionStates.WaitingGenerateTumblerTransactionKey)
{
......@@ -159,6 +165,8 @@ namespace Breeze.TumbleBit.Client
logger.LogInformation("Tumbler escrow broadcasted " + session.PromiseClientSession.EscrowedCoin.Outpoint.Hash);
}
break;
// the tumbler then creates 2 transactions: an escrow transaction and a redeem transaction (in case things don't go as planned with Bob)
case CyclePhase.PaymentPhase:
if (session.PromiseClientSession != null)
{
......@@ -219,6 +227,7 @@ namespace Breeze.TumbleBit.Client
}
}
break;
// now Bob can unlock the signature of the transaction and broadcast it to take his coin.
case CyclePhase.ClientCashoutPhase:
if (session.SolverClientSession != null)
{
......
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