Commit 0e28ba41 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Added endpoint to get general information about the state of a particular wallet

parent 848c1a11
......@@ -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
......
......@@ -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);
}
}
}
......@@ -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)
......
......@@ -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.
......
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; }
}
}
......@@ -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 />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment