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);
}
}
......@@ -21,6 +29,7 @@ namespace Breeze.Api
.AddFeature<ApiFeature>()
.FeatureServices(services =>
{
services.AddSingleton(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)
{
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();
......
......@@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Breeze.Wallet.Wrappers;
namespace Breeze.Api
{
......@@ -27,11 +26,8 @@ namespace Breeze.Api
// Add framework services.
services.AddMvc()
// add serializers for NBitcoin objects
.AddJsonOptions(options => NBitcoin.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings));
// add DI classes for controllers.
services.AddTransient<ISafeWrapper, SafeWrapper>();
services.AddTransient<ITrackerWrapper, TrackerWrapper>();
.AddJsonOptions(options => NBitcoin.JsonConverters.Serializer.RegisterFrontConverters(options.SerializerSettings))
.AddControllers(services);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
{
"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
{
......@@ -18,7 +19,7 @@ namespace Breeze.Deamon
var node = (FullNode)new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
//.UseWallet()
.UseWallet()
.UseApi()
//.UseBlockNotification()
.Build();
......
......@@ -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
......
......@@ -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