Start configuring swagger
MODIFY
MagicalCryptoWallet.Backend/Controllers/BlockchainController.cs
MagicalCryptoWallet.Backend/Controllers/BlockchainController.cs
@@ -11,9 +11,17 @@ using NBitcoin;
namespace MagicalCryptoWallet.Backend.Controllers
{
+ /// <summary>
+ /// To interact with the Bitcoin blockchain.
+ /// </summary>
[Route("api/v1/btc/[controller]")]
public class BlockchainController : Controller
{
+ /// <summary>
+ /// Get fees for the requested confirmation targets based on Bitcoin Core's estimatesmartfee output.
+ /// </summary>
+ /// <param name="confirmationTargets">Confirmation target in blocks. (2 - 1008)</param>
+ /// <returns>ConfirmationTarget[] contains estimation mode and byte per satoshi pairs. Example: </returns>
[HttpGet("fees")]
public IActionResult GetFees(IEnumerable<int> confirmationTargets) // ToDo: make it comma separated, currently: ?confirmationTargets=1&confirmationTargets=2
{
@@ -31,6 +39,11 @@ namespace MagicalCryptoWallet.Backend.Controllers
return Ok(feeEstimations);
}
+ /// <summary>
+ /// Attempts to broadcast a transaction.
+ /// </summary>
+ /// <param name="hex">The hex string of the raw transaction.</param>
+ /// <returns>200 Ok</returns>
[HttpPost("broadcast")]
public IActionResult Broadcast([FromBody]string hex)
{
@@ -39,11 +52,15 @@ namespace MagicalCryptoWallet.Backend.Controllers
return BadRequest();
}
- // if fail return BadRequest?
+ // ToDo: if fail return BadRequest?
return Ok();
}
+ /// <summary>
+ /// Gets exchange rates for one Bitcoin.
+ /// </summary>
+ /// <returns>ExchangeRates[] contains ticker and exchange rate pairs.</returns>
[HttpGet("exchange-rates")]
public IEnumerable<ExchangeRate> GetExchangeRates()
{
@@ -56,10 +73,15 @@ namespace MagicalCryptoWallet.Backend.Controllers
return exchangeRates;
}
+ /// <summary>
+ /// Gets block filters from the specified block hash.
+ /// </summary>
+ /// <param name="bestKnownBlockHash">The best block hash the client knows its filter.</param>
+ /// <returns>An array of block hash : filter pairs.</returns>
[HttpGet("filters/{blockHash}")]
- public IActionResult GetFilters(uint256 blockHash)
+ public IActionResult GetFilters(string bestKnownBlockHash)
{
- if (blockHash == null)
+ if (string.IsNullOrWhiteSpace(bestKnownBlockHash))
{
return BadRequest();
}
@@ -67,8 +89,8 @@ namespace MagicalCryptoWallet.Backend.Controllers
// if blockHash is not found, return NotFound
var filters = new List<BlockHashFilterPair>
{
- new BlockHashFilterPair(){BlockHash = uint256.Zero, FilterHex = "foo"},
- new BlockHashFilterPair(){BlockHash = uint256.One, FilterHex = "bar"},
+ new BlockHashFilterPair(){BlockHash = "asdasdasd", FilterHex = "foo"},
+ new BlockHashFilterPair(){BlockHash = "asdsadasdad", FilterHex = "bar"},
};
return Ok(filters);

MODIFY
MagicalCryptoWallet.Backend/MagicalCryptoWallet.Backend.csproj
MagicalCryptoWallet.Backend/MagicalCryptoWallet.Backend.csproj
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
+ <LangVersion>latest</LangVersion>
+ <NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MagicalCryptoWallet\MagicalCryptoWallet.csproj" />
</ItemGroup>
- <PropertyGroup>
- <LangVersion>latest</LangVersion>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+ <DocumentationFile>bin\Debug\netcoreapp2.0\MagicalCryptoWallet.Backend.xml</DocumentationFile>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+ <DocumentationFile>bin\Release\netcoreapp2.0\MagicalCryptoWallet.Backend.xml</DocumentationFile>
</PropertyGroup>
</Project>

MODIFY
MagicalCryptoWallet.Backend/Startup.cs
MagicalCryptoWallet.Backend/Startup.cs
@@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
+using Swashbuckle.AspNetCore.Swagger;
namespace MagicalCryptoWallet.Backend
{
@@ -17,11 +18,34 @@ namespace MagicalCryptoWallet.Backend
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
+
+ // Register the Swagger generator, defining one or more Swagger documents
+ services.AddSwaggerGen(c =>
+ {
+ c.SwaggerDoc("v1", new Info
+ {
+ Version = "v1",
+ Title = "Magical Crypto API",
+ Description = "Privacy oriented Bitcoin Web API",
+ TermsOfService = "None",
+ Contact = new Contact { Name = "nopara73", Email = "adam.ficsor73@gmail.com", Url = "https://twitter.com/nopara73" },
+ License = new License { Name = "Use under MIT", Url = "https://github.com/nopara73/MagicalCryptoWallet/blob/master/LICENSE.md" }
+ });
+ });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
+ // Enable middleware to serve generated Swagger as a JSON endpoint.
+ app.UseSwagger();
+
+ // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), specifying the Swagger JSON endpoint.
+ app.UseSwaggerUI(c =>
+ {
+ c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
+ });
+
app.UseMvc();
}
}

MODIFY
MagicalCryptoWallet.Tests/MagicalCryptoWallet.Tests.csproj
MagicalCryptoWallet.Tests/MagicalCryptoWallet.Tests.csproj
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
-
<IsPackable>false</IsPackable>
+ <LangVersion>latest</LangVersion>
+ <NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MagicalCryptoWallet\MagicalCryptoWallet.csproj" />
</ItemGroup>
- <PropertyGroup>
- <LangVersion>latest</LangVersion>
- </PropertyGroup>
-
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

MODIFY
MagicalCryptoWallet/Backend/Models/BlockHashFilterPair.cs
MagicalCryptoWallet/Backend/Models/BlockHashFilterPair.cs
@@ -7,7 +7,7 @@ namespace MagicalCryptoWallet.Backend.Models
{
public class BlockHashFilterPair
{
- public uint256 BlockHash { get; set; }
+ public string BlockHash { get; set; }
public string FilterHex { get; set; }
}
}

MODIFY
MagicalCryptoWallet/MagicalCryptoWallet.csproj
MagicalCryptoWallet/MagicalCryptoWallet.csproj
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
- </PropertyGroup>
-
- <PropertyGroup>
<LangVersion>latest</LangVersion>
+ <NoWarn>1701;1702;1705;1591</NoWarn>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
+ <DocumentationFile>bin\Release\netcoreapp2.0\MagicalCryptoWallet.xml</DocumentationFile>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
+ <DocumentationFile>bin\Debug\netcoreapp2.0\MagicalCryptoWallet.xml</DocumentationFile>
+ </PropertyGroup>
+
<ItemGroup>
<PackageReference Include="NBitcoin" Version="4.0.0.54" />
<PackageReference Include="Nito.AsyncEx.Coordination" Version="1.0.2" />
+ <PackageReference Include="Swashbuckle.AspNetCore" Version="1.1.0" />
</ItemGroup>
</Project>

Start configuring swagger