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
fe3f4aff
Commit
fe3f4aff
authored
Jun 06, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added a method to start receiving blocks
parent
c3beda01
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
151 additions
and
40 deletions
+151
-40
BlockObserver.cs
Breeze/src/Breeze.TumbleBit.Client/BlockObserver.cs
+33
-0
TumbleBitController.cs
...reeze.TumbleBit.Client/Controllers/TumbleBitController.cs
+29
-3
ITumbleBitManager.cs
Breeze/src/Breeze.TumbleBit.Client/ITumbleBitManager.cs
+12
-1
RequestModels.cs
Breeze/src/Breeze.TumbleBit.Client/Models/RequestModels.cs
+6
-0
TumbleBitFeature.cs
Breeze/src/Breeze.TumbleBit.Client/TumbleBitFeature.cs
+1
-1
TumbleBitManager.cs
Breeze/src/Breeze.TumbleBit.Client/TumbleBitManager.cs
+70
-0
TumblerManager.cs
Breeze/src/Breeze.TumbleBit.Client/TumblerManager.cs
+0
-35
No files found.
Breeze/src/Breeze.TumbleBit.Client/BlockObserver.cs
0 → 100644
View file @
fe3f4aff
using
Breeze.TumbleBit.Client
;
using
NBitcoin
;
using
Stratis.Bitcoin
;
namespace
Breeze.TumbleBit
{
/// <summary>
/// Observer that receives notifications about the arrival of new <see cref="Block"/>s.
/// </summary>
public
class
BlockObserver
:
SignalObserver
<
Block
>
{
private
readonly
ConcurrentChain
chain
;
private
readonly
ITumbleBitManager
tumbleBitManager
;
public
BlockObserver
(
ConcurrentChain
chain
,
ITumbleBitManager
tumbleBitManager
)
{
this
.
chain
=
chain
;
this
.
tumbleBitManager
=
tumbleBitManager
;
}
/// <summary>
/// Manages what happens when a new block is received.
/// </summary>
/// <param name="block">The new block</param>
protected
override
void
OnNextCore
(
Block
block
)
{
var
hash
=
block
.
Header
.
GetHash
();
var
height
=
this
.
chain
.
GetBlock
(
hash
).
Height
;
this
.
tumbleBitManager
.
ProcessBlock
(
height
,
block
);
}
}
}
Breeze/src/Breeze.TumbleBit.Client/Controllers/TumbleBitController.cs
View file @
fe3f4aff
...
...
@@ -4,6 +4,7 @@ using System.Net;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Mvc
;
using
Breeze.TumbleBit.Client
;
using
Breeze.TumbleBit.Models
;
using
Stratis.Bitcoin.Common.JsonErrors
;
namespace
Breeze.TumbleBit.Controllers
...
...
@@ -25,8 +26,8 @@ namespace Breeze.TumbleBit.Controllers
/// Connect to a tumbler.
/// </summary>
[
Route
(
"connect"
)]
[
Http
Ge
t
]
public
async
Task
<
IActionResult
>
ConnectAsync
()
[
Http
Pos
t
]
public
async
Task
<
IActionResult
>
ConnectAsync
(
[
FromBody
]
TumblerConnectionRequest
request
)
{
// checks the request is valid
if
(!
this
.
ModelState
.
IsValid
)
...
...
@@ -37,7 +38,7 @@ namespace Breeze.TumbleBit.Controllers
try
{
var
tumblerParameters
=
await
this
.
tumbleBitManager
.
ConnectToTumblerAsync
();
var
tumblerParameters
=
await
this
.
tumbleBitManager
.
ConnectToTumblerAsync
(
request
.
ServerAddress
);
return
this
.
Json
(
tumblerParameters
);
}
catch
(
Exception
e
)
...
...
@@ -45,5 +46,30 @@ namespace Breeze.TumbleBit.Controllers
return
ErrorHelpers
.
BuildErrorResponse
(
HttpStatusCode
.
BadRequest
,
$"An error occured connecting to the tumbler."
,
e
.
ToString
());
}
}
/// <summary>
/// Connect to a tumbler.
/// </summary>
[
Route
(
"tumble"
)]
[
HttpPost
]
public
async
Task
<
IActionResult
>
TumbleAsync
([
FromBody
]
TumbleRequest
request
)
{
// checks the request is valid
if
(!
this
.
ModelState
.
IsValid
)
{
var
errors
=
this
.
ModelState
.
Values
.
SelectMany
(
e
=>
e
.
Errors
.
Select
(
m
=>
m
.
ErrorMessage
));
return
ErrorHelpers
.
BuildErrorResponse
(
HttpStatusCode
.
BadRequest
,
"Formatting error"
,
string
.
Join
(
Environment
.
NewLine
,
errors
));
}
try
{
await
this
.
tumbleBitManager
.
TumbleAsync
(
request
.
DestinationWalletName
);
return
this
.
Ok
();
}
catch
(
Exception
e
)
{
return
ErrorHelpers
.
BuildErrorResponse
(
HttpStatusCode
.
BadRequest
,
$"An error occured connecting to the tumbler."
,
e
.
ToString
());
}
}
}
}
Breeze/src/Breeze.TumbleBit.Client/ITumbleBitManager.cs
View file @
fe3f4aff
...
...
@@ -2,6 +2,7 @@
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading.Tasks
;
using
NBitcoin
;
using
NTumbleBit.ClassicTumbler
;
namespace
Breeze.TumbleBit.Client
...
...
@@ -14,7 +15,17 @@ namespace Breeze.TumbleBit.Client
/// <summary>
/// Connects to the tumbler.
/// </summary>
/// <param name="serverAddress">The URI of the tumbler.</param>
/// <returns></returns>
Task
<
ClassicTumblerParameters
>
ConnectToTumblerAsync
();
Task
<
ClassicTumblerParameters
>
ConnectToTumblerAsync
(
Uri
serverAddress
);
Task
TumbleAsync
(
string
destinationWalletName
);
/// <summary>
/// Processes a block received from the network.
/// </summary>
/// <param name="height">The height of the block in the blockchain.</param>
/// <param name="block">The block.</param>
void
ProcessBlock
(
int
height
,
Block
block
);
}
}
Breeze/src/Breeze.TumbleBit.Client/Models/RequestModels.cs
View file @
fe3f4aff
...
...
@@ -25,4 +25,10 @@ namespace Breeze.TumbleBit.Models
public
string
Network
{
get
;
set
;
}
}
public
class
TumbleRequest
{
[
Required
(
ErrorMessage
=
"A wallet name is required."
)]
public
string
DestinationWalletName
{
get
;
set
;
}
}
}
Breeze/src/Breeze.TumbleBit.Client/TumbleBitFeature.cs
View file @
fe3f4aff
...
...
@@ -35,7 +35,7 @@ namespace Breeze.TumbleBit
.
AddFeature
<
TumbleBitFeature
>()
.
FeatureServices
(
services
=>
{
services
.
AddSingleton
<
ITumbleBitManager
>(
new
TumbleBitManager
(
serverAddress
)
);
services
.
AddSingleton
<
ITumbleBitManager
,
TumbleBitManager
>
(
);
services
.
AddSingleton
<
TumbleBitController
>();
});
});
...
...
Breeze/src/Breeze.TumbleBit.Client/TumbleBitManager.cs
0 → 100644
View file @
fe3f4aff
using
System
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
NTumbleBit.ClassicTumbler
;
using
Stratis.Bitcoin
;
using
Stratis.Bitcoin.Logging
;
using
Stratis.Bitcoin.Wallet
;
namespace
Breeze.TumbleBit.Client
{
/// <summary>
/// An implementation of a tumbler manager.
/// </summary>
/// <seealso cref="Breeze.TumbleBit.Client.ITumbleBitManager" />
public
class
TumbleBitManager
:
ITumbleBitManager
{
private
ITumblerService
tumblerService
;
private
IWalletManager
walletManager
;
private
readonly
ILogger
logger
;
private
readonly
Signals
signals
;
private
readonly
ConcurrentChain
chain
;
private
ClassicTumblerParameters
TumblerParameters
{
get
;
set
;
}
public
TumbleBitManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
Signals
signals
)
{
this
.
walletManager
=
walletManager
;
this
.
chain
=
chain
;
this
.
signals
=
signals
;
this
.
logger
=
loggerFactory
.
CreateLogger
(
this
.
GetType
().
FullName
);
}
/// <inheritdoc />
public
async
Task
<
ClassicTumblerParameters
>
ConnectToTumblerAsync
(
Uri
serverAddress
)
{
this
.
tumblerService
=
new
TumblerService
(
serverAddress
);
this
.
TumblerParameters
=
await
this
.
tumblerService
.
GetClassicTumblerParametersAsync
();
return
this
.
TumblerParameters
;
}
/// <inheritdoc />
public
Task
TumbleAsync
(
string
destinationWalletName
)
{
if
(
this
.
TumblerParameters
==
null
||
this
.
tumblerService
==
null
)
{
throw
new
Exception
(
"Please connect to the tumbler first."
);
}
Wallet
destinationWallet
=
this
.
walletManager
.
GetWallet
(
destinationWalletName
);
if
(
destinationWallet
==
null
)
{
throw
new
Exception
(
$"Destination not found. Have you created a wallet with name
{
destinationWalletName
}
?"
);
}
// subscribe to receiving blocks and transactions
this
.
signals
.
Blocks
.
Subscribe
(
new
BlockObserver
(
this
.
chain
,
this
));
return
Task
.
CompletedTask
;
}
/// <inheritdoc />
public
void
ProcessBlock
(
int
height
,
Block
block
)
{
// TODO start the state machine
this
.
logger
.
LogDebug
(
$"Receive block with height
{
height
}
"
);
}
}
}
Breeze/src/Breeze.TumbleBit.Client/TumblerManager.cs
deleted
100644 → 0
View file @
c3beda01
using
System
;
using
System.Threading.Tasks
;
using
NTumbleBit.ClassicTumbler
;
namespace
Breeze.TumbleBit.Client
{
/// <summary>
/// An implementation of a tumbler manager.
/// </summary>
/// <seealso cref="Breeze.TumbleBit.Client.ITumbleBitManager" />
public
class
TumbleBitManager
:
ITumbleBitManager
{
private
ITumblerService
tumblerService
;
public
TumbleBitManager
(
Uri
serverAddress
)
{
this
.
InitializeTumblerService
(
serverAddress
);
}
/// <summary>
/// Initializes the tumbler service.
/// </summary>
/// <param name="serverAddress">The server address.</param>
public
void
InitializeTumblerService
(
Uri
serverAddress
)
{
this
.
tumblerService
=
new
TumblerService
(
serverAddress
);
}
/// <inheritdoc />
public
async
Task
<
ClassicTumblerParameters
>
ConnectToTumblerAsync
()
{
return
await
this
.
tumblerService
.
GetClassicTumblerParametersAsync
();
}
}
}
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