Commit 6bb09403 authored by Dan Gershony's avatar Dan Gershony

Adding a shutdown api method

parent 896fcfa5
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using NBitcoin; using NBitcoin;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Notifications; using Stratis.Bitcoin.Notifications;
namespace Breeze.Api.Controllers namespace Breeze.Api.Controllers
...@@ -8,11 +10,11 @@ namespace Breeze.Api.Controllers ...@@ -8,11 +10,11 @@ namespace Breeze.Api.Controllers
[Route("api/[controller]")] [Route("api/[controller]")]
public class NodeController : Controller public class NodeController : Controller
{ {
private readonly BlockNotification blockNotification; private readonly IFullNode fullNode;
public NodeController(BlockNotification blockNotification) public NodeController(IFullNode fullNode)
{ {
this.blockNotification = blockNotification; this.fullNode = fullNode;
} }
/// <summary> /// <summary>
...@@ -27,27 +29,18 @@ namespace Breeze.Api.Controllers ...@@ -27,27 +29,18 @@ namespace Breeze.Api.Controllers
} }
/// <summary> /// <summary>
/// Starts sending block to the wallet for synchronisation. /// Trigger a shoutdown of the current running node.
/// This is for demo and testing use only.
/// </summary> /// </summary>
/// <param name="model">The hash of the block from which to start syncing.</param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[Route("sync")] [Route("shutdown")]
public IActionResult Sync([FromBody] HashModel model) public IActionResult Shutdown()
{ {
if (!ModelState.IsValid) // start the node shutdown process
{ this.fullNode.Stop();
return this.BadRequest();
}
this.blockNotification.SyncFrom(uint256.Parse(model.Hash));
return this.Ok(); return this.Ok();
} }
} }
public class HashModel
{
[Required(AllowEmptyStrings = false)]
public string Hash { get; set; }
}
} }
\ No newline at end of file
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