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
e752cba2
Commit
e752cba2
authored
May 22, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the height of last block that was synced without waiting to receive a new block
parent
c0f1bac6
Show 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 @
e752cba2
...
@@ -130,7 +130,7 @@ namespace Breeze.Wallet.Controllers
...
@@ -130,7 +130,7 @@ namespace Breeze.Wallet.Controllers
{
{
// get the wallet folder
// get the wallet folder
DirectoryInfo
walletFolder
=
GetWalletFolder
(
request
.
FolderPath
);
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
// start syncing the wallet from the creation date
this
.
tracker
.
SyncFrom
(
request
.
CreationDate
);
this
.
tracker
.
SyncFrom
(
request
.
CreationDate
);
...
...
Breeze/src/Breeze.Wallet/ITracker.cs
View file @
e752cba2
...
@@ -22,7 +22,14 @@ namespace Breeze.Wallet
...
@@ -22,7 +22,14 @@ namespace Breeze.Wallet
/// Synchronize the wallet starting from the date passed as a parameter.
/// Synchronize the wallet starting from the date passed as a parameter.
/// </summary>
/// </summary>
/// <param name="date">The date from which to start the sync process.</param>
/// <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
);
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 @
e752cba2
...
@@ -41,7 +41,7 @@ namespace Breeze.Wallet
...
@@ -41,7 +41,7 @@ namespace Breeze.Wallet
/// <param name="passphrase">The passphrase used in the seed.</param>
/// <param name="passphrase">The passphrase used in the seed.</param>
/// <param name="creationTime">The date and time this wallet was created.</param>
/// <param name="creationTime">The date and time this wallet was created.</param>
/// <returns>The recovered wallet.</returns>
/// <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>
/// <summary>
/// Deletes a wallet.
/// Deletes a wallet.
...
@@ -163,5 +163,29 @@ namespace Breeze.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="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>
/// <param name="blockTime">The block time.</param>
void
ProcessTransaction
(
Transaction
transaction
,
int
?
blockHeight
=
null
,
uint
?
blockTime
=
null
);
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 @
e752cba2
...
@@ -90,7 +90,13 @@ namespace Breeze.Wallet
...
@@ -90,7 +90,13 @@ namespace Breeze.Wallet
int
blockSyncStart
=
this
.
chain
.
GetHeightAtTime
(
date
);
int
blockSyncStart
=
this
.
chain
.
GetHeightAtTime
(
date
);
// start syncing blocks
// 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
()
private
bool
BlocksSynced
()
...
...
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
e752cba2
...
@@ -33,6 +33,8 @@ namespace Breeze.Wallet
...
@@ -33,6 +33,8 @@ namespace Breeze.Wallet
private
readonly
ConnectionManager
connectionManager
;
private
readonly
ConnectionManager
connectionManager
;
private
readonly
ConcurrentChain
chain
;
private
Dictionary
<
Script
,
HdAddress
>
keysLookup
;
private
Dictionary
<
Script
,
HdAddress
>
keysLookup
;
/// <summary>
/// <summary>
...
@@ -40,7 +42,7 @@ namespace Breeze.Wallet
...
@@ -40,7 +42,7 @@ namespace Breeze.Wallet
/// </summary>
/// </summary>
public
event
EventHandler
<
TransactionFoundEventArgs
>
TransactionFound
;
public
event
EventHandler
<
TransactionFoundEventArgs
>
TransactionFound
;
public
WalletManager
(
ConnectionManager
connectionManager
,
Network
network
)
public
WalletManager
(
ConnectionManager
connectionManager
,
Network
network
,
ConcurrentChain
chain
)
{
{
this
.
Wallets
=
new
List
<
Wallet
>();
this
.
Wallets
=
new
List
<
Wallet
>();
...
@@ -53,6 +55,7 @@ namespace Breeze.Wallet
...
@@ -53,6 +55,7 @@ namespace Breeze.Wallet
this
.
connectionManager
=
connectionManager
;
this
.
connectionManager
=
connectionManager
;
this
.
network
=
network
;
this
.
network
=
network
;
this
.
coinType
=
(
CoinType
)
network
.
Consensus
.
CoinType
;
this
.
coinType
=
(
CoinType
)
network
.
Consensus
.
CoinType
;
this
.
chain
=
chain
;
// load data in memory for faster lookups
// load data in memory for faster lookups
this
.
LoadKeysLookup
();
this
.
LoadKeysLookup
();
...
@@ -88,6 +91,9 @@ namespace Breeze.Wallet
...
@@ -88,6 +91,9 @@ namespace Breeze.Wallet
this
.
CreateAddressesInAccount
(
account
,
coinNetwork
,
UnusedAddressesBuffer
,
true
);
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
// save the changes to the file and add addresses to be tracked
this
.
SaveToFile
(
wallet
);
this
.
SaveToFile
(
wallet
);
this
.
Load
(
wallet
);
this
.
Load
(
wallet
);
...
@@ -109,7 +115,7 @@ namespace Breeze.Wallet
...
@@ -109,7 +115,7 @@ namespace Breeze.Wallet
}
}
/// <inheritdoc />
/// <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.
// for now the passphrase is set to be the password by default.
if
(
passphrase
==
null
)
if
(
passphrase
==
null
)
...
@@ -133,6 +139,9 @@ namespace Breeze.Wallet
...
@@ -133,6 +139,9 @@ namespace Breeze.Wallet
this
.
CreateAddressesInAccount
(
account
,
coinNetwork
,
UnusedAddressesBuffer
,
true
);
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
// save the changes to the file and add addresses to be tracked
this
.
SaveToFile
(
wallet
);
this
.
SaveToFile
(
wallet
);
this
.
Load
(
wallet
);
this
.
Load
(
wallet
);
...
@@ -446,13 +455,7 @@ namespace Breeze.Wallet
...
@@ -446,13 +455,7 @@ namespace Breeze.Wallet
}
}
// update the wallets with the last processed block height
// update the wallets with the last processed block height
foreach
(
var
wallet
in
this
.
Wallets
)
this
.
UpdateLastBlockSyncedHeight
(
height
);
{
foreach
(
var
accountRoot
in
wallet
.
AccountsRoot
.
Where
(
a
=>
a
.
CoinType
==
this
.
coinType
))
{
accountRoot
.
LastBlockSyncedHeight
=
height
;
}
}
}
}
/// <inheritdoc />
/// <inheritdoc />
...
@@ -608,6 +611,41 @@ namespace Breeze.Wallet
...
@@ -608,6 +611,41 @@ namespace Breeze.Wallet
File
.
Delete
(
walletFilePath
);
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 />
/// <inheritdoc />
public
void
Dispose
()
public
void
Dispose
()
{
{
...
@@ -658,15 +696,6 @@ namespace Breeze.Wallet
...
@@ -658,15 +696,6 @@ namespace Breeze.Wallet
return
walletFile
;
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>
/// <summary>
/// Gets the wallet located at the specified path.
/// Gets the wallet located at the specified path.
/// </summary>
/// </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