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
07459133
Commit
07459133
authored
Jul 24, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tabs cleanup
parent
8d101c54
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
245 additions
and
255 deletions
+245
-255
ApiFeature.cs
Breeze/src/Breeze.Api/ApiFeature.cs
+62
-63
NodeController.cs
Breeze/src/Breeze.Api/Controllers/NodeController.cs
+44
-49
MvcBuilderExtensions.cs
Breeze/src/Breeze.Api/MvcBuilderExtensions.cs
+17
-17
Program.cs
Breeze/src/Breeze.Api/Program.cs
+39
-39
Startup.cs
Breeze/src/Breeze.Api/Startup.cs
+67
-67
LightWalletFeature.cs
Breeze/src/Breeze.Wallet/LightWalletFeature.cs
+4
-6
LightWalletSyncManager.cs
Breeze/src/Breeze.Wallet/LightWalletSyncManager.cs
+12
-14
No files found.
Breeze/src/Breeze.Api/ApiFeature.cs
View file @
07459133
...
...
@@ -6,43 +6,42 @@ using Microsoft.Extensions.Logging;
using
Stratis.Bitcoin
;
using
Stratis.Bitcoin.Builder
;
using
Stratis.Bitcoin.Builder.Feature
;
using
Stratis.Bitcoin.Logging
;
using
Stratis.Bitcoin.Utilities
;
namespace
Breeze.Api
{
/// <summary>
/// Provides an Api to the full node
/// </summary>
public
class
ApiFeature
:
FullNodeFeature
{
private
readonly
IFullNodeBuilder
fullNodeBuilder
;
private
readonly
FullNode
fullNode
;
private
readonly
ApiFeatureOptions
apiFeatureOptions
;
private
readonly
IAsyncLoopFactory
asyncLoopFactory
;
private
readonly
ILogger
logger
;
/// <summary>
/// Provides an Api to the full node
/// </summary>
public
class
ApiFeature
:
FullNodeFeature
{
private
readonly
IFullNodeBuilder
fullNodeBuilder
;
private
readonly
FullNode
fullNode
;
private
readonly
ApiFeatureOptions
apiFeatureOptions
;
private
readonly
IAsyncLoopFactory
asyncLoopFactory
;
private
readonly
ILogger
logger
;
public
ApiFeature
(
IFullNodeBuilder
fullNodeBuilder
,
FullNode
fullNode
,
ApiFeatureOptions
apiFeatureOptions
,
IAsyncLoopFactory
asyncLoopFactory
,
ILoggerFactory
loggerFactory
)
{
this
.
fullNodeBuilder
=
fullNodeBuilder
;
this
.
fullNode
=
fullNode
;
this
.
apiFeatureOptions
=
apiFeatureOptions
;
this
.
asyncLoopFactory
=
asyncLoopFactory
;
this
.
logger
=
loggerFactory
.
CreateLogger
(
this
.
GetType
().
FullName
);
}
public
ApiFeature
(
IFullNodeBuilder
fullNodeBuilder
,
FullNode
fullNode
,
ApiFeatureOptions
apiFeatureOptions
,
IAsyncLoopFactory
asyncLoopFactory
,
ILoggerFactory
loggerFactory
)
{
this
.
fullNodeBuilder
=
fullNodeBuilder
;
this
.
fullNode
=
fullNode
;
this
.
apiFeatureOptions
=
apiFeatureOptions
;
this
.
asyncLoopFactory
=
asyncLoopFactory
;
this
.
logger
=
loggerFactory
.
CreateLogger
(
this
.
GetType
().
FullName
);
}
public
override
void
Start
()
{
this
.
logger
.
LogInformation
(
$"Api starting on url
{
this
.
fullNode
.
Settings
.
ApiUri
}
"
);
public
override
void
Start
()
{
this
.
logger
.
LogInformation
(
$"Api starting on url
{
this
.
fullNode
.
Settings
.
ApiUri
}
"
);
Program
.
Initialize
(
this
.
fullNodeBuilder
.
Services
,
this
.
fullNode
);
this
.
TryStartKeepaliveMonitor
();
}
this
.
TryStartKeepaliveMonitor
();
}
/// <summary>
/// A KeepaliveMonitor when enabled will shutdown the
...
...
@@ -50,26 +49,26 @@ namespace Breeze.Api
/// during a certain trashold window
/// </summary>
public
void
TryStartKeepaliveMonitor
()
{
if
(
this
.
apiFeatureOptions
.
KeepaliveMonitor
?.
KeepaliveInterval
.
TotalSeconds
>
0
)
{
this
.
asyncLoopFactory
.
Run
(
"ApiFeature.KeepaliveMonitor"
,
token
=>
{
// shortened for redability
var
monitor
=
this
.
apiFeatureOptions
.
KeepaliveMonitor
;
{
if
(
this
.
apiFeatureOptions
.
KeepaliveMonitor
?.
KeepaliveInterval
.
TotalSeconds
>
0
)
{
this
.
asyncLoopFactory
.
Run
(
"ApiFeature.KeepaliveMonitor"
,
token
=>
{
// shortened for redability
var
monitor
=
this
.
apiFeatureOptions
.
KeepaliveMonitor
;
// check the trashold to trigger a shutdown
if
(
monitor
.
LastBeat
.
Add
(
monitor
.
KeepaliveInterval
)
<
DateTime
.
UtcNow
)
this
.
fullNode
.
Stop
();
// check the trashold to trigger a shutdown
if
(
monitor
.
LastBeat
.
Add
(
monitor
.
KeepaliveInterval
)
<
DateTime
.
UtcNow
)
this
.
fullNode
.
Stop
();
return
Task
.
CompletedTask
;
},
this
.
fullNode
.
NodeLifetime
.
ApplicationStopping
,
repeatEvery
:
this
.
apiFeatureOptions
.
KeepaliveMonitor
?.
KeepaliveInterval
,
startAfter
:
TimeSpans
.
Minute
);
}
}
}
return
Task
.
CompletedTask
;
},
this
.
fullNode
.
NodeLifetime
.
ApplicationStopping
,
repeatEvery
:
this
.
apiFeatureOptions
.
KeepaliveMonitor
?.
KeepaliveInterval
,
startAfter
:
TimeSpans
.
Minute
);
}
}
}
public
class
ApiFeatureOptions
{
...
...
@@ -82,25 +81,25 @@ namespace Breeze.Api
}
public
static
class
ApiFeatureExtension
{
public
static
IFullNodeBuilder
UseApi
(
this
IFullNodeBuilder
fullNodeBuilder
,
Action
<
ApiFeatureOptions
>
optionsAction
=
null
)
{
{
public
static
IFullNodeBuilder
UseApi
(
this
IFullNodeBuilder
fullNodeBuilder
,
Action
<
ApiFeatureOptions
>
optionsAction
=
null
)
{
// TODO: move the options in to the feature builder
var
options
=
new
ApiFeatureOptions
();
var
options
=
new
ApiFeatureOptions
();
optionsAction
?.
Invoke
(
options
);
fullNodeBuilder
.
ConfigureFeature
(
features
=>
{
features
.
AddFeature
<
ApiFeature
>()
.
FeatureServices
(
services
=>
{
services
.
AddSingleton
(
fullNodeBuilder
);
services
.
AddSingleton
(
options
);
});
});
{
features
.
AddFeature
<
ApiFeature
>()
.
FeatureServices
(
services
=>
{
services
.
AddSingleton
(
fullNodeBuilder
);
services
.
AddSingleton
(
options
);
});
});
return
fullNodeBuilder
;
}
}
return
fullNodeBuilder
;
}
}
}
Breeze/src/Breeze.Api/Controllers/NodeController.cs
View file @
07459133
using
System
;
using
System.ComponentModel.DataAnnotations
;
using
Breeze.Api.Models
;
using
Microsoft.AspNetCore.Hosting
;
using
Microsoft.AspNetCore.Mvc
;
using
NBitcoin
;
using
Stratis.Bitcoin.Builder
;
using
Stratis.Bitcoin.Notifications
;
namespace
Breeze.Api.Controllers
{
[
Route
(
"api/[controller]"
)]
public
class
NodeController
:
Controller
{
private
readonly
IFullNode
fullNode
;
private
readonly
ApiFeatureOptions
apiFeatureOptions
;
public
NodeController
(
IFullNode
fullNode
,
ApiFeatureOptions
apiFeatureOptions
)
{
this
.
fullNode
=
fullNode
;
this
.
apiFeatureOptions
=
apiFeatureOptions
;
}
{
[
Route
(
"api/[controller]"
)]
public
class
NodeController
:
Controller
{
private
readonly
IFullNode
fullNode
;
private
readonly
ApiFeatureOptions
apiFeatureOptions
;
public
NodeController
(
IFullNode
fullNode
,
ApiFeatureOptions
apiFeatureOptions
)
{
this
.
fullNode
=
fullNode
;
this
.
apiFeatureOptions
=
apiFeatureOptions
;
}
/// <summary>
/// Returns some general information about the status of the underlying node.
/// </summary>
/// <returns></returns>
[
HttpGet
]
[
Route
(
"status"
)]
public
IActionResult
Status
()
{
return
this
.
NotFound
();
}
[
HttpGet
]
[
Route
(
"status"
)]
public
IActionResult
Status
()
{
return
this
.
NotFound
();
}
/// <summary>
/// Trigger a shoutdown of the current running node.
/// </summary>
/// <returns></returns>
[
HttpPost
]
[
Route
(
"shutdown"
)]
public
IActionResult
Shutdown
()
{
/// <summary>
/// Trigger a shoutdown of the current running node.
/// </summary>
/// <returns></returns>
[
HttpPost
]
[
Route
(
"shutdown"
)]
public
IActionResult
Shutdown
()
{
// start the node shutdown process
this
.
fullNode
.
Stop
();
return
this
.
Ok
();
}
/// <summary>
/// Set the keepalive flag.
/// </summary>
/// <returns></returns>
[
HttpPost
]
[
Route
(
"keepalive"
)]
public
IActionResult
Keepalive
()
{
if
(
this
.
apiFeatureOptions
.
KeepaliveMonitor
==
null
)
return
new
ObjectResult
(
"Keepalive Disabled"
)
{
StatusCode
=
405
};
// (405) Method Not Allowed
return
this
.
Ok
();
}
this
.
apiFeatureOptions
.
KeepaliveMonitor
.
LastBeat
=
DateTime
.
UtcNow
;
return
this
.
Ok
();
}
}
/// <summary>
/// Set the keepalive flag.
/// </summary>
/// <returns></returns>
[
HttpPost
]
[
Route
(
"keepalive"
)]
public
IActionResult
Keepalive
()
{
if
(
this
.
apiFeatureOptions
.
KeepaliveMonitor
==
null
)
return
new
ObjectResult
(
"Keepalive Disabled"
)
{
StatusCode
=
405
};
// (405) Method Not Allowed
this
.
apiFeatureOptions
.
KeepaliveMonitor
.
LastBeat
=
DateTime
.
UtcNow
;
return
this
.
Ok
();
}
}
}
\ No newline at end of file
Breeze/src/Breeze.Api/MvcBuilderExtensions.cs
View file @
07459133
...
...
@@ -7,22 +7,22 @@ namespace Breeze.Api
{
public
static
class
MvcBuilderExtensions
{
/// <summary>
/// Finds all the types that are <see cref="Controller"/> and add them to the Api as services.
/// </summary>
/// <param name="builder">The builder</param>
/// <param name="services">The services to look into</param>
/// <returns>The Mvc builder</returns>
public
static
IMvcBuilder
AddControllers
(
this
IMvcBuilder
builder
,
IServiceCollection
services
)
{
var
controllerTypes
=
services
.
Where
(
s
=>
s
.
ServiceType
.
GetTypeInfo
().
BaseType
==
typeof
(
Controller
));
foreach
(
var
controllerType
in
controllerTypes
)
{
builder
.
AddApplicationPart
(
controllerType
.
ServiceType
.
GetTypeInfo
().
Assembly
);
}
/// <summary>
/// Finds all the types that are <see cref="Controller"/> and add them to the Api as services.
/// </summary>
/// <param name="builder">The builder</param>
/// <param name="services">The services to look into</param>
/// <returns>The Mvc builder</returns>
public
static
IMvcBuilder
AddControllers
(
this
IMvcBuilder
builder
,
IServiceCollection
services
)
{
var
controllerTypes
=
services
.
Where
(
s
=>
s
.
ServiceType
.
GetTypeInfo
().
BaseType
==
typeof
(
Controller
));
foreach
(
var
controllerType
in
controllerTypes
)
{
builder
.
AddApplicationPart
(
controllerType
.
ServiceType
.
GetTypeInfo
().
Assembly
);
}
builder
.
AddControllersAsServices
();
return
builder
;
}
}
builder
.
AddControllersAsServices
();
return
builder
;
}
}
}
Breeze/src/Breeze.Api/Program.cs
View file @
07459133
...
...
@@ -6,45 +6,45 @@ using Stratis.Bitcoin;
namespace
Breeze.Api
{
public
class
Program
{
public
static
void
Main
(
string
[]
args
)
{
}
public
class
Program
{
public
static
void
Main
(
string
[]
args
)
{
}
public
static
void
Initialize
(
IEnumerable
<
ServiceDescriptor
>
services
,
FullNode
fullNode
)
{
var
host
=
new
WebHostBuilder
()
.
UseKestrel
()
.
UseContentRoot
(
Directory
.
GetCurrentDirectory
())
.
UseIISIntegration
()
.
UseUrls
(
fullNode
.
Settings
.
ApiUri
.
ToString
())
.
ConfigureServices
(
collection
=>
{
if
(
services
==
null
||
fullNode
==
null
)
{
return
;
}
// copies all the services defined for the full node to the Api.
// also copies over singleton instances already defined
foreach
(
var
service
in
services
)
{
var
obj
=
fullNode
.
Services
.
ServiceProvider
.
GetService
(
service
.
ServiceType
);
if
(
obj
!=
null
&&
service
.
Lifetime
==
ServiceLifetime
.
Singleton
&&
service
.
ImplementationInstance
==
null
)
{
collection
.
AddSingleton
(
service
.
ServiceType
,
obj
);
}
else
{
collection
.
Add
(
service
);
}
}
})
.
UseStartup
<
Startup
>()
.
Build
();
public
static
void
Initialize
(
IEnumerable
<
ServiceDescriptor
>
services
,
FullNode
fullNode
)
{
var
host
=
new
WebHostBuilder
()
.
UseKestrel
()
.
UseContentRoot
(
Directory
.
GetCurrentDirectory
())
.
UseIISIntegration
()
.
UseUrls
(
fullNode
.
Settings
.
ApiUri
.
ToString
())
.
ConfigureServices
(
collection
=>
{
if
(
services
==
null
||
fullNode
==
null
)
{
return
;
}
host
.
Start
();
}
}
// copies all the services defined for the full node to the Api.
// also copies over singleton instances already defined
foreach
(
var
service
in
services
)
{
var
obj
=
fullNode
.
Services
.
ServiceProvider
.
GetService
(
service
.
ServiceType
);
if
(
obj
!=
null
&&
service
.
Lifetime
==
ServiceLifetime
.
Singleton
&&
service
.
ImplementationInstance
==
null
)
{
collection
.
AddSingleton
(
service
.
ServiceType
,
obj
);
}
else
{
collection
.
Add
(
service
);
}
}
})
.
UseStartup
<
Startup
>()
.
Build
();
host
.
Start
();
}
}
}
Breeze/src/Breeze.Api/Startup.cs
View file @
07459133
...
...
@@ -11,83 +11,83 @@ using Swashbuckle.AspNetCore.Swagger;
namespace
Breeze.Api
{
public
class
Startup
{
public
Startup
(
IHostingEnvironment
env
)
{
var
builder
=
new
ConfigurationBuilder
()
.
SetBasePath
(
env
.
ContentRootPath
)
.
AddJsonFile
(
"appsettings.json"
,
optional
:
true
,
reloadOnChange
:
true
)
.
AddJsonFile
(
$"appsettings.
{
env
.
EnvironmentName
}
.json"
,
optional
:
true
)
.
AddEnvironmentVariables
();
Configuration
=
builder
.
Build
();
}
public
class
Startup
{
public
Startup
(
IHostingEnvironment
env
)
{
var
builder
=
new
ConfigurationBuilder
()
.
SetBasePath
(
env
.
ContentRootPath
)
.
AddJsonFile
(
"appsettings.json"
,
optional
:
true
,
reloadOnChange
:
true
)
.
AddJsonFile
(
$"appsettings.
{
env
.
EnvironmentName
}
.json"
,
optional
:
true
)
.
AddEnvironmentVariables
();
Configuration
=
builder
.
Build
();
}
public
IConfigurationRoot
Configuration
{
get
;
}
public
IConfigurationRoot
Configuration
{
get
;
}
// This method gets called by the runtime. Use this method to add services to the container.
public
void
ConfigureServices
(
IServiceCollection
services
)
{
// Add service and create Policy to allow Cross-Origin Requests
services
.
AddCors
(
options
=>
{
options
.
AddPolicy
(
"CorsPolicy"
,
// This method gets called by the runtime. Use this method to add services to the container.
public
void
ConfigureServices
(
IServiceCollection
services
)
{
// Add service and create Policy to allow Cross-Origin Requests
services
.
AddCors
(
options
=>
{
options
.
AddPolicy
(
"CorsPolicy"
,
builder
=>
{
var
allowedDomains
=
new
[]{
"http://localhost"
,
"http://localhost:4200"
};
builder
=>
{
var
allowedDomains
=
new
[]
{
"http://localhost"
,
"http://localhost:4200"
};
builder
.
WithOrigins
(
allowedDomains
)
.
AllowAnyMethod
()
.
AllowAnyHeader
()
.
AllowCredentials
();
}
);
});
// Add framework services.
services
.
AddMvc
(
options
=>
options
.
Filters
.
Add
(
typeof
(
LoggingActionFilter
)))
// add serializers for NBitcoin objects
.
AddJsonOptions
(
options
=>
NBitcoin
.
JsonConverters
.
Serializer
.
RegisterFrontConverters
(
options
.
SerializerSettings
))
.
AddControllers
(
services
);
builder
.
WithOrigins
(
allowedDomains
)
.
AllowAnyMethod
()
.
AllowAnyHeader
()
.
AllowCredentials
();
}
);
});
// Register the Swagger generator, defining one or more Swagger documents
services
.
AddSwaggerGen
(
setup
=>
{
setup
.
SwaggerDoc
(
"v1"
,
new
Info
{
Title
=
"Breeze.Api"
,
Version
=
"v1"
});
// Add framework services.
services
.
AddMvc
(
options
=>
options
.
Filters
.
Add
(
typeof
(
LoggingActionFilter
)))
// add serializers for NBitcoin objects
.
AddJsonOptions
(
options
=>
NBitcoin
.
JsonConverters
.
Serializer
.
RegisterFrontConverters
(
options
.
SerializerSettings
))
.
AddControllers
(
services
);
//Set the comments path for the swagger json and ui.
var
basePath
=
PlatformServices
.
Default
.
Application
.
ApplicationBasePath
;
var
apiXmlPath
=
Path
.
Combine
(
basePath
,
"Breeze.Api.xml"
);
var
walletXmlPath
=
Path
.
Combine
(
basePath
,
"Breeze.Wallet.xml"
);
setup
.
IncludeXmlComments
(
apiXmlPath
);
setup
.
IncludeXmlComments
(
walletXmlPath
);
// Register the Swagger generator, defining one or more Swagger documents
services
.
AddSwaggerGen
(
setup
=>
{
setup
.
SwaggerDoc
(
"v1"
,
new
Info
{
Title
=
"Breeze.Api"
,
Version
=
"v1"
});
//Set the comments path for the swagger json and ui.
var
basePath
=
PlatformServices
.
Default
.
Application
.
ApplicationBasePath
;
var
apiXmlPath
=
Path
.
Combine
(
basePath
,
"Breeze.Api.xml"
);
var
walletXmlPath
=
Path
.
Combine
(
basePath
,
"Breeze.Wallet.xml"
);
setup
.
IncludeXmlComments
(
apiXmlPath
);
setup
.
IncludeXmlComments
(
walletXmlPath
);
});
}
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public
void
Configure
(
IApplicationBuilder
app
,
IHostingEnvironment
env
,
ILoggerFactory
loggerFactory
)
{
loggerFactory
.
AddConsole
(
this
.
Configuration
.
GetSection
(
"Logging"
));
loggerFactory
.
AddDebug
();
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public
void
Configure
(
IApplicationBuilder
app
,
IHostingEnvironment
env
,
ILoggerFactory
loggerFactory
)
{
loggerFactory
.
AddConsole
(
this
.
Configuration
.
GetSection
(
"Logging"
));
loggerFactory
.
AddDebug
();
app
.
UseCors
(
"CorsPolicy"
);
app
.
UseCors
(
"CorsPolicy"
);
app
.
UseMvc
();
app
.
UseMvc
();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app
.
UseSwagger
();
// Enable middleware to serve generated Swagger as a JSON endpoint.
app
.
UseSwagger
();
// Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
app
.
UseSwaggerUI
(
c
=>
{
c
.
SwaggerEndpoint
(
"/swagger/v1/swagger.json"
,
"Breeze.Api V1"
);
});
}
}
// Enable middleware to serve swagger-ui (HTML, JS, CSS etc.), specifying the Swagger JSON endpoint.
app
.
UseSwaggerUI
(
c
=>
{
c
.
SwaggerEndpoint
(
"/swagger/v1/swagger.json"
,
"Breeze.Api V1"
);
});
}
}
}
Breeze/src/Breeze.Wallet/LightWalletFeature.cs
View file @
07459133
using
System
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Stratis.Bitcoin.Builder.Feature
;
using
Microsoft.Extensions.DependencyInjection
;
...
...
@@ -8,7 +7,6 @@ using NBitcoin.Protocol;
using
Stratis.Bitcoin
;
using
Stratis.Bitcoin.Builder
;
using
Stratis.Bitcoin.Connection
;
using
Stratis.Bitcoin.Consensus
;
using
Stratis.Bitcoin.Consensus.Deployments
;
using
Stratis.Bitcoin.Utilities
;
using
Stratis.Bitcoin.Wallet
;
...
...
@@ -25,9 +23,9 @@ namespace Breeze.Wallet
private
readonly
ConcurrentChain
chain
;
private
readonly
NodeDeployments
nodeDeployments
;
private
readonly
IAsyncLoopFactory
asyncLoopFactory
;
private
readonly
INodeLifetime
nodeLifetime
;
private
readonly
INodeLifetime
nodeLifetime
;
public
LightWalletFeature
(
IWalletSyncManager
walletSyncManager
,
IWalletManager
walletManager
,
IConnectionManager
connectionManager
,
public
LightWalletFeature
(
IWalletSyncManager
walletSyncManager
,
IWalletManager
walletManager
,
IConnectionManager
connectionManager
,
ConcurrentChain
chain
,
NodeDeployments
nodeDeployments
,
IAsyncLoopFactory
asyncLoopFactory
,
INodeLifetime
nodeLifetime
)
{
this
.
walletSyncManager
=
walletSyncManager
;
...
...
@@ -36,7 +34,7 @@ namespace Breeze.Wallet
this
.
chain
=
chain
;
this
.
nodeDeployments
=
nodeDeployments
;
this
.
asyncLoopFactory
=
asyncLoopFactory
;
this
.
nodeLifetime
=
nodeLifetime
;
this
.
nodeLifetime
=
nodeLifetime
;
}
public
override
void
Start
()
...
...
Breeze/src/Breeze.Wallet/LightWalletSyncManager.cs
View file @
07459133
using
System
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
NBitcoin.JsonConverters
;
using
Stratis.Bitcoin
;
using
Stratis.Bitcoin.Notifications
;
using
Stratis.Bitcoin.Utilities
;
...
...
@@ -23,20 +21,20 @@ namespace Breeze.Wallet
private
readonly
ILogger
logger
;
private
readonly
Signals
signals
;
private
ChainedBlock
walletTip
;
private
readonly
INodeLifetime
nodeLifetime
;
private
readonly
IAsyncLoopFactory
asyncLoopFactory
;
private
readonly
INodeLifetime
nodeLifetime
;
private
readonly
IAsyncLoopFactory
asyncLoopFactory
;
public
ChainedBlock
WalletTip
=>
this
.
walletTip
;
public
ChainedBlock
WalletTip
=>
this
.
walletTip
;
public
LightWalletSyncManager
(
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
ILoggerFactory
loggerFactory
,
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Network
network
,
BlockNotification
blockNotification
,
Signals
signals
,
INodeLifetime
nodeLifetime
,
IAsyncLoopFactory
asyncLoopFactory
)
Signals
signals
,
INodeLifetime
nodeLifetime
,
IAsyncLoopFactory
asyncLoopFactory
)
{
this
.
walletManager
=
walletManager
as
WalletManager
;
this
.
chain
=
chain
;
...
...
@@ -45,7 +43,7 @@ namespace Breeze.Wallet
this
.
coinType
=
(
CoinType
)
network
.
Consensus
.
CoinType
;
this
.
logger
=
loggerFactory
.
CreateLogger
(
this
.
GetType
().
FullName
);
this
.
nodeLifetime
=
nodeLifetime
;
this
.
asyncLoopFactory
=
asyncLoopFactory
;
this
.
asyncLoopFactory
=
asyncLoopFactory
;
}
/// <inheritdoc />
...
...
@@ -183,7 +181,7 @@ namespace Breeze.Wallet
// if the chain is already past the height we want to sync from, we don't wait, even though the chain might not be fully downloaded.
if
(
this
.
chain
.
Tip
.
Height
<
height
)
{
this
.
asyncLoopFactory
.
RunUntil
(
"WalletFeature.DownloadChain"
,
this
.
nodeLifetime
.
ApplicationStopping
,
this
.
asyncLoopFactory
.
RunUntil
(
"WalletFeature.DownloadChain"
,
this
.
nodeLifetime
.
ApplicationStopping
,
()
=>
this
.
chain
.
Tip
.
Height
>=
height
,
()
=>
this
.
StartSync
(
height
),
(
ex
)
=>
...
...
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