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
## 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/status - Displays dynamic information on the wallet
POST /wallet/create - Creates the wallet
......@@ -86,7 +86,7 @@ POST /wallet/send-transaction - Attempts to send a transaction
# Details
## GET /wallet/general - Displays general information on the wallet
## GET /wallet/general-info - Displays general information on the wallet
### Responses
```
{
......@@ -95,7 +95,7 @@ POST /wallet/send-transaction - Attempts to send a transaction
"chainCode": "q/Fn7+RSIVM0p0Nj6rIuNkybF+0WKeSZPMQS2QCbDzY=",
"network": "main", // main/testnet
"creationTime": "2017-03-21",
"decrypted": "true",
"isDecrypted": true,
"uniqueId": "sadwpiqjdpijwqdpijwqidjoi" // can only get if decrypted, if not it's empty string
}
```
......@@ -194,13 +194,13 @@ Works as expected.
{
"txid": "9a9949476b629b4075b31d8faad64dad352586a18df8f2810c5a7bb900478c60",
"amount": "0.1",
"confirmed": "true",
"confirmed": true,
"timestamp": "2016.12.19. 23:15:05" // if confirmed it's the blocktime, utc
},
{
"txid": "9a9949476b629b4075b31d8faad64dad352586a18df8f2810c5a7bb900478c60",
"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
}
]
......@@ -211,7 +211,7 @@ Works as expected.
### Responses
```
{
"synced": "true",
"isSynced": true,
"confirmed": "0.144",
"unconfirmed": "-6.23"
}
......@@ -228,7 +228,7 @@ Unconfirmed balance is the difference of unconfirmed incoming and outgoing trans
"address": "1Xyz...",
"amount": "0.12", // in btc, if 0, then spends all available
"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
#### 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",
"feePercentOfSent": "0.1" // Percentage of the total spent amount, there must be a safety limit implemented here
"hex": "0100000002d9dced2b6fc80c706d3564670cb6706afe7a798863a9218efcdcf415d58f0f82000000006a473044022030b8bea478444bd52f08de33b082cde1176d3137111f506eefefa91b47b1f6bf02204f12746abd1aeac5805872d163592cf145967fa0619339a9c5348d674852ef4801210224ec1e4c270ce373e6999eebfa01d0a7e7db3c537c026f265233350d5aab81fbfeffffffa0706db65c5e3594d43df5a2a8b6dfd3c9ee506b678f8c26f7820b324b26aa0f000000006a473044022061b718034f876590d6d80bac77a63248b2548d934849acd02c4f4236309e853002201aded6b24f553b6902cf571276b37b12f76b75650164d8738c74469b4edd547e012103d649294a0ca4db920a69eacd6a75cb8a38ae1b81129900621ce45e6ba3438a7bfeffffff0280a90300000000001976a914d0965947ebb329b776328624ebde8f8b32dc639788ac1cc80f00000000001976a914c2a420d34fc86cff932b8c3191549a0ddfd2b0d088acba770f00"
......
......@@ -20,7 +20,7 @@
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Moq" Version="4.7.1" />
<PackageReference Include="Moq" Version="4.7.8" />
</ItemGroup>
</Project>
......@@ -2,7 +2,7 @@
"variables": [],
"info": {
"name": "Wallet",
"_postman_id": "88e42ac6-4e01-8ec4-c109-12a07b8722de",
"_postman_id": "25ac0bc5-23f5-e00d-932f-a8fde7787e7a",
"description": "Requests relating to operations on the wallet",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
......@@ -90,7 +90,7 @@
{
"name": "Get wallet Info",
"request": {
"url": "http://localhost:5000/api/v1/wallet/info?name=mywallet",
"url": "http://localhost:5000/api/v1/wallet/general-info?name=mywallet",
"method": "GET",
"header": [
{
......@@ -199,7 +199,10 @@
"description": ""
}
],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"description": "Gets all the wallets files stored in the default folder"
},
"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 @@
"dotnet-test-xunit": "1.0.0-rc2-build10025",
"Breeze.Api": "1.0.0-*",
"Microsoft.DotNet.InternalAbstractions": "1.0.0",
"Moq": "4.7.1",
"Moq": "4.7.8",
"Breeze.Wallet": "1.0.0-*"
},
"testRunner": "xunit",
......
......@@ -29,7 +29,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" 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="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="Swashbuckle.AspNetCore" Version="1.0.0-rc3" />
<PackageReference Include="System.Reactive" Version="3.1.1" />
......
......@@ -14,7 +14,7 @@
"Microsoft.Extensions.Logging.Debug": "1.1.1",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.1",
"Microsoft.NETCore.App": "1.1.0",
"NBitcoin": "3.0.2.10",
"NBitcoin": "3.0.2.15",
"Stratis.Bitcoin": "1.0.1.3-alpha",
"Swashbuckle.AspNetCore": "1.0.0-rc3",
"System.Reactive": "3.1.1",
......
......@@ -16,9 +16,9 @@
</PropertyGroup>
<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="NBitcoin" Version="3.0.2.10" />
<PackageReference Include="NBitcoin" Version="3.0.2.15" />
<PackageReference Include="Stratis.Bitcoin" Version="1.0.1.3-alpha" />
</ItemGroup>
......
......@@ -82,7 +82,7 @@ namespace Breeze.Wallet.Controllers
}
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)
{
......@@ -123,12 +123,7 @@ namespace Breeze.Wallet.Controllers
{
// indicates that this wallet does not exist
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)
{
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
......@@ -140,9 +135,9 @@ namespace Breeze.Wallet.Controllers
/// </summary>
/// <param name="model">The name of the wallet.</param>
/// <returns></returns>
[Route("info")]
[Route("general-info")]
[HttpGet]
public IActionResult GetInfo([FromQuery] WalletName model)
public IActionResult GetGeneralInfo([FromQuery] WalletName model)
{
// checks the request is valid
if (!this.ModelState.IsValid)
......@@ -153,7 +148,7 @@ namespace Breeze.Wallet.Controllers
try
{
return this.Json(this.walletWrapper.GetInfo(model.Name));
return this.Json(this.walletWrapper.GetGeneralInfo(model.Name));
}
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
public Money Fee { get; set; }
[JsonProperty(PropertyName = "feePercentOfSent")]
public double FeePercentOfSent { get; set; }
public decimal FeePercentOfSent { get; set; }
[JsonProperty(PropertyName = "hex")]
public string Hex { get; set; }
......
......@@ -6,10 +6,10 @@ using Newtonsoft.Json;
namespace Breeze.Wallet.Models
{
public class WalletInfoModel
public class WalletGeneralInfoModel
{
[JsonProperty(PropertyName = "filePath")]
public string FilePath { get; set; }
[JsonProperty(PropertyName = "walletFilePath")]
public string WalletFilePath { get; set; }
[JsonProperty(PropertyName = "encryptedSeed")]
public string EncryptedSeed { get; set; }
......
......@@ -19,7 +19,7 @@ namespace Breeze.Wallet.Models
public Money Amount { get; set; }
[JsonProperty(PropertyName = "confirmed")]
public Money Confirmed { get; set; }
public bool Confirmed { get; set; }
[JsonProperty(PropertyName = "timestamp")]
public string Timestamp { get; set; }
......
......@@ -17,7 +17,7 @@ namespace Breeze.Wallet.Wrappers
WalletModel Recover(string password, string folderPath, string name, string network, string mnemonic);
WalletInfoModel GetInfo(string walletName);
WalletGeneralInfoModel GetGeneralInfo(string walletName);
WalletBalanceModel GetBalance(string walletName);
......
using System.IO;
using System;
using System.IO;
using System.Linq;
using Breeze.Wallet.Helpers;
using Breeze.Wallet.Models;
using HBitcoin.KeyManagement;
using NBitcoin;
......@@ -22,7 +24,7 @@ namespace Breeze.Wallet.Wrappers
public string Create(string password, string folderPath, string name, string network)
{
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();
}
......@@ -57,7 +59,7 @@ namespace Breeze.Wallet.Wrappers
/// <returns></returns>
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
return new WalletModel
......@@ -67,21 +69,8 @@ namespace Breeze.Wallet.Wrappers
FileName = wallet.WalletFilePath
};
}
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 WalletGeneralInfoModel GetGeneralInfo(string name)
{
throw new System.NotImplementedException();
}
......
......@@ -2,9 +2,9 @@
"version": "1.0.0-*",
"dependencies": {
"HBitcoin": "0.1.5",
"HBitcoin": "0.1.6",
"Microsoft.AspNetCore.Mvc.Versioning": "1.0.3",
"NBitcoin": "3.0.2.10",
"NBitcoin": "3.0.2.15",
"NETStandard.Library": "1.6.1",
"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