mirror of
https://github.com/ACINQ/eclair.git
synced 2024-11-19 09:54:02 +01:00
* 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]
This commit is contained in:
parent
c0ad616a32
commit
12c90a7efe
@ -92,6 +92,7 @@ option | description | default value
|
|||||||
|
|
||||||
method | params | description
|
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
|
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
|
open | host, port, nodeId, fundingSatoshis, pushMsat | opens a channel with another lightning node
|
||||||
peers | | list existing local peers
|
peers | | list existing local peers
|
||||||
|
@ -8,7 +8,7 @@ import akka.http.scaladsl.Http
|
|||||||
import akka.stream.ActorMaterializer
|
import akka.stream.ActorMaterializer
|
||||||
import akka.util.Timeout
|
import akka.util.Timeout
|
||||||
import fr.acinq.bitcoin.{Base58Check, OP_CHECKSIG, OP_DUP, OP_EQUALVERIFY, OP_HASH160, OP_PUSHDATA, Script}
|
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.rpc.BitcoinJsonRPCClient
|
||||||
import fr.acinq.eclair.blockchain.zmq.ZMQActor
|
import fr.acinq.eclair.blockchain.zmq.ZMQActor
|
||||||
import fr.acinq.eclair.blockchain.{ExtendedBitcoinClient, PeerWatcher}
|
import fr.acinq.eclair.blockchain.{ExtendedBitcoinClient, PeerWatcher}
|
||||||
@ -22,7 +22,7 @@ import org.json4s.JsonAST.JString
|
|||||||
|
|
||||||
import scala.compat.Platform
|
import scala.compat.Platform
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import scala.concurrent.{Await, ExecutionContext, Promise}
|
import scala.concurrent.{Await, ExecutionContext, Future, Promise}
|
||||||
import scala.util.Try
|
import scala.util.Try
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,7 +108,9 @@ class Setup(datadir: File, actorSystemName: String = "default") extends Logging
|
|||||||
override val paymentHandler: ActorRef = _setup.paymentHandler
|
override val paymentHandler: ActorRef = _setup.paymentHandler
|
||||||
override val paymentInitiator: ActorRef = _setup.paymentInitiator
|
override val paymentInitiator: ActorRef = _setup.paymentInitiator
|
||||||
override val system: ActorSystem = _setup.system
|
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"))
|
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
|
Try(Await.result(zmqConnected.future, 5 seconds)).recover { case _ => throw BitcoinZMQConnectionTimeoutException }.get
|
||||||
|
@ -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 Error(code: Int, message: String)
|
||||||
case class JsonRPCRes(result: AnyRef, error: Option[Error], id: String)
|
case class JsonRPCRes(result: AnyRef, error: Option[Error], id: String)
|
||||||
case class Status(node_id: String)
|
case class Status(node_id: String)
|
||||||
|
case class GetInfoResponse(nodeId: PublicKey, alias: String, port: Int, chainHash: String, blockHeight: Int)
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
trait Service extends Logging {
|
trait Service extends Logging {
|
||||||
@ -61,6 +62,8 @@ trait Service extends Logging {
|
|||||||
|
|
||||||
def system: ActorSystem
|
def system: ActorSystem
|
||||||
|
|
||||||
|
def getInfoResponse: Future[GetInfoResponse]
|
||||||
|
|
||||||
val customHeaders = `Access-Control-Allow-Origin`(*) ::
|
val customHeaders = `Access-Control-Allow-Origin`(*) ::
|
||||||
`Access-Control-Allow-Headers`("Content-Type, Authorization") ::
|
`Access-Control-Allow-Headers`("Content-Type, Authorization") ::
|
||||||
`Access-Control-Allow-Methods`(PUT, GET, POST, DELETE, OPTIONS) ::
|
`Access-Control-Allow-Methods`(PUT, GET, POST, DELETE, OPTIONS) ::
|
||||||
@ -79,6 +82,7 @@ trait Service extends Logging {
|
|||||||
entity(as[JsonRPCBody]) {
|
entity(as[JsonRPCBody]) {
|
||||||
req =>
|
req =>
|
||||||
val f_res: Future[AnyRef] = req match {
|
val f_res: Future[AnyRef] = req match {
|
||||||
|
case JsonRPCBody(_, _, "getinfo", _) => getInfoResponse
|
||||||
case JsonRPCBody(_, _, "connect", JString(host) :: JInt(port) :: JString(nodeId) :: Nil) =>
|
case JsonRPCBody(_, _, "connect", JString(host) :: JInt(port) :: JString(nodeId) :: Nil) =>
|
||||||
(switchboard ? NewConnection(PublicKey(nodeId), new InetSocketAddress(host, port.toInt), None)).mapTo[String]
|
(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) =>
|
case JsonRPCBody(_, _, "open", JString(host) :: JInt(port) :: JString(nodeId) :: JInt(fundingSatoshi) :: JInt(pushMsat) :: Nil) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user