Commit e201ad10 authored by Jeremy Bokobza's avatar Jeremy Bokobza Committed by GitHub

Merge pull request #124 from dangershony/b-node-shutdown-api

Adding a shutdown api method
parents 542c55ba 6bb09403
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using NBitcoin;
using Stratis.Bitcoin.Builder;
using Stratis.Bitcoin.Notifications;
namespace Breeze.Api.Controllers
......@@ -8,11 +10,11 @@ namespace Breeze.Api.Controllers
[Route("api/[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>
......@@ -27,27 +29,18 @@ namespace Breeze.Api.Controllers
}
/// <summary>
/// Starts sending block to the wallet for synchronisation.
/// This is for demo and testing use only.
/// Trigger a shoutdown of the current running node.
/// </summary>
/// <param name="model">The hash of the block from which to start syncing.</param>
/// <returns></returns>
[HttpPost]
[Route("sync")]
public IActionResult Sync([FromBody] HashModel model)
[Route("shutdown")]
public IActionResult Shutdown()
{
if (!ModelState.IsValid)
{
return this.BadRequest();
}
this.blockNotification.SyncFrom(uint256.Parse(model.Hash));
// start the node shutdown process
this.fullNode.Stop();
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