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
Show 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
...
@@ -63,7 +63,7 @@ namespace Breeze.TumbleBit.Controllers
try
try
{
{
await
this
.
tumbleBitManager
.
TumbleAsync
(
request
.
DestinationWalletName
);
await
this
.
tumbleBitManager
.
TumbleAsync
(
request
.
OriginWalletName
,
request
.
DestinationWalletName
);
return
this
.
Ok
();
return
this
.
Ok
();
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
...
...
Breeze/src/Breeze.TumbleBit.Client/ITumbleBitManager.cs
View file @
b200b823
...
@@ -17,7 +17,7 @@ namespace Breeze.TumbleBit.Client
...
@@ -17,7 +17,7 @@ namespace Breeze.TumbleBit.Client
/// <returns></returns>
/// <returns></returns>
Task
<
ClassicTumblerParameters
>
ConnectToTumblerAsync
(
Uri
serverAddress
);
Task
<
ClassicTumblerParameters
>
ConnectToTumblerAsync
(
Uri
serverAddress
);
Task
TumbleAsync
(
string
destinationWalletName
);
Task
TumbleAsync
(
string
originWalletName
,
string
destinationWalletName
);
/// <summary>
/// <summary>
/// Processes a block received from the network.
/// 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
...
@@ -28,7 +28,10 @@ namespace Breeze.TumbleBit.Models
public
class
TumbleRequest
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
;
}
public
string
DestinationWalletName
{
get
;
set
;
}
}
}
}
}
Breeze/src/Breeze.TumbleBit.Client/TumbleBitManager.cs
View file @
b200b823
...
@@ -23,13 +23,11 @@ namespace Breeze.TumbleBit.Client
...
@@ -23,13 +23,11 @@ namespace Breeze.TumbleBit.Client
private
readonly
Network
network
;
private
readonly
Network
network
;
private
TumblingState
tumblingState
;
private
TumblingState
tumblingState
;
private
IDisposable
blockReceiver
;
private
IDisposable
blockReceiver
;
int
lastCycleStarted
;
private
ClassicTumblerParameters
TumblerParameters
{
get
;
set
;
}
private
ClassicTumblerParameters
TumblerParameters
{
get
;
set
;
}
public
TumbleBitManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
Signals
signals
)
public
TumbleBitManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
Signals
signals
)
{
{
this
.
lastCycleStarted
=
0
;
this
.
walletManager
=
walletManager
;
this
.
walletManager
=
walletManager
;
this
.
chain
=
chain
;
this
.
chain
=
chain
;
this
.
signals
=
signals
;
this
.
signals
=
signals
;
...
@@ -64,7 +62,7 @@ namespace Breeze.TumbleBit.Client
...
@@ -64,7 +62,7 @@ namespace Breeze.TumbleBit.Client
}
}
/// <inheritdoc />
/// <inheritdoc />
public
Task
TumbleAsync
(
string
destinationWalletName
)
public
Task
TumbleAsync
(
string
originWalletName
,
string
destinationWalletName
)
{
{
// make sure the tumbler service is initialized
// make sure the tumbler service is initialized
if
(
this
.
TumblerParameters
==
null
||
this
.
tumblerService
==
null
)
if
(
this
.
TumblerParameters
==
null
||
this
.
tumblerService
==
null
)
...
@@ -81,11 +79,19 @@ namespace Breeze.TumbleBit.Client
...
@@ -81,11 +79,19 @@ namespace Breeze.TumbleBit.Client
Wallet
destinationWallet
=
this
.
walletManager
.
GetWallet
(
destinationWalletName
);
Wallet
destinationWallet
=
this
.
walletManager
.
GetWallet
(
destinationWalletName
);
if
(
destinationWallet
==
null
)
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
// update the state and save
this
.
tumblingState
.
DestinationWalletName
=
destinationWalletName
;
this
.
tumblingState
.
DestinationWalletName
=
destinationWalletName
;
this
.
tumblingState
.
OriginWalletName
=
originWalletName
;
this
.
tumblingState
.
Save
();
this
.
tumblingState
.
Save
();
// subscribe to receiving blocks
// subscribe to receiving blocks
...
@@ -114,29 +120,12 @@ namespace Breeze.TumbleBit.Client
...
@@ -114,29 +120,12 @@ namespace Breeze.TumbleBit.Client
/// <inheritdoc />
/// <inheritdoc />
public
void
ProcessBlock
(
int
height
,
Block
block
)
public
void
ProcessBlock
(
int
height
,
Block
block
)
{
{
// TODO start the state machine
this
.
logger
.
LogDebug
(
$"Received block with height
{
height
}
during tumbling session."
);
this
.
logger
.
LogDebug
(
$"Receive block with height
{
height
}
"
);
// update the block height in the tumbling state
// update the block height in the tumbling state
this
.
tumblingState
.
LastBlockReceivedHeight
=
height
;
this
.
tumblingState
.
LastBlockReceivedHeight
=
height
;
this
.
tumblingState
.
Save
();
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
// update the state of the tumbling session in this new block
this
.
tumblingState
.
Update
();
this
.
tumblingState
.
Update
();
}
}
...
...
Breeze/src/Breeze.TumbleBit.Client/TumblingState.cs
View file @
b200b823
...
@@ -4,10 +4,12 @@ using System.IO;
...
@@ -4,10 +4,12 @@ using System.IO;
using
System.Linq
;
using
System.Linq
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
using
NTumbleBit.ClassicTumbler
;
using
NTumbleBit.ClassicTumbler
;
using
NTumbleBit.PuzzlePromise
;
using
NTumbleBit.PuzzlePromise
;
using
NTumbleBit.PuzzleSolver
;
using
NTumbleBit.PuzzleSolver
;
using
Stratis.Bitcoin.Wallet
;
namespace
Breeze.TumbleBit.Client
namespace
Breeze.TumbleBit.Client
{
{
...
@@ -24,9 +26,13 @@ namespace Breeze.TumbleBit.Client
...
@@ -24,9 +26,13 @@ namespace Breeze.TumbleBit.Client
[
JsonProperty
(
"lastBlockReceivedHeight"
)]
[
JsonProperty
(
"lastBlockReceivedHeight"
)]
public
int
LastBlockReceivedHeight
{
get
;
set
;
}
public
int
LastBlockReceivedHeight
{
get
;
set
;
}
[
JsonProperty
(
"originWalletName"
)]
public
string
OriginWalletName
{
get
;
set
;
}
[
JsonProperty
(
"destinationWalletName"
)]
[
JsonProperty
(
"destinationWalletName"
)]
public
string
DestinationWalletName
{
get
;
set
;
}
public
string
DestinationWalletName
{
get
;
set
;
}
[
JsonProperty
(
"sessions"
)]
public
IList
<
Session
>
Sessions
{
get
;
set
;
}
public
IList
<
Session
>
Sessions
{
get
;
set
;
}
public
TumblingState
()
public
TumblingState
()
...
@@ -56,9 +62,22 @@ namespace Breeze.TumbleBit.Client
...
@@ -56,9 +62,22 @@ namespace Breeze.TumbleBit.Client
/// <inheritdoc />
/// <inheritdoc />
public
void
Update
()
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
// get a list of cycles we expect to have at this height
var
cycles
=
this
.
TumblerParameters
.
CycleGenerator
.
GetCycles
(
this
.
LastBlockReceivedHeight
);
var
cycles
=
this
.
TumblerParameters
.
CycleGenerator
.
GetCycles
(
this
.
LastBlockReceivedHeight
);
var
existingSessions
=
cycles
.
SelectMany
(
c
=>
this
.
Sessions
.
Where
(
s
=>
s
.
StartCycle
==
c
.
Start
)).
ToList
();
var
existingSessions
=
cycles
.
SelectMany
(
c
=>
this
.
Sessions
.
Where
(
s
=>
s
.
StartCycle
==
c
.
Start
)).
ToList
();
foreach
(
var
existingSession
in
existingSessions
)
foreach
(
var
existingSession
in
existingSessions
)
{
{
...
@@ -152,10 +171,13 @@ namespace Breeze.TumbleBit.Client
...
@@ -152,10 +171,13 @@ namespace Breeze.TumbleBit.Client
public
SolverClientSession
.
State
SolverClientState
{
get
;
set
;
}
public
SolverClientSession
.
State
SolverClientState
{
get
;
set
;
}
[
JsonIgnore
]
public
ClientChannelNegotiation
ClientChannelNegotiation
{
get
;
set
;
}
public
ClientChannelNegotiation
ClientChannelNegotiation
{
get
;
set
;
}
[
JsonIgnore
]
public
SolverClientSession
SolverClientSession
{
get
;
set
;
}
public
SolverClientSession
SolverClientSession
{
get
;
set
;
}
[
JsonIgnore
]
public
PromiseClientSession
PromiseClientSession
{
get
;
set
;
}
public
PromiseClientSession
PromiseClientSession
{
get
;
set
;
}
public
void
Update
()
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