@@ -205,26 +205,43 @@ private[channel] object ChannelCodecs5 {
205205 (" acked" | listOfN(uint16, updateMessageCodec)) ::
206206 (" signed" | listOfN(uint16, updateMessageCodec))).as[RemoteChanges ]
207207
208- val localColdCodec : Codec [Origin . LocalCold ] = (" id" | uuid).as[Origin . LocalCold ]
208+ val upstreamLocalCodec : Codec [Upstream . Local ] = (" id" | uuid).as[Upstream . Local ]
209209
210- val localCodec : Codec [Origin .Local ] = localColdCodec.xmap[Origin .Local ](o => o : Origin .Local , o => Origin .LocalCold (o.id))
210+ val upstreamChannelCodec : Codec [Upstream .Cold .Channel ] = (
211+ (" originChannelId" | bytes32) ::
212+ (" originHtlcId" | int64) ::
213+ (" amountIn" | millisatoshi)).as[Upstream .Cold .Channel ]
211214
212- val relayedColdCodec : Codec [Origin . ChannelRelayedCold ] = (
215+ val legacyUpstreamChannelCodec : Codec [Upstream . Cold . Channel ] = (
213216 (" originChannelId" | bytes32) ::
214217 (" originHtlcId" | int64) ::
215218 (" amountIn" | millisatoshi) ::
216- (" amountOut" | millisatoshi)) .as[Origin . ChannelRelayedCold ]
219+ (" amountOut" | ignore( 64 ))) .as[Upstream . Cold . Channel ]
217220
218- val relayedCodec : Codec [Origin .ChannelRelayed ] = relayedColdCodec.xmap[Origin .ChannelRelayed ](o => o : Origin .ChannelRelayed , o => Origin .ChannelRelayedCold (o.originChannelId, o.originHtlcId, o.amountIn, o.amountOut))
221+ val upstreamChannelWithoutAmountCodec : Codec [Upstream .Cold .Channel ] = (
222+ (" originChannelId" | bytes32) ::
223+ (" originHtlcId" | int64) ::
224+ (" amountIn" | provide(0 msat))).as[Upstream .Cold .Channel ]
219225
220- val trampolineRelayedColdCodec : Codec [Origin . TrampolineRelayedCold ] = listOfN(uint16, bytes32 ~ int64 ).as[Origin . TrampolineRelayedCold ]
226+ val legacyUpstreamTrampolineCodec : Codec [Upstream . Cold . Trampoline ] = listOfN(uint16, upstreamChannelWithoutAmountCodec ).as[Upstream . Cold . Trampoline ]
221227
222- val trampolineRelayedCodec : Codec [Origin . TrampolineRelayed ] = trampolineRelayedColdCodec.xmap[ Origin . TrampolineRelayed ](o => o : Origin . TrampolineRelayed , o => Origin . TrampolineRelayedCold (o.htlcs))
228+ val upstreamTrampolineCodec : Codec [Upstream . Cold . Trampoline ] = listOfN(uint16, upstreamChannelCodec).as[ Upstream . Cold . Trampoline ]
223229
224- val originCodec : Codec [Origin ] = discriminated[Origin ].by(uint16)
225- .typecase(0x02 , relayedCodec)
226- .typecase(0x03 , localCodec)
227- .typecase(0x04 , trampolineRelayedCodec)
230+ val coldUpstreamCodec : Codec [Upstream .Cold ] = discriminated[Upstream .Cold ].by(uint16)
231+ // NB: order matters!
232+ .typecase(0x06 , upstreamChannelCodec)
233+ .typecase(0x05 , upstreamTrampolineCodec)
234+ .typecase(0x04 , legacyUpstreamTrampolineCodec)
235+ .typecase(0x03 , upstreamLocalCodec)
236+ .typecase(0x02 , legacyUpstreamChannelCodec)
237+
238+ val originCodec : Codec [Origin ] = coldUpstreamCodec.xmap[Origin ](
239+ upstream => Origin .Cold (upstream),
240+ {
241+ case Origin .Hot (_, upstream) => Upstream .Cold (upstream)
242+ case Origin .Cold (upstream) => upstream
243+ }
244+ )
228245
229246 def mapCodec [K , V ](keyCodec : Codec [K ], valueCodec : Codec [V ]): Codec [Map [K , V ]] = listOfN(uint16, keyCodec ~ valueCodec).xmap(_.toMap, _.toList)
230247
0 commit comments