Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move http APIs to subproject eclair-node #1102

Merged
merged 7 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions eclair-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@
<artifactId>akka-slf4j_${scala.version.short}</artifactId>
<version>${akka.version}</version>
</dependency>
<!-- HTTP SERVER -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-core_${scala.version.short}</artifactId>
<version>${akka.http.version}</version>
</dependency>
<!-- HTTP CLIENT -->
<dependency>
<groupId>com.softwaremill.sttp</groupId>
Expand All @@ -144,11 +138,6 @@
<artifactId>json4s-jackson_${scala.version.short}</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>de.heikoseeberger</groupId>
<artifactId>akka-http-json4s_${scala.version.short}</artifactId>
<version>1.19.0</version>
</dependency>
<dependency>
<groupId>com.softwaremill.sttp</groupId>
<artifactId>json4s_${scala.version.short}</artifactId>
Expand Down Expand Up @@ -254,12 +243,6 @@
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-testkit_${scala.version.short}</artifactId>
<version>${akka.http.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-scala-scalatest_2.11</artifactId>
Expand Down
30 changes: 0 additions & 30 deletions eclair-core/src/main/scala/fr/acinq/eclair/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ import java.util.concurrent.TimeUnit

import akka.Done
import akka.actor.{ActorRef, ActorSystem, Props, SupervisorStrategy}
import akka.http.scaladsl.Http
import akka.pattern.after
import akka.stream.{ActorMaterializer, BindFailedException}
import akka.util.Timeout
import com.softwaremill.sttp.okhttp.OkHttpFutureBackend
import com.typesafe.config.{Config, ConfigFactory}
import fr.acinq.bitcoin.{Block, ByteVector32}
import fr.acinq.eclair.NodeParams.{BITCOIND, ELECTRUM}
import fr.acinq.eclair.api._
import fr.acinq.eclair.blockchain.bitcoind.rpc.{BasicBitcoinJsonRPCClient, BatchingBitcoinJsonRPCClient, ExtendedBitcoinClient}
import fr.acinq.eclair.blockchain.bitcoind.zmq.ZMQActor
import fr.acinq.eclair.blockchain.bitcoind.{BitcoinCoreWallet, ZmqWatcher}
Expand Down Expand Up @@ -71,7 +68,6 @@ class Setup(datadir: File,
seed_opt: Option[ByteVector] = None,
db: Option[Databases] = None)(implicit system: ActorSystem) extends Logging {

implicit val materializer = ActorMaterializer()
implicit val timeout = Timeout(30 seconds)
implicit val formats = org.json4s.DefaultFormats
implicit val ec = ExecutionContext.Implicits.global
Expand Down Expand Up @@ -287,32 +283,6 @@ class Setup(datadir: File,
_ <- Future.firstCompletedOf(zmqBlockConnected.future :: zmqBlockTimeout :: Nil)
_ <- Future.firstCompletedOf(zmqTxConnected.future :: zmqTxTimeout :: Nil)
_ <- Future.firstCompletedOf(tcpBound.future :: tcpTimeout :: Nil)
_ <- if (config.getBoolean("api.enabled")) {
logger.info(s"json-rpc api enabled on port=${config.getInt("api.port")}")
implicit val materializer = ActorMaterializer()
val getInfo = GetInfoResponse(nodeId = nodeParams.nodeId,
alias = nodeParams.alias,
chainHash = nodeParams.chainHash,
blockHeight = Globals.blockCount.intValue(),
publicAddresses = nodeParams.publicAddresses)
val apiPassword = config.getString("api.password") match {
case "" => throw EmptyAPIPasswordException
case valid => valid
}
val apiRoute = new Service {
override val actorSystem = kit.system
override val mat = materializer
override val password = apiPassword
override val eclairApi: Eclair = new EclairImpl(kit)
}.route
val httpBound = Http().bindAndHandle(apiRoute, config.getString("api.binding-ip"), config.getInt("api.port")).recover {
case _: BindFailedException => throw TCPBindException(config.getInt("api.port"))
}
val httpTimeout = after(5 seconds, using = system.scheduler)(Future.failed(TCPBindException(config.getInt("api.port"))))
Future.firstCompletedOf(httpBound :: httpTimeout :: Nil)
} else {
Future.successful(logger.info("json-rpc api is disabled"))
}
} yield kit

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import akka.actor.ActorRef
import fr.acinq.bitcoin.Crypto.PublicKey
import fr.acinq.bitcoin.{ByteVector32, Satoshi, Transaction}
import fr.acinq.eclair.{MilliSatoshi, ShortChannelId}
import fr.acinq.eclair.api.MilliSatoshiSerializer
import fr.acinq.eclair.channel.Channel.ChannelError
import fr.acinq.eclair.channel.Helpers.Closing.ClosingType
import fr.acinq.eclair.wire.{ChannelAnnouncement, ChannelUpdate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@

package fr.acinq.eclair.wire

import java.net.InetSocketAddress
import java.util.UUID

import akka.actor.ActorSystem
import fr.acinq.bitcoin.Crypto.PrivateKey
import com.google.common.net.HostAndPort
import fr.acinq.bitcoin.Crypto.{PrivateKey, PublicKey}
import fr.acinq.bitcoin.DeterministicWallet.KeyPath
import fr.acinq.bitcoin.{Block, ByteVector32, Crypto, DeterministicWallet, OutPoint, Satoshi, Transaction}
import fr.acinq.eclair.api.JsonSupport
import fr.acinq.bitcoin.{Block, ByteVector32, ByteVector64, Crypto, DeterministicWallet, OutPoint, Satoshi, Transaction}
import fr.acinq.eclair.channel.Helpers.Funding
import fr.acinq.eclair.channel._
import fr.acinq.eclair.crypto.{LocalKeyManager, ShaChain}
import fr.acinq.eclair.payment.{Local, Relayed}
import fr.acinq.eclair.router.Announcements
import fr.acinq.eclair.transactions.Transactions.CommitTx
import fr.acinq.eclair.transactions.Transactions.{CommitTx, InputInfo, TransactionWithInputInfo}
import fr.acinq.eclair.transactions._
import fr.acinq.eclair.wire.ChannelCodecs._
import fr.acinq.eclair.{TestConstants, UInt64, randomBytes, randomBytes32, randomKey, _}
import org.json4s.{CustomKeySerializer, CustomSerializer}
import org.json4s.JsonAST._
import org.json4s.jackson.Serialization
import org.scalatest.FunSuite
import scodec.bits._
Expand All @@ -43,8 +46,8 @@ import scala.io.Source
import scala.util.Random

/**
* Created by PM on 31/05/2016.
*/
* Created by PM on 31/05/2016.
*/

class ChannelCodecsSpec extends FunSuite {

Expand Down Expand Up @@ -333,9 +336,7 @@ class ChannelCodecsSpec extends FunSuite {
assert(oldjson === refjson)
assert(newjson === refjson)
}

}

}

object ChannelCodecsSpec {
Expand Down Expand Up @@ -402,4 +403,155 @@ object ChannelCodecsSpec {
val channelUpdate = Announcements.makeChannelUpdate(ByteVector32(ByteVector.fill(32)(1)), randomKey, randomKey.publicKey, ShortChannelId(142553), CltvExpiryDelta(42), 15 msat, 575 msat, 53, Channel.MAX_FUNDING.toMilliSatoshi)

val normal = DATA_NORMAL(commitments, ShortChannelId(42), true, None, channelUpdate, None, None)
}

object JsonSupport {

class ByteVectorSerializer extends CustomSerializer[ByteVector](format => ( {
null
}, {
case x: ByteVector => JString(x.toHex)
}))

class ByteVector32Serializer extends CustomSerializer[ByteVector32](format => ( {
null
}, {
case x: ByteVector32 => JString(x.toHex)
}))

class ByteVector64Serializer extends CustomSerializer[ByteVector64](format => ( {
null
}, {
case x: ByteVector64 => JString(x.toHex)
}))

class UInt64Serializer extends CustomSerializer[UInt64](format => ( {
null
}, {
case x: UInt64 => JInt(x.toBigInt)
}))

class SatoshiSerializer extends CustomSerializer[Satoshi](format => ( {
null
}, {
case x: Satoshi => JInt(x.toLong)
}))

class MilliSatoshiSerializer extends CustomSerializer[MilliSatoshi](format => ( {
null
}, {
case x: MilliSatoshi => JInt(x.toLong)
}))

class CltvExpirySerializer extends CustomSerializer[CltvExpiry](format => ( {
null
}, {
case x: CltvExpiry => JLong(x.toLong)
}))

class CltvExpiryDeltaSerializer extends CustomSerializer[CltvExpiryDelta](format => ( {
null
}, {
case x: CltvExpiryDelta => JInt(x.toInt)
}))

class ShortChannelIdSerializer extends CustomSerializer[ShortChannelId](format => ( {
null
}, {
case x: ShortChannelId => JString(x.toString())
}))

class StateSerializer extends CustomSerializer[State](format => ( {
null
}, {
case x: State => JString(x.toString())
}))

class ShaChainSerializer extends CustomSerializer[ShaChain](format => ( {
null
}, {
case x: ShaChain => JNull
}))

class PublicKeySerializer extends CustomSerializer[PublicKey](format => ( {
null
}, {
case x: PublicKey => JString(x.toString())
}))

class PrivateKeySerializer extends CustomSerializer[PrivateKey](format => ( {
null
}, {
case x: PrivateKey => JString("XXX")
}))

class ChannelVersionSerializer extends CustomSerializer[ChannelVersion](format => ( {
null
}, {
case x: ChannelVersion => JString(x.bits.toBin)
}))

class TransactionSerializer extends CustomSerializer[TransactionWithInputInfo](ser = format => ( {
null
}, {
case x: Transaction => JObject(List(
JField("txid", JString(x.txid.toHex)),
JField("tx", JString(x.toString()))
))
}))

class TransactionWithInputInfoSerializer extends CustomSerializer[TransactionWithInputInfo](ser = format => ( {
null
}, {
case x: TransactionWithInputInfo => JObject(List(
JField("txid", JString(x.tx.txid.toHex)),
JField("tx", JString(x.tx.toString()))
))
}))

class InetSocketAddressSerializer extends CustomSerializer[InetSocketAddress](format => ( {
null
}, {
case address: InetSocketAddress => JString(HostAndPort.fromParts(address.getHostString, address.getPort).toString)
}))

class OutPointSerializer extends CustomSerializer[OutPoint](format => ( {
null
}, {
case x: OutPoint => JString(s"${x.txid}:${x.index}")
}))

class OutPointKeySerializer extends CustomKeySerializer[OutPoint](format => ( {
null
}, {
case x: OutPoint => s"${x.txid}:${x.index}"
}))

class InputInfoSerializer extends CustomSerializer[InputInfo](format => ( {
null
}, {
case x: InputInfo => JObject(("outPoint", JString(s"${x.outPoint.txid}:${x.outPoint.index}")), ("amountSatoshis", JInt(x.txOut.amount.toLong)))
}))

implicit val formats = org.json4s.DefaultFormats +
new ByteVectorSerializer +
new ByteVector32Serializer +
new ByteVector64Serializer +
new UInt64Serializer +
new SatoshiSerializer +
new MilliSatoshiSerializer +
new CltvExpirySerializer +
new CltvExpiryDeltaSerializer +
new ShortChannelIdSerializer +
new StateSerializer +
new ShaChainSerializer +
new PublicKeySerializer +
new PrivateKeySerializer +
new TransactionSerializer +
new TransactionWithInputInfoSerializer +
new InetSocketAddressSerializer +
new OutPointSerializer +
new OutPointKeySerializer +
new ChannelVersionSerializer +
new InputInfoSerializer
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ class LightningMessageCodecsSpec extends FunSuite {
case class TestItem(msg: Any, hex: String)

test("test vectors for extended channel queries ") {
import org.json4s.{CustomSerializer, ShortTypeHints}
import org.json4s.JsonAST.JString
import org.json4s.jackson.Serialization
import fr.acinq.eclair.api._

val query_channel_range = QueryChannelRange(Block.RegtestGenesisBlock.blockId, 100000, 1500, TlvStream.empty)
val query_channel_range_timestamps_checksums = QueryChannelRange(Block.RegtestGenesisBlock.blockId,
35000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import akka.actor.ActorSystem
import fr.acinq.eclair.gui.{FxApp, FxPreloader}
import grizzled.slf4j.Logging
import javafx.application.Application

import scala.concurrent.ExecutionContext.Implicits.global
/**
* Created by PM on 25/01/2016.
*/
Expand All @@ -33,7 +33,10 @@ object JavafxBoot extends App with Logging {

if (headless) {
implicit val system = ActorSystem("eclair-node-gui")
new Setup(datadir).bootstrap
val setup = new Setup(datadir)
setup.bootstrap.map { kit =>
Boot.startApiServiceIfEnabled(setup.config, kit)
}
} else {
System.setProperty("javafx.preloader", classOf[FxPreloader].getName)
Application.launch(classOf[FxApp], datadir.getAbsolutePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class FxApp extends Application with Logging {
system.eventStream.subscribe(guiUpdater, classOf[ElectrumEvent])
pKit.completeWith(setup.bootstrap)
pKit.future.onComplete {
case Success(_) =>
case Success(kit) =>
Boot.startApiServiceIfEnabled(setup.config, kit)
Platform.runLater(new Runnable {
override def run(): Unit = {
val scene = new Scene(mainRoot)
Expand Down
24 changes: 24 additions & 0 deletions eclair-node/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,29 @@
<artifactId>janino</artifactId>
<version>3.0.7</version>
</dependency>
<!-- http server -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-core_${scala.version.short}</artifactId>
<version>${akka.http.version}</version>
</dependency>
<dependency>
<groupId>de.heikoseeberger</groupId>
<artifactId>akka-http-json4s_${scala.version.short}</artifactId>
<version>1.19.0</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-testkit_${scala.version.short}</artifactId>
<version>${akka.http.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-scala-scalatest_2.11</artifactId>
<version>1.4.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading