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
04b41c22
Commit
04b41c22
authored
Apr 13, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Completed the GetNetwork method
parent
ede7dece
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
17 deletions
+101
-17
WalletHelpersTest.cs
Breeze/src/Breeze.Api.Tests/WalletHelpersTest.cs
+58
-0
WalletHelpers.cs
Breeze/src/Breeze.Wallet/Helpers/WalletHelpers.cs
+37
-0
WalletWrapper.cs
Breeze/src/Breeze.Wallet/Wrappers/WalletWrapper.cs
+6
-17
No files found.
Breeze/src/Breeze.Api.Tests/WalletHelpersTest.cs
0 → 100644
View file @
04b41c22
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
Breeze.Wallet.Helpers
;
using
NBitcoin
;
using
Xunit
;
namespace
Breeze.Api.Tests
{
public
class
WalletHelpersTest
{
[
Fact
]
public
void
GetMainNetworkRetuirnsNetworkMain
()
{
Network
network
=
WalletHelpers
.
GetNetwork
(
"main"
);
Assert
.
Equal
(
Network
.
Main
,
network
);
}
[
Fact
]
public
void
GetMainNetNetworkRetuirnsNetworkMain
()
{
Network
network
=
WalletHelpers
.
GetNetwork
(
"mainnet"
);
Assert
.
Equal
(
Network
.
Main
,
network
);
}
[
Fact
]
public
void
GetTestNetworkRetuirnsNetworkTest
()
{
Network
network
=
WalletHelpers
.
GetNetwork
(
"test"
);
Assert
.
Equal
(
Network
.
TestNet
,
network
);
}
[
Fact
]
public
void
GetTestNetNetworkRetuirnsNetworkTest
()
{
Network
network
=
WalletHelpers
.
GetNetwork
(
"testnet"
);
Assert
.
Equal
(
Network
.
TestNet
,
network
);
}
[
Fact
]
public
void
GetNetworkIsCaseInsensitive
()
{
Network
testNetwork
=
WalletHelpers
.
GetNetwork
(
"Test"
);
Assert
.
Equal
(
Network
.
TestNet
,
testNetwork
);
Network
mainNetwork
=
WalletHelpers
.
GetNetwork
(
"MainNet"
);
Assert
.
Equal
(
Network
.
Main
,
mainNetwork
);
}
[
Fact
]
public
void
WrongNetworkThrowsArgumentException
()
{
var
exception
=
Record
.
Exception
(()
=>
WalletHelpers
.
GetNetwork
(
"myNetwork"
));
Assert
.
NotNull
(
exception
);
Assert
.
IsType
<
ArgumentException
>(
exception
);
}
}
}
Breeze/src/Breeze.Wallet/Helpers/WalletHelpers.cs
0 → 100644
View file @
04b41c22
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
NBitcoin
;
using
Stratis.Bitcoin.Utilities
;
namespace
Breeze.Wallet.Helpers
{
/// <summary>
/// Contains a collection of helpers methods.
/// </summary>
public
static
class
WalletHelpers
{
/// <summary>
/// Get the network on which to operate.
/// </summary>
/// <param name="network">The network</param>
/// <returns>A <see cref="Network"/> object.</returns>
public
static
Network
GetNetwork
(
string
network
)
{
Guard
.
NotEmpty
(
network
,
nameof
(
network
));
switch
(
network
.
ToLowerInvariant
())
{
case
"main"
:
case
"mainnet"
:
return
Network
.
Main
;
case
"test"
:
case
"testnet"
:
return
Network
.
TestNet
;
default
:
throw
new
ArgumentException
(
$"Network '
{
network
}
' is not a valid network."
);
}
}
}
}
Breeze/src/Breeze.Wallet/Wrappers/WalletWrapper.cs
View file @
04b41c22
using
System.IO
;
using
System
;
using
System.IO
;
using
System.Linq
;
using
System.Linq
;
using
Breeze.Wallet.Helpers
;
using
Breeze.Wallet.Models
;
using
Breeze.Wallet.Models
;
using
HBitcoin.KeyManagement
;
using
HBitcoin.KeyManagement
;
using
NBitcoin
;
using
NBitcoin
;
...
@@ -22,7 +24,7 @@ namespace Breeze.Wallet.Wrappers
...
@@ -22,7 +24,7 @@ namespace Breeze.Wallet.Wrappers
public
string
Create
(
string
password
,
string
folderPath
,
string
name
,
string
network
)
public
string
Create
(
string
password
,
string
folderPath
,
string
name
,
string
network
)
{
{
Mnemonic
mnemonic
;
Mnemonic
mnemonic
;
Safe
wallet
=
Safe
.
Create
(
out
mnemonic
,
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
),
thi
s
.
GetNetwork
(
network
));
Safe
wallet
=
Safe
.
Create
(
out
mnemonic
,
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
),
WalletHelper
s
.
GetNetwork
(
network
));
return
mnemonic
.
ToString
();
return
mnemonic
.
ToString
();
}
}
...
@@ -57,7 +59,7 @@ namespace Breeze.Wallet.Wrappers
...
@@ -57,7 +59,7 @@ namespace Breeze.Wallet.Wrappers
/// <returns></returns>
/// <returns></returns>
public
WalletModel
Recover
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
)
public
WalletModel
Recover
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
)
{
{
Safe
wallet
=
Safe
.
Recover
(
new
Mnemonic
(
mnemonic
),
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
),
thi
s
.
GetNetwork
(
network
));
Safe
wallet
=
Safe
.
Recover
(
new
Mnemonic
(
mnemonic
),
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
),
WalletHelper
s
.
GetNetwork
(
network
));
//TODO review here which data should be returned
//TODO review here which data should be returned
return
new
WalletModel
return
new
WalletModel
...
@@ -68,19 +70,6 @@ namespace Breeze.Wallet.Wrappers
...
@@ -68,19 +70,6 @@ namespace Breeze.Wallet.Wrappers
};
};
}
}
private
Network
GetNetwork
(
string
network
)
{
// any network different than MainNet will default to TestNet
switch
(
network
.
ToLowerInvariant
())
{
case
"main"
:
case
"mainnet"
:
return
Network
.
Main
;
default
:
return
Network
.
TestNet
;
}
}
public
WalletInfoModel
GetInfo
(
string
name
)
public
WalletInfoModel
GetInfo
(
string
name
)
{
{
throw
new
System
.
NotImplementedException
();
throw
new
System
.
NotImplementedException
();
...
...
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