@@ -65,12 +65,15 @@ interface LightningMessage {
6565 UpdateFulfillHtlc .type -> UpdateFulfillHtlc .read(stream)
6666 UpdateFee .type -> UpdateFee .read(stream)
6767 AnnouncementSignatures .type -> AnnouncementSignatures .read(stream)
68+ ChannelAnnouncement .type -> ChannelAnnouncement .read(stream)
6869 ChannelUpdate .type -> ChannelUpdate .read(stream)
6970 Shutdown .type -> Shutdown .read(stream)
7071 ClosingSigned .type -> ClosingSigned .read(stream)
7172 PayToOpenRequest .type -> PayToOpenRequest .read(stream)
73+ PayToOpenResponse .type -> PayToOpenResponse .read(stream)
7274 FCMToken .type -> FCMToken .read(stream)
7375 UnsetFCMToken .type -> UnsetFCMToken
76+ SwapInRequest .type -> SwapInRequest .read(stream)
7477 SwapInResponse .type -> SwapInResponse .read(stream)
7578 SwapInPending .type -> SwapInPending .read(stream)
7679 SwapInConfirmed .type -> SwapInConfirmed .read(stream)
@@ -800,14 +803,52 @@ data class ChannelAnnouncement(
800803 override val type: Long get() = ChannelAnnouncement .type
801804
802805 override fun write (out : Output ) {
803- TODO ()
806+ LightningCodecs .writeBytes(nodeSignature1, out )
807+ LightningCodecs .writeBytes(nodeSignature2, out )
808+ LightningCodecs .writeBytes(bitcoinSignature1, out )
809+ LightningCodecs .writeBytes(bitcoinSignature2, out )
810+ val featureBytes = features.toByteArray()
811+ LightningCodecs .writeU16(featureBytes.size, out )
812+ LightningCodecs .writeBytes(featureBytes, out )
813+ LightningCodecs .writeBytes(chainHash, out )
814+ LightningCodecs .writeU64(shortChannelId.toLong(), out )
815+ LightningCodecs .writeBytes(nodeId1.value, out )
816+ LightningCodecs .writeBytes(nodeId2.value, out )
817+ LightningCodecs .writeBytes(bitcoinKey1.value, out )
818+ LightningCodecs .writeBytes(bitcoinKey2.value, out )
819+ LightningCodecs .writeBytes(unknownFields, out )
804820 }
805821
806822 companion object : LightningMessageReader <ChannelAnnouncement > {
807823 const val type: Long = 256
808824
809825 override fun read (input : Input ): ChannelAnnouncement {
810- TODO ()
826+ val nodeSignature1 = LightningCodecs .bytes(input, 64 ).toByteVector64()
827+ val nodeSignature2 = LightningCodecs .bytes(input, 64 ).toByteVector64()
828+ val bitcoinSignature1 = LightningCodecs .bytes(input, 64 ).toByteVector64()
829+ val bitcoinSignature2 = LightningCodecs .bytes(input, 64 ).toByteVector64()
830+ val featureBytes = LightningCodecs .bytes(input, LightningCodecs .u16(input))
831+ val chainHash = LightningCodecs .bytes(input, 32 ).toByteVector32()
832+ val shortChannelId = ShortChannelId (LightningCodecs .u64(input))
833+ val nodeId1 = PublicKey (LightningCodecs .bytes(input, 33 ))
834+ val nodeId2 = PublicKey (LightningCodecs .bytes(input, 33 ))
835+ val bitcoinKey1 = PublicKey (LightningCodecs .bytes(input, 33 ))
836+ val bitcoinKey2 = PublicKey (LightningCodecs .bytes(input, 33 ))
837+ val unknownBytes = if (input.availableBytes > 0 ) LightningCodecs .bytes(input, input.availableBytes).toByteVector() else ByteVector .empty
838+ return ChannelAnnouncement (
839+ nodeSignature1,
840+ nodeSignature2,
841+ bitcoinSignature1,
842+ bitcoinSignature2,
843+ Features (featureBytes),
844+ chainHash,
845+ shortChannelId,
846+ nodeId1,
847+ nodeId2,
848+ bitcoinKey1,
849+ bitcoinKey2,
850+ unknownBytes
851+ )
811852 }
812853 }
813854}
@@ -981,7 +1022,15 @@ data class PayToOpenRequest(
9811022 override val type: Long get() = PayToOpenRequest .type
9821023
9831024 override fun write (out : Output ) {
984- TODO (" Not implemented (not needed)" )
1025+ LightningCodecs .writeBytes(chainHash, out )
1026+ LightningCodecs .writeU64(fundingSatoshis.toLong(), out )
1027+ LightningCodecs .writeU64(amountMsat.toLong(), out )
1028+ LightningCodecs .writeU64(payToOpenMinAmountMsat.toLong(), out )
1029+ LightningCodecs .writeU64(payToOpenFeeSatoshis.toLong(), out )
1030+ LightningCodecs .writeBytes(paymentHash, out )
1031+ LightningCodecs .writeU32(expireAt.toInt(), out )
1032+ LightningCodecs .writeU16(finalPacket.payload.size(), out )
1033+ OnionRoutingPacketSerializer (finalPacket.payload.size()).write(finalPacket, out )
9851034 }
9861035
9871036 companion object : LightningMessageReader <PayToOpenRequest > {
@@ -1050,7 +1099,15 @@ data class PayToOpenResponse(override val chainHash: ByteVector32, val paymentHa
10501099 const val type: Long = 35003
10511100
10521101 override fun read (input : Input ): PayToOpenResponse {
1053- TODO (" Not yet implemented" )
1102+ val chainHash = LightningCodecs .bytes(input, 32 ).toByteVector32()
1103+ val paymentHash = LightningCodecs .bytes(input, 32 ).toByteVector32()
1104+ return when (val preimage = LightningCodecs .bytes(input, 32 ).toByteVector32()) {
1105+ ByteVector32 .Zeroes -> {
1106+ val failure = if (input.availableBytes > 0 ) LightningCodecs .bytes(input, LightningCodecs .u16(input)).toByteVector() else null
1107+ PayToOpenResponse (chainHash, paymentHash, Result .Failure (failure))
1108+ }
1109+ else -> PayToOpenResponse (chainHash, paymentHash, Result .Success (preimage))
1110+ }
10541111 }
10551112 }
10561113}
@@ -1079,11 +1136,10 @@ data class FCMToken(@Serializable(with = ByteVectorKSerializer::class) val token
10791136
10801137@Serializable
10811138object UnsetFCMToken : LightningMessage {
1082-
10831139 override val type: Long get() = 35019
1084-
10851140 override fun write (out : Output ) {}
10861141}
1142+
10871143@OptIn(ExperimentalUnsignedTypes ::class )
10881144data class SwapInRequest (
10891145 override val chainHash : ByteVector32
@@ -1098,7 +1154,7 @@ data class SwapInRequest(
10981154 const val type: Long = 35007
10991155
11001156 override fun read (input : Input ): SwapInRequest {
1101- TODO ( " Not implemented (not needed) " )
1157+ return SwapInRequest ( LightningCodecs .bytes(input, 32 ).toByteVector32() )
11021158 }
11031159 }
11041160}
@@ -1111,7 +1167,10 @@ data class SwapInResponse(
11111167 override val type: Long get() = SwapInResponse .type
11121168
11131169 override fun write (out : Output ) {
1114- TODO (" Not implemented (not needed)" )
1170+ LightningCodecs .writeBytes(chainHash, out )
1171+ val addressBytes = bitcoinAddress.encodeToByteArray()
1172+ LightningCodecs .writeU16(addressBytes.size, out )
1173+ LightningCodecs .writeBytes(addressBytes, out )
11151174 }
11161175
11171176 companion object : LightningMessageReader <SwapInResponse > {
@@ -1134,7 +1193,10 @@ data class SwapInPending(
11341193 override val type: Long get() = SwapInPending .type
11351194
11361195 override fun write (out : Output ) {
1137- TODO (" Not implemented (not needed)" )
1196+ val addressBytes = bitcoinAddress.encodeToByteArray()
1197+ LightningCodecs .writeU16(addressBytes.size, out )
1198+ LightningCodecs .writeBytes(addressBytes, out )
1199+ LightningCodecs .writeU64(amount.toLong(), out )
11381200 }
11391201
11401202 companion object : LightningMessageReader <SwapInPending > {
@@ -1157,7 +1219,10 @@ data class SwapInConfirmed(
11571219 override val type: Long get() = SwapInConfirmed .type
11581220
11591221 override fun write (out : Output ) {
1160- TODO (" Not implemented (not needed)" )
1222+ val addressBytes = bitcoinAddress.encodeToByteArray()
1223+ LightningCodecs .writeU16(addressBytes.size, out )
1224+ LightningCodecs .writeBytes(addressBytes, out )
1225+ LightningCodecs .writeU64(amount.toLong(), out )
11611226 }
11621227
11631228 companion object : LightningMessageReader <SwapInConfirmed > {
0 commit comments