Merge pull request #1268 from benthecarman/cli-stop

CLI command to stop node
This commit is contained in:
Ben Carman 2020-03-30 12:43:00 -05:00 committed by GitHub
commit 47c2bc08c4
2 changed files with 16 additions and 1 deletions

View File

@ -148,6 +148,9 @@ object ConsoleCli {
cmd("getpeers")
.action((_, conf) => conf.copy(command = GetPeers))
.text(s"List the connected peers"),
cmd("stop")
.action((_, conf) => conf.copy(command = Stop))
.text("Request a graceful shutdown of Bitcoin-S"),
note(sys.props("line.separator") + "=== PSBT ==="),
cmd("combinepsbts")
.action((_, conf) => conf.copy(command = CombinePSBTs(Seq.empty)))
@ -275,6 +278,7 @@ object ConsoleCli {
case GetBestBlockHash => RequestParam("getbestblockhash")
// peers
case GetPeers => RequestParam("getpeers")
case Stop => RequestParam("stop")
// PSBTs
case CombinePSBTs(psbts) =>
RequestParam("combinepsbts", Seq(up.writeJs(psbts)))
@ -386,6 +390,7 @@ object CliCommand {
// Node
case object GetPeers extends CliCommand
case object Stop extends CliCommand
// Chain
case object GetBestBlockHash extends CliCommand

View File

@ -8,12 +8,22 @@ import org.bitcoins.node.Node
case class NodeRoutes(node: Node)(implicit system: ActorSystem)
extends ServerRoute {
implicit val materializer = ActorMaterializer()
import system.dispatcher
implicit val materializer: ActorMaterializer = ActorMaterializer()
def handleCommand: PartialFunction[ServerCommand, StandardRoute] = {
case ServerCommand("getpeers", _) =>
complete {
Server.httpSuccess("TODO implement getpeers")
}
case ServerCommand("stop", _) =>
complete {
val nodeStopping = node.stop().map { _ =>
Server.httpSuccess("Node shutting down")
}
system.terminate()
nodeStopping
}
}
}