1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-19 18:10:42 +01:00

(API) Added a method to return all known channels (closes #126) (#133)

* Added an 'allchannels' call that returns local and non-local channels
* Added API calls `allchannels` and `allnodes` to documentation
This commit is contained in:
dpad85 2017-08-23 14:14:33 +02:00 committed by Pierre-Marie Padiou
parent 43d6c80f9e
commit 7acb75d50c
2 changed files with 11 additions and 6 deletions

View File

@ -104,7 +104,8 @@ option | description | default value
peers | | list existing local peers peers | | list existing local peers
channels | | list existing local channels channels | | list existing local channels
channel | channelId | retrieve detailed information about a given channel channel | channelId | retrieve detailed information about a given channel
network | | list all nodes that have been announced allnodes | | list all known nodes
allchannels | | list all known channels
receive | amountMsat, description | generate a payment request for a given amount receive | amountMsat, description | generate a payment request for a given amount
send | amountMsat, paymentHash, nodeId | send a payment to a lightning node send | amountMsat, paymentHash, nodeId | send a payment to a lightning node
send | paymentRequest | send a payment to a lightning node using a BOLT11 payment request send | paymentRequest | send a payment to a lightning node using a BOLT11 payment request

View File

@ -2,7 +2,7 @@ package fr.acinq.eclair.api
import java.net.InetSocketAddress import java.net.InetSocketAddress
import akka.actor.{ActorRef, ActorSystem} import akka.actor.ActorRef
import akka.http.scaladsl.model.HttpMethods._ import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.model.headers.CacheDirectives.{`max-age`, `no-store`, public} import akka.http.scaladsl.model.headers.CacheDirectives.{`max-age`, `no-store`, public}
@ -19,7 +19,7 @@ import fr.acinq.eclair.Kit
import fr.acinq.eclair.channel._ import fr.acinq.eclair.channel._
import fr.acinq.eclair.io.Switchboard.{NewChannel, NewConnection} import fr.acinq.eclair.io.Switchboard.{NewChannel, NewConnection}
import fr.acinq.eclair.payment.{PaymentRequest, PaymentResult, ReceivePayment, SendPayment} import fr.acinq.eclair.payment.{PaymentRequest, PaymentResult, ReceivePayment, SendPayment}
import fr.acinq.eclair.wire.NodeAnnouncement import fr.acinq.eclair.wire.{ChannelAnnouncement, NodeAnnouncement}
import grizzled.slf4j.Logging import grizzled.slf4j.Logging
import org.json4s.JsonAST.{JInt, JString} import org.json4s.JsonAST.{JInt, JString}
import org.json4s.{JValue, jackson} import org.json4s.{JValue, jackson}
@ -38,6 +38,7 @@ 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) case class GetInfoResponse(nodeId: PublicKey, alias: String, port: Int, chainHash: String, blockHeight: Int)
case class ChannelInfo(shortChannelId: String, nodeId1: PublicKey , nodeId2: PublicKey)
// @formatter:on // @formatter:on
trait Service extends Logging { trait Service extends Logging {
@ -90,10 +91,12 @@ trait Service extends Logging {
(register ? 'channels).mapTo[Map[Long, ActorRef]].map(_.keys) (register ? 'channels).mapTo[Map[Long, ActorRef]].map(_.keys)
case JsonRPCBody(_, _, "channel", JString(channelId) :: Nil) => case JsonRPCBody(_, _, "channel", JString(channelId) :: Nil) =>
getChannel(channelId).flatMap(_ ? CMD_GETINFO).mapTo[RES_GETINFO] getChannel(channelId).flatMap(_ ? CMD_GETINFO).mapTo[RES_GETINFO]
case JsonRPCBody(_, _, "network", _) => case JsonRPCBody(_, _, "allnodes", _) =>
(router ? 'nodes).mapTo[Iterable[NodeAnnouncement]].map(_.map(_.nodeId)) (router ? 'nodes).mapTo[Iterable[NodeAnnouncement]].map(_.map(_.nodeId))
case JsonRPCBody(_, _, "allchannels", _) =>
(router ? 'channels).mapTo[Iterable[ChannelAnnouncement]].map(_.map(c => ChannelInfo(c.shortChannelId.toHexString, c.nodeId1, c.nodeId2)))
case JsonRPCBody(_,_, "receive", JInt(amountMsat) :: JString(description) :: Nil) => case JsonRPCBody(_,_, "receive", JInt(amountMsat) :: JString(description) :: Nil) =>
(paymentHandler ? ReceivePayment(new MilliSatoshi(amountMsat.toLong), description)).mapTo[PaymentRequest].map(PaymentRequest.write(_)) (paymentHandler ? ReceivePayment(MilliSatoshi(amountMsat.toLong), description)).mapTo[PaymentRequest].map(PaymentRequest.write)
case JsonRPCBody(_, _, "send", JInt(amountMsat) :: JString(paymentHash) :: JString(nodeId) :: Nil) => case JsonRPCBody(_, _, "send", JInt(amountMsat) :: JString(paymentHash) :: JString(nodeId) :: Nil) =>
(paymentInitiator ? SendPayment(amountMsat.toLong, paymentHash, PublicKey(nodeId))).mapTo[PaymentResult] (paymentInitiator ? SendPayment(amountMsat.toLong, paymentHash, PublicKey(nodeId))).mapTo[PaymentResult]
case JsonRPCBody(_, _, "send", JString(paymentRequest) :: Nil) => case JsonRPCBody(_, _, "send", JString(paymentRequest) :: Nil) =>
@ -112,7 +115,8 @@ trait Service extends Logging {
"peers: list existing local peers", "peers: list existing local peers",
"channels: list existing local channels", "channels: list existing local channels",
"channel (channelId): retrieve detailed information about a given channel", "channel (channelId): retrieve detailed information about a given channel",
"network: list all the nodes announced in network", "allnodes: list all known nodes",
"allchannels: list all known channels",
"receive (amountMsat, description): generate a payment request for a given amount", "receive (amountMsat, description): generate a payment request for a given amount",
"send (amountMsat, paymentHash, nodeId): send a payment to a lightning node", "send (amountMsat, paymentHash, nodeId): send a payment to a lightning node",
"send (paymentRequest): send a payment to a lightning node using a BOLT11 payment request", "send (paymentRequest): send a payment to a lightning node using a BOLT11 payment request",