@@ -62,6 +62,9 @@ module internal TypeFlag =
62
62
[<Literal>]
63
63
let Error = 17 us
64
64
65
+ [<Literal>]
66
+ let Warning = 1 us
67
+
65
68
[<Literal>]
66
69
let Ping = 18 us
67
70
@@ -210,6 +213,7 @@ module ILightningSerializable =
210
213
match t with
211
214
| TypeFlag.Init -> deserialize< InitMsg>( ls) :> ILightningMsg
212
215
| TypeFlag.Error -> deserialize< ErrorMsg>( ls) :> ILightningMsg
216
+ | TypeFlag.Warning -> deserialize< WarningMsg>( ls) :> ILightningMsg
213
217
| TypeFlag.Ping -> deserialize< PingMsg>( ls) :> ILightningMsg
214
218
| TypeFlag.Pong -> deserialize< PongMsg>( ls) :> ILightningMsg
215
219
| TypeFlag.OpenChannel ->
@@ -272,6 +276,11 @@ module ILightningSerializable =
272
276
273
277
( d :> ILightningSerializable< ErrorMsg>)
274
278
.Serialize( ls)
279
+ | :? WarningMsg as warningMsg ->
280
+ ls.Write( TypeFlag.Warning, false )
281
+
282
+ ( warningMsg :> ILightningSerializable< WarningMsg>)
283
+ .Serialize ls
275
284
| :? PingMsg as d ->
276
285
ls.Write( TypeFlag.Ping, false )
277
286
@@ -1809,6 +1818,50 @@ and WhichChannel =
1809
1818
| SpecificChannel of ChannelId
1810
1819
| All
1811
1820
1821
+
1822
+ [<RequireQualifiedAccess>]
1823
+ [<CLIMutable>]
1824
+ type WarningMsg =
1825
+ {
1826
+ mutable ChannelId: WhichChannel
1827
+ mutable Data: array < byte >
1828
+ }
1829
+
1830
+ interface ISetupMsg
1831
+
1832
+ interface ILightningSerializable< WarningMsg> with
1833
+ member this.Deserialize readStream =
1834
+ match readStream.ReadUInt256 true with
1835
+ | id when id = uint256.Zero -> this.ChannelId <- All
1836
+ | id -> this.ChannelId <- SpecificChannel( ChannelId id)
1837
+
1838
+ this.Data <- readStream.ReadWithLen()
1839
+
1840
+ member this.Serialize writeStream =
1841
+ match this.ChannelId with
1842
+ | SpecificChannel( ChannelId id) -> writeStream.Write( id.ToBytes())
1843
+ | All -> writeStream.Write( Array.zeroCreate 32 )
1844
+
1845
+ writeStream.WriteWithLen this.Data
1846
+
1847
+ member this.GetFailureMsgData () =
1848
+ let minPrintableAsciiChar = 32 uy
1849
+
1850
+ let isPrintableAsciiChar ( asciiChar : byte ) =
1851
+ asciiChar >= minPrintableAsciiChar
1852
+
1853
+ let isPrintableAsciiString =
1854
+ this.Data |> Array.forall isPrintableAsciiChar
1855
+
1856
+ if isPrintableAsciiString then
1857
+ System.Text.ASCIIEncoding.ASCII.GetString this.Data
1858
+ else
1859
+ Seq.fold
1860
+ ( fun msg ( asciiChar : byte ) -> sprintf " %s %02x " msg asciiChar)
1861
+ " <warning contains non-printable binary data>:"
1862
+ this.Data
1863
+
1864
+
1812
1865
#nowarn " 0044" // "This construct is deprecated" warning
1813
1866
// sadly we don't have a way to restore warnings yet.
1814
1867
// ref: https://github.com/fsharp/fslang-suggestions/issues/278
0 commit comments