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
a9fa39ab
Commit
a9fa39ab
authored
May 25, 2017
by
Jeremy Bokobza
Committed by
GitHub
May 25, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #81 from bokobza/master
Added logging to a rolling file
parents
99adb77d
92eb9c0a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
23 deletions
+33
-23
.gitignore
.gitignore
+1
-0
Breeze.Wallet.csproj
Breeze/src/Breeze.Wallet/Breeze.Wallet.csproj
+2
-1
Tracker.cs
Breeze/src/Breeze.Wallet/Tracker.cs
+11
-11
WalletFeature.cs
Breeze/src/Breeze.Wallet/WalletFeature.cs
+12
-8
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+7
-3
No files found.
.gitignore
View file @
a9fa39ab
...
@@ -296,3 +296,4 @@ Thumbs.db
...
@@ -296,3 +296,4 @@ Thumbs.db
# DNX
# DNX
project.lock.json
project.lock.json
/Breeze/src/Breeze.Daemon/Wallets
/Breeze/src/Breeze.Daemon/Wallets
/Breeze/src/Breeze.Daemon/Logs
Breeze/src/Breeze.Wallet/Breeze.Wallet.csproj
View file @
a9fa39ab
...
@@ -16,7 +16,8 @@
...
@@ -16,7 +16,8 @@
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.0.3" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.0.1" />
<PackageReference Include="System.ValueTuple" Version="4.3.1" />
<PackageReference Include="System.ValueTuple" Version="4.3.1" />
<PackageReference Include="Stratis.Bitcoin" Version="1.0.1.8-alpha" />
<PackageReference Include="Stratis.Bitcoin" Version="1.0.1.8-alpha" />
</ItemGroup>
</ItemGroup>
...
...
Breeze/src/Breeze.Wallet/Tracker.cs
View file @
a9fa39ab
...
@@ -7,6 +7,7 @@ using System.Text;
...
@@ -7,6 +7,7 @@ using System.Text;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Breeze.Wallet.Notifications
;
using
Breeze.Wallet.Notifications
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
NBitcoin
;
using
Stratis.Bitcoin
;
using
Stratis.Bitcoin
;
using
Stratis.Bitcoin.Notifications
;
using
Stratis.Bitcoin.Notifications
;
...
@@ -21,14 +22,16 @@ namespace Breeze.Wallet
...
@@ -21,14 +22,16 @@ namespace Breeze.Wallet
private
readonly
Signals
signals
;
private
readonly
Signals
signals
;
private
readonly
BlockNotification
blockNotification
;
private
readonly
BlockNotification
blockNotification
;
private
readonly
CoinType
coinType
;
private
readonly
CoinType
coinType
;
private
readonly
ILogger
logger
;
public
Tracker
(
IWalletManager
walletManager
,
ConcurrentChain
chain
,
Signals
signals
,
BlockNotification
blockNotification
,
Network
network
)
public
Tracker
(
I
LoggerFactory
loggerFactory
,
I
WalletManager
walletManager
,
ConcurrentChain
chain
,
Signals
signals
,
BlockNotification
blockNotification
,
Network
network
)
{
{
this
.
walletManager
=
walletManager
as
WalletManager
;
this
.
walletManager
=
walletManager
as
WalletManager
;
this
.
chain
=
chain
;
this
.
chain
=
chain
;
this
.
signals
=
signals
;
this
.
signals
=
signals
;
this
.
blockNotification
=
blockNotification
;
this
.
blockNotification
=
blockNotification
;
this
.
coinType
=
(
CoinType
)
network
.
Consensus
.
CoinType
;
this
.
coinType
=
(
CoinType
)
network
.
Consensus
.
CoinType
;
this
.
logger
=
loggerFactory
.
CreateLogger
(
this
.
GetType
().
FullName
);
}
}
/// <inheritdoc />
/// <inheritdoc />
...
@@ -44,7 +47,9 @@ namespace Breeze.Wallet
...
@@ -44,7 +47,9 @@ namespace Breeze.Wallet
txSub
.
Subscribe
();
txSub
.
Subscribe
();
// start syncing blocks
// start syncing blocks
this
.
blockNotification
.
SyncFrom
(
this
.
chain
.
GetBlock
(
this
.
FindBestHeightForSyncing
()).
HashBlock
);
var
bestHeightForSyncing
=
this
.
FindBestHeightForSyncing
();
this
.
SyncFrom
(
bestHeightForSyncing
);
this
.
logger
.
LogInformation
(
$"Tracker initialized. Syncing from
{
bestHeightForSyncing
}
."
);
}
}
private
int
FindBestHeightForSyncing
()
private
int
FindBestHeightForSyncing
()
...
@@ -75,6 +80,7 @@ namespace Breeze.Wallet
...
@@ -75,6 +80,7 @@ namespace Breeze.Wallet
// wait until the chain is downloaded. We wait until a block is from an hour ago.
// wait until the chain is downloaded. We wait until a block is from an hour ago.
if
(
this
.
chain
.
IsDownloaded
())
if
(
this
.
chain
.
IsDownloaded
())
{
{
this
.
logger
.
LogInformation
(
$"Chain downloaded. Tip height is
{
this
.
chain
.
Tip
.
Height
}
."
);
cancellationTokenSource
.
Cancel
();
cancellationTokenSource
.
Cancel
();
}
}
...
@@ -88,21 +94,15 @@ namespace Breeze.Wallet
...
@@ -88,21 +94,15 @@ namespace Breeze.Wallet
public
void
SyncFrom
(
DateTime
date
)
public
void
SyncFrom
(
DateTime
date
)
{
{
int
blockSyncStart
=
this
.
chain
.
GetHeightAtTime
(
date
);
int
blockSyncStart
=
this
.
chain
.
GetHeightAtTime
(
date
);
// start syncing blocks
// start syncing blocks
this
.
SyncFrom
(
blockSyncStart
);
this
.
SyncFrom
(
blockSyncStart
);
}
}
/// <inheritdoc />
/// <inheritdoc />
public
void
SyncFrom
(
int
height
)
public
void
SyncFrom
(
int
height
)
{
this
.
blockNotification
.
SyncFrom
(
this
.
chain
.
GetBlock
(
height
).
HashBlock
);
}
private
bool
BlocksSynced
()
{
{
return
this
.
walletManager
.
Wallets
.
All
(
w
=>
w
.
AccountsRoot
.
Single
(
a
=>
a
.
CoinType
==
this
.
coinType
).
LastBlockSyncedHeight
==
this
.
chain
.
Tip
.
Height
);
this
.
blockNotification
.
SyncFrom
(
this
.
chain
.
GetBlock
(
height
).
HashBlock
);
}
}
}
}
}
}
Breeze/src/Breeze.Wallet/WalletFeature.cs
View file @
a9fa39ab
...
@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
...
@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
using
Stratis.Bitcoin.Builder
;
using
Stratis.Bitcoin.Builder
;
using
Stratis.Bitcoin.Logging
;
using
Stratis.Bitcoin.Logging
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Logging
;
using
Serilog
;
namespace
Breeze.Wallet
namespace
Breeze.Wallet
{
{
...
@@ -11,7 +12,7 @@ namespace Breeze.Wallet
...
@@ -11,7 +12,7 @@ namespace Breeze.Wallet
{
{
private
readonly
ITracker
tracker
;
private
readonly
ITracker
tracker
;
private
readonly
IWalletManager
walletManager
;
private
readonly
IWalletManager
walletManager
;
public
WalletFeature
(
ITracker
tracker
,
IWalletManager
walletManager
)
public
WalletFeature
(
ITracker
tracker
,
IWalletManager
walletManager
)
{
{
this
.
tracker
=
tracker
;
this
.
tracker
=
tracker
;
...
@@ -19,7 +20,7 @@ namespace Breeze.Wallet
...
@@ -19,7 +20,7 @@ namespace Breeze.Wallet
}
}
public
override
void
Start
()
public
override
void
Start
()
{
{
this
.
tracker
.
Initialize
();
this
.
tracker
.
Initialize
();
}
}
...
@@ -39,12 +40,15 @@ namespace Breeze.Wallet
...
@@ -39,12 +40,15 @@ namespace Breeze.Wallet
features
features
.
AddFeature
<
WalletFeature
>()
.
AddFeature
<
WalletFeature
>()
.
FeatureServices
(
services
=>
.
FeatureServices
(
services
=>
{
{
services
.
AddSingleton
<
ITracker
,
Tracker
>();
var
loggerFactory
=
Logs
.
LoggerFactory
;
services
.
AddSingleton
<
ILoggerFactory
>(
Logs
.
LoggerFactory
);
loggerFactory
.
AddFile
(
"Logs/Breeze-{Date}.json"
,
isJson
:
true
,
minimumLevel
:
LogLevel
.
Debug
,
fileSizeLimitBytes
:
10000000
);
services
.
AddSingleton
<
IWalletManager
,
WalletManager
>();
services
.
AddSingleton
<
WalletController
>();
services
.
AddSingleton
<
ITracker
,
Tracker
>();
});
services
.
AddSingleton
<
ILoggerFactory
>(
loggerFactory
);
services
.
AddSingleton
<
IWalletManager
,
WalletManager
>();
services
.
AddSingleton
<
WalletController
>();
});
});
});
return
fullNodeBuilder
;
return
fullNodeBuilder
;
...
...
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
a9fa39ab
...
@@ -5,6 +5,7 @@ using System.Linq;
...
@@ -5,6 +5,7 @@ using System.Linq;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
using
Breeze.Wallet.Helpers
;
using
Breeze.Wallet.Helpers
;
using
Breeze.Wallet.Models
;
using
Breeze.Wallet.Models
;
using
Microsoft.Extensions.Logging
;
using
NBitcoin
;
using
NBitcoin
;
using
NBitcoin.DataEncoders
;
using
NBitcoin.DataEncoders
;
using
NBitcoin.Protocol
;
using
NBitcoin.Protocol
;
...
@@ -37,13 +38,16 @@ namespace Breeze.Wallet
...
@@ -37,13 +38,16 @@ namespace Breeze.Wallet
private
Dictionary
<
Script
,
HdAddress
>
keysLookup
;
private
Dictionary
<
Script
,
HdAddress
>
keysLookup
;
private
readonly
ILogger
logger
;
/// <summary>
/// <summary>
/// Occurs when a transaction is found.
/// Occurs when a transaction is found.
/// </summary>
/// </summary>
public
event
EventHandler
<
TransactionFoundEventArgs
>
TransactionFound
;
public
event
EventHandler
<
TransactionFoundEventArgs
>
TransactionFound
;
public
WalletManager
(
ConnectionManager
connectionManager
,
Network
network
,
ConcurrentChain
chain
)
public
WalletManager
(
ILoggerFactory
loggerFactory
,
ConnectionManager
connectionManager
,
Network
network
,
ConcurrentChain
chain
)
{
{
this
.
logger
=
loggerFactory
.
CreateLogger
(
this
.
GetType
().
FullName
);
this
.
Wallets
=
new
List
<
Wallet
>();
this
.
Wallets
=
new
List
<
Wallet
>();
// find wallets and load them in memory
// find wallets and load them in memory
...
@@ -447,7 +451,7 @@ namespace Breeze.Wallet
...
@@ -447,7 +451,7 @@ namespace Breeze.Wallet
/// <inheritdoc />
/// <inheritdoc />
public
void
ProcessBlock
(
int
height
,
Block
block
)
public
void
ProcessBlock
(
int
height
,
Block
block
)
{
{
Console
.
WriteLine
(
$"block notification: height:
{
height
}
, block hash:
{
block
.
Header
.
GetHash
()}
, coin type
:
{
this
.
coinType
}
"
);
this
.
logger
.
LogDebug
(
$"block notification - height:
{
height
}
, hash:
{
block
.
Header
.
GetHash
()}
, coin
:
{
this
.
coinType
}
"
);
foreach
(
Transaction
transaction
in
block
.
Transactions
)
foreach
(
Transaction
transaction
in
block
.
Transactions
)
{
{
...
@@ -461,7 +465,7 @@ namespace Breeze.Wallet
...
@@ -461,7 +465,7 @@ namespace Breeze.Wallet
/// <inheritdoc />
/// <inheritdoc />
public
void
ProcessTransaction
(
Transaction
transaction
,
int
?
blockHeight
=
null
,
Block
block
=
null
)
public
void
ProcessTransaction
(
Transaction
transaction
,
int
?
blockHeight
=
null
,
Block
block
=
null
)
{
{
Console
.
WriteLine
(
$"transaction notification: tx hash
{
transaction
.
GetHash
()}
, coin type
:
{
this
.
coinType
}
"
);
this
.
logger
.
LogDebug
(
$"transaction received - hash:
{
transaction
.
GetHash
()}
, coin
:
{
this
.
coinType
}
"
);
// check the outputs
// check the outputs
foreach
(
var
pubKey
in
this
.
keysLookup
.
Keys
)
foreach
(
var
pubKey
in
this
.
keysLookup
.
Keys
)
...
...
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