-
Notifications
You must be signed in to change notification settings - Fork 1
/
HostedChannelCodecs.scala
119 lines (103 loc) · 3.8 KB
/
HostedChannelCodecs.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package scoin.hc
import scala.util.Try
import scodec.codecs._
import scodec.bits._
import scodec.{Attempt, Err}
import scoin.CommonCodecs._
import scoin.ln._
import scoin.ln.LightningMessageCodecs._
object HostedChannelCodecs {
val invokeHostedChannelCodec = (
("chainHash" | bytes32) ::
("refundScriptPubKey" | varsizebinarydata) ::
("secret" | varsizebinarydata)
).as[InvokeHostedChannel]
val initHostedChannelCodec = (
("maxHtlcValueInFlight" | millisatoshi) ::
("htlcMinimum" | millisatoshi) ::
("maxAcceptedHtlcs" | uint16) ::
("channelCapacity" | millisatoshi) ::
("initialClientBalance" | millisatoshi) ::
("features" | listOfN(uint16, uint16))
).as[InitHostedChannel]
val hostedChannelBrandingCodec = (
("rgbColor" | rgb) ::
("pngIcon" | optional(bool8, varsizebinarydata)) ::
("contactInfo" | variableSizeBytes(uint16, utf8))
).as[HostedChannelBranding]
lazy val lastCrossSignedStateCodec = (
("isHost" | bool8) ::
("refundScriptPubKey" | varsizebinarydata) ::
("initHostedChannel" | lengthDelimited(initHostedChannelCodec)) ::
("blockDay" | uint32) ::
("localBalance" | millisatoshi) ::
("remoteBalance" | millisatoshi) ::
("localUpdates" | uint32) ::
("remoteUpdates" | uint32) ::
("incomingHtlcs" | listOfN(
uint16,
lengthDelimited(updateAddHtlcCodec)
)) ::
("outgoingHtlcs" | listOfN(
uint16,
lengthDelimited(updateAddHtlcCodec)
)) ::
("remoteSigOfLocal" | bytes64) ::
("localSigOfRemote" | bytes64)
).as[LastCrossSignedState]
val stateUpdateCodec = (
("blockDay" | uint32) ::
("localUpdates" | uint32) ::
("remoteUpdates" | uint32) ::
("localSigOfRemoteLCSS" | bytes64)
).as[StateUpdate]
val stateOverrideCodec = (
("blockDay" | uint32) ::
("localBalance" | millisatoshi) ::
("localUpdates" | uint32) ::
("remoteUpdates" | uint32) ::
("localSigOfRemoteLCSS" | bytes64)
).as[StateOverride]
val announcementSignatureCodec = (
("nodeSignature" | bytes64) ::
("wantsReply" | bool8)
).as[AnnouncementSignature]
val resizeChannelCodec = (
("newCapacity" | satoshi) ::
("clientSig" | bytes64)
).as[ResizeChannel]
val askBrandingInfoCodec =
("chainHash" | bytes32).as[AskBrandingInfo]
val queryPublicHostedChannelsCodec =
("chainHash" | bytes32).as[QueryPublicHostedChannels]
val replyPublicHostedChannelsEndCodec =
("chainHash" | bytes32).as[ReplyPublicHostedChannelsEnd]
val queryPreimagesCodec =
("hashes" | listOfN(uint16, bytes32)).as[QueryPreimages]
val replyPreimagesCodec =
("preimages" | listOfN(uint16, bytes32)).as[ReplyPreimages]
val hostedMessageCodec = discriminated[LightningMessage]
.by(uint16)
.typecase(65535, invokeHostedChannelCodec)
.typecase(65533, initHostedChannelCodec)
.typecase(65531, lastCrossSignedStateCodec)
.typecase(65529, stateUpdateCodec)
.typecase(65527, stateOverrideCodec)
.typecase(65525, hostedChannelBrandingCodec)
.typecase(65523, announcementSignatureCodec)
.typecase(65521, resizeChannelCodec)
.typecase(65519, queryPublicHostedChannelsCodec)
.typecase(65517, replyPublicHostedChannelsEndCodec)
.typecase(65515, queryPreimagesCodec)
.typecase(65513, replyPreimagesCodec)
.typecase(65511, askBrandingInfoCodec)
.typecase(64513, channelAnnouncementCodec) // PHC gossip
.typecase(64511, channelAnnouncementCodec) // PHC sync
.typecase(64509, channelUpdateCodec) // PHC gossip
.typecase(64507, channelUpdateCodec) // PHC sync
.typecase(63505, updateAddHtlcCodec)
.typecase(63503, updateFulfillHtlcCodec)
.typecase(63501, updateFailHtlcCodec)
.typecase(63499, updateFailMalformedHtlcCodec)
.typecase(63497, errorCodec)
}