Commit 136bc94a authored by Jeremy Bokobza's avatar Jeremy Bokobza

Added Api and Wallet features

Moved Wallet Controller and types out of the Api
parent fc9814a6
...@@ -3,10 +3,10 @@ using System.IO; ...@@ -3,10 +3,10 @@ using System.IO;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Xunit; using Xunit;
using Moq; using Moq;
using Breeze.Api.Controllers;
using Breeze.Api.Models;
using Breeze.Wallet.Wrappers; using Breeze.Wallet.Wrappers;
using Breeze.Wallet; using Breeze.Wallet;
using Breeze.Wallet.Controllers;
using Breeze.Wallet.Models;
namespace Breeze.Api.Tests namespace Breeze.Api.Tests
{ {
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
"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.1",
"Breeze.Wallet": "1.0.0-*"
}, },
"testRunner": "xunit", "testRunner": "xunit",
"frameworks": { "frameworks": {
......
using Stratis.Bitcoin.Builder; using Microsoft.Extensions.DependencyInjection;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Builder.Feature; using Stratis.Bitcoin.Builder.Feature;
namespace Breeze.Api namespace Breeze.Api
{ {
public class ApiFeature : FullNodeFeature public class ApiFeature : FullNodeFeature
{ {
private readonly IFullNodeBuilder fullNodeBuilder;
public ApiFeature(IFullNodeBuilder fullNodeBuilder)
{
this.fullNodeBuilder = fullNodeBuilder;
}
public override void Start() public override void Start()
{ {
Program.Main(null); Program.Initialize(this.fullNodeBuilder.Services);
} }
} }
...@@ -20,11 +28,12 @@ namespace Breeze.Api ...@@ -20,11 +28,12 @@ namespace Breeze.Api
features features
.AddFeature<ApiFeature>() .AddFeature<ApiFeature>()
.FeatureServices(services => .FeatureServices(services =>
{ {
}); services.AddSingleton(fullNodeBuilder);
});
}); });
return fullNodeBuilder; return fullNodeBuilder;
} }
} }
} }
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
namespace Breeze.Api
{
public static class MvcBuilderExtensions
{
/// <summary>
/// Finds all the types that are <see cref="Controller"/> and add them to the Api as services.
/// </summary>
/// <param name="builder">The builder</param>
/// <param name="services">The services to look into</param>
/// <returns>The Mvc builder</returns>
public static IMvcBuilder AddControllers(this IMvcBuilder builder, IServiceCollection services)
{
var controllerTypes = services.Where(s => s.ServiceType.GetTypeInfo().BaseType == typeof(Controller));
foreach (var controllerType in controllerTypes)
{
builder.AddApplicationPart(controllerType.ServiceType.GetTypeInfo().Assembly);
}
builder.AddControllersAsServices();
return builder;
}
}
}
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection;
namespace Breeze.Api namespace Breeze.Api
{ {
public class Program public class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
Initialize();
}
public static void Initialize(IEnumerable<ServiceDescriptor> services = null)
{
var host = new WebHostBuilder() var host = new WebHostBuilder()
.UseKestrel() .UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() .UseIISIntegration()
.ConfigureServices(collection =>
{
if (services == null)
{
return;
}
foreach (var service in services)
{
collection.Add(service);
}
})
.UseStartup<Startup>() .UseStartup<Startup>()
.Build(); .Build();
host.Run(); host.Run();
} }
} }
} }
...@@ -3,44 +3,40 @@ using Microsoft.AspNetCore.Hosting; ...@@ -3,44 +3,40 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Breeze.Wallet.Wrappers;
namespace Breeze.Api namespace Breeze.Api
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IHostingEnvironment env)
{ {
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath) .SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables(); .AddEnvironmentVariables();
Configuration = builder.Build(); Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services. // Add framework services.
services.AddMvc() services.AddMvc()
// add serializers for NBitcoin objects // add serializers for NBitcoin objects
.AddJsonOptions(options => NBitcoin.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings)); .AddJsonOptions(options => NBitcoin.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings))
.AddControllers(services);
}
// add DI classes for controllers. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
services.AddTransient<ISafeWrapper, SafeWrapper>(); public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
services.AddTransient<ITrackerWrapper, TrackerWrapper>(); {
} loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. app.UseMvc();
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) }
{ }
loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc();
}
}
} }
{ {
"dependencies": { "dependencies": {
"Breeze.Wallet": "1.0.0-*",
"Microsoft.AspNetCore.Mvc": "1.1.2", "Microsoft.AspNetCore.Mvc": "1.1.2",
"Microsoft.AspNetCore.Routing": "1.1.1", "Microsoft.AspNetCore.Routing": "1.1.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.1", "Microsoft.AspNetCore.Server.IISIntegration": "1.1.1",
...@@ -8,6 +7,7 @@ ...@@ -8,6 +7,7 @@
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.1", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.1",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.1", "Microsoft.Extensions.Configuration.FileExtensions": "1.1.1",
"Microsoft.Extensions.Configuration.Json": "1.1.1", "Microsoft.Extensions.Configuration.Json": "1.1.1",
"Microsoft.Extensions.DependencyModel": "1.1.1",
"Microsoft.Extensions.Logging": "1.1.1", "Microsoft.Extensions.Logging": "1.1.1",
"Microsoft.Extensions.Logging.Console": "1.1.1", "Microsoft.Extensions.Logging.Console": "1.1.1",
"Microsoft.Extensions.Logging.Debug": "1.1.1", "Microsoft.Extensions.Logging.Debug": "1.1.1",
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
"Microsoft.NETCore.App": "1.1.0", "Microsoft.NETCore.App": "1.1.0",
"NBitcoin": "3.0.2.10", "NBitcoin": "3.0.2.10",
"Stratis.Bitcoin": "1.0.1.2-alpha", "Stratis.Bitcoin": "1.0.1.2-alpha",
"System.Reactive": "3.1.1" "System.Reactive": "3.1.1",
"System.Runtime.Loader": "4.3.0"
}, },
"tools": { "tools": {
...@@ -34,7 +35,6 @@ ...@@ -34,7 +35,6 @@
"buildOptions": { "buildOptions": {
"emitEntryPoint": true, "emitEntryPoint": true,
"preserveCompilationContext": true "preserveCompilationContext": true
}, },
"runtimeOptions": { "runtimeOptions": {
......
...@@ -5,6 +5,7 @@ using Stratis.Bitcoin; ...@@ -5,6 +5,7 @@ using Stratis.Bitcoin;
using Stratis.Bitcoin.Builder; using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Configuration; using Stratis.Bitcoin.Configuration;
using Stratis.Bitcoin.Logging; using Stratis.Bitcoin.Logging;
using Breeze.Wallet;
namespace Breeze.Deamon namespace Breeze.Deamon
{ {
...@@ -16,11 +17,11 @@ namespace Breeze.Deamon ...@@ -16,11 +17,11 @@ namespace Breeze.Deamon
Logs.Configure(new LoggerFactory().AddConsole(LogLevel.Trace, false)); Logs.Configure(new LoggerFactory().AddConsole(LogLevel.Trace, false));
NodeSettings nodeSettings = NodeSettings.FromArguments(args); NodeSettings nodeSettings = NodeSettings.FromArguments(args);
var node = (FullNode)new FullNodeBuilder() var node = (FullNode)new FullNodeBuilder()
.UseNodeSettings(nodeSettings) .UseNodeSettings(nodeSettings)
//.UseWallet() .UseWallet()
.UseApi() .UseApi()
//.UseBlockNotification() //.UseBlockNotification()
.Build(); .Build();
System.Console.WriteLine(); System.Console.WriteLine();
......
...@@ -4,11 +4,12 @@ using System.Linq; ...@@ -4,11 +4,12 @@ using System.Linq;
using System.Net; using System.Net;
using System.Security; using System.Security;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Breeze.Api.Models; using Breeze.Wallet.Models;
using Breeze.Wallet.Wrappers; using Breeze.Wallet.Wrappers;
using Stratis.Bitcoin;
namespace Breeze.Api.Controllers namespace Breeze.Wallet.Controllers
{ {
[Route("api/[controller]")] [Route("api/[controller]")]
public class SafeController : Controller public class SafeController : Controller
...@@ -19,13 +20,13 @@ namespace Breeze.Api.Controllers ...@@ -19,13 +20,13 @@ namespace Breeze.Api.Controllers
{ {
this.safeWrapper = safeWrapper; this.safeWrapper = safeWrapper;
} }
/// <summary> /// <summary>
/// Creates a new safe on the local machine. /// Creates a new safe on the local machine.
/// </summary> /// </summary>
/// <param name="safeCreation">The object containing the parameters used to create the wallet.</param> /// <param name="safeCreation">The object containing the parameters used to create the wallet.</param>
/// <returns>A JSON object contaibibg the mnemonic created for the new wallet.</returns> /// <returns>A JSON object contaibibg the mnemonic created for the new wallet.</returns>
[HttpPost] [HttpPost]
public IActionResult Create([FromBody]SafeCreationModel safeCreation) public IActionResult Create([FromBody]SafeCreationModel safeCreation)
{ {
// checks the request is valid // checks the request is valid
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
namespace Breeze.Api.Models namespace Breeze.Wallet.Models
{ {
/// <summary> /// <summary>
/// Object used to create a new wallet /// Object used to create a new wallet
......
using Stratis.Bitcoin.Builder.Feature;
using Breeze.Wallet.Controllers;
using Breeze.Wallet.Wrappers;
using Microsoft.Extensions.DependencyInjection;
using Stratis.Bitcoin.Builder;
namespace Breeze.Wallet
{
public class WalletFeature : FullNodeFeature
{
public override void Start()
{
}
}
public static class WalletFeatureExtension
{
public static IFullNodeBuilder UseWallet(this IFullNodeBuilder fullNodeBuilder)
{
fullNodeBuilder.ConfigureFeature(features =>
{
features
.AddFeature<WalletFeature>()
.FeatureServices(services =>
{
services.AddTransient<ISafeWrapper, SafeWrapper>();
services.AddTransient<ITrackerWrapper, TrackerWrapper>();
services.AddSingleton<SafeController>();
});
});
return fullNodeBuilder;
}
}
}
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
"dependencies": { "dependencies": {
"HBitcoin": "0.1.5", "HBitcoin": "0.1.5",
"NBitcoin": "3.0.2.10", "NBitcoin": "3.0.2.10",
"NETStandard.Library": "1.6.1" "NETStandard.Library": "1.6.1",
"Stratis.Bitcoin": "1.0.1.2-alpha"
}, },
"frameworks": { "frameworks": {
......
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