mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-22 14:22:39 +01:00
Finish merging master
This commit is contained in:
parent
8ec8574d97
commit
c557f70af5
4 changed files with 52 additions and 13 deletions
|
@ -43,7 +43,7 @@ trait Eclair {
|
|||
|
||||
def allupdates(nodeId: Option[PublicKey]): Future[Iterable[ChannelUpdate]]
|
||||
|
||||
def receive(description: String, amountMsat: Option[Long], expire: Option[Long]): Future[String]
|
||||
def receive(description: String, amountMsat: Option[Long], expire: Option[Long], fallbackAddress: Option[String]): Future[String]
|
||||
|
||||
def findRoute(targetNodeId: PublicKey, amountMsat: Long, assistedRoutes: Seq[Seq[PaymentRequest.ExtraHop]] = Seq.empty): Future[RouteResponse]
|
||||
|
||||
|
@ -122,8 +122,9 @@ class EclairImpl(appKit: Kit) extends Eclair {
|
|||
case Some(pk) => (appKit.router ? 'updatesMap).mapTo[Map[ChannelDesc, ChannelUpdate]].map(_.filter(e => e._1.a == pk || e._1.b == pk).values)
|
||||
}
|
||||
|
||||
override def receive(description: String, amountMsat: Option[Long], expire: Option[Long]): Future[String] = {
|
||||
(appKit.paymentHandler ? ReceivePayment(description = description, amountMsat_opt = amountMsat.map(MilliSatoshi), expirySeconds_opt = expire)).mapTo[PaymentRequest].map { pr =>
|
||||
override def receive(description: String, amountMsat: Option[Long], expire: Option[Long], fallbackAddress: Option[String]): Future[String] = {
|
||||
fallbackAddress.map { fa => fr.acinq.eclair.addressToPublicKeyScript(fa, appKit.nodeParams.chainHash) } // if it's not a bitcoin address throws an exception
|
||||
(appKit.paymentHandler ? ReceivePayment(description = description, amountMsat_opt = amountMsat.map(MilliSatoshi), expirySeconds_opt = expire, fallbackAddress = fallbackAddress)).mapTo[PaymentRequest].map { pr =>
|
||||
PaymentRequest.write(pr)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,19 @@
|
|||
/*
|
||||
* Copyright 2018 ACINQ SAS
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package fr.acinq.eclair.api
|
||||
|
||||
import akka.http.scaladsl.server._
|
||||
|
@ -16,12 +32,16 @@ import akka.http.scaladsl.server.directives.{Credentials, LoggingMagnet}
|
|||
import akka.stream.{ActorMaterializer, OverflowStrategy}
|
||||
import akka.stream.scaladsl.{BroadcastHub, Flow, Keep, Source}
|
||||
import fr.acinq.eclair.io.NodeURI
|
||||
import fr.acinq.eclair.payment.{PaymentLifecycle, PaymentReceived, PaymentRequest}
|
||||
import fr.acinq.eclair.payment.PaymentLifecycle.PaymentFailed
|
||||
import fr.acinq.eclair.payment._
|
||||
import grizzled.slf4j.Logging
|
||||
import org.json4s.ShortTypeHints
|
||||
import org.json4s.jackson.Serialization
|
||||
import scodec.bits.ByteVector
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.Try
|
||||
|
||||
case class ErrorResponse(error: String)
|
||||
|
||||
|
@ -64,13 +84,30 @@ trait Service extends Directives with Logging {
|
|||
// create a flow transforming a queue of string -> string
|
||||
val (flowInput, flowOutput) = Source.queue[String](10, OverflowStrategy.dropTail).toMat(BroadcastHub.sink[String])(Keep.both).run()
|
||||
|
||||
// register an actor that feeds the queue when a payment is received
|
||||
val _formats = formats
|
||||
|
||||
// register an actor that feeds the queue on payment related events
|
||||
actorSystem.actorOf(Props(new Actor {
|
||||
override def preStart: Unit = context.system.eventStream.subscribe(self, classOf[PaymentReceived])
|
||||
|
||||
implicit val formats = _formats.withTypeHintFieldName("type") +
|
||||
ShortTypeHints(List(
|
||||
classOf[PaymentSent],
|
||||
classOf[PaymentRelayed],
|
||||
classOf[PaymentReceived],
|
||||
classOf[PaymentSettlingOnChain],
|
||||
classOf[PaymentFailed]))
|
||||
|
||||
override def preStart: Unit = {
|
||||
context.system.eventStream.subscribe(self, classOf[PaymentFailed])
|
||||
context.system.eventStream.subscribe(self, classOf[PaymentEvent])
|
||||
}
|
||||
|
||||
def receive: Receive = {
|
||||
case received: PaymentReceived => flowInput.offer(received.paymentHash.toString)
|
||||
case message: PaymentFailed => flowInput.offer(Serialization write message)
|
||||
case message: PaymentEvent => flowInput.offer(Serialization write message)
|
||||
case other => logger.info(s"Unexpected ws message: $other")
|
||||
}
|
||||
|
||||
}))
|
||||
|
||||
Flow[Message]
|
||||
|
@ -155,8 +192,8 @@ trait Service extends Directives with Logging {
|
|||
}
|
||||
} ~
|
||||
path("receive") {
|
||||
formFields("description".as[String], "amountMsat".as[Long].?, "expireIn".as[Long].?) { (desc, amountMsat, expire) =>
|
||||
complete(eclairApi.receive(desc, amountMsat, expire))
|
||||
formFields("description".as[String], "amountMsat".as[Long].?, "expireIn".as[Long].?, "fallbackAddress".as[String].?) { (desc, amountMsat, expire, fallBackAddress) =>
|
||||
complete(eclairApi.receive(desc, amountMsat, expire, fallBackAddress))
|
||||
}
|
||||
} ~
|
||||
path("parseinvoice") {
|
||||
|
|
|
@ -65,7 +65,7 @@ class ApiServiceSpec extends FunSuite with ScalatestRouteTest {
|
|||
|
||||
override def allupdates(nodeId: Option[Crypto.PublicKey]): Future[Iterable[ChannelUpdate]] = ???
|
||||
|
||||
override def receive(description: String, amountMsat: Option[Long], expire: Option[Long]): Future[String] = ???
|
||||
override def receive(description: String, amountMsat: Option[Long], expire: Option[Long], fallbackAddress: Option[String]): Future[String] = ???
|
||||
|
||||
override def findRoute(targetNodeId: Crypto.PublicKey, amountMsat: Long, assistedRoutes: Seq[Seq[PaymentRequest.ExtraHop]]): Future[RouteResponse] = ???
|
||||
|
||||
|
|
|
@ -77,8 +77,9 @@ class JsonSerializersSpec extends FunSuite with Matchers {
|
|||
}
|
||||
|
||||
test("type hints") {
|
||||
implicit val formats = DefaultFormats.withTypeHintFieldName("type") + ShortTypeHints(List(classOf[PaymentSettlingOnChain])) + new BinaryDataSerializer + new MilliSatoshiSerializer
|
||||
val e1 = PaymentSettlingOnChain(MilliSatoshi(42), randomBytes(32))
|
||||
println(Serialization.writePretty(e1))
|
||||
implicit val formats = DefaultFormats.withTypeHintFieldName("type") + ShortTypeHints(List(classOf[PaymentSettlingOnChain])) + new MilliSatoshiSerializer
|
||||
val e1 = PaymentSettlingOnChain(MilliSatoshi(42), randomBytes32)
|
||||
// println(Serialization.writePretty(e1))
|
||||
assert(Serialization.writePretty(e1).contains("\"type\" : \"PaymentSettlingOnChain\""))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue