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
d3b95586
Commit
d3b95586
authored
Mar 28, 2017
by
Jeremy Bokobza
Committed by
GitHub
Mar 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Safe to Wallet (
#4
)
parent
5c919e29
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
149 additions
and
66 deletions
+149
-66
ControllersTests.cs
Breeze/src/Breeze.Api.Tests/ControllersTests.cs
+29
-29
Safe.postman_collection.json
...e.Api.Tests/Postman requests/Safe.postman_collection.json
+10
-10
WalletController.cs
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
+14
-14
WalletCreation.cs
Breeze/src/Breeze.Wallet/Models/WalletCreation.cs
+7
-7
WalletFeature.cs
Breeze/src/Breeze.Wallet/WalletFeature.cs
+2
-2
WalletModel.cs
Breeze/src/Breeze.Wallet/WalletModel.cs
+1
-1
IWalletWrapper.cs
Breeze/src/Breeze.Wallet/Wrappers/IWalletWrapper.cs
+3
-3
WalletWrapper.cs
Breeze/src/Breeze.Wallet/Wrappers/WalletWrapper.cs
+83
-0
No files found.
Breeze/src/Breeze.Api.Tests/ControllersTests.cs
View file @
d3b95586
...
@@ -13,15 +13,15 @@ namespace Breeze.Api.Tests
...
@@ -13,15 +13,15 @@ namespace Breeze.Api.Tests
public
class
ControllersTests
public
class
ControllersTests
{
{
[
Fact
]
[
Fact
]
public
void
Create
Safe
SuccessfullyReturnsMnemonic
()
public
void
Create
Wallet
SuccessfullyReturnsMnemonic
()
{
{
var
mock
SafeCreate
=
new
Mock
<
ISafe
Wrapper
>();
var
mock
WalletCreate
=
new
Mock
<
IWallet
Wrapper
>();
mock
SafeCreate
.
Setup
(
safe
=>
safe
.
Create
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Returns
(
"mnemonic"
);
mock
WalletCreate
.
Setup
(
wallet
=>
wallet
.
Create
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Returns
(
"mnemonic"
);
var
controller
=
new
SafeController
(
mockSafe
Create
.
Object
);
var
controller
=
new
WalletController
(
mockWallet
Create
.
Object
);
// Act
// Act
var
result
=
controller
.
Create
(
new
Safe
CreationModel
var
result
=
controller
.
Create
(
new
Wallet
CreationModel
{
{
Name
=
"myName"
,
Name
=
"myName"
,
FolderPath
=
""
,
FolderPath
=
""
,
...
@@ -30,29 +30,29 @@ namespace Breeze.Api.Tests
...
@@ -30,29 +30,29 @@ namespace Breeze.Api.Tests
});
});
// Assert
// Assert
mock
Safe
Create
.
VerifyAll
();
mock
Wallet
Create
.
VerifyAll
();
var
viewResult
=
Assert
.
IsType
<
JsonResult
>(
result
);
var
viewResult
=
Assert
.
IsType
<
JsonResult
>(
result
);
Assert
.
Equal
(
"mnemonic"
,
viewResult
.
Value
);
Assert
.
Equal
(
"mnemonic"
,
viewResult
.
Value
);
Assert
.
NotNull
(
result
);
Assert
.
NotNull
(
result
);
}
}
[
Fact
]
[
Fact
]
public
void
Load
SafeSuccessfullyReturnsSafe
Model
()
public
void
Load
WalletSuccessfullyReturnsWallet
Model
()
{
{
SafeModel
safeModel
=
new
Safe
Model
WalletModel
walletModel
=
new
Wallet
Model
{
{
FileName
=
"myWallet"
,
FileName
=
"myWallet"
,
Network
=
"MainNet"
,
Network
=
"MainNet"
,
Addresses
=
new
List
<
string
>
{
"address1"
,
"address2"
,
"address3"
,
"address4"
,
"address5"
}
Addresses
=
new
List
<
string
>
{
"address1"
,
"address2"
,
"address3"
,
"address4"
,
"address5"
}
};
};
var
mock
SafeWrapper
=
new
Mock
<
ISafe
Wrapper
>();
var
mock
WalletWrapper
=
new
Mock
<
IWallet
Wrapper
>();
mock
SafeWrapper
.
Setup
(
safe
=>
safe
.
Recover
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Returns
(
safe
Model
);
mock
WalletWrapper
.
Setup
(
wallet
=>
wallet
.
Recover
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Returns
(
wallet
Model
);
var
controller
=
new
SafeController
(
mockSafe
Wrapper
.
Object
);
var
controller
=
new
WalletController
(
mockWallet
Wrapper
.
Object
);
// Act
// Act
var
result
=
controller
.
Recover
(
new
Safe
RecoveryModel
var
result
=
controller
.
Recover
(
new
Wallet
RecoveryModel
{
{
Name
=
"myName"
,
Name
=
"myName"
,
FolderPath
=
""
,
FolderPath
=
""
,
...
@@ -62,32 +62,32 @@ namespace Breeze.Api.Tests
...
@@ -62,32 +62,32 @@ namespace Breeze.Api.Tests
});
});
// Assert
// Assert
mock
Safe
Wrapper
.
VerifyAll
();
mock
Wallet
Wrapper
.
VerifyAll
();
var
viewResult
=
Assert
.
IsType
<
JsonResult
>(
result
);
var
viewResult
=
Assert
.
IsType
<
JsonResult
>(
result
);
Assert
.
NotNull
(
viewResult
.
Value
);
Assert
.
NotNull
(
viewResult
.
Value
);
Assert
.
IsType
<
Safe
Model
>(
viewResult
.
Value
);
Assert
.
IsType
<
Wallet
Model
>(
viewResult
.
Value
);
var
model
=
viewResult
.
Value
as
Safe
Model
;
var
model
=
viewResult
.
Value
as
Wallet
Model
;
Assert
.
Equal
(
"myWallet"
,
model
.
FileName
);
Assert
.
Equal
(
"myWallet"
,
model
.
FileName
);
}
}
[
Fact
]
[
Fact
]
public
void
Recover
SafeSuccessfullyReturnsSafe
Model
()
public
void
Recover
WalletSuccessfullyReturnsWallet
Model
()
{
{
SafeModel
safeModel
=
new
Safe
Model
WalletModel
walletModel
=
new
Wallet
Model
{
{
FileName
=
"myWallet"
,
FileName
=
"myWallet"
,
Network
=
"MainNet"
,
Network
=
"MainNet"
,
Addresses
=
new
List
<
string
>
{
"address1"
,
"address2"
,
"address3"
,
"address4"
,
"address5"
}
Addresses
=
new
List
<
string
>
{
"address1"
,
"address2"
,
"address3"
,
"address4"
,
"address5"
}
};
};
var
mock
SafeWrapper
=
new
Mock
<
ISafe
Wrapper
>();
var
mock
WalletWrapper
=
new
Mock
<
IWallet
Wrapper
>();
mock
SafeWrapper
.
Setup
(
safe
=>
safe
.
Load
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Returns
(
safe
Model
);
mock
WalletWrapper
.
Setup
(
wallet
=>
wallet
.
Load
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Returns
(
wallet
Model
);
var
controller
=
new
SafeController
(
mockSafe
Wrapper
.
Object
);
var
controller
=
new
WalletController
(
mockWallet
Wrapper
.
Object
);
// Act
// Act
var
result
=
controller
.
Load
(
new
Safe
LoadModel
var
result
=
controller
.
Load
(
new
Wallet
LoadModel
{
{
Name
=
"myName"
,
Name
=
"myName"
,
FolderPath
=
""
,
FolderPath
=
""
,
...
@@ -95,25 +95,25 @@ namespace Breeze.Api.Tests
...
@@ -95,25 +95,25 @@ namespace Breeze.Api.Tests
});
});
// Assert
// Assert
mock
Safe
Wrapper
.
VerifyAll
();
mock
Wallet
Wrapper
.
VerifyAll
();
var
viewResult
=
Assert
.
IsType
<
JsonResult
>(
result
);
var
viewResult
=
Assert
.
IsType
<
JsonResult
>(
result
);
Assert
.
NotNull
(
viewResult
.
Value
);
Assert
.
NotNull
(
viewResult
.
Value
);
Assert
.
IsType
<
Safe
Model
>(
viewResult
.
Value
);
Assert
.
IsType
<
Wallet
Model
>(
viewResult
.
Value
);
var
model
=
viewResult
.
Value
as
Safe
Model
;
var
model
=
viewResult
.
Value
as
Wallet
Model
;
Assert
.
Equal
(
"myWallet"
,
model
.
FileName
);
Assert
.
Equal
(
"myWallet"
,
model
.
FileName
);
}
}
[
Fact
]
[
Fact
]
public
void
FileNotFoundExceptionandReturns404
()
public
void
FileNotFoundExceptionandReturns404
()
{
{
var
mock
SafeWrapper
=
new
Mock
<
ISafe
Wrapper
>();
var
mock
WalletWrapper
=
new
Mock
<
IWallet
Wrapper
>();
mock
SafeWrapper
.
Setup
(
safe
=>
safe
.
Load
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Throws
<
FileNotFoundException
>();
mock
WalletWrapper
.
Setup
(
wallet
=>
wallet
.
Load
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Throws
<
FileNotFoundException
>();
var
controller
=
new
SafeController
(
mockSafe
Wrapper
.
Object
);
var
controller
=
new
WalletController
(
mockWallet
Wrapper
.
Object
);
// Act
// Act
var
result
=
controller
.
Load
(
new
Safe
LoadModel
var
result
=
controller
.
Load
(
new
Wallet
LoadModel
{
{
Name
=
"myName"
,
Name
=
"myName"
,
FolderPath
=
""
,
FolderPath
=
""
,
...
@@ -121,7 +121,7 @@ namespace Breeze.Api.Tests
...
@@ -121,7 +121,7 @@ namespace Breeze.Api.Tests
});
});
// Assert
// Assert
mock
Safe
Wrapper
.
VerifyAll
();
mock
Wallet
Wrapper
.
VerifyAll
();
var
viewResult
=
Assert
.
IsType
<
ObjectResult
>(
result
);
var
viewResult
=
Assert
.
IsType
<
ObjectResult
>(
result
);
Assert
.
NotNull
(
viewResult
);
Assert
.
NotNull
(
viewResult
);
Assert
.
Equal
(
404
,
viewResult
.
StatusCode
);
Assert
.
Equal
(
404
,
viewResult
.
StatusCode
);
...
...
Breeze/src/Breeze.Api.Tests/Postman requests/Safe.postman_collection.json
View file @
d3b95586
{
{
"variables"
:
[],
"variables"
:
[],
"info"
:
{
"info"
:
{
"name"
:
"
Safe
"
,
"name"
:
"
Wallet
"
,
"_postman_id"
:
"11f915f1-7aac-bfeb-000c-b66348f4636f"
,
"_postman_id"
:
"11f915f1-7aac-bfeb-000c-b66348f4636f"
,
"description"
:
"Requests relating to operations on the
safe
"
,
"description"
:
"Requests relating to operations on the
wallet
"
,
"schema"
:
"https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
"schema"
:
"https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
},
"item"
:
[
"item"
:
[
{
{
"name"
:
"Create
safe
- success"
,
"name"
:
"Create
wallet
- success"
,
"request"
:
{
"request"
:
{
"url"
:
"http://localhost:5000/api/
safe
/"
,
"url"
:
"http://localhost:5000/api/
wallet
/"
,
"method"
:
"POST"
,
"method"
:
"POST"
,
"header"
:
[
"header"
:
[
{
{
...
@@ -28,9 +28,9 @@
...
@@ -28,9 +28,9 @@
"response"
:
[]
"response"
:
[]
},
},
{
{
"name"
:
"Create
safe
- validation errors"
,
"name"
:
"Create
wallet
- validation errors"
,
"request"
:
{
"request"
:
{
"url"
:
"http://localhost:5000/api/
safe
/"
,
"url"
:
"http://localhost:5000/api/
wallet
/"
,
"method"
:
"POST"
,
"method"
:
"POST"
,
"header"
:
[
"header"
:
[
{
{
...
@@ -48,9 +48,9 @@
...
@@ -48,9 +48,9 @@
"response"
:
[]
"response"
:
[]
},
},
{
{
"name"
:
"Load
safe
"
,
"name"
:
"Load
wallet
"
,
"request"
:
{
"request"
:
{
"url"
:
"http://localhost:5000/api/
safe
/?password=123456&folderPath=MyWallets&name=myFirstWallet"
,
"url"
:
"http://localhost:5000/api/
wallet
/?password=123456&folderPath=MyWallets&name=myFirstWallet"
,
"method"
:
"GET"
,
"method"
:
"GET"
,
"header"
:
[
"header"
:
[
{
{
...
@@ -68,9 +68,9 @@
...
@@ -68,9 +68,9 @@
"response"
:
[]
"response"
:
[]
},
},
{
{
"name"
:
"Recover
safe
"
,
"name"
:
"Recover
wallet
"
,
"request"
:
{
"request"
:
{
"url"
:
"http://localhost:5000/api/
safe
/recover"
,
"url"
:
"http://localhost:5000/api/
wallet
/recover"
,
"method"
:
"POST"
,
"method"
:
"POST"
,
"header"
:
[
"header"
:
[
{
{
...
...
Breeze/src/Breeze.Wallet/Controllers/
Safe
Controller.cs
→
Breeze/src/Breeze.Wallet/Controllers/
Wallet
Controller.cs
View file @
d3b95586
...
@@ -12,22 +12,22 @@ using Stratis.Bitcoin;
...
@@ -12,22 +12,22 @@ using Stratis.Bitcoin;
namespace
Breeze.Wallet.Controllers
namespace
Breeze.Wallet.Controllers
{
{
[
Route
(
"api/[controller]"
)]
[
Route
(
"api/[controller]"
)]
public
class
Safe
Controller
:
Controller
public
class
Wallet
Controller
:
Controller
{
{
private
readonly
I
SafeWrapper
safe
Wrapper
;
private
readonly
I
WalletWrapper
wallet
Wrapper
;
public
SafeController
(
ISafeWrapper
safe
Wrapper
)
public
WalletController
(
IWalletWrapper
wallet
Wrapper
)
{
{
this
.
safeWrapper
=
safe
Wrapper
;
this
.
walletWrapper
=
wallet
Wrapper
;
}
}
/// <summary>
/// <summary>
/// Creates a new
safe
on the local machine.
/// Creates a new
wallet
on the local machine.
/// </summary>
/// </summary>
/// <param name="
safe
Creation">The object containing the parameters used to create the wallet.</param>
/// <param name="
wallet
Creation">The object containing the parameters used to create the wallet.</param>
/// <returns>A JSON object containing the mnemonic created for the new wallet.</returns>
/// <returns>A JSON object containing the mnemonic created for the new wallet.</returns>
[
HttpPost
]
[
HttpPost
]
public
IActionResult
Create
([
FromBody
]
SafeCreationModel
safe
Creation
)
public
IActionResult
Create
([
FromBody
]
WalletCreationModel
wallet
Creation
)
{
{
// checks the request is valid
// checks the request is valid
if
(!
this
.
ModelState
.
IsValid
)
if
(!
this
.
ModelState
.
IsValid
)
...
@@ -38,7 +38,7 @@ namespace Breeze.Wallet.Controllers
...
@@ -38,7 +38,7 @@ namespace Breeze.Wallet.Controllers
try
try
{
{
var
mnemonic
=
this
.
safeWrapper
.
Create
(
safeCreation
.
Password
,
safeCreation
.
FolderPath
,
safeCreation
.
Name
,
safe
Creation
.
Network
);
var
mnemonic
=
this
.
walletWrapper
.
Create
(
walletCreation
.
Password
,
walletCreation
.
FolderPath
,
walletCreation
.
Name
,
wallet
Creation
.
Network
);
return
this
.
Json
(
mnemonic
);
return
this
.
Json
(
mnemonic
);
}
}
catch
(
NotSupportedException
e
)
catch
(
NotSupportedException
e
)
...
@@ -50,7 +50,7 @@ namespace Breeze.Wallet.Controllers
...
@@ -50,7 +50,7 @@ namespace Breeze.Wallet.Controllers
}
}
}
}
public
IActionResult
Load
(
SafeLoadModel
safe
Load
)
public
IActionResult
Load
(
WalletLoadModel
wallet
Load
)
{
{
// checks the request is valid
// checks the request is valid
if
(!
this
.
ModelState
.
IsValid
)
if
(!
this
.
ModelState
.
IsValid
)
...
@@ -61,8 +61,8 @@ namespace Breeze.Wallet.Controllers
...
@@ -61,8 +61,8 @@ namespace Breeze.Wallet.Controllers
try
try
{
{
var
safe
=
this
.
safeWrapper
.
Load
(
safeLoad
.
Password
,
safeLoad
.
FolderPath
,
safe
Load
.
Name
);
var
wallet
=
this
.
walletWrapper
.
Load
(
walletLoad
.
Password
,
walletLoad
.
FolderPath
,
wallet
Load
.
Name
);
return
this
.
Json
(
safe
);
return
this
.
Json
(
wallet
);
}
}
catch
(
FileNotFoundException
e
)
catch
(
FileNotFoundException
e
)
...
@@ -88,7 +88,7 @@ namespace Breeze.Wallet.Controllers
...
@@ -88,7 +88,7 @@ namespace Breeze.Wallet.Controllers
[
Route
(
"recover"
)]
[
Route
(
"recover"
)]
[
HttpPost
]
[
HttpPost
]
public
IActionResult
Recover
([
FromBody
]
SafeRecoveryModel
safe
Recovery
)
public
IActionResult
Recover
([
FromBody
]
WalletRecoveryModel
wallet
Recovery
)
{
{
// checks the request is valid
// checks the request is valid
if
(!
this
.
ModelState
.
IsValid
)
if
(!
this
.
ModelState
.
IsValid
)
...
@@ -99,8 +99,8 @@ namespace Breeze.Wallet.Controllers
...
@@ -99,8 +99,8 @@ namespace Breeze.Wallet.Controllers
try
try
{
{
var
safe
=
this
.
safeWrapper
.
Recover
(
safeRecovery
.
Password
,
safeRecovery
.
FolderPath
,
safeRecovery
.
Name
,
safeRecovery
.
Network
,
safe
Recovery
.
Mnemonic
);
var
wallet
=
this
.
walletWrapper
.
Recover
(
walletRecovery
.
Password
,
walletRecovery
.
FolderPath
,
walletRecovery
.
Name
,
walletRecovery
.
Network
,
wallet
Recovery
.
Mnemonic
);
return
this
.
Json
(
safe
);
return
this
.
Json
(
wallet
);
}
}
catch
(
FileNotFoundException
e
)
catch
(
FileNotFoundException
e
)
...
...
Breeze/src/Breeze.Wallet/Models/
Safe
Creation.cs
→
Breeze/src/Breeze.Wallet/Models/
Wallet
Creation.cs
View file @
d3b95586
...
@@ -7,21 +7,21 @@ namespace Breeze.Wallet.Models
...
@@ -7,21 +7,21 @@ namespace Breeze.Wallet.Models
/// <summary>
/// <summary>
/// Object used to create a new wallet
/// Object used to create a new wallet
/// </summary>
/// </summary>
public
class
Safe
CreationModel
public
class
Wallet
CreationModel
{
{
[
Required
(
ErrorMessage
=
"A password is required."
)]
[
Required
(
ErrorMessage
=
"A password is required."
)]
public
string
Password
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
string
Network
{
get
;
set
;
}
public
string
Network
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"The folder path where the
safe
will be created is required."
)]
[
Required
(
ErrorMessage
=
"The folder path where the
wallet
will be created is required."
)]
public
string
FolderPath
{
get
;
set
;
}
public
string
FolderPath
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"The name of the
safe
to create is missing."
)]
[
Required
(
ErrorMessage
=
"The name of the
wallet
to create is missing."
)]
public
string
Name
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
}
public
class
Safe
LoadModel
public
class
Wallet
LoadModel
{
{
[
Required
(
ErrorMessage
=
"A password is required."
)]
[
Required
(
ErrorMessage
=
"A password is required."
)]
public
string
Password
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
...
@@ -29,11 +29,11 @@ namespace Breeze.Wallet.Models
...
@@ -29,11 +29,11 @@ namespace Breeze.Wallet.Models
[
Required
(
ErrorMessage
=
"The folder path is required."
)]
[
Required
(
ErrorMessage
=
"The folder path is required."
)]
public
string
FolderPath
{
get
;
set
;
}
public
string
FolderPath
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"The name of the
safe
is missing."
)]
[
Required
(
ErrorMessage
=
"The name of the
wallet
is missing."
)]
public
string
Name
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
}
public
class
Safe
RecoveryModel
public
class
Wallet
RecoveryModel
{
{
[
Required
(
ErrorMessage
=
"A mnemonic is required."
)]
[
Required
(
ErrorMessage
=
"A mnemonic is required."
)]
public
string
Mnemonic
{
get
;
set
;
}
public
string
Mnemonic
{
get
;
set
;
}
...
@@ -44,7 +44,7 @@ namespace Breeze.Wallet.Models
...
@@ -44,7 +44,7 @@ namespace Breeze.Wallet.Models
[
Required
(
ErrorMessage
=
"The folder path is required."
)]
[
Required
(
ErrorMessage
=
"The folder path is required."
)]
public
string
FolderPath
{
get
;
set
;
}
public
string
FolderPath
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"The name of the
safe
is missing."
)]
[
Required
(
ErrorMessage
=
"The name of the
wallet
is missing."
)]
public
string
Name
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
string
Network
{
get
;
set
;
}
public
string
Network
{
get
;
set
;
}
...
...
Breeze/src/Breeze.Wallet/WalletFeature.cs
View file @
d3b95586
...
@@ -23,9 +23,9 @@ namespace Breeze.Wallet
...
@@ -23,9 +23,9 @@ namespace Breeze.Wallet
.
AddFeature
<
WalletFeature
>()
.
AddFeature
<
WalletFeature
>()
.
FeatureServices
(
services
=>
.
FeatureServices
(
services
=>
{
{
services
.
AddTransient
<
I
SafeWrapper
,
Safe
Wrapper
>();
services
.
AddTransient
<
I
WalletWrapper
,
Wallet
Wrapper
>();
services
.
AddTransient
<
ITrackerWrapper
,
TrackerWrapper
>();
services
.
AddTransient
<
ITrackerWrapper
,
TrackerWrapper
>();
services
.
AddSingleton
<
Safe
Controller
>();
services
.
AddSingleton
<
Wallet
Controller
>();
});
});
});
});
...
...
Breeze/src/Breeze.Wallet/
Safe
Model.cs
→
Breeze/src/Breeze.Wallet/
Wallet
Model.cs
View file @
d3b95586
...
@@ -5,7 +5,7 @@ using System.Threading.Tasks;
...
@@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace
Breeze.Wallet
namespace
Breeze.Wallet
{
{
public
class
Safe
Model
public
class
Wallet
Model
{
{
public
string
Network
{
get
;
set
;
}
public
string
Network
{
get
;
set
;
}
...
...
Breeze/src/Breeze.Wallet/Wrappers/I
Safe
Wrapper.cs
→
Breeze/src/Breeze.Wallet/Wrappers/I
Wallet
Wrapper.cs
View file @
d3b95586
...
@@ -4,12 +4,12 @@ namespace Breeze.Wallet.Wrappers
...
@@ -4,12 +4,12 @@ namespace Breeze.Wallet.Wrappers
/// <summary>
/// <summary>
/// An interface enabling wallet operations.
/// An interface enabling wallet operations.
/// </summary>
/// </summary>
public
interface
I
Safe
Wrapper
public
interface
I
Wallet
Wrapper
{
{
string
Create
(
string
password
,
string
folderPath
,
string
name
,
string
network
);
string
Create
(
string
password
,
string
folderPath
,
string
name
,
string
network
);
Safe
Model
Load
(
string
password
,
string
folderPath
,
string
name
);
Wallet
Model
Load
(
string
password
,
string
folderPath
,
string
name
);
Safe
Model
Recover
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
);
Wallet
Model
Recover
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
);
}
}
}
}
Breeze/src/Breeze.Wallet/Wrappers/
Safe
Wrapper.cs
→
Breeze/src/Breeze.Wallet/Wrappers/
Wallet
Wrapper.cs
View file @
d3b95586
...
@@ -6,64 +6,64 @@ using NBitcoin;
...
@@ -6,64 +6,64 @@ using NBitcoin;
namespace
Breeze.Wallet.Wrappers
namespace
Breeze.Wallet.Wrappers
{
{
/// <summary>
/// <summary>
/// An implementation of the <see cref="I
Safe
Wrapper"/> interface.
/// An implementation of the <see cref="I
Wallet
Wrapper"/> interface.
/// </summary>
/// </summary>
public
class
SafeWrapper
:
ISafe
Wrapper
public
class
WalletWrapper
:
IWallet
Wrapper
{
{
/// <summary>
/// <summary>
/// Creates a
safe
on the local device.
/// Creates a
wallet
on the local device.
/// </summary>
/// </summary>
/// <param name="password">The user's password.</param>
/// <param name="password">The user's password.</param>
/// <param name="folderPath">The folder where the
safe
will be saved.</param>
/// <param name="folderPath">The folder where the
wallet
will be saved.</param>
/// <param name="name">The name of the
safe
.</param>
/// <param name="name">The name of the
wallet
.</param>
/// <param name="network">The network for which to create a
safe
.</param>
/// <param name="network">The network for which to create a
wallet
.</param>
/// <returns>A mnemonic allowing recovery of the
safe
.</returns>
/// <returns>A mnemonic allowing recovery of the
wallet
.</returns>
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
safe
=
Safe
.
Create
(
out
mnemonic
,
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
),
this
.
GetNetwork
(
network
));
Safe
wallet
=
Safe
.
Create
(
out
mnemonic
,
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
),
this
.
GetNetwork
(
network
));
return
mnemonic
.
ToString
();
return
mnemonic
.
ToString
();
}
}
/// <summary>
/// <summary>
/// Loads a
safe
from the local device.
/// Loads a
wallet
from the local device.
/// </summary>
/// </summary>
/// <param name="password">The user's password.</param>
/// <param name="password">The user's password.</param>
/// <param name="folderPath">The folder where the
safe
will be loaded.</param>
/// <param name="folderPath">The folder where the
wallet
will be loaded.</param>
/// <param name="name">The name of the
safe
.</param>
/// <param name="name">The name of the
wallet
.</param>
/// <returns>The
safe
loaded from the local device</returns>
/// <returns>The
wallet
loaded from the local device</returns>
public
Safe
Model
Load
(
string
password
,
string
folderPath
,
string
name
)
public
Wallet
Model
Load
(
string
password
,
string
folderPath
,
string
name
)
{
{
Safe
safe
=
Safe
.
Load
(
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
));
Safe
wallet
=
Safe
.
Load
(
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
));
//TODO review here which data should be returned
//TODO review here which data should be returned
return
new
Safe
Model
return
new
Wallet
Model
{
{
Network
=
safe
.
Network
.
Name
,
Network
=
wallet
.
Network
.
Name
,
Addresses
=
safe
.
GetFirstNAddresses
(
10
).
Select
(
a
=>
a
.
ToWif
()),
Addresses
=
wallet
.
GetFirstNAddresses
(
10
).
Select
(
a
=>
a
.
ToWif
()),
FileName
=
safe
.
WalletFilePath
FileName
=
wallet
.
WalletFilePath
};
};
}
}
/// <summary>
/// <summary>
/// Recovers a
safe
from the local device.
/// Recovers a
wallet
from the local device.
/// </summary>
/// </summary>
/// <param name="password">The user's password.</param>
/// <param name="password">The user's password.</param>
/// <param name="folderPath">The folder where the
safe
will be loaded.</param>
/// <param name="folderPath">The folder where the
wallet
will be loaded.</param>
/// <param name="name">The name of the
safe
.</param>
/// <param name="name">The name of the
wallet
.</param>
/// <param name="network">The network in which to creae this wallet</param>
/// <param name="network">The network in which to creae this wallet</param>
/// <param name="mnemonic">The user's mnemonic for the
safe
.</param>
/// <param name="mnemonic">The user's mnemonic for the
wallet
.</param>
/// <returns></returns>
/// <returns></returns>
public
Safe
Model
Recover
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
)
public
Wallet
Model
Recover
(
string
password
,
string
folderPath
,
string
name
,
string
network
,
string
mnemonic
)
{
{
Safe
safe
=
Safe
.
Recover
(
new
Mnemonic
(
mnemonic
),
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
),
this
.
GetNetwork
(
network
));
Safe
wallet
=
Safe
.
Recover
(
new
Mnemonic
(
mnemonic
),
password
,
Path
.
Combine
(
folderPath
,
$"
{
name
}
.json"
),
this
.
GetNetwork
(
network
));
//TODO review here which data should be returned
//TODO review here which data should be returned
return
new
Safe
Model
return
new
Wallet
Model
{
{
Network
=
safe
.
Network
.
Name
,
Network
=
wallet
.
Network
.
Name
,
Addresses
=
safe
.
GetFirstNAddresses
(
10
).
Select
(
a
=>
a
.
ToWif
()),
Addresses
=
wallet
.
GetFirstNAddresses
(
10
).
Select
(
a
=>
a
.
ToWif
()),
FileName
=
safe
.
WalletFilePath
FileName
=
wallet
.
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