1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-03-11 01:35:01 +01:00

moved wire from a module to a package

This commit is contained in:
pm47 2016-11-17 13:12:28 +01:00
parent 0a5bf62aae
commit cc11ec8d14
7 changed files with 67 additions and 84 deletions

View file

@ -102,6 +102,11 @@
<artifactId>lenses_${scala.version.short}</artifactId>
<version>0.4</version>
</dependency>
<dependency>
<groupId>org.scodec</groupId>
<artifactId>scodec-core_${scala.version.short}</artifactId>
<version>1.10.3</version>
</dependency>
<!-- LOGGING -->
<dependency>
<groupId>org.clapper</groupId>

View file

@ -1,7 +1,7 @@
package fr.acinq.eclair.wire.bolt2.sdc
package fr.acinq.eclair.wire
import fr.acinq.bitcoin.BinaryData
import fr.acinq.eclair.wire.bolt2.custom._
import fr.acinq.eclair.wire
import scodec.bits.ByteVector
import scodec.codecs._
import scodec.{Attempt, Codec, Err}
@ -59,15 +59,32 @@ object Codecs {
val fundingLockedCodec: Codec[FundingLocked] = (
("temporaryChannelId" | uint64) ::
("channelId" | uint64) ::
("channelId" | uint64) ::
("nextKeyOffset" | binarydata(32)) ::
("nextRevocationHalfKey" | binarydata(33))).as[FundingLocked]
val updateFeeCodec: Codec[UpdateFee] = (
("channelId" | uint64) ::
("feeratePerKb" | uint32)).as[UpdateFee]
val shutdownCodec: Codec[wire.Shutdown] = (
("channelId" | uint64) ::
("len" | uint32) ::
("scriptPubKey" | binarydata(32))).as[Shutdown]
val closeSignatureCodec: Codec[CloseSignature] = (
("channelId" | uint64) ::
("feeSatoshis" | uint64) ::
("signature" | binarydata(64))).as[CloseSignature]
val lightningMessageCodec = discriminated[LightningMessage].by(uint32)
.typecase(32L, openChannelCodec)
.typecase(33L, acceptChannelCodec)
.typecase(34L, fundingCreatedCodec)
.typecase(35L, fundingSignedCodec)
.typecase(36L, fundingLockedCodec)
.typecase(37L, updateFeeCodec)
.typecase(38L, shutdownCodec)
.typecase(39L, closeSignatureCodec)
}

View file

@ -1,9 +1,9 @@
package fr.acinq.eclair.wire.bolt2.custom
package fr.acinq.eclair.wire
import java.io.{InputStream, OutputStream}
import fr.acinq.bitcoin.{BinaryData, BtcMessage}
import fr.acinq.bitcoin.Protocol._
import fr.acinq.bitcoin.{BinaryData, BtcMessage}
/**
* Created by PM on 15/11/2016.
@ -92,3 +92,14 @@ case class FundingLocked(temporaryChannelId: Long,
channelId: Long,
nextKeyOffset: BinaryData,
nextRevocationHalfKey: BinaryData) extends ChannelMessage
case class UpdateFee(channelId: Long,
feeratePerKb: Long) extends ChannelMessage
case class Shutdown(channelId: Long,
len: Long,
scriptPubKey: BinaryData) extends ChannelMessage
case class CloseSignature(channelId: Long,
feeSatoshis: Long,
signature: BinaryData) extends ChannelMessage

View file

@ -0,0 +1,29 @@
package fr.acinq.eclair.wire
import fr.acinq.eclair.wire.Codecs.lightningMessageCodec
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner
/**
* Created by PM on 31/05/2016.
*/
@RunWith(classOf[JUnitRunner])
class CodecsSpec extends FunSuite {
test("encode/decode all messages") {
val open = OpenChannel(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, Array.fill[Byte](33)(1), Array.fill[Byte](33)(2), Array.fill[Byte](33)(3))
val accept = AcceptChannel(2, 3, 4, 5, 6, 7, 8, Array.fill[Byte](32)(0), 9, Array.fill[Byte](33)(1), Array.fill[Byte](33)(2), Array.fill[Byte](33)(3))
val funding_created = FundingCreated(2, Array.fill[Byte](32)(0), 3, Array.fill[Byte](64)(1))
val funding_signed = FundingSigned(2, Array.fill[Byte](64)(1))
val funding_locked = FundingLocked(1, 2, Array.fill[Byte](32)(1), Array.fill[Byte](33)(2))
val msgs: List[LightningMessage] = open :: accept :: funding_created :: funding_signed :: funding_locked :: Nil
msgs.foreach {
case msg => assert(msg === lightningMessageCodec.encode(msg).flatMap(lightningMessageCodec.decode(_)).toOption.get.value)
}
}
}

View file

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.acinq.eclair</groupId>
<artifactId>eclair_2.11</artifactId>
<version>0.2-SNAPSHOT</version>
</parent>
<artifactId>eclair-wire_2.11</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/scala</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.scodec</groupId>
<artifactId>scodec-core_${scala.version.short}</artifactId>
<version>1.10.3</version>
</dependency>
<dependency>
<groupId>fr.acinq</groupId>
<artifactId>bitcoin-lib_${scala.version.short}</artifactId>
<version>${bitcoinlib.version}</version>
</dependency>
</dependencies>
</project>

View file

@ -1,27 +0,0 @@
package fr.acinq.eclair.wire.bolt2
import fr.acinq.eclair.wire.bolt2.custom._
import fr.acinq.eclair.wire.bolt2.sdc.Codecs.lightningMessageCodec
/**
* Created by PM on 15/11/2016.
*/
object Test extends App {
val open = OpenChannel(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, Array.fill[Byte](33)(1), Array.fill[Byte](33)(2), Array.fill[Byte](33)(3))
val accept = AcceptChannel(2, 3, 4, 5, 6, 7, 8, Array.fill[Byte](32)(0), 9, Array.fill[Byte](33)(1), Array.fill[Byte](33)(2), Array.fill[Byte](33)(3))
val funding_created = FundingCreated(2, Array.fill[Byte](32)(0), 3, Array.fill[Byte](64)(1))
val funding_signed = FundingSigned(2, Array.fill[Byte](64)(1))
val funding_locked = FundingLocked(1, 2, Array.fill[Byte](32)(1), Array.fill[Byte](33)(2))
val msgs: List[LightningMessage] = open :: accept :: funding_created :: funding_signed :: funding_locked :: Nil
msgs.foreach {
case msg =>
val bin = lightningMessageCodec.encode(msg)
println(bin)
println(bin.flatMap(lightningMessageCodec.decode(_)))
}
}

View file

@ -8,7 +8,6 @@
<packaging>pom</packaging>
<modules>
<module>eclair-wire</module>
<module>lightning-types</module>
<module>eclair-node</module>
</modules>