Commit 16d3e3cb authored by Jeremy Bokobza's avatar Jeremy Bokobza

added some comments

parent 25670725
...@@ -54,6 +54,8 @@ namespace Breeze.TumbleBit.Client ...@@ -54,6 +54,8 @@ namespace Breeze.TumbleBit.Client
FeeRate feeRate = null; FeeRate feeRate = null;
switch (phase) 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: case CyclePhase.Registration:
if (session.ClientChannelNegotiation == null) if (session.ClientChannelNegotiation == null)
{ {
...@@ -69,6 +71,9 @@ namespace Breeze.TumbleBit.Client ...@@ -69,6 +71,9 @@ namespace Breeze.TumbleBit.Client
logger.LogInformation("Registration Complete"); logger.LogInformation("Registration Complete");
} }
break; 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: case CyclePhase.ClientChannelEstablishment:
if (session.ClientChannelNegotiation.Status == TumblerClientSessionStates.WaitingTumblerClientTransactionKey) if (session.ClientChannelNegotiation.Status == TumblerClientSessionStates.WaitingTumblerClientTransactionKey)
{ {
...@@ -89,16 +94,13 @@ namespace Breeze.TumbleBit.Client ...@@ -89,16 +94,13 @@ namespace Breeze.TumbleBit.Client
break; break;
} }
session.SolverClientSession = session.ClientChannelNegotiation.SetClientSignedTransaction(clientEscrowTx); session.SolverClientSession = session.ClientChannelNegotiation.SetClientSignedTransaction(clientEscrowTx);
correlation = GetCorrelation(session.SolverClientSession.EscrowedCoin.ScriptPubKey); correlation = GetCorrelation(session.SolverClientSession.EscrowedCoin.ScriptPubKey);
// Tracker.AddressCreated(cycle.Start, TransactionType.ClientEscrow, escrowTxOut.ScriptPubKey, correlation); // Tracker.AddressCreated(cycle.Start, TransactionType.ClientEscrow, escrowTxOut.ScriptPubKey, correlation);
// Tracker.TransactionCreated(cycle.Start, TransactionType.ClientEscrow, clientEscrowTx.GetHash(), correlation); // Tracker.TransactionCreated(cycle.Start, TransactionType.ClientEscrow, clientEscrowTx.GetHash(), correlation);
services.Track(escrowTxOut.ScriptPubKey); services.Track(escrowTxOut.ScriptPubKey);
var redeemDestination = this.OriginWallet.GetAccountsByCoinType(this.coinType).First().GetFirstUnusedReceivingAddress().ScriptPubKey;// Services.WalletService.GenerateAddress().ScriptPubKey; var redeemDestination = this.OriginWallet.GetAccountsByCoinType(this.coinType).First().GetFirstUnusedReceivingAddress().ScriptPubKey;// Services.WalletService.GenerateAddress().ScriptPubKey;
var redeemTx = session.SolverClientSession.CreateRedeemTransaction(feeRate, redeemDestination); var redeemTx = session.SolverClientSession.CreateRedeemTransaction(feeRate, redeemDestination);
...@@ -106,7 +108,6 @@ namespace Breeze.TumbleBit.Client ...@@ -106,7 +108,6 @@ namespace Breeze.TumbleBit.Client
//redeemTx does not be to be recorded to the tracker, this is TrustedBroadcastService job //redeemTx does not be to be recorded to the tracker, this is TrustedBroadcastService job
services.Broadcast(clientEscrowTx); services.Broadcast(clientEscrowTx);
services.TrustedBroadcast(cycle.Start, TransactionType.ClientRedeem, correlation, redeemTx); services.TrustedBroadcast(cycle.Start, TransactionType.ClientRedeem, correlation, redeemTx);
logger.LogInformation("Client escrow broadcasted " + clientEscrowTx.GetHash()); logger.LogInformation("Client escrow broadcasted " + clientEscrowTx.GetHash());
...@@ -133,6 +134,11 @@ namespace Breeze.TumbleBit.Client ...@@ -133,6 +134,11 @@ namespace Breeze.TumbleBit.Client
} }
} }
break; 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: case CyclePhase.TumblerChannelEstablishment:
if (session.ClientChannelNegotiation != null && session.ClientChannelNegotiation.Status == TumblerClientSessionStates.WaitingGenerateTumblerTransactionKey) if (session.ClientChannelNegotiation != null && session.ClientChannelNegotiation.Status == TumblerClientSessionStates.WaitingGenerateTumblerTransactionKey)
{ {
...@@ -159,6 +165,8 @@ namespace Breeze.TumbleBit.Client ...@@ -159,6 +165,8 @@ namespace Breeze.TumbleBit.Client
logger.LogInformation("Tumbler escrow broadcasted " + session.PromiseClientSession.EscrowedCoin.Outpoint.Hash); logger.LogInformation("Tumbler escrow broadcasted " + session.PromiseClientSession.EscrowedCoin.Outpoint.Hash);
} }
break; 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: case CyclePhase.PaymentPhase:
if (session.PromiseClientSession != null) if (session.PromiseClientSession != null)
{ {
...@@ -219,6 +227,7 @@ namespace Breeze.TumbleBit.Client ...@@ -219,6 +227,7 @@ namespace Breeze.TumbleBit.Client
} }
} }
break; break;
// now Bob can unlock the signature of the transaction and broadcast it to take his coin.
case CyclePhase.ClientCashoutPhase: case CyclePhase.ClientCashoutPhase:
if (session.SolverClientSession != null) 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