Skip to content

Commit

Permalink
api: add a simple getinfo method (closes ACINQ#98) (ACINQ#100)
Browse files Browse the repository at this point in the history
* api: add a simple getinfo method returning node id, node alias, port, chain hash and current block height
* api: add short description of getinfo [ci skip]
  • Loading branch information
sstone authored and pm47 committed Jun 27, 2017
1 parent c0ad616 commit 12c90a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ option | description | default value

method | params | description
-------------|-----------------------------------------------|-----------------------------------------------------------
getinfo | | return basic node information (id, chain hash, current block height)
connect | host, port, nodeId | connect to another lightning node through a secure connection
open | host, port, nodeId, fundingSatoshis, pushMsat | opens a channel with another lightning node
peers | | list existing local peers
Expand Down
6 changes: 4 additions & 2 deletions eclair-core/src/main/scala/fr/acinq/eclair/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
import akka.util.Timeout
import fr.acinq.bitcoin.{Base58Check, OP_CHECKSIG, OP_DUP, OP_EQUALVERIFY, OP_HASH160, OP_PUSHDATA, Script}
import fr.acinq.eclair.api.Service
import fr.acinq.eclair.api.{GetInfoResponse, Service}
import fr.acinq.eclair.blockchain.rpc.BitcoinJsonRPCClient
import fr.acinq.eclair.blockchain.zmq.ZMQActor
import fr.acinq.eclair.blockchain.{ExtendedBitcoinClient, PeerWatcher}
Expand All @@ -22,7 +22,7 @@ import org.json4s.JsonAST.JString

import scala.compat.Platform
import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContext, Promise}
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
import scala.util.Try

/**
Expand Down Expand Up @@ -108,7 +108,9 @@ class Setup(datadir: File, actorSystemName: String = "default") extends Logging
override val paymentHandler: ActorRef = _setup.paymentHandler
override val paymentInitiator: ActorRef = _setup.paymentInitiator
override val system: ActorSystem = _setup.system
override def getInfoResponse: Future[GetInfoResponse] = Future.successful(GetInfoResponse(nodeId = nodeParams.privateKey.publicKey, alias = nodeParams.alias, port = config.getInt("server.port"), chainHash = chainHash, blockHeight = Globals.blockCount.intValue()))
}

val httpBound = Http().bindAndHandle(api.route, config.getString("api.binding-ip"), config.getInt("api.port"))

Try(Await.result(zmqConnected.future, 5 seconds)).recover { case _ => throw BitcoinZMQConnectionTimeoutException }.get
Expand Down
4 changes: 4 additions & 0 deletions eclair-core/src/main/scala/fr/acinq/eclair/api/Service.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ case class JsonRPCBody(jsonrpc: String = "1.0", id: String = "scala-client", met
case class Error(code: Int, message: String)
case class JsonRPCRes(result: AnyRef, error: Option[Error], id: String)
case class Status(node_id: String)
case class GetInfoResponse(nodeId: PublicKey, alias: String, port: Int, chainHash: String, blockHeight: Int)
// @formatter:on

trait Service extends Logging {
Expand All @@ -61,6 +62,8 @@ trait Service extends Logging {

def system: ActorSystem

def getInfoResponse: Future[GetInfoResponse]

val customHeaders = `Access-Control-Allow-Origin`(*) ::
`Access-Control-Allow-Headers`("Content-Type, Authorization") ::
`Access-Control-Allow-Methods`(PUT, GET, POST, DELETE, OPTIONS) ::
Expand All @@ -79,6 +82,7 @@ trait Service extends Logging {
entity(as[JsonRPCBody]) {
req =>
val f_res: Future[AnyRef] = req match {
case JsonRPCBody(_, _, "getinfo", _) => getInfoResponse
case JsonRPCBody(_, _, "connect", JString(host) :: JInt(port) :: JString(nodeId) :: Nil) =>
(switchboard ? NewConnection(PublicKey(nodeId), new InetSocketAddress(host, port.toInt), None)).mapTo[String]
case JsonRPCBody(_, _, "open", JString(host) :: JInt(port) :: JString(nodeId) :: JInt(fundingSatoshi) :: JInt(pushMsat) :: Nil) =>
Expand Down

0 comments on commit 12c90a7

Please sign in to comment.