Commit 8b25d8f1 authored by Jeremy Bokobza's avatar Jeremy Bokobza Committed by GitHub

Merge pull request #75 from bokobza/pre-alpha-dev-release

Added looger to log all incoming api requests
parents e524ccbe d50d1ecf
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
namespace Breeze.Api
{
/// <summary>
/// An asynchronous action filter whose role is to log details from the Http requests to the API.
/// </summary>
/// <seealso cref="Microsoft.AspNetCore.Mvc.Filters.IAsyncActionFilter" />
public class LoggingActionFilter : IAsyncActionFilter
{
private readonly ILogger logger;
public LoggingActionFilter(ILoggerFactory loggerFactory)
{
this.logger = loggerFactory.CreateLogger("api.request.logger");
}
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
HttpRequest request = context.HttpContext.Request;
// get the body
var body = string.Empty;
var arguments = context.ActionArguments;
if (request.ContentLength != null && arguments != null && arguments.Any())
{
body = string.Join(Environment.NewLine, arguments.Values);
}
this.logger.LogDebug($"Received {request.Method} {request.GetDisplayUrl()}. Body: '{body}'");
await next();
}
}
}
......@@ -51,7 +51,7 @@ namespace Breeze.Api
});
// Add framework services.
services.AddMvc()
services.AddMvc(options => options.Filters.Add(typeof(LoggingActionFilter)))
// add serializers for NBitcoin objects
.AddJsonOptions(options => NBitcoin.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings))
.AddControllers(services);
......
......@@ -7,10 +7,18 @@ using Newtonsoft.Json.Converters;
namespace Breeze.Wallet.Models
{
public class RequestModel
{
public override string ToString()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
/// <summary>
/// Object used to create a new wallet
/// </summary>
public class WalletCreationRequest
public class WalletCreationRequest : RequestModel
{
[Required(ErrorMessage = "A password is required.")]
public string Password { get; set; }
......@@ -23,7 +31,7 @@ namespace Breeze.Wallet.Models
public string Name { get; set; }
}
public class WalletLoadRequest
public class WalletLoadRequest : RequestModel
{
[Required(ErrorMessage = "A password is required.")]
public string Password { get; set; }
......@@ -34,7 +42,7 @@ namespace Breeze.Wallet.Models
public string Name { get; set; }
}
public class WalletRecoveryRequest
public class WalletRecoveryRequest : RequestModel
{
[Required(ErrorMessage = "A mnemonic is required.")]
public string Mnemonic { get; set; }
......@@ -53,7 +61,7 @@ namespace Breeze.Wallet.Models
public DateTime CreationDate { get; set; }
}
public class WalletHistoryRequest
public class WalletHistoryRequest : RequestModel
{
[Required(ErrorMessage = "The name of the wallet is missing.")]
public string WalletName { get; set; }
......@@ -62,7 +70,7 @@ namespace Breeze.Wallet.Models
public CoinType CoinType { get; set; }
}
public class WalletBalanceRequest
public class WalletBalanceRequest : RequestModel
{
[Required(ErrorMessage = "The name of the wallet is missing.")]
public string WalletName { get; set; }
......@@ -71,13 +79,13 @@ namespace Breeze.Wallet.Models
public CoinType CoinType { get; set; }
}
public class WalletName
public class WalletName : RequestModel
{
[Required(ErrorMessage = "The name of the wallet is missing.")]
public string Name { get; set; }
}
public class BuildTransactionRequest
public class BuildTransactionRequest : RequestModel
{
[Required(ErrorMessage = "The name of the wallet is missing.")]
public string WalletName { get; set; }
......@@ -103,13 +111,13 @@ namespace Breeze.Wallet.Models
public bool AllowUnconfirmed { get; set; }
}
public class SendTransactionRequest
public class SendTransactionRequest : RequestModel
{
[Required(ErrorMessage = "A transaction in hexadecimal format is required.")]
public string Hex { get; set; }
}
public class GetUnusedAddressModel
public class GetUnusedAddressModel : RequestModel
{
/// <summary>
/// The name of the wallet from which to get the address.
......@@ -130,7 +138,7 @@ namespace Breeze.Wallet.Models
public string AccountName { get; set; }
}
public class GetUnusedAccountModel
public class GetUnusedAccountModel : RequestModel
{
/// <summary>
/// The name of the wallet in which to create the account.
......
using Stratis.Bitcoin.Builder.Feature;
using Breeze.Wallet.Controllers;
using Microsoft.Extensions.DependencyInjection;
using NBitcoin;
using Stratis.Bitcoin;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Logging;
using Microsoft.Extensions.Logging;
namespace Breeze.Wallet
{
......@@ -41,6 +41,7 @@ namespace Breeze.Wallet
.FeatureServices(services =>
{
services.AddSingleton<ITracker, Tracker>();
services.AddSingleton<ILoggerFactory>(Logs.LoggerFactory);
services.AddSingleton<IWalletManager, WalletManager>();
services.AddSingleton<WalletController>();
});
......
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