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,12 +10,12 @@ namespace Breeze.Api.Controllers ...@@ -8,12 +10,12 @@ 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>
/// Returns some general information about the status of the underlying node. /// Returns some general information about the status of the underlying node.
...@@ -26,28 +28,19 @@ namespace Breeze.Api.Controllers ...@@ -26,28 +28,19 @@ namespace Breeze.Api.Controllers
return this.NotFound(); return this.NotFound();
} }
/// <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> /// <returns></returns>
/// <param name="model">The hash of the block from which to start syncing.</param> [HttpPost]
/// <returns></returns> [Route("shutdown")]
[HttpPost] public IActionResult Shutdown()
[Route("sync")] {
public IActionResult Sync([FromBody] HashModel model) // start the node shutdown process
{ this.fullNode.Stop();
if (!ModelState.IsValid)
{ return this.Ok();
return this.BadRequest(); }
} }
this.blockNotification.SyncFrom(uint256.Parse(model.Hash));
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