Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Breeze
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DeStream-public
Breeze
Commits
b200b823
Commit
b200b823
authored
Jun 13, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Brought creation of a session inside the tumbling state class
parent
0f834536
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
31 deletions
+45
-31
TumbleBitController.cs
...reeze.TumbleBit.Client/Controllers/TumbleBitController.cs
+1
-1
ITumbleBitManager.cs
Breeze/src/Breeze.TumbleBit.Client/ITumbleBitManager.cs
+1
-1
RequestModels.cs
Breeze/src/Breeze.TumbleBit.Client/Models/RequestModels.cs
+4
-1
TumbleBitManager.cs
Breeze/src/Breeze.TumbleBit.Client/TumbleBitManager.cs
+13
-24
TumblingState.cs
Breeze/src/Breeze.TumbleBit.Client/TumblingState.cs
+26
-4
No files found.
Breeze/src/Breeze.TumbleBit.Client/Controllers/TumbleBitController.cs
View file @
b200b823
...
...
@@ -63,7 +63,7 @@ namespace Breeze.TumbleBit.Controllers
try
{
await
this
.
tumbleBitManager
.
TumbleAsync
(
request
.
DestinationWalletName
);
await
this
.
tumbleBitManager
.
TumbleAsync
(
request
.
OriginWalletName
,
request
.
DestinationWalletName
);
return
this
.
Ok
();
}
catch
(
Exception
e
)
...
...
Breeze/src/Breeze.TumbleBit.Client/ITumbleBitManager.cs
View file @
b200b823
...
...
@@ -17,7 +17,7 @@ namespace Breeze.TumbleBit.Client
/// <returns></returns>
Task
<
ClassicTumblerParameters
>
ConnectToTumblerAsync
(
Uri
serverAddress
);
Task
TumbleAsync
(
string
destinationWalletName
);
Task
TumbleAsync
(
string
originWalletName
,
string
destinationWalletName
);
/// <summary>
/// Processes a block received from the network.
...
...
Breeze/src/Breeze.TumbleBit.Client/Models/RequestModels.cs
View file @
b200b823
...
...
@@ -28,7 +28,10 @@ namespace Breeze.TumbleBit.Models
public
class
TumbleRequest
{
[
Required
(
ErrorMessage
=
"A wallet name is required."
)]
[
Required
(
ErrorMessage
=
"The name of the origin wallet is required."
)]
public
string
OriginWalletName
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"The name of the destination wallet is required."
)]
public
string
DestinationWalletName
{
get
;
set
;
}
}
}
Breeze/src/Breeze.TumbleBit.Client/TumbleBitManager.cs
View file @
b200b823
...
...
@@ -23,13 +23,11 @@ namespace Breeze.TumbleBit.Client
private
readonly
Network
network
;
private
TumblingState
tumblingState
;
private
IDisposable
blockReceiver
;
int
lastCycleStarted
;
private
ClassicTumblerParameters
TumblerParameters
{
get
;
set
;
}
public
TumbleBitManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
Signals
signals
)
{
this
.
lastCycleStarted
=
0
;
this
.
walletManager
=
walletManager
;
this
.
chain
=
chain
;
this
.
signals
=
signals
;
...
...
@@ -64,7 +62,7 @@ namespace Breeze.TumbleBit.Client
}
/// <inheritdoc />
public
Task
TumbleAsync
(
string
destinationWalletName
)
public
Task
TumbleAsync
(
string
originWalletName
,
string
destinationWalletName
)
{
// make sure the tumbler service is initialized
if
(
this
.
TumblerParameters
==
null
||
this
.
tumblerService
==
null
)
...
...
@@ -81,11 +79,19 @@ namespace Breeze.TumbleBit.Client
Wallet
destinationWallet
=
this
.
walletManager
.
GetWallet
(
destinationWalletName
);
if
(
destinationWallet
==
null
)
{
throw
new
Exception
(
$"Destination not found. Have you created a wallet with name
{
destinationWalletName
}
?"
);
throw
new
Exception
(
$"Destination wallet not found. Have you created a wallet with name
{
destinationWalletName
}
?"
);
}
Wallet
originWallet
=
this
.
walletManager
.
GetWallet
(
originWalletName
);
if
(
originWallet
==
null
)
{
throw
new
Exception
(
$"Origin wallet not found. Have you created a wallet with name
{
originWalletName
}
?"
);
}
// update the state and save
this
.
tumblingState
.
DestinationWalletName
=
destinationWalletName
;
this
.
tumblingState
.
OriginWalletName
=
originWalletName
;
this
.
tumblingState
.
Save
();
// subscribe to receiving blocks
...
...
@@ -113,30 +119,13 @@ namespace Breeze.TumbleBit.Client
/// <inheritdoc />
public
void
ProcessBlock
(
int
height
,
Block
block
)
{
// TODO start the state machine
this
.
logger
.
LogDebug
(
$"Receive block with height
{
height
}
"
);
{
this
.
logger
.
LogDebug
(
$"Received block with height
{
height
}
during tumbling session."
);
// update the block height in the tumbling state
this
.
tumblingState
.
LastBlockReceivedHeight
=
height
;
this
.
tumblingState
.
Save
();
// get the next cycle to be started
var
cycle
=
this
.
TumblerParameters
.
CycleGenerator
.
GetRegistratingCycle
(
height
);
// check if we need to start a new session starting from the registration cycle
if
(
this
.
lastCycleStarted
!=
cycle
.
Start
)
{
this
.
lastCycleStarted
=
cycle
.
Start
;
this
.
logger
.
LogDebug
(
$"new registration cycle at
{
cycle
.
Start
}
"
);
if
(
this
.
tumblingState
.
Sessions
.
SingleOrDefault
(
s
=>
s
.
StartCycle
==
cycle
.
Start
)
==
null
)
{
this
.
tumblingState
.
CreateNewSession
(
cycle
.
Start
);
this
.
logger
.
LogDebug
(
$"new session created at
{
cycle
.
Start
}
"
);
}
}
// update the state of the tumbling session in this new block
this
.
tumblingState
.
Update
();
}
...
...
Breeze/src/Breeze.TumbleBit.Client/TumblingState.cs
View file @
b200b823
...
...
@@ -4,10 +4,12 @@ using System.IO;
using
System.Linq
;
using
System.Runtime.InteropServices
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
Newtonsoft.Json
;
using
NTumbleBit.ClassicTumbler
;
using
NTumbleBit.PuzzlePromise
;
using
NTumbleBit.PuzzleSolver
;
using
Stratis.Bitcoin.Wallet
;
namespace
Breeze.TumbleBit.Client
{
...
...
@@ -24,16 +26,20 @@ namespace Breeze.TumbleBit.Client
[
JsonProperty
(
"lastBlockReceivedHeight"
)]
public
int
LastBlockReceivedHeight
{
get
;
set
;
}
[
JsonProperty
(
"originWalletName"
)]
public
string
OriginWalletName
{
get
;
set
;
}
[
JsonProperty
(
"destinationWalletName"
)]
public
string
DestinationWalletName
{
get
;
set
;
}
[
JsonProperty
(
"sessions"
)]
public
IList
<
Session
>
Sessions
{
get
;
set
;
}
public
TumblingState
()
{
this
.
Sessions
=
new
List
<
Session
>();
}
/// <inheritdoc />
public
void
Save
()
{
...
...
@@ -56,9 +62,22 @@ namespace Breeze.TumbleBit.Client
/// <inheritdoc />
public
void
Update
()
{
// get the next cycle to be started
var
cycle
=
this
.
TumblerParameters
.
CycleGenerator
.
GetRegistratingCycle
(
this
.
LastBlockReceivedHeight
);
var
lastCycleStarted
=
this
.
Sessions
.
Max
(
s
=>
s
.
StartCycle
);
// check if we need to start a new session starting from the registration cycle
// TODO remove the limitation to have only 1 session
if
(
lastCycleStarted
!=
cycle
.
Start
&&
this
.
Sessions
.
Count
==
0
)
{
if
(
this
.
Sessions
.
SingleOrDefault
(
s
=>
s
.
StartCycle
==
cycle
.
Start
)
==
null
)
{
this
.
CreateNewSession
(
cycle
.
Start
);
}
}
// get a list of cycles we expect to have at this height
var
cycles
=
this
.
TumblerParameters
.
CycleGenerator
.
GetCycles
(
this
.
LastBlockReceivedHeight
);
var
existingSessions
=
cycles
.
SelectMany
(
c
=>
this
.
Sessions
.
Where
(
s
=>
s
.
StartCycle
==
c
.
Start
)).
ToList
();
foreach
(
var
existingSession
in
existingSessions
)
{
...
...
@@ -75,7 +94,7 @@ namespace Breeze.TumbleBit.Client
session
.
PromiseClientSession
=
new
PromiseClientSession
(
this
.
TumblerParameters
.
CreatePromiseParamaters
(),
existingSession
.
PromiseClientState
);
if
(
existingSession
.
SolverClientState
!=
null
)
session
.
SolverClientSession
=
new
SolverClientSession
(
this
.
TumblerParameters
.
CreateSolverParamaters
(),
existingSession
.
SolverClientState
);
// update the session
session
.
Update
();
...
...
@@ -152,10 +171,13 @@ namespace Breeze.TumbleBit.Client
public
SolverClientSession
.
State
SolverClientState
{
get
;
set
;
}
[
JsonIgnore
]
public
ClientChannelNegotiation
ClientChannelNegotiation
{
get
;
set
;
}
[
JsonIgnore
]
public
SolverClientSession
SolverClientSession
{
get
;
set
;
}
[
JsonIgnore
]
public
PromiseClientSession
PromiseClientSession
{
get
;
set
;
}
public
void
Update
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment