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
2cf7a185
Commit
2cf7a185
authored
May 22, 2017
by
Jeremy Bokobza
Committed by
GitHub
May 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #72 from stratisproject/pre-alpha-dev-release
block sync height early persist
parents
c0f1bac6
18911b37
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
26 deletions
+92
-26
WalletController.cs
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
+1
-1
ITracker.cs
Breeze/src/Breeze.Wallet/ITracker.cs
+8
-1
IWalletManager.cs
Breeze/src/Breeze.Wallet/IWalletManager.cs
+25
-1
Tracker.cs
Breeze/src/Breeze.Wallet/Tracker.cs
+7
-1
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+51
-22
No files found.
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
View file @
2cf7a185
...
...
@@ -130,7 +130,7 @@ namespace Breeze.Wallet.Controllers
{
// get the wallet folder
DirectoryInfo
walletFolder
=
GetWalletFolder
(
request
.
FolderPath
);
Wallet
wallet
=
this
.
walletManager
.
RecoverWallet
(
request
.
Password
,
walletFolder
.
FullName
,
request
.
Name
,
request
.
Network
,
request
.
Mnemonic
,
null
,
request
.
CreationDate
);
Wallet
wallet
=
this
.
walletManager
.
RecoverWallet
(
request
.
Password
,
walletFolder
.
FullName
,
request
.
Name
,
request
.
Network
,
request
.
Mnemonic
,
request
.
CreationDate
,
null
);
// start syncing the wallet from the creation date
this
.
tracker
.
SyncFrom
(
request
.
CreationDate
);
...
...
Breeze/src/Breeze.Wallet/ITracker.cs
View file @
2cf7a185
...
...
@@ -22,7 +22,14 @@ namespace Breeze.Wallet
/// Synchronize the wallet starting from the date passed as a parameter.
/// </summary>
/// <param name="date">The date from which to start the sync process.</param>
/// <returns></returns>
/// <returns>
The height of the block sync will start from
</returns>
void
SyncFrom
(
DateTime
date
);
/// <summary>
/// Synchronize the wallet starting from the height passed as a parameter.
/// </summary>
/// <param name="height">The height from which to start the sync process.</param>
/// <returns>The height of the block sync will start from</returns>
void
SyncFrom
(
int
height
);
}
}
Breeze/src/Breeze.Wallet/IWalletManager.cs
View file @
2cf7a185
...
...
@@ -41,7 +41,7 @@ namespace Breeze.Wallet
/// <param name="passphrase">The passphrase used in the seed.</param>
/// <param name="creationTime">The date and time this wallet was created.</param>
/// <returns>The recovered wallet.</returns>
Wallet
RecoverWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
,
string
passphrase
=
null
,
DateTime
?
creationTim
e
=
null
);
Wallet
RecoverWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
,
DateTime
creationTime
,
string
passphras
e
=
null
);
/// <summary>
/// Deletes a wallet.
...
...
@@ -163,5 +163,29 @@ namespace Breeze.Wallet
/// <param name="blockHeight">The height of the block this transaction came from. Null if it was not a transaction included in a block.</param>
/// <param name="blockTime">The block time.</param>
void
ProcessTransaction
(
Transaction
transaction
,
int
?
blockHeight
=
null
,
uint
?
blockTime
=
null
);
/// <summary>
/// Saves the wallet into the file system.
/// </summary>
/// <param name="wallet">The wallet to save.</param>
void
SaveToFile
(
Wallet
wallet
);
/// <summary>
/// Saves all the loaded wallets into the file system.
/// </summary>
void
SaveToFile
();
/// <summary>
/// Updates the wallet with the height of the last block synced.
/// </summary>
/// <param name="wallet">The wallet to update.</param>
/// <param name="height">The height of the last block synced.</param>
void
UpdateLastBlockSyncedHeight
(
Wallet
wallet
,
int
height
);
/// <summary>
/// Updates all the loaded wallets with the height of the last block synced.
/// </summary>
/// <param name="height">The height of the last block synced.</param>
void
UpdateLastBlockSyncedHeight
(
int
height
);
}
}
Breeze/src/Breeze.Wallet/Tracker.cs
View file @
2cf7a185
...
...
@@ -90,7 +90,13 @@ namespace Breeze.Wallet
int
blockSyncStart
=
this
.
chain
.
GetHeightAtTime
(
date
);
// start syncing blocks
this
.
blockNotification
.
SyncFrom
(
this
.
chain
.
GetBlock
(
blockSyncStart
).
HashBlock
);
this
.
SyncFrom
(
blockSyncStart
);
}
/// <inheritdoc />
public
void
SyncFrom
(
int
height
)
{
this
.
blockNotification
.
SyncFrom
(
this
.
chain
.
GetBlock
(
height
).
HashBlock
);
}
private
bool
BlocksSynced
()
...
...
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
2cf7a185
...
...
@@ -33,6 +33,8 @@ namespace Breeze.Wallet
private
readonly
ConnectionManager
connectionManager
;
private
readonly
ConcurrentChain
chain
;
private
Dictionary
<
Script
,
HdAddress
>
keysLookup
;
/// <summary>
...
...
@@ -40,7 +42,7 @@ namespace Breeze.Wallet
/// </summary>
public
event
EventHandler
<
TransactionFoundEventArgs
>
TransactionFound
;
public
WalletManager
(
ConnectionManager
connectionManager
,
Network
network
)
public
WalletManager
(
ConnectionManager
connectionManager
,
Network
network
,
ConcurrentChain
chain
)
{
this
.
Wallets
=
new
List
<
Wallet
>();
...
...
@@ -53,6 +55,7 @@ namespace Breeze.Wallet
this
.
connectionManager
=
connectionManager
;
this
.
network
=
network
;
this
.
coinType
=
(
CoinType
)
network
.
Consensus
.
CoinType
;
this
.
chain
=
chain
;
// load data in memory for faster lookups
this
.
LoadKeysLookup
();
...
...
@@ -88,11 +91,14 @@ namespace Breeze.Wallet
this
.
CreateAddressesInAccount
(
account
,
coinNetwork
,
UnusedAddressesBuffer
,
true
);
}
// update the height of the we start syncing from
this
.
UpdateLastBlockSyncedHeight
(
wallet
,
this
.
chain
.
Tip
.
Height
);
// save the changes to the file and add addresses to be tracked
this
.
SaveToFile
(
wallet
);
this
.
Load
(
wallet
);
this
.
LoadKeysLookup
();
return
mnemonic
;
}
...
...
@@ -109,7 +115,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public
Wallet
RecoverWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
,
string
passphrase
=
null
,
DateTime
?
creationTim
e
=
null
)
public
Wallet
RecoverWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
,
DateTime
creationTime
,
string
passphras
e
=
null
)
{
// for now the passphrase is set to be the password by default.
if
(
passphrase
==
null
)
...
...
@@ -133,6 +139,9 @@ namespace Breeze.Wallet
this
.
CreateAddressesInAccount
(
account
,
coinNetwork
,
UnusedAddressesBuffer
,
true
);
}
int
blockSyncStart
=
this
.
chain
.
GetHeightAtTime
(
creationTime
);
this
.
UpdateLastBlockSyncedHeight
(
wallet
,
blockSyncStart
);
// save the changes to the file and add addresses to be tracked
this
.
SaveToFile
(
wallet
);
this
.
Load
(
wallet
);
...
...
@@ -320,7 +329,7 @@ namespace Breeze.Wallet
Wallet
wallet
=
this
.
GetWalletByName
(
walletName
);
return
wallet
;
}
/// <inheritdoc />
public
IEnumerable
<
HdAccount
>
GetAccountsByCoinType
(
string
walletName
,
CoinType
coinType
)
{
...
...
@@ -446,13 +455,7 @@ namespace Breeze.Wallet
}
// update the wallets with the last processed block height
foreach
(
var
wallet
in
this
.
Wallets
)
{
foreach
(
var
accountRoot
in
wallet
.
AccountsRoot
.
Where
(
a
=>
a
.
CoinType
==
this
.
coinType
))
{
accountRoot
.
LastBlockSyncedHeight
=
height
;
}
}
this
.
UpdateLastBlockSyncedHeight
(
height
);
}
/// <inheritdoc />
...
...
@@ -483,7 +486,7 @@ namespace Breeze.Wallet
// We first include the keys we don't hold and then we include the keys we do hold but that are for receiving addresses (which would mean the user paid itself).
IEnumerable
<
TxOut
>
paidoutto
=
transaction
.
Outputs
.
Where
(
o
=>
!
this
.
keysLookup
.
Keys
.
Contains
(
o
.
ScriptPubKey
)
||
(
this
.
keysLookup
.
ContainsKey
(
o
.
ScriptPubKey
)
&&
!
this
.
keysLookup
[
o
.
ScriptPubKey
].
IsChangeAddress
()));
AddTransactionToWallet
(
transaction
.
GetHash
(),
transaction
.
Time
,
null
,
-
tTx
.
Amount
,
keyToSpend
,
blockHeight
,
blockTime
,
tTx
.
Id
,
tTx
.
Index
,
paidoutto
);
AddTransactionToWallet
(
transaction
.
GetHash
(),
transaction
.
Time
,
null
,
-
tTx
.
Amount
,
keyToSpend
,
blockHeight
,
blockTime
,
tTx
.
Id
,
tTx
.
Index
,
paidoutto
);
}
}
...
...
@@ -560,7 +563,7 @@ namespace Breeze.Wallet
if
(
blockTime
!=
null
)
{
foundTransaction
.
CreationTime
=
DateTimeOffset
.
FromUnixTimeSeconds
(
blockTime
.
Value
);
}
}
}
// notify a transaction has been found
...
...
@@ -608,6 +611,41 @@ namespace Breeze.Wallet
File
.
Delete
(
walletFilePath
);
}
/// <inheritdoc />
public
void
SaveToFile
(
Wallet
wallet
)
{
File
.
WriteAllText
(
wallet
.
WalletFilePath
,
JsonConvert
.
SerializeObject
(
wallet
,
Formatting
.
Indented
));
}
/// <inheritdoc />
public
void
UpdateLastBlockSyncedHeight
(
int
height
)
{
// update the wallets with the last processed block height
foreach
(
var
wallet
in
this
.
Wallets
)
{
this
.
UpdateLastBlockSyncedHeight
(
wallet
,
height
);
}
}
/// <inheritdoc />
public
void
UpdateLastBlockSyncedHeight
(
Wallet
wallet
,
int
height
)
{
// update the wallets with the last processed block height
foreach
(
var
accountRoot
in
wallet
.
AccountsRoot
.
Where
(
a
=>
a
.
CoinType
==
this
.
coinType
))
{
accountRoot
.
LastBlockSyncedHeight
=
height
;
}
}
/// <inheritdoc />
public
void
SaveToFile
()
{
foreach
(
var
wallet
in
this
.
Wallets
)
{
this
.
SaveToFile
(
wallet
);
}
}
/// <inheritdoc />
public
void
Dispose
()
{
...
...
@@ -658,15 +696,6 @@ namespace Breeze.Wallet
return
walletFile
;
}
/// <summary>
/// Saves the wallet into the file system.
/// </summary>
/// <param name="wallet">The wallet to save.</param>
private
void
SaveToFile
(
Wallet
wallet
)
{
File
.
WriteAllText
(
wallet
.
WalletFilePath
,
JsonConvert
.
SerializeObject
(
wallet
,
Formatting
.
Indented
));
}
/// <summary>
/// Gets the wallet located at the specified path.
/// </summary>
...
...
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