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