Commit f4a62d20 authored by Pieterjan Vanhoof's avatar Pieterjan Vanhoof Committed by GitHub

Small API changes (#31)

Small API changes 
parents 5ae9c823 e60dd91e
...@@ -54,7 +54,7 @@ This error message comes at all request if the wallet is not loaded yet, except ...@@ -54,7 +54,7 @@ This error message comes at all request if the wallet is not loaded yet, except
## Key Management ## Key Management
``` ```
GET /wallet/general - Displays general information on the wallet GET /wallet/general-info - Displays general information on the wallet
GET /wallet/sensitive - Displays sensitive information on the wallet GET /wallet/sensitive - Displays sensitive information on the wallet
GET /wallet/status - Displays dynamic information on the wallet GET /wallet/status - Displays dynamic information on the wallet
POST /wallet/create - Creates the wallet POST /wallet/create - Creates the wallet
...@@ -86,7 +86,7 @@ POST /wallet/send-transaction - Attempts to send a transaction ...@@ -86,7 +86,7 @@ POST /wallet/send-transaction - Attempts to send a transaction
# Details # Details
## GET /wallet/general - Displays general information on the wallet ## GET /wallet/general-info - Displays general information on the wallet
### Responses ### Responses
``` ```
{ {
...@@ -95,7 +95,7 @@ POST /wallet/send-transaction - Attempts to send a transaction ...@@ -95,7 +95,7 @@ POST /wallet/send-transaction - Attempts to send a transaction
"chainCode": "q/Fn7+RSIVM0p0Nj6rIuNkybF+0WKeSZPMQS2QCbDzY=", "chainCode": "q/Fn7+RSIVM0p0Nj6rIuNkybF+0WKeSZPMQS2QCbDzY=",
"network": "main", // main/testnet "network": "main", // main/testnet
"creationTime": "2017-03-21", "creationTime": "2017-03-21",
"decrypted": "true", "isDecrypted": true,
"uniqueId": "sadwpiqjdpijwqdpijwqidjoi" // can only get if decrypted, if not it's empty string "uniqueId": "sadwpiqjdpijwqdpijwqidjoi" // can only get if decrypted, if not it's empty string
} }
``` ```
...@@ -194,13 +194,13 @@ Works as expected. ...@@ -194,13 +194,13 @@ Works as expected.
{ {
"txid": "9a9949476b629b4075b31d8faad64dad352586a18df8f2810c5a7bb900478c60", "txid": "9a9949476b629b4075b31d8faad64dad352586a18df8f2810c5a7bb900478c60",
"amount": "0.1", "amount": "0.1",
"confirmed": "true", "confirmed": true,
"timestamp": "2016.12.19. 23:15:05" // if confirmed it's the blocktime, utc "timestamp": "2016.12.19. 23:15:05" // if confirmed it's the blocktime, utc
}, },
{ {
"txid": "9a9949476b629b4075b31d8faad64dad352586a18df8f2810c5a7bb900478c60", "txid": "9a9949476b629b4075b31d8faad64dad352586a18df8f2810c5a7bb900478c60",
"amount": "-0.1", "amount": "-0.1",
"confirmed": "false", "confirmed": false,
"timestamp": "2016.12.20. 1:15:36" // if unconfirmed it's the time our node first seen this transaction, utc "timestamp": "2016.12.20. 1:15:36" // if unconfirmed it's the time our node first seen this transaction, utc
} }
] ]
...@@ -211,7 +211,7 @@ Works as expected. ...@@ -211,7 +211,7 @@ Works as expected.
### Responses ### Responses
``` ```
{ {
"synced": "true", "isSynced": true,
"confirmed": "0.144", "confirmed": "0.144",
"unconfirmed": "-6.23" "unconfirmed": "-6.23"
} }
...@@ -228,7 +228,7 @@ Unconfirmed balance is the difference of unconfirmed incoming and outgoing trans ...@@ -228,7 +228,7 @@ Unconfirmed balance is the difference of unconfirmed incoming and outgoing trans
"address": "1Xyz...", "address": "1Xyz...",
"amount": "0.12", // in btc, if 0, then spends all available "amount": "0.12", // in btc, if 0, then spends all available
"feeType": "low", // "low"/"medium"/"high" "feeType": "low", // "low"/"medium"/"high"
"allowUnconfirmed": "true" // if spending unconfirmed outputs is allowed "allowUnconfirmed": true // if spending unconfirmed outputs is allowed
} }
``` ```
...@@ -236,7 +236,7 @@ Unconfirmed balance is the difference of unconfirmed incoming and outgoing trans ...@@ -236,7 +236,7 @@ Unconfirmed balance is the difference of unconfirmed incoming and outgoing trans
#### Successful #### Successful
``` ```
{ {
"spendsUnconfirmed": "false", // If spends unconfirmed you can ask the user if it's sure about spending unconfirmed transaction (if inputs are malleated or inputs never confirm then this transaction will never confirm either" "spendsUnconfirmed": false, // If spends unconfirmed you can ask the user if it's sure about spending unconfirmed transaction (if inputs are malleated or inputs never confirm then this transaction will never confirm either"
"fee": "0.0001", "fee": "0.0001",
"feePercentOfSent": "0.1" // Percentage of the total spent amount, there must be a safety limit implemented here "feePercentOfSent": "0.1" // Percentage of the total spent amount, there must be a safety limit implemented here
"hex": "0100000002d9dced2b6fc80c706d3564670cb6706afe7a798863a9218efcdcf415d58f0f82000000006a473044022030b8bea478444bd52f08de33b082cde1176d3137111f506eefefa91b47b1f6bf02204f12746abd1aeac5805872d163592cf145967fa0619339a9c5348d674852ef4801210224ec1e4c270ce373e6999eebfa01d0a7e7db3c537c026f265233350d5aab81fbfeffffffa0706db65c5e3594d43df5a2a8b6dfd3c9ee506b678f8c26f7820b324b26aa0f000000006a473044022061b718034f876590d6d80bac77a63248b2548d934849acd02c4f4236309e853002201aded6b24f553b6902cf571276b37b12f76b75650164d8738c74469b4edd547e012103d649294a0ca4db920a69eacd6a75cb8a38ae1b81129900621ce45e6ba3438a7bfeffffff0280a90300000000001976a914d0965947ebb329b776328624ebde8f8b32dc639788ac1cc80f00000000001976a914c2a420d34fc86cff932b8c3191549a0ddfd2b0d088acba770f00" "hex": "0100000002d9dced2b6fc80c706d3564670cb6706afe7a798863a9218efcdcf415d58f0f82000000006a473044022030b8bea478444bd52f08de33b082cde1176d3137111f506eefefa91b47b1f6bf02204f12746abd1aeac5805872d163592cf145967fa0619339a9c5348d674852ef4801210224ec1e4c270ce373e6999eebfa01d0a7e7db3c537c026f265233350d5aab81fbfeffffffa0706db65c5e3594d43df5a2a8b6dfd3c9ee506b678f8c26f7820b324b26aa0f000000006a473044022061b718034f876590d6d80bac77a63248b2548d934849acd02c4f4236309e853002201aded6b24f553b6902cf571276b37b12f76b75650164d8738c74469b4edd547e012103d649294a0ca4db920a69eacd6a75cb8a38ae1b81129900621ce45e6ba3438a7bfeffffff0280a90300000000001976a914d0965947ebb329b776328624ebde8f8b32dc639788ac1cc80f00000000001976a914c2a420d34fc86cff932b8c3191549a0ddfd2b0d088acba770f00"
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" /> <PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" /> <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" /> <PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Moq" Version="4.7.1" /> <PackageReference Include="Moq" Version="4.7.8" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"variables": [], "variables": [],
"info": { "info": {
"name": "Wallet", "name": "Wallet",
"_postman_id": "88e42ac6-4e01-8ec4-c109-12a07b8722de", "_postman_id": "25ac0bc5-23f5-e00d-932f-a8fde7787e7a",
"description": "Requests relating to operations on the wallet", "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"
}, },
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
{ {
"name": "Get wallet Info", "name": "Get wallet Info",
"request": { "request": {
"url": "http://localhost:5000/api/v1/wallet/info?name=mywallet", "url": "http://localhost:5000/api/v1/wallet/general-info?name=mywallet",
"method": "GET", "method": "GET",
"header": [ "header": [
{ {
...@@ -199,7 +199,10 @@ ...@@ -199,7 +199,10 @@
"description": "" "description": ""
} }
], ],
"body": {}, "body": {
"mode": "raw",
"raw": ""
},
"description": "Gets all the wallets files stored in the default folder" "description": "Gets all the wallets files stored in the default folder"
}, },
"response": [] "response": []
......
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);
}
}
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
"dotnet-test-xunit": "1.0.0-rc2-build10025", "dotnet-test-xunit": "1.0.0-rc2-build10025",
"Breeze.Api": "1.0.0-*", "Breeze.Api": "1.0.0-*",
"Microsoft.DotNet.InternalAbstractions": "1.0.0", "Microsoft.DotNet.InternalAbstractions": "1.0.0",
"Moq": "4.7.1", "Moq": "4.7.8",
"Breeze.Wallet": "1.0.0-*" "Breeze.Wallet": "1.0.0-*"
}, },
"testRunner": "xunit", "testRunner": "xunit",
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" /> <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
<PackageReference Include="NBitcoin" Version="3.0.2.10" /> <PackageReference Include="NBitcoin" Version="3.0.2.15" />
<PackageReference Include="Stratis.Bitcoin" Version="1.0.1.3-alpha" /> <PackageReference Include="Stratis.Bitcoin" Version="1.0.1.3-alpha" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0-rc3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0-rc3" />
<PackageReference Include="System.Reactive" Version="3.1.1" /> <PackageReference Include="System.Reactive" Version="3.1.1" />
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"Microsoft.Extensions.Logging.Debug": "1.1.1", "Microsoft.Extensions.Logging.Debug": "1.1.1",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1",
"Microsoft.NETCore.App": "1.1.0", "Microsoft.NETCore.App": "1.1.0",
"NBitcoin": "3.0.2.10", "NBitcoin": "3.0.2.15",
"Stratis.Bitcoin": "1.0.1.3-alpha", "Stratis.Bitcoin": "1.0.1.3-alpha",
"Swashbuckle.AspNetCore": "1.0.0-rc3", "Swashbuckle.AspNetCore": "1.0.0-rc3",
"System.Reactive": "3.1.1", "System.Reactive": "3.1.1",
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="HBitcoin" Version="0.1.5" /> <PackageReference Include="HBitcoin" Version="0.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.0.3" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.0.3" />
<PackageReference Include="NBitcoin" Version="3.0.2.10" /> <PackageReference Include="NBitcoin" Version="3.0.2.15" />
<PackageReference Include="Stratis.Bitcoin" Version="1.0.1.3-alpha" /> <PackageReference Include="Stratis.Bitcoin" Version="1.0.1.3-alpha" />
</ItemGroup> </ItemGroup>
......
...@@ -82,7 +82,7 @@ namespace Breeze.Wallet.Controllers ...@@ -82,7 +82,7 @@ namespace Breeze.Wallet.Controllers
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.Conflict, "This wallet already exists.", e.ToString()); return ErrorHelpers.BuildErrorResponse(HttpStatusCode.NotFound, "This wallet was not found at the specified location.", e.ToString());
} }
catch (SecurityException e) catch (SecurityException e)
{ {
...@@ -123,12 +123,7 @@ namespace Breeze.Wallet.Controllers ...@@ -123,12 +123,7 @@ namespace Breeze.Wallet.Controllers
{ {
// indicates that this wallet does not exist // indicates that this wallet does not exist
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.NotFound, "Wallet not found.", e.ToString()); return ErrorHelpers.BuildErrorResponse(HttpStatusCode.NotFound, "Wallet not found.", e.ToString());
} }
catch (SecurityException e)
{
// indicates that the password is wrong
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Wrong password, please try again.", e.ToString());
}
catch (Exception e) catch (Exception e)
{ {
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()); return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
...@@ -140,9 +135,9 @@ namespace Breeze.Wallet.Controllers ...@@ -140,9 +135,9 @@ namespace Breeze.Wallet.Controllers
/// </summary> /// </summary>
/// <param name="model">The name of the wallet.</param> /// <param name="model">The name of the wallet.</param>
/// <returns></returns> /// <returns></returns>
[Route("info")] [Route("general-info")]
[HttpGet] [HttpGet]
public IActionResult GetInfo([FromQuery] WalletName model) public IActionResult GetGeneralInfo([FromQuery] WalletName model)
{ {
// checks the request is valid // checks the request is valid
if (!this.ModelState.IsValid) if (!this.ModelState.IsValid)
...@@ -153,7 +148,7 @@ namespace Breeze.Wallet.Controllers ...@@ -153,7 +148,7 @@ namespace Breeze.Wallet.Controllers
try try
{ {
return this.Json(this.walletWrapper.GetInfo(model.Name)); return this.Json(this.walletWrapper.GetGeneralInfo(model.Name));
} }
catch (Exception e) catch (Exception e)
......
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.");
}
}
}
}
...@@ -16,7 +16,7 @@ namespace Breeze.Wallet.Models ...@@ -16,7 +16,7 @@ namespace Breeze.Wallet.Models
public Money Fee { get; set; } public Money Fee { get; set; }
[JsonProperty(PropertyName = "feePercentOfSent")] [JsonProperty(PropertyName = "feePercentOfSent")]
public double FeePercentOfSent { get; set; } public decimal FeePercentOfSent { get; set; }
[JsonProperty(PropertyName = "hex")] [JsonProperty(PropertyName = "hex")]
public string Hex { get; set; } public string Hex { get; set; }
......
...@@ -6,10 +6,10 @@ using Newtonsoft.Json; ...@@ -6,10 +6,10 @@ using Newtonsoft.Json;
namespace Breeze.Wallet.Models namespace Breeze.Wallet.Models
{ {
public class WalletInfoModel public class WalletGeneralInfoModel
{ {
[JsonProperty(PropertyName = "filePath")] [JsonProperty(PropertyName = "walletFilePath")]
public string FilePath { get; set; } public string WalletFilePath { get; set; }
[JsonProperty(PropertyName = "encryptedSeed")] [JsonProperty(PropertyName = "encryptedSeed")]
public string EncryptedSeed { get; set; } public string EncryptedSeed { get; set; }
......
...@@ -19,7 +19,7 @@ namespace Breeze.Wallet.Models ...@@ -19,7 +19,7 @@ namespace Breeze.Wallet.Models
public Money Amount { get; set; } public Money Amount { get; set; }
[JsonProperty(PropertyName = "confirmed")] [JsonProperty(PropertyName = "confirmed")]
public Money Confirmed { get; set; } public bool Confirmed { get; set; }
[JsonProperty(PropertyName = "timestamp")] [JsonProperty(PropertyName = "timestamp")]
public string Timestamp { get; set; } public string Timestamp { get; set; }
......
...@@ -17,7 +17,7 @@ namespace Breeze.Wallet.Wrappers ...@@ -17,7 +17,7 @@ namespace Breeze.Wallet.Wrappers
WalletModel Recover(string password, string folderPath, string name, string network, string mnemonic); WalletModel Recover(string password, string folderPath, string name, string network, string mnemonic);
WalletInfoModel GetInfo(string walletName); WalletGeneralInfoModel GetGeneralInfo(string walletName);
WalletBalanceModel GetBalance(string walletName); WalletBalanceModel GetBalance(string walletName);
......
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"), this.GetNetwork(network)); Safe wallet = Safe.Create(out mnemonic, password, Path.Combine(folderPath, $"{name}.json"), WalletHelpers.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"), this.GetNetwork(network)); Safe wallet = Safe.Recover(new Mnemonic(mnemonic), password, Path.Combine(folderPath, $"{name}.json"), WalletHelpers.GetNetwork(network));
//TODO review here which data should be returned //TODO review here which data should be returned
return new WalletModel return new WalletModel
...@@ -67,21 +69,8 @@ namespace Breeze.Wallet.Wrappers ...@@ -67,21 +69,8 @@ namespace Breeze.Wallet.Wrappers
FileName = wallet.WalletFilePath FileName = wallet.WalletFilePath
}; };
} }
private Network GetNetwork(string network) public WalletGeneralInfoModel GetGeneralInfo(string name)
{
// 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)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
"version": "1.0.0-*", "version": "1.0.0-*",
"dependencies": { "dependencies": {
"HBitcoin": "0.1.5", "HBitcoin": "0.1.6",
"Microsoft.AspNetCore.Mvc.Versioning": "1.0.3", "Microsoft.AspNetCore.Mvc.Versioning": "1.0.3",
"NBitcoin": "3.0.2.10", "NBitcoin": "3.0.2.15",
"NETStandard.Library": "1.6.1", "NETStandard.Library": "1.6.1",
"Stratis.Bitcoin": "1.0.1.3-alpha" "Stratis.Bitcoin": "1.0.1.3-alpha"
}, },
......
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