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
2279ba4a
Commit
2279ba4a
authored
May 09, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Internal addresses creation in wallet recovery
parent
aea19297
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
19 deletions
+25
-19
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+25
-19
No files found.
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
2279ba4a
...
...
@@ -97,6 +97,7 @@ namespace Breeze.Wallet
{
HdAccount
account
=
CreateNewAccount
(
wallet
,
CoinType
.
Bitcoin
,
password
);
this
.
CreateAddressesInAccount
(
account
,
coinNetwork
,
UnusedAddressesBuffer
);
this
.
CreateAddressesInAccount
(
account
,
coinNetwork
,
UnusedAddressesBuffer
,
true
);
}
// save the changes to the file and add addresses to be tracked
...
...
@@ -200,11 +201,10 @@ namespace Breeze.Wallet
if
(
account
.
ExternalAddresses
.
Any
())
{
// check last created address contains transactions.
int
lastAddressIndex
=
account
.
ExternalAddresses
.
Max
(
a
=>
a
.
Index
);
var
lastAddress
=
account
.
ExternalAddresses
.
SingleOrDefault
(
a
=>
a
.
Index
==
lastAddressIndex
);
if
(
lastAddress
!=
null
&&
!
lastAddress
.
Transactions
.
Any
())
var
firstUnusedExternalAddress
=
account
.
GetFirstUnusedExternalAddress
();
if
(
firstUnusedExternalAddress
!=
null
)
{
return
last
Address
.
Address
;
return
firstUnusedExternal
Address
.
Address
;
}
}
...
...
@@ -225,34 +225,31 @@ namespace Breeze.Wallet
/// <param name="account">The account.</param>
/// <param name="network">The network.</param>
/// <param name="addressesQuantity">The number of addresses to create.</param>
/// <param name="isChange">Whether the addresses added are change (internal) addresses or receiving (external) addresses.</param>
/// <returns>A list of addresses in Base58.</returns>
private
List
<
string
>
CreateAddressesInAccount
(
HdAccount
account
,
Network
network
,
int
addressesQuantity
)
private
List
<
string
>
CreateAddressesInAccount
(
HdAccount
account
,
Network
network
,
int
addressesQuantity
,
bool
isChange
=
false
)
{
List
<
string
>
addressesCreated
=
new
List
<
string
>();
var
addresses
=
isChange
?
account
.
InternalAddresses
:
account
.
ExternalAddresses
;
// gets the index of the last address with transactions
int
indexOfLastUsedAddress
=
0
;
if
(
a
ccount
.
ExternalA
ddresses
.
Any
())
int
firstNewAddressIndex
=
0
;
if
(
addresses
.
Any
())
{
indexOfLastUsedAddress
=
account
.
ExternalAddresses
.
Where
(
a
=>
a
.
Transactions
.
Any
()).
Max
(
add
=>
add
.
Index
)
;
firstNewAddressIndex
=
addresses
.
Max
(
add
=>
add
.
Index
)
+
1
;
}
for
(
int
i
=
indexOfLastUsedAddress
;
i
<=
indexOfLastUsedAddress
+
addressesQuantity
;
i
++)
for
(
int
i
=
firstNewAddressIndex
;
i
<
firstNewAddressIndex
+
addressesQuantity
;
i
++)
{
// skip over addresses that already exist
if
(
account
.
ExternalAddresses
.
ElementAtOrDefault
(
i
)
!=
null
)
{
continue
;
}
// generate new receiving address
BitcoinPubKeyAddress
address
=
this
.
GenerateAddress
(
account
.
ExtendedPubKey
,
i
,
false
,
network
);
// add address details
a
ccount
.
ExternalAddresses
=
account
.
ExternalA
ddresses
.
Concat
(
new
[]
{
new
HdAddress
a
ddresses
=
a
ddresses
.
Concat
(
new
[]
{
new
HdAddress
{
Index
=
i
,
HdPath
=
CreateBip44Path
(
account
.
GetCoinType
(),
account
.
Index
,
i
,
fals
e
),
HdPath
=
CreateBip44Path
(
account
.
GetCoinType
(),
account
.
Index
,
i
,
isChang
e
),
ScriptPubKey
=
address
.
ScriptPubKey
,
Address
=
address
.
ToString
(),
Transactions
=
new
List
<
TransactionData
>(),
...
...
@@ -262,6 +259,15 @@ namespace Breeze.Wallet
addressesCreated
.
Add
(
address
.
ToString
());
}
if
(
isChange
)
{
account
.
InternalAddresses
=
addresses
;
}
else
{
account
.
ExternalAddresses
=
addresses
;
}
return
addressesCreated
;
}
...
...
@@ -546,8 +552,8 @@ namespace Breeze.Wallet
SelectMany
(
a
=>
a
.
Accounts
).
SelectMany
(
a
=>
a
.
ExternalAddresses
).
Select
(
s
=>
s
.
ScriptPubKey
));
// uncomment the following for testing on a random address
//Select(t => (new BitcoinPubKeyAddress(t.Address, Network.Main)).ScriptPubKey));
// uncomment the following for testing on a random address
//Select(t => (new BitcoinPubKeyAddress(t.Address, Network.Main)).ScriptPubKey));
}
/// <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