mirror of
https://github.com/ACINQ/eclair.git
synced 2024-11-19 18:10:42 +01:00
merged from wip-akka-http
This commit is contained in:
commit
30fb6c18eb
@ -58,6 +58,16 @@
|
||||
<artifactId>akka-slf4j_${scala.version.short}</artifactId>
|
||||
<version>${akka.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.typesafe.akka</groupId>
|
||||
<artifactId>akka-http-core_${scala.version.short}</artifactId>
|
||||
<version>${akka.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.typesafe.akka</groupId>
|
||||
<artifactId>akka-http-experimental_${scala.version.short}</artifactId>
|
||||
<version>${akka.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fr.acinq</groupId>
|
||||
<artifactId>bitcoin-lib_${scala.version.short}</artifactId>
|
||||
@ -84,16 +94,6 @@
|
||||
<groupId>com.trueaccord.lenses</groupId>
|
||||
<artifactId>lenses_${scala.version.short}</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spray</groupId>
|
||||
<artifactId>spray-routing_${scala.version.short}</artifactId>
|
||||
<version>${spray.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spray</groupId>
|
||||
<artifactId>spray-can_${scala.version.short}</artifactId>
|
||||
<version>${spray.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
|
@ -3,16 +3,16 @@ package fr.acinq.eclair
|
||||
import java.net.InetSocketAddress
|
||||
|
||||
import akka.actor.{ActorRef, ActorSystem, Props}
|
||||
import akka.io.IO
|
||||
import akka.http.scaladsl.Http
|
||||
import akka.http.scaladsl.server.Directives._
|
||||
import akka.util.Timeout
|
||||
import akka.stream.ActorMaterializer
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import fr.acinq.eclair.api.ServiceActor
|
||||
import fr.acinq.eclair.api.Service
|
||||
import fr.acinq.eclair.blockchain.{ExtendedBitcoinClient, PollingWatcher}
|
||||
import fr.acinq.eclair.channel.Register
|
||||
import fr.acinq.eclair.io.{Client, Server}
|
||||
import grizzled.slf4j.Logging
|
||||
import spray.can.Http
|
||||
|
||||
import scala.concurrent.{Await, ExecutionContext}
|
||||
import scala.concurrent.duration._
|
||||
import Globals._
|
||||
@ -23,6 +23,7 @@ import Globals._
|
||||
object Boot extends App with Logging {
|
||||
|
||||
implicit val system = ActorSystem()
|
||||
implicit val materializer = ActorMaterializer()
|
||||
implicit val timeout = Timeout(30 seconds)
|
||||
implicit val formats = org.json4s.DefaultFormats
|
||||
implicit val ec = ExecutionContext.Implicits.global
|
||||
@ -38,12 +39,11 @@ object Boot extends App with Logging {
|
||||
val register = system.actorOf(Props[Register], name = "register")
|
||||
|
||||
val server = system.actorOf(Server.props(config.getString("eclair.server.address"), config.getInt("eclair.server.port")), "server")
|
||||
val api = system.actorOf(Props(new ServiceActor {
|
||||
val api = new Service {
|
||||
override val register: ActorRef = Boot.register
|
||||
|
||||
override def connect(addr: InetSocketAddress, amount: Long): Unit = system.actorOf(Props(classOf[Client], addr, amount))
|
||||
}), "api")
|
||||
}
|
||||
Http().bindAndHandle(api.route, config.getString("eclair.api.address"), config.getInt("eclair.api.port"))
|
||||
|
||||
// start a new HTTP server on port 8080 with our service actor as the handler
|
||||
IO(Http) ! Http.Bind(api, config.getString("eclair.api.address"), config.getInt("eclair.api.port"))
|
||||
}
|
||||
|
@ -2,8 +2,11 @@ package fr.acinq.eclair.api
|
||||
|
||||
import java.net.InetSocketAddress
|
||||
|
||||
import akka.actor.{Actor, ActorRef}
|
||||
|
||||
import akka.actor.ActorRef
|
||||
import akka.http.scaladsl.model.{HttpEntity, StatusCodes, ContentTypes, HttpResponse}
|
||||
import akka.util.Timeout
|
||||
import akka.http.scaladsl.server.Directives._
|
||||
import fr.acinq.bitcoin.BinaryData
|
||||
import fr.acinq.eclair._
|
||||
import fr.acinq.eclair.channel._
|
||||
@ -15,8 +18,6 @@ import org.json4s.JsonAST.JString
|
||||
import org.json4s._
|
||||
import org.json4s.jackson.JsonMethods._
|
||||
import org.json4s.jackson.Serialization
|
||||
import spray.http.{ContentTypes, HttpEntity, HttpResponse, StatusCodes}
|
||||
import spray.routing.HttpService
|
||||
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
import scala.concurrent.duration._
|
||||
@ -28,26 +29,12 @@ import fr.acinq.eclair.channel.Register.ListChannels
|
||||
* Created by PM on 25/01/2016.
|
||||
*/
|
||||
|
||||
// we don't implement our route structure directly in the service actor because
|
||||
// we want to be able to test it independently, without having to spin up an actor
|
||||
abstract class ServiceActor extends Actor with Service {
|
||||
|
||||
// the HttpService trait defines only one abstract member, which
|
||||
// connects the services environment to the enclosing actor or test
|
||||
def actorRefFactory = context
|
||||
|
||||
// this actor only runs our route, but you could add
|
||||
// other things here, like request stream processing,
|
||||
// timeout handling or alternative handler registration
|
||||
def receive = runRoute(route)
|
||||
}
|
||||
|
||||
case class JsonRPCBody(jsonrpc: String = "1.0", id: String = "scala-client", method: String, params: Seq[JValue])
|
||||
case class Error(code: Int, message: String)
|
||||
case class JsonRPCRes(result: AnyRef, error: Option[Error], id: String)
|
||||
|
||||
//TODO : use Json4sSupport ?
|
||||
trait Service extends HttpService with Logging {
|
||||
trait Service extends Logging {
|
||||
|
||||
implicit def ec: ExecutionContext = ExecutionContext.Implicits.global
|
||||
|
||||
|
1
pom.xml
1
pom.xml
@ -44,7 +44,6 @@
|
||||
<scala.version>2.11.7</scala.version>
|
||||
<scala.version.short>2.11</scala.version.short>
|
||||
<akka.version>2.4.4</akka.version>
|
||||
<spray.version>1.3.3</spray.version>
|
||||
<bitcoinlib.version>0.9.5</bitcoinlib.version>
|
||||
<acinqtools.version>1.2</acinqtools.version>
|
||||
</properties>
|
||||
|
Loading…
Reference in New Issue
Block a user