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
aea19297
Commit
aea19297
authored
May 09, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generate multiple accounts and addresses for wallet recovery
parent
8c4ab891
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+20
-4
No files found.
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
aea19297
...
...
@@ -21,7 +21,11 @@ namespace Breeze.Wallet
public
HashSet
<
Script
>
PubKeys
{
get
;
set
;
}
public
HashSet
<
TransactionDetails
>
TrackedTransactions
{
get
;
}
private
const
int
UnusedAddressesBuffer
=
20
;
private
const
int
WalletRecoveryAccountsCreationCount
=
3
;
public
WalletManager
()
{
this
.
Wallets
=
new
List
<
Wallet
>();
...
...
@@ -83,9 +87,21 @@ namespace Breeze.Wallet
// generate the root seed used to generate keys
ExtKey
extendedKey
=
(
new
Mnemonic
(
mnemonic
)).
DeriveExtKey
(
passphrase
);
Network
coinNetwork
=
WalletHelpers
.
GetNetwork
(
network
);
// create a wallet file
Wallet
wallet
=
this
.
GenerateWalletFile
(
password
,
folderPath
,
name
,
WalletHelpers
.
GetNetwork
(
network
)
,
extendedKey
,
creationTime
);
Wallet
wallet
=
this
.
GenerateWalletFile
(
password
,
folderPath
,
name
,
coinNetwork
,
extendedKey
,
creationTime
);
// generate multiple accounts and addresses from the get-go
for
(
int
i
=
0
;
i
<
WalletRecoveryAccountsCreationCount
;
i
++)
{
HdAccount
account
=
CreateNewAccount
(
wallet
,
CoinType
.
Bitcoin
,
password
);
this
.
CreateAddressesInAccount
(
account
,
coinNetwork
,
UnusedAddressesBuffer
);
}
// save the changes to the file and add addresses to be tracked
this
.
SaveToFile
(
wallet
);
this
.
PubKeys
=
this
.
LoadKeys
(
CoinType
.
Bitcoin
);
this
.
Load
(
wallet
);
return
wallet
;
}
...
...
@@ -208,7 +224,7 @@ namespace Breeze.Wallet
/// </summary>
/// <param name="account">The account.</param>
/// <param name="network">The network.</param>
/// <param name="addressesQuantity">The
addresses quantity
.</param>
/// <param name="addressesQuantity">The
number of addresses to create
.</param>
/// <returns>A list of addresses in Base58.</returns>
private
List
<
string
>
CreateAddressesInAccount
(
HdAccount
account
,
Network
network
,
int
addressesQuantity
)
{
...
...
@@ -221,7 +237,7 @@ namespace Breeze.Wallet
indexOfLastUsedAddress
=
account
.
ExternalAddresses
.
Where
(
a
=>
a
.
Transactions
.
Any
()).
Max
(
add
=>
add
.
Index
);
}
for
(
int
i
=
indexOfLastUsedAddress
+
1
;
i
<=
indexOfLastUsedAddress
+
addressesQuantity
;
i
++)
for
(
int
i
=
indexOfLastUsedAddress
;
i
<=
indexOfLastUsedAddress
+
addressesQuantity
;
i
++)
{
// skip over addresses that already exist
if
(
account
.
ExternalAddresses
.
ElementAtOrDefault
(
i
)
!=
null
)
...
...
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