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
0e28ba41
Commit
0e28ba41
authored
May 18, 2017
by
Jeremy Bokobza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added endpoint to get general information about the state of a particular wallet
parent
848c1a11
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
43 deletions
+92
-43
ApiSpecification.md
Breeze.Documentation/ApiSpecification.md
+11
-7
ControllersTests.cs
Breeze/src/Breeze.Api.Tests/ControllersTests.cs
+7
-7
WalletController.cs
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
+29
-4
IWalletManager.cs
Breeze/src/Breeze.Wallet/IWalletManager.cs
+6
-1
WalletGeneralInfoModel.cs
Breeze/src/Breeze.Wallet/Models/WalletGeneralInfoModel.cs
+34
-21
WalletManager.cs
Breeze/src/Breeze.Wallet/WalletManager.cs
+5
-3
No files found.
Breeze.Documentation/ApiSpecification.md
View file @
0e28ba41
...
...
@@ -89,16 +89,20 @@ POST /wallet/send-transaction - Attempts to send a transaction
# Details
## GET /wallet/general-info - Displays general information on the wallet
### Query parameters
`walletName`
(required) - the name of the wallet.
### Responses
```
{
"walletFilePath":
"path to the wallet file",
"encryptedSeed": "6PYKWP34en1wELfcJDgXaFRPugjgkDdEk2p2Pzytm1158dxgNyLAUXwpKL",
"chainCode": "q/Fn7+RSIVM0p0Nj6rIuNkybF+0WKeSZPMQS2QCbDzY=
",
"network": "main", // main/testnet
"creationTime": "2017-03-21"
,
"isDecrypted": true,
"uniqueId": "sadwpiqjdpijwqdpijwqidjoi" // can only get if decrypted, if not it's empty string
"walletFilePath":
"path to the wallet file",
"network":"main", //"testnet", "stratismain", "stratistest"
"creationTime":"2017-03-21
",
"isDecrypted":true,
"lastBlockHeight":123234
,
"chainTip": 173721,
"connectedNodes": 5
}
```
## GET /wallet/sensitive - Displays sensitive information on the wallet
...
...
Breeze/src/Breeze.Api.Tests/ControllersTests.cs
View file @
0e28ba41
...
...
@@ -10,6 +10,7 @@ using Breeze.Wallet.Errors;
using
Breeze.Wallet.Helpers
;
using
Breeze.Wallet.Models
;
using
NBitcoin
;
using
Stratis.Bitcoin.Connection
;
namespace
Breeze.Api.Tests
{
...
...
@@ -22,7 +23,7 @@ namespace Breeze.Api.Tests
var
mockWalletCreate
=
new
Mock
<
IWalletManager
>();
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
,
new
Mock
<
ITracker
>().
Object
);
var
controller
=
new
WalletController
(
mockWalletCreate
.
Object
,
new
Mock
<
ITracker
>().
Object
,
new
Mock
<
ConnectionManager
>().
Object
,
new
Mock
<
Network
>().
Object
,
new
Mock
<
ConcurrentChain
>().
Object
);
// Act
var
result
=
controller
.
Create
(
new
WalletCreationRequest
...
...
@@ -52,7 +53,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
,
It
.
IsAny
<
DateTime
>())).
Returns
(
wallet
);
var
controller
=
new
WalletController
(
mockWalletWrapper
.
Object
,
new
Mock
<
ITracker
>().
Object
);
var
controller
=
new
WalletController
(
mockWalletWrapper
.
Object
,
new
Mock
<
ITracker
>().
Object
,
new
Mock
<
ConnectionManager
>().
Object
,
new
Mock
<
Network
>().
Object
,
new
Mock
<
ConcurrentChain
>().
Object
);
// Act
var
result
=
controller
.
Recover
(
new
WalletRecoveryRequest
...
...
@@ -81,7 +82,7 @@ namespace Breeze.Api.Tests
var
mockWalletWrapper
=
new
Mock
<
IWalletManager
>();
mockWalletWrapper
.
Setup
(
w
=>
w
.
LoadWallet
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Returns
(
wallet
);
var
controller
=
new
WalletController
(
mockWalletWrapper
.
Object
,
new
Mock
<
ITracker
>().
Object
);
var
controller
=
new
WalletController
(
mockWalletWrapper
.
Object
,
new
Mock
<
ITracker
>().
Object
,
new
Mock
<
ConnectionManager
>().
Object
,
new
Mock
<
Network
>().
Object
,
new
Mock
<
ConcurrentChain
>().
Object
);
// Act
var
result
=
controller
.
Load
(
new
WalletLoadRequest
...
...
@@ -103,7 +104,7 @@ namespace Breeze.Api.Tests
var
mockWalletWrapper
=
new
Mock
<
IWalletManager
>();
mockWalletWrapper
.
Setup
(
wallet
=>
wallet
.
LoadWallet
(
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>(),
It
.
IsAny
<
string
>())).
Throws
<
FileNotFoundException
>();
var
controller
=
new
WalletController
(
mockWalletWrapper
.
Object
,
new
Mock
<
ITracker
>().
Object
);
var
controller
=
new
WalletController
(
mockWalletWrapper
.
Object
,
new
Mock
<
ITracker
>().
Object
,
new
Mock
<
ConnectionManager
>().
Object
,
new
Mock
<
Network
>().
Object
,
new
Mock
<
ConcurrentChain
>().
Object
);
// Act
var
result
=
controller
.
Load
(
new
WalletLoadRequest
...
...
@@ -119,6 +120,5 @@ namespace Breeze.Api.Tests
Assert
.
NotNull
(
viewResult
);
Assert
.
Equal
(
404
,
viewResult
.
StatusCode
);
}
}
}
Breeze/src/Breeze.Wallet/Controllers/WalletController.cs
View file @
0e28ba41
...
...
@@ -8,6 +8,7 @@ using Breeze.Wallet.Errors;
using
Microsoft.AspNetCore.Mvc
;
using
Breeze.Wallet.Models
;
using
NBitcoin
;
using
Stratis.Bitcoin.Connection
;
namespace
Breeze.Wallet.Controllers
{
...
...
@@ -21,10 +22,22 @@ namespace Breeze.Wallet.Controllers
private
readonly
ITracker
tracker
;
public
WalletController
(
IWalletManager
walletManager
,
ITracker
tracker
)
private
readonly
CoinType
coinType
;
private
readonly
Network
network
;
private
readonly
ConnectionManager
connectionManager
;
private
readonly
ConcurrentChain
chain
;
public
WalletController
(
IWalletManager
walletManager
,
ITracker
tracker
,
ConnectionManager
connectionManager
,
Network
network
,
ConcurrentChain
chain
)
{
this
.
walletManager
=
walletManager
;
this
.
tracker
=
tracker
;
this
.
connectionManager
=
connectionManager
;
this
.
network
=
network
;
this
.
coinType
=
(
CoinType
)
network
.
Consensus
.
CoinType
;
this
.
chain
=
chain
;
}
/// <summary>
...
...
@@ -143,11 +156,11 @@ namespace Breeze.Wallet.Controllers
/// <summary>
/// Get some general info about a wallet.
/// </summary>
/// <param name="
model
">The name of the wallet.</param>
/// <param name="
request
">The name of the wallet.</param>
/// <returns></returns>
[
Route
(
"general-info"
)]
[
HttpGet
]
public
IActionResult
GetGeneralInfo
([
FromQuery
]
WalletName
model
)
public
IActionResult
GetGeneralInfo
([
FromQuery
]
WalletName
request
)
{
// checks the request is valid
if
(!
this
.
ModelState
.
IsValid
)
...
...
@@ -158,7 +171,19 @@ namespace Breeze.Wallet.Controllers
try
{
return
this
.
Json
(
this
.
walletManager
.
GetGeneralInfo
(
model
.
Name
));
Wallet
wallet
=
this
.
walletManager
.
GetWallet
(
request
.
Name
);
var
model
=
new
WalletGeneralInfoModel
{
Network
=
wallet
.
Network
,
WalletFilePath
=
wallet
.
WalletFilePath
,
CreationTime
=
wallet
.
CreationTime
,
LastBlockSyncedHeight
=
wallet
.
AccountsRoot
.
Single
(
a
=>
a
.
CoinType
==
this
.
coinType
).
LastBlockSyncedHeight
,
ConnectedNodes
=
this
.
connectionManager
.
ConnectedNodes
.
Count
(),
ChainTip
=
this
.
chain
.
Tip
.
Height
,
IsDecrypted
=
true
};
return
this
.
Json
(
model
);
}
catch
(
Exception
e
)
...
...
Breeze/src/Breeze.Wallet/IWalletManager.cs
View file @
0e28ba41
...
...
@@ -113,7 +113,12 @@ namespace Breeze.Wallet
/// <returns></returns>
IEnumerable
<
HdAddress
>
GetHistoryByCoinType
(
Wallet
wallet
,
CoinType
coinType
);
WalletGeneralInfoModel
GetGeneralInfo
(
string
walletName
);
/// <summary>
/// Gets some general information about a wallet.
/// </summary>
/// <param name="walletName">The name of the wallet.</param>
/// <returns></returns>
Wallet
GetWallet
(
string
walletName
);
/// <summary>
/// Gets a list of accounts filtered by coin type.
...
...
Breeze/src/Breeze.Wallet/Models/WalletGeneralInfoModel.cs
View file @
0e28ba41
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
Breeze.Wallet.JsonConverters
;
using
NBitcoin
;
using
Newtonsoft.Json
;
namespace
Breeze.Wallet.Models
...
...
@@ -11,22 +10,36 @@ namespace Breeze.Wallet.Models
[
JsonProperty
(
PropertyName
=
"walletFilePath"
)]
public
string
WalletFilePath
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"encryptedSeed"
)]
public
string
EncryptedSeed
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"chainCode"
)]
public
string
ChainCode
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"network"
)]
public
string
Network
{
get
;
set
;
}
[
JsonConverter
(
typeof
(
NetworkConverter
))]
public
Network
Network
{
get
;
set
;
}
/// <summary>
/// The time this wallet was created.
/// </summary>
[
JsonProperty
(
PropertyName
=
"creationTime"
)]
public
string
CreationTime
{
get
;
set
;
}
[
JsonConverter
(
typeof
(
DateTimeOffsetConverter
))]
public
DateTimeOffset
CreationTime
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"isDecrypted"
)]
public
bool
IsDecrypted
{
get
;
set
;
}
[
JsonProperty
(
PropertyName
=
"uniqueId"
)]
public
string
UniqueId
{
get
;
set
;
}
/// <summary>
/// The height of the last block that was synced.
/// </summary>
[
JsonProperty
(
PropertyName
=
"lastBlockSyncedHeight"
)]
public
int
?
LastBlockSyncedHeight
{
get
;
set
;
}
/// <summary>
/// The total number of blocks.
/// </summary>
[
JsonProperty
(
PropertyName
=
"chainTip"
)]
public
int
?
ChainTip
{
get
;
set
;
}
/// <summary>
/// The total number of nodes that we're connected to.
/// </summary>
[
JsonProperty
(
PropertyName
=
"connectedNodes"
)]
public
int
ConnectedNodes
{
get
;
set
;
}
}
}
Breeze/src/Breeze.Wallet/WalletManager.cs
View file @
0e28ba41
...
...
@@ -314,9 +314,11 @@ namespace Breeze.Wallet
return
addressesCreated
;
}
public
WalletGeneralInfoModel
GetGeneralInfo
(
string
name
)
/// <inheritdoc />
public
Wallet
GetWallet
(
string
walletName
)
{
throw
new
System
.
NotImplementedException
();
Wallet
wallet
=
this
.
GetWalletByName
(
walletName
);
return
wallet
;
}
/// <inheritdoc />
...
...
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