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
bf06398b
Commit
bf06398b
authored
Apr 25, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Regrouped the accounts for different coins under the same wallet
parent
da338538
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
64 additions
and
35 deletions
+64
-35
ControllersTests.cs
Breeze/src/Breeze.Api.Tests/ControllersTests.cs
+2
-2
Wallet.postman_collection.json
...Api.Tests/Postman requests/Wallet.postman_collection.json
+2
-2
WalletController.cs
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
+2
-2
IWalletManager.cs
Breeze/src/Breeze.Wallet/IWalletManager.cs
+6
-6
CreateAccountModel.cs
Breeze/src/Breeze.Wallet/Models/CreateAccountModel.cs
+6
-0
CreateAddressModel.cs
Breeze/src/Breeze.Wallet/Models/CreateAddressModel.cs
+6
-0
Wallet.cs
Breeze/src/Breeze.Wallet/Wallet.cs
+12
-0
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+28
-23
No files found.
Breeze/src/Breeze.Api.Tests/ControllersTests.cs
View file @
bf06398b
...
...
@@ -20,7 +20,7 @@ namespace Breeze.Api.Tests
{
Mnemonic
mnemonic
=
new
Mnemonic
(
Wordlist
.
English
,
WordCount
.
Twelve
);
var
mockWalletCreate
=
new
Mock
<
IWalletManager
>();
mockWalletCreate
.
Setup
(
wallet
=>
wallet
.
CreateWallet
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
null
,
CoinType
.
Bitcoin
)).
Returns
(
mnemonic
);
mockWalletCreate
.
Setup
(
wallet
=>
wallet
.
CreateWallet
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
null
)).
Returns
(
mnemonic
);
var
controller
=
new
WalletController
(
mockWalletCreate
.
Object
);
...
...
@@ -50,7 +50,7 @@ namespace Breeze.Api.Tests
};
var
mockWalletWrapper
=
new
Mock
<
IWalletManager
>();
mockWalletWrapper
.
Setup
(
w
=>
w
.
RecoverWallet
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
null
,
CoinType
.
Bitcoin
,
null
)).
Returns
(
wallet
);
mockWalletWrapper
.
Setup
(
w
=>
w
.
RecoverWallet
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
null
,
null
)).
Returns
(
wallet
);
var
controller
=
new
WalletController
(
mockWalletWrapper
.
Object
);
...
...
Breeze/src/Breeze.Api.Tests/Postman requests/Wallet.postman_collection.json
View file @
bf06398b
...
...
@@ -241,7 +241,7 @@
],
"body"
:
{
"mode"
:
"raw"
,
"raw"
:
"{
\n\t\"
walletName
\"
:
\"
myFirstWallet
\"
,
\n\t\"
accountName
\"
:
\"
account one
\"
,
\n\t\"
password
\"
:
\"
123456
\"\n
}"
"raw"
:
"{
\n\t\"
walletName
\"
:
\"
myFirstWallet
\"
,
\n\t\"
accountName
\"
:
\"
account one
\"
,
\n\t\"
password
\"
:
\"
123456
\"
,
\n\t\"
coinType
\"
: 105
\n
}"
},
"description"
:
""
},
...
...
@@ -261,7 +261,7 @@
],
"body"
:
{
"mode"
:
"raw"
,
"raw"
:
"{
\n\t\"
walletName
\"
:
\"
myFirstWallet
\"
,
\n\t\"
accountName
\"
:
\"
account one
\"\n
}"
"raw"
:
"{
\n\t\"
walletName
\"
:
\"
myFirstWallet
\"
,
\n\t\"
accountName
\"
:
\"
account one
\"
,
\n\t\"
coinType
\"
: 0
\n
}"
},
"description"
:
""
},
...
...
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
View file @
bf06398b
...
...
@@ -328,7 +328,7 @@ namespace Breeze.Wallet.Controllers
try
{
var
result
=
this
.
walletManager
.
CreateNewAccount
(
request
.
WalletName
,
request
.
AccountName
,
request
.
Password
);
var
result
=
this
.
walletManager
.
CreateNewAccount
(
request
.
WalletName
,
request
.
CoinType
,
request
.
AccountName
,
request
.
Password
);
return
this
.
Json
(
result
);
}
catch
(
Exception
e
)
...
...
@@ -354,7 +354,7 @@ namespace Breeze.Wallet.Controllers
try
{
var
result
=
this
.
walletManager
.
CreateNewAddress
(
request
.
WalletName
,
request
.
AccountName
);
var
result
=
this
.
walletManager
.
CreateNewAddress
(
request
.
WalletName
,
request
.
CoinType
,
request
.
AccountName
);
return
this
.
Json
(
result
);
}
catch
(
Exception
e
)
...
...
Breeze/src/Breeze.Wallet/IWalletManager.cs
View file @
bf06398b
...
...
@@ -17,9 +17,8 @@ namespace Breeze.Wallet
/// <param name="name">The name of the wallet.</param>
/// <param name="network">The network this wallet is for.</param>
/// <param name="passphrase">The passphrase used in the seed.</param>
/// <param name="coinType">The type of coin this wallet will contain.</param>
/// <returns>A mnemonic defining the wallet's seed used to generate addresses.</returns>
Mnemonic
CreateWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
passphrase
=
null
,
CoinType
coinType
=
CoinType
.
Bitcoin
);
Mnemonic
CreateWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
passphrase
=
null
);
/// <summary>
/// Loads a wallet from a file.
...
...
@@ -39,10 +38,9 @@ namespace Breeze.Wallet
/// <param name="network">The network in which to creae this wallet</param>
/// <param name="mnemonic">The user's mnemonic for the wallet.</param>
/// <param name="passphrase">The passphrase used in the seed.</param>
/// <param name="coinType">The type of coin this wallet will contain.</param>
/// <param name="creationTime">The 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
,
CoinType
coinType
=
CoinType
.
Bitcoin
,
DateTimeOffset
?
creationTime
=
null
);
Wallet
RecoverWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
,
string
passphrase
=
null
,
DateTimeOffset
?
creationTime
=
null
);
/// <summary>
/// Deleted a wallet.
...
...
@@ -54,6 +52,7 @@ namespace Breeze.Wallet
/// Creates a new account.
/// </summary>
/// <param name="walletName">The name of the wallet in which this account will be created.</param>
/// <param name="coinType">the type of coin for which to create an account.</param>
/// <param name="accountName">The name by which this account will be identified.</param>
/// <param name="password">The password used to decrypt the private key.</param>
/// <remarks>
...
...
@@ -61,15 +60,16 @@ namespace Breeze.Wallet
/// at index (i - 1) contains transactions.
/// </remarks>
/// <returns>The name of the new account.</returns>
string
CreateNewAccount
(
string
walletName
,
string
accountName
,
string
password
);
string
CreateNewAccount
(
string
walletName
,
CoinType
coinType
,
string
accountName
,
string
password
);
/// <summary>
/// Creates the new address.
/// </summary>
/// <param name="walletName">The name of the wallet in which this address will be created.</param>
/// <param name="coinType">the type of coin for which to create an account.</param>
/// <param name="accountName">The name of the account in which this address will be created.</param>
/// <returns>The new address, in Base58 format.</returns>
string
CreateNewAddress
(
string
walletName
,
string
accountName
);
string
CreateNewAddress
(
string
walletName
,
CoinType
coinType
,
string
accountName
);
WalletGeneralInfoModel
GetGeneralInfo
(
string
walletName
);
...
...
Breeze/src/Breeze.Wallet/Models/CreateAccountModel.cs
View file @
bf06398b
...
...
@@ -13,6 +13,12 @@ namespace Breeze.Wallet.Models
[
Required
]
public
string
WalletName
{
get
;
set
;
}
/// <summary>
/// The type of coin this account contains.
/// </summary>
[
Required
]
public
CoinType
CoinType
{
get
;
set
;
}
/// <summary>
/// The name of the account.
/// </summary>
...
...
Breeze/src/Breeze.Wallet/Models/CreateAddressModel.cs
View file @
bf06398b
...
...
@@ -13,6 +13,12 @@ namespace Breeze.Wallet.Models
[
Required
]
public
string
WalletName
{
get
;
set
;
}
/// <summary>
/// The type of coin this account contains.
/// </summary>
[
Required
]
public
CoinType
CoinType
{
get
;
set
;
}
/// <summary>
/// The name of the account in which to create the address.
/// </summary>
...
...
Breeze/src/Breeze.Wallet/Wallet.cs
View file @
bf06398b
...
...
@@ -51,6 +51,18 @@ namespace Breeze.Wallet
[
JsonProperty
(
PropertyName
=
"walletFilePath"
)]
public
string
WalletFilePath
{
get
;
set
;
}
/// <summary>
/// The root of the accounts tree.
/// </summary>
[
JsonProperty
(
PropertyName
=
"accountsRoot"
)]
public
IEnumerable
<
AccountRoot
>
AccountsRoot
{
get
;
set
;
}
}
/// <summary>
/// The root for the accounts for any type of coins.
/// </summary>
public
class
AccountRoot
{
/// <summary>
/// The type of coin, Bitcoin or Stratis.
/// </summary>
...
...
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
bf06398b
...
...
@@ -23,7 +23,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public
Mnemonic
CreateWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
passphrase
=
null
,
CoinType
coinType
=
CoinType
.
Bitcoin
)
public
Mnemonic
CreateWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
passphrase
=
null
)
{
// for now the passphrase is set to be the password by default.
if
(
passphrase
==
null
)
...
...
@@ -37,7 +37,7 @@ namespace Breeze.Wallet
ExtKey
extendedKey
=
mnemonic
.
DeriveExtKey
(
passphrase
);
// create a wallet file
Wallet
wallet
=
this
.
GenerateWalletFile
(
password
,
folderPath
,
name
,
WalletHelpers
.
GetNetwork
(
network
),
extendedKey
,
coinType
);
Wallet
wallet
=
this
.
GenerateWalletFile
(
password
,
folderPath
,
name
,
WalletHelpers
.
GetNetwork
(
network
),
extendedKey
);
this
.
Load
(
wallet
);
return
mnemonic
;
...
...
@@ -59,7 +59,7 @@ namespace Breeze.Wallet
}
/// <inheritdoc />
public
Wallet
RecoverWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
,
string
passphrase
=
null
,
CoinType
coinType
=
CoinType
.
Bitcoin
,
DateTimeOffset
?
creationTime
=
null
)
public
Wallet
RecoverWallet
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
,
string
passphrase
=
null
,
DateTimeOffset
?
creationTime
=
null
)
{
// for now the passphrase is set to be the password by default.
if
(
passphrase
==
null
)
...
...
@@ -71,14 +71,14 @@ namespace Breeze.Wallet
ExtKey
extendedKey
=
(
new
Mnemonic
(
mnemonic
)).
DeriveExtKey
(
passphrase
);
// create a wallet file
Wallet
wallet
=
this
.
GenerateWalletFile
(
password
,
folderPath
,
name
,
WalletHelpers
.
GetNetwork
(
network
),
extendedKey
,
c
oinType
,
c
reationTime
);
Wallet
wallet
=
this
.
GenerateWalletFile
(
password
,
folderPath
,
name
,
WalletHelpers
.
GetNetwork
(
network
),
extendedKey
,
creationTime
);
this
.
Load
(
wallet
);
return
wallet
;
}
/// <inheritdoc />
public
string
CreateNewAccount
(
string
walletName
,
string
accountName
,
string
password
)
public
string
CreateNewAccount
(
string
walletName
,
CoinType
coinType
,
string
accountName
,
string
password
)
{
Wallet
wallet
=
this
.
Wallets
.
SingleOrDefault
(
w
=>
w
.
Name
==
walletName
);
if
(
wallet
==
null
)
...
...
@@ -86,20 +86,22 @@ namespace Breeze.Wallet
throw
new
Exception
(
$"No wallet with name
{
walletName
}
could be found."
);
}
// get the accounts for this type of coin
var
accounts
=
wallet
.
AccountsRoot
.
Single
(
a
=>
a
.
CoinType
==
coinType
).
Accounts
.
ToList
();
int
newAccountIndex
=
0
;
// validate account creation
if
(
wallet
.
A
ccounts
.
Any
())
if
(
a
ccounts
.
Any
())
{
// check account with same name doesn't already exists
if
(
wallet
.
A
ccounts
.
Any
(
a
=>
a
.
Name
==
accountName
))
if
(
a
ccounts
.
Any
(
a
=>
a
.
Name
==
accountName
))
{
throw
new
Exception
(
$"Account with name '
{
accountName
}
' already exists in '
{
walletName
}
'."
);
}
// check account at index i - 1 contains transactions.
int
lastAccountIndex
=
wallet
.
A
ccounts
.
Max
(
a
=>
a
.
Index
);
HdAccount
previousAccount
=
wallet
.
A
ccounts
.
Single
(
a
=>
a
.
Index
==
lastAccountIndex
);
int
lastAccountIndex
=
a
ccounts
.
Max
(
a
=>
a
.
Index
);
HdAccount
previousAccount
=
a
ccounts
.
Single
(
a
=>
a
.
Index
==
lastAccountIndex
);
if
(!
previousAccount
.
ExternalAddresses
.
Any
(
addresses
=>
addresses
.
Transactions
.
Any
())
&&
!
previousAccount
.
InternalAddresses
.
Any
(
addresses
=>
addresses
.
Transactions
.
Any
()))
{
throw
new
Exception
(
$"Cannot create new account '
{
accountName
}
' in '
{
walletName
}
' if the previous account '
{
previousAccount
.
Name
}
' has not been used."
);
...
...
@@ -111,11 +113,11 @@ namespace Breeze.Wallet
// get the extended pub key used to generate addresses for this account
var
privateKey
=
Key
.
Parse
(
wallet
.
EncryptedSeed
,
password
,
wallet
.
Network
);
var
seedExtKey
=
new
ExtKey
(
privateKey
,
wallet
.
ChainCode
);
KeyPath
keyPath
=
new
KeyPath
(
$"m/44'/
{(
int
)
wallet
.
C
oinType
}
'/
{
newAccountIndex
}
'"
);
var
accountExtKey
=
seedExtKey
.
Derive
(
keyPath
);
KeyPath
keyPath
=
new
KeyPath
(
$"m/44'/
{(
int
)
c
oinType
}
'/
{
newAccountIndex
}
'"
);
ExtKey
accountExtKey
=
seedExtKey
.
Derive
(
keyPath
);
ExtPubKey
accountExtPubKey
=
accountExtKey
.
Neuter
();
wallet
.
Accounts
=
wallet
.
Accounts
.
Concat
(
new
[]
{
new
HdAccount
accounts
.
Add
(
new
HdAccount
{
Index
=
newAccountIndex
,
ExtendedPubKey
=
accountExtPubKey
.
ToString
(
wallet
.
Network
),
...
...
@@ -123,15 +125,16 @@ namespace Breeze.Wallet
InternalAddresses
=
new
List
<
HdAddress
>(),
Name
=
accountName
,
CreationTime
=
DateTimeOffset
.
Now
}
}
);
});
wallet
.
AccountsRoot
.
Single
(
a
=>
a
.
CoinType
==
coinType
).
Accounts
=
accounts
;
this
.
SaveToFile
(
wallet
);
return
accountName
;
}
/// <inheritdoc />
public
string
CreateNewAddress
(
string
walletName
,
string
accountName
)
public
string
CreateNewAddress
(
string
walletName
,
CoinType
coinType
,
string
accountName
)
{
Wallet
wallet
=
this
.
Wallets
.
SingleOrDefault
(
w
=>
w
.
Name
==
walletName
);
if
(
wallet
==
null
)
...
...
@@ -139,7 +142,8 @@ namespace Breeze.Wallet
throw
new
Exception
(
$"No wallet with name
{
walletName
}
could be found."
);
}
HdAccount
account
=
wallet
.
Accounts
.
SingleOrDefault
(
a
=>
a
.
Name
==
accountName
);
// get the account
HdAccount
account
=
wallet
.
AccountsRoot
.
Single
(
a
=>
a
.
CoinType
==
coinType
).
Accounts
.
SingleOrDefault
(
a
=>
a
.
Name
==
accountName
);
if
(
account
==
null
)
{
throw
new
Exception
(
$"No account with name
{
accountName
}
could be found."
);
...
...
@@ -168,7 +172,7 @@ namespace Breeze.Wallet
account
.
ExternalAddresses
=
account
.
ExternalAddresses
.
Concat
(
new
[]
{
new
HdAddress
{
Index
=
newAddressIndex
,
HdPath
=
CreateBip44Path
(
wallet
.
C
oinType
,
account
.
Index
,
newAddressIndex
,
false
),
HdPath
=
CreateBip44Path
(
c
oinType
,
account
.
Index
,
newAddressIndex
,
false
),
ScriptPubKey
=
address
.
ScriptPubKey
,
Address
=
address
.
ToString
(),
Transactions
=
new
List
<
TransactionData
>(),
...
...
@@ -230,7 +234,7 @@ namespace Breeze.Wallet
/// <param name="creationTime">The time this wallet was created.</param>
/// <returns></returns>
/// <exception cref="System.NotSupportedException"></exception>
private
Wallet
GenerateWalletFile
(
string
password
,
string
folderPath
,
string
name
,
Network
network
,
ExtKey
extendedKey
,
CoinType
coinType
=
CoinType
.
Bitcoin
,
DateTimeOffset
?
creationTime
=
null
)
private
Wallet
GenerateWalletFile
(
string
password
,
string
folderPath
,
string
name
,
Network
network
,
ExtKey
extendedKey
,
DateTimeOffset
?
creationTime
=
null
)
{
string
walletFilePath
=
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
);
...
...
@@ -244,8 +248,9 @@ namespace Breeze.Wallet
ChainCode
=
extendedKey
.
ChainCode
,
CreationTime
=
creationTime
??
DateTimeOffset
.
Now
,
Network
=
network
,
Accounts
=
new
List
<
HdAccount
>(),
CoinType
=
coinType
,
AccountsRoot
=
new
List
<
AccountRoot
>
{
new
AccountRoot
{
Accounts
=
new
List
<
HdAccount
>(),
CoinType
=
CoinType
.
Bitcoin
},
new
AccountRoot
{
Accounts
=
new
List
<
HdAccount
>(),
CoinType
=
CoinType
.
Stratis
}
},
WalletFilePath
=
walletFilePath
};
...
...
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