| | 1 | | using Microsoft.Extensions.Options; |
| | 2 | |
|
| | 3 | | namespace NLightning.Application.Protocol.Factories; |
| | 4 | |
|
| | 5 | | using Domain.Bitcoin.ValueObjects; |
| | 6 | | using Domain.Channels.ValueObjects; |
| | 7 | | using Domain.Crypto.ValueObjects; |
| | 8 | | using Domain.Money; |
| | 9 | | using Domain.Node.Options; |
| | 10 | | using Domain.Protocol.Interfaces; |
| | 11 | | using Domain.Protocol.Messages; |
| | 12 | | using Domain.Protocol.Models; |
| | 13 | | using Domain.Protocol.Payloads; |
| | 14 | | using Domain.Protocol.Tlv; |
| | 15 | | using Domain.Protocol.ValueObjects; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Factory for creating messages. |
| | 19 | | /// </summary> |
| | 20 | | public class MessageFactory : IMessageFactory |
| | 21 | | { |
| | 22 | | private readonly NodeOptions _nodeOptions; |
| | 23 | | private readonly BitcoinNetwork _bitcoinNetwork; |
| | 24 | |
|
| 0 | 25 | | public MessageFactory(IOptions<NodeOptions> nodeOptions) |
| | 26 | | { |
| 0 | 27 | | _nodeOptions = nodeOptions.Value; |
| 0 | 28 | | _bitcoinNetwork = _nodeOptions.BitcoinNetwork; |
| 0 | 29 | | } |
| | 30 | |
|
| | 31 | | #region Init Message |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Create an Init message. |
| | 35 | | /// </summary> |
| | 36 | | /// <returns>The Init message.</returns> |
| | 37 | | /// <seealso cref="InitMessage"/> |
| | 38 | | /// <seealso cref="InitPayload"/> |
| | 39 | | public InitMessage CreateInitMessage() |
| | 40 | | { |
| | 41 | | // Get features from options |
| 0 | 42 | | var features = _nodeOptions.Features.GetNodeFeatures(); |
| 0 | 43 | | var payload = new InitPayload(features); |
| | 44 | |
|
| 0 | 45 | | return new InitMessage(payload, _nodeOptions.Features.GetInitTlvs()); |
| | 46 | | } |
| | 47 | |
|
| | 48 | | #endregion |
| | 49 | |
|
| | 50 | | #region Control Messages |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Create a Warning message. |
| | 54 | | /// </summary> |
| | 55 | | /// <param name="message">The message to be sent.</param> |
| | 56 | | /// <param name="channelId">The channel id, if any.</param> |
| | 57 | | /// <returns>The Warning message.</returns> |
| | 58 | | /// <seealso cref="WarningMessage"/> |
| | 59 | | /// <seealso cref="ChannelId"/> |
| | 60 | | /// <seealso cref="ErrorPayload"/> |
| | 61 | | public WarningMessage CreateWarningMessage(string message, ChannelId? channelId) |
| | 62 | | { |
| 0 | 63 | | var payload = channelId is null ? new ErrorPayload(message) : new ErrorPayload(channelId, message); |
| 0 | 64 | | return new WarningMessage(payload); |
| | 65 | | } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// Create a Warning message. |
| | 69 | | /// </summary> |
| | 70 | | /// <param name="data">The data to be sent.</param> |
| | 71 | | /// <param name="channelId">The channel id, if any.</param> |
| | 72 | | /// <returns>The Warning message.</returns> |
| | 73 | | /// <seealso cref="WarningMessage"/> |
| | 74 | | /// <seealso cref="ChannelId"/> |
| | 75 | | /// <seealso cref="ErrorPayload"/> |
| | 76 | | public WarningMessage CreateWarningMessage(byte[] data, ChannelId? channelId) |
| | 77 | | { |
| 0 | 78 | | var payload = channelId is null ? new ErrorPayload(data) : new ErrorPayload(channelId.Value, data); |
| 0 | 79 | | return new WarningMessage(payload); |
| | 80 | | } |
| | 81 | |
|
| | 82 | | /// <summary> |
| | 83 | | /// Create a Stfu message. |
| | 84 | | /// </summary> |
| | 85 | | /// <param name="channelId">The channel id, if any.</param> |
| | 86 | | /// <param name="initiator">If we are the sender of the message.</param> |
| | 87 | | /// <returns>The Stfu message.</returns> |
| | 88 | | /// <seealso cref="StfuMessage"/> |
| | 89 | | /// <seealso cref="ChannelId"/> |
| | 90 | | /// <seealso cref="StfuPayload"/> |
| | 91 | | public StfuMessage CreateStfuMessage(ChannelId channelId, bool initiator) |
| | 92 | | { |
| 0 | 93 | | var payload = new StfuPayload(channelId, initiator); |
| 0 | 94 | | return new StfuMessage(payload); |
| | 95 | | } |
| | 96 | |
|
| | 97 | | /// <summary> |
| | 98 | | /// Create an Error message. |
| | 99 | | /// </summary> |
| | 100 | | /// <param name="message">The message to be sent.</param> |
| | 101 | | /// <param name="channelId">The channel id, if any.</param> |
| | 102 | | /// <returns>The Error message.</returns> |
| | 103 | | /// <seealso cref="ErrorMessage"/> |
| | 104 | | /// <seealso cref="ChannelId"/> |
| | 105 | | /// <seealso cref="ErrorPayload"/> |
| | 106 | | public ErrorMessage CreateErrorMessage(string message, ChannelId? channelId) |
| | 107 | | { |
| 0 | 108 | | var payload = channelId is null ? new ErrorPayload(message) : new ErrorPayload(channelId.Value, message); |
| 0 | 109 | | return new ErrorMessage(payload); |
| | 110 | | } |
| | 111 | |
|
| | 112 | | /// <summary> |
| | 113 | | /// Create an Error message. |
| | 114 | | /// </summary> |
| | 115 | | /// <param name="data">The data to be sent.</param> |
| | 116 | | /// <param name="channelId">The channel id, if any.</param> |
| | 117 | | /// <returns>The Error message.</returns> |
| | 118 | | /// <seealso cref="ErrorMessage"/> |
| | 119 | | /// <seealso cref="ChannelId"/> |
| | 120 | | /// <seealso cref="ErrorPayload"/> |
| | 121 | | public ErrorMessage CreateErrorMessage(byte[] data, ChannelId? channelId) |
| | 122 | | { |
| 0 | 123 | | var payload = channelId is null ? new ErrorPayload(data) : new ErrorPayload(channelId.Value, data); |
| 0 | 124 | | return new ErrorMessage(payload); |
| | 125 | | } |
| | 126 | |
|
| | 127 | | /// <summary> |
| | 128 | | /// Create a Ping message. |
| | 129 | | /// </summary> |
| | 130 | | /// <returns>The Ping message.</returns> |
| | 131 | | /// <seealso cref="PingMessage"/> |
| | 132 | | /// <seealso cref="PingPayload"/> |
| | 133 | | public PingMessage CreatePingMessage() |
| | 134 | | { |
| 0 | 135 | | return new PingMessage(); |
| | 136 | | } |
| | 137 | |
|
| | 138 | | /// <summary> |
| | 139 | | /// Create a Pong message. |
| | 140 | | /// </summary> |
| | 141 | | /// <param name="pingMessage">The ping message we're responding to</param> |
| | 142 | | /// <returns>The Pong message.</returns> |
| | 143 | | /// <seealso cref="PongMessage"/> |
| | 144 | | /// <seealso cref="PongPayload"/> |
| | 145 | | public PongMessage CreatePongMessage(IMessage pingMessage) |
| | 146 | | { |
| 0 | 147 | | if (pingMessage is not PingMessage ping) |
| | 148 | | { |
| 0 | 149 | | throw new ArgumentException("Ping message is required", nameof(pingMessage)); |
| | 150 | | } |
| | 151 | |
|
| 0 | 152 | | return new PongMessage(ping.Payload.NumPongBytes); |
| | 153 | | } |
| | 154 | |
|
| | 155 | | #endregion |
| | 156 | |
|
| | 157 | | #region Interactive Transaction Construction |
| | 158 | |
|
| | 159 | | /// <summary> |
| | 160 | | /// Create a TxAddInput message. |
| | 161 | | /// </summary> |
| | 162 | | /// <param name="channelId">The channel id.</param> |
| | 163 | | /// <param name="serialId">The serial id.</param> |
| | 164 | | /// <param name="prevTx">The previous transaction.</param> |
| | 165 | | /// <param name="prevTxVout">The previous transaction vout.</param> |
| | 166 | | /// <param name="sequence">The sequence number.</param> |
| | 167 | | /// <returns>The TxAddInput message.</returns> |
| | 168 | | /// <seealso cref="TxAddInputMessage"/> |
| | 169 | | /// <seealso cref="ChannelId"/> |
| | 170 | | /// <seealso cref="TxAddInputPayload"/> |
| | 171 | | public TxAddInputMessage CreateTxAddInputMessage(ChannelId channelId, ulong serialId, byte[] prevTx, |
| | 172 | | uint prevTxVout, |
| | 173 | | uint sequence) |
| | 174 | | { |
| 0 | 175 | | var payload = new TxAddInputPayload(channelId, serialId, prevTx, prevTxVout, sequence); |
| | 176 | |
|
| 0 | 177 | | return new TxAddInputMessage(payload); |
| | 178 | | } |
| | 179 | |
|
| | 180 | | /// <summary> |
| | 181 | | /// Create a TxAddOutput message. |
| | 182 | | /// </summary> |
| | 183 | | /// <param name="channelId">The channel id.</param> |
| | 184 | | /// <param name="serialId">The serial id.</param> |
| | 185 | | /// <param name="amount">The number of satoshis.</param> |
| | 186 | | /// <param name="script">The script.</param> |
| | 187 | | /// <returns>The TxAddOutput message.</returns> |
| | 188 | | /// <seealso cref="TxAddOutputMessage"/> |
| | 189 | | /// <seealso cref="ChannelId"/> |
| | 190 | | /// <seealso cref="TxAddOutputPayload"/> |
| | 191 | | public TxAddOutputMessage CreateTxAddOutputMessage(ChannelId channelId, ulong serialId, LightningMoney amount, |
| | 192 | | BitcoinScript script) |
| | 193 | | { |
| 0 | 194 | | var payload = new TxAddOutputPayload(amount, channelId, script, serialId); |
| | 195 | |
|
| 0 | 196 | | return new TxAddOutputMessage(payload); |
| | 197 | | } |
| | 198 | |
|
| | 199 | | /// <summary> |
| | 200 | | /// Create a TxRemoveInput message. |
| | 201 | | /// </summary> |
| | 202 | | /// <param name="channelId">The channel id.</param> |
| | 203 | | /// <param name="serialId">The serial id.</param> |
| | 204 | | /// <returns>The TxRemoveInput message.</returns> |
| | 205 | | /// <seealso cref="TxRemoveInputMessage"/> |
| | 206 | | /// <seealso cref="ChannelId"/> |
| | 207 | | /// <seealso cref="TxRemoveInputPayload"/> |
| | 208 | | public TxRemoveInputMessage CreateTxRemoveInputMessage(ChannelId channelId, ulong serialId) |
| | 209 | | { |
| 0 | 210 | | var payload = new TxRemoveInputPayload(channelId, serialId); |
| | 211 | |
|
| 0 | 212 | | return new TxRemoveInputMessage(payload); |
| | 213 | | } |
| | 214 | |
|
| | 215 | | /// <summary> |
| | 216 | | /// Create a TxRemoveOutput message. |
| | 217 | | /// </summary> |
| | 218 | | /// <param name="channelId">The channel id.</param> |
| | 219 | | /// <param name="serialId">The serial id.</param> |
| | 220 | | /// <returns>The TxRemoveOutput message.</returns> |
| | 221 | | /// <seealso cref="TxRemoveOutputMessage"/> |
| | 222 | | /// <seealso cref="ChannelId"/> |
| | 223 | | /// <seealso cref="TxRemoveOutputPayload"/> |
| | 224 | | public TxRemoveOutputMessage CreateTxRemoveOutputMessage(ChannelId channelId, ulong serialId) |
| | 225 | | { |
| 0 | 226 | | var payload = new TxRemoveOutputPayload(channelId, serialId); |
| | 227 | |
|
| 0 | 228 | | return new TxRemoveOutputMessage(payload); |
| | 229 | | } |
| | 230 | |
|
| | 231 | | /// <summary> |
| | 232 | | /// Create a TxComplete message. |
| | 233 | | /// </summary> |
| | 234 | | /// <param name="channelId">The channel id.</param> |
| | 235 | | /// <returns>The TxComplete message.</returns> |
| | 236 | | /// <seealso cref="TxCompleteMessage"/> |
| | 237 | | /// <seealso cref="ChannelId"/> |
| | 238 | | /// <seealso cref="TxCompletePayload"/> |
| | 239 | | public TxCompleteMessage CreateTxCompleteMessage(ChannelId channelId) |
| | 240 | | { |
| 0 | 241 | | var payload = new TxCompletePayload(channelId); |
| | 242 | |
|
| 0 | 243 | | return new TxCompleteMessage(payload); |
| | 244 | | } |
| | 245 | |
|
| | 246 | | /// <summary> |
| | 247 | | /// Create a TxSignatures message. |
| | 248 | | /// </summary> |
| | 249 | | /// <param name="channelId">The channel id.</param> |
| | 250 | | /// <param name="txId">The transaction id.</param> |
| | 251 | | /// <param name="witnesses">The witnesses.</param> |
| | 252 | | /// <returns>The TxSignatures message.</returns> |
| | 253 | | /// <seealso cref="TxSignaturesMessage"/> |
| | 254 | | /// <seealso cref="ChannelId"/> |
| | 255 | | /// <seealso cref="TxSignaturesPayload"/> |
| | 256 | | public TxSignaturesMessage CreateTxSignaturesMessage(ChannelId channelId, byte[] txId, List<Witness> witnesses) |
| | 257 | | { |
| 0 | 258 | | var payload = new TxSignaturesPayload(channelId, txId, witnesses); |
| | 259 | |
|
| 0 | 260 | | return new TxSignaturesMessage(payload); |
| | 261 | | } |
| | 262 | |
|
| | 263 | | /// <summary> |
| | 264 | | /// Create a TxInitRbf message. |
| | 265 | | /// </summary> |
| | 266 | | /// <param name="channelId">The channel id.</param> |
| | 267 | | /// <param name="locktime">The locktime.</param> |
| | 268 | | /// <param name="feerate">The feerate</param> |
| | 269 | | /// <param name="fundingOutputContrubution">The output contribution.</param> |
| | 270 | | /// <param name="requireConfirmedInputs">How many confirmed inputs we need.</param> |
| | 271 | | /// <returns>The TxInitRbf message.</returns> |
| | 272 | | /// <seealso cref="TxInitRbfMessage"/> |
| | 273 | | /// <seealso cref="ChannelId"/> |
| | 274 | | /// <seealso cref="TxInitRbfPayload"/> |
| | 275 | | public TxInitRbfMessage CreateTxInitRbfMessage(ChannelId channelId, uint locktime, uint feerate, |
| | 276 | | long fundingOutputContrubution, bool requireConfirmedInputs) |
| | 277 | | { |
| 0 | 278 | | FundingOutputContributionTlv? fundingOutputContributionTlv = null; |
| 0 | 279 | | RequireConfirmedInputsTlv? requireConfirmedInputsTlv = null; |
| | 280 | |
|
| 0 | 281 | | if (fundingOutputContrubution > 0) |
| | 282 | | { |
| 0 | 283 | | fundingOutputContributionTlv = new FundingOutputContributionTlv(fundingOutputContrubution); |
| | 284 | | } |
| | 285 | |
|
| 0 | 286 | | if (requireConfirmedInputs) |
| | 287 | | { |
| 0 | 288 | | requireConfirmedInputsTlv = new RequireConfirmedInputsTlv(); |
| | 289 | | } |
| | 290 | |
|
| 0 | 291 | | var payload = new TxInitRbfPayload(channelId, locktime, feerate); |
| | 292 | |
|
| 0 | 293 | | return new TxInitRbfMessage(payload, fundingOutputContributionTlv, requireConfirmedInputsTlv); |
| | 294 | | } |
| | 295 | |
|
| | 296 | | /// <summary> |
| | 297 | | /// Create a TxAckRbf message. |
| | 298 | | /// </summary> |
| | 299 | | /// <param name="channelId">The channel id.</param> |
| | 300 | | /// <param name="fundingOutputContrubution">The output contribution.</param> |
| | 301 | | /// <param name="requireConfirmedInputs">How many confirmed inputs we need.</param> |
| | 302 | | /// <returns>The TxAckRbf message.</returns> |
| | 303 | | /// <seealso cref="TxAckRbfMessage"/> |
| | 304 | | /// <seealso cref="ChannelId"/> |
| | 305 | | /// <seealso cref="TxAckRbfPayload"/> |
| | 306 | | /// <seealso cref="TlvStream"/> |
| | 307 | | /// <seealso cref="FundingOutputContributionTlv"/> |
| | 308 | | /// <seealso cref="RequireConfirmedInputsTlv"/> |
| | 309 | | public TxAckRbfMessage CreateTxAckRbfMessage(ChannelId channelId, long fundingOutputContrubution, |
| | 310 | | bool requireConfirmedInputs) |
| | 311 | | { |
| 0 | 312 | | FundingOutputContributionTlv? fundingOutputContributionTlv = null; |
| 0 | 313 | | RequireConfirmedInputsTlv? requireConfirmedInputsTlv = null; |
| | 314 | |
|
| 0 | 315 | | if (fundingOutputContrubution > 0) |
| | 316 | | { |
| 0 | 317 | | fundingOutputContributionTlv = new FundingOutputContributionTlv(fundingOutputContrubution); |
| | 318 | | } |
| | 319 | |
|
| 0 | 320 | | if (requireConfirmedInputs) |
| | 321 | | { |
| 0 | 322 | | requireConfirmedInputsTlv = new RequireConfirmedInputsTlv(); |
| | 323 | | } |
| | 324 | |
|
| 0 | 325 | | var payload = new TxAckRbfPayload(channelId); |
| | 326 | |
|
| 0 | 327 | | return new TxAckRbfMessage(payload, fundingOutputContributionTlv, requireConfirmedInputsTlv); |
| | 328 | | } |
| | 329 | |
|
| | 330 | | /// <summary> |
| | 331 | | /// Create a TxAbort message. |
| | 332 | | /// </summary> |
| | 333 | | /// <param name="channelId">The channel id.</param> |
| | 334 | | /// <param name="data">The data.</param> |
| | 335 | | /// <returns>The TxAbort message.</returns> |
| | 336 | | /// <seealso cref="TxAbortMessage"/> |
| | 337 | | /// <seealso cref="ChannelId"/> |
| | 338 | | /// <seealso cref="TxAbortPayload"/> |
| | 339 | | public TxAbortMessage CreateTxAbortMessage(ChannelId channelId, byte[] data) |
| | 340 | | { |
| 0 | 341 | | var payload = new TxAbortPayload(channelId, data); |
| | 342 | |
|
| 0 | 343 | | return new TxAbortMessage(payload); |
| | 344 | | } |
| | 345 | |
|
| | 346 | | #endregion |
| | 347 | |
|
| | 348 | | #region Channel Messages |
| | 349 | |
|
| | 350 | | /// <summary> |
| | 351 | | /// Create a ChannelReady message. |
| | 352 | | /// </summary> |
| | 353 | | /// <param name="channelId">The channel id.</param> |
| | 354 | | /// <param name="secondPerCommitmentPoint">The second per commitment point.</param> |
| | 355 | | /// <param name="shortChannelId">The channel's shortChannelId.</param> |
| | 356 | | /// <returns>The ChannelReady message.</returns> |
| | 357 | | /// <seealso cref="ChannelReadyMessage"/> |
| | 358 | | /// <seealso cref="ChannelId"/> |
| | 359 | | /// <seealso cref="CompactPubKey"/> |
| | 360 | | /// <seealso cref="ShortChannelId"/> |
| | 361 | | /// <seealso cref="ChannelReadyPayload"/> |
| | 362 | | public ChannelReadyMessage CreateChannelReadyMessage(ChannelId channelId, CompactPubKey secondPerCommitmentPoint, |
| | 363 | | ShortChannelId? shortChannelId = null) |
| | 364 | | { |
| 0 | 365 | | var payload = new ChannelReadyPayload(channelId, secondPerCommitmentPoint); |
| | 366 | |
|
| 0 | 367 | | return new ChannelReadyMessage(payload, |
| 0 | 368 | | shortChannelId is null ? null : new ShortChannelIdTlv(shortChannelId.Value)); |
| | 369 | | } |
| | 370 | |
|
| | 371 | | /// <summary> |
| | 372 | | /// Create a Shutdown message. |
| | 373 | | /// </summary> |
| | 374 | | /// <param name="channelId">The channel id.</param> |
| | 375 | | /// <param name="scriptPubkey">The ScriptPubKey to send closing funds to.</param> |
| | 376 | | /// <returns>The Shutdown message.</returns> |
| | 377 | | /// <seealso cref="ShutdownMessage"/> |
| | 378 | | /// <seealso cref="ChannelId"/> |
| | 379 | | /// <seealso cref="BitcoinScript"/> |
| | 380 | | /// <seealso cref="ShutdownPayload"/> |
| | 381 | | public ShutdownMessage CreateShutdownMessage(ChannelId channelId, BitcoinScript scriptPubkey) |
| | 382 | | { |
| 0 | 383 | | var payload = new ShutdownPayload(channelId, scriptPubkey); |
| | 384 | |
|
| 0 | 385 | | return new ShutdownMessage(payload); |
| | 386 | | } |
| | 387 | |
|
| | 388 | | /// <summary> |
| | 389 | | /// Create a ClosingSigned message. |
| | 390 | | /// </summary> |
| | 391 | | /// <param name="channelId">The channel id.</param> |
| | 392 | | /// <param name="feeSatoshis">The fee we want them to pay for closing the channel.</param> |
| | 393 | | /// <param name="signature">The signature for closing the channel.</param> |
| | 394 | | /// <param name="minFeeSatoshis">The min fee we will accept them to pay to close the channel.</param> |
| | 395 | | /// <param name="maxFeeSatoshis">The max fee we will accept them to pay to close the channel.</param> |
| | 396 | | /// <returns>The ClosingSigned message.</returns> |
| | 397 | | /// <seealso cref="ClosingSignedMessage"/> |
| | 398 | | /// <seealso cref="ChannelId"/> |
| | 399 | | /// <seealso cref="CompactSignature"/> |
| | 400 | | /// <seealso cref="ClosingSignedPayload"/> |
| | 401 | | public ClosingSignedMessage CreateClosingSignedMessage(ChannelId channelId, ulong feeSatoshis, |
| | 402 | | CompactSignature signature, |
| | 403 | | ulong minFeeSatoshis, ulong maxFeeSatoshis) |
| | 404 | | { |
| 0 | 405 | | var payload = new ClosingSignedPayload(channelId, feeSatoshis, signature); |
| | 406 | |
|
| 0 | 407 | | return new ClosingSignedMessage(payload, new FeeRangeTlv(minFeeSatoshis, maxFeeSatoshis)); |
| | 408 | | } |
| | 409 | |
|
| | 410 | | /// <summary> |
| | 411 | | /// Create an OpenChannel1 message. |
| | 412 | | /// </summary> |
| | 413 | | /// <param name="temporaryChannelId">The temporary channel id.</param> |
| | 414 | | /// <param name="fundingAmount">The amount of satoshis we're adding to the channel.</param> |
| | 415 | | /// <param name="fundingPubKey">The funding pubkey of the channel.</param> |
| | 416 | | /// <param name="pushAmount">The amount of satoshis we're pushing to the other side.</param> |
| | 417 | | /// <param name="channelReserveAmount">The channel reserve amount.</param> |
| | 418 | | /// <param name="feeRatePerKw">The fee rate per kw.</param> |
| | 419 | | /// <param name="maxAcceptedHtlcs">The max accepted htlcs.</param> |
| | 420 | | /// <param name="revocationBasepoint">The revocation pubkey.</param> |
| | 421 | | /// <param name="paymentBasepoint">The payment pubkey.</param> |
| | 422 | | /// <param name="delayedPaymentBasepoint">The delayed payment pubkey.</param> |
| | 423 | | /// <param name="htlcBasepoint">The htlc pubkey.</param> |
| | 424 | | /// <param name="firstPerCommitmentPoint">The first per-commitment pubkey.</param> |
| | 425 | | /// <param name="channelFlags">The flags for the channel.</param> |
| | 426 | | /// <param name="upfrontShutdownScriptTlv">The upfront shutdown script tlv.</param> |
| | 427 | | /// <param name="channelTypeTlv">The channel type tlv.</param> |
| | 428 | | /// <returns>The OpenChannel1 message.</returns> |
| | 429 | | /// <seealso cref="OpenChannel1Message"/> |
| | 430 | | /// <seealso cref="ChannelId"/> |
| | 431 | | /// <seealso cref="LightningMoney"/> |
| | 432 | | /// <seealso cref="CompactPubKey"/> |
| | 433 | | /// <seealso cref="UpfrontShutdownScriptTlv"/> |
| | 434 | | /// <seealso cref="ChannelTypeTlv"/> |
| | 435 | | public OpenChannel1Message CreateOpenChannel1Message(ChannelId temporaryChannelId, LightningMoney fundingAmount, |
| | 436 | | CompactPubKey fundingPubKey, LightningMoney pushAmount, |
| | 437 | | LightningMoney channelReserveAmount, |
| | 438 | | LightningMoney feeRatePerKw, ushort maxAcceptedHtlcs, |
| | 439 | | CompactPubKey revocationBasepoint, |
| | 440 | | CompactPubKey paymentBasepoint, |
| | 441 | | CompactPubKey delayedPaymentBasepoint, |
| | 442 | | CompactPubKey htlcBasepoint, |
| | 443 | | CompactPubKey firstPerCommitmentPoint, |
| | 444 | | ChannelFlags channelFlags, |
| | 445 | | UpfrontShutdownScriptTlv? upfrontShutdownScriptTlv, |
| | 446 | | ChannelTypeTlv? channelTypeTlv) |
| | 447 | | { |
| 0 | 448 | | var maxHtlcValueInFlight = |
| 0 | 449 | | LightningMoney.Satoshis(_nodeOptions.AllowUpToPercentageOfChannelFundsInFlight * fundingAmount.Satoshi / |
| 0 | 450 | | 100M); |
| 0 | 451 | | var payload = new OpenChannel1Payload(_nodeOptions.BitcoinNetwork.ChainHash, channelFlags, temporaryChannelId, |
| 0 | 452 | | channelReserveAmount, delayedPaymentBasepoint, |
| 0 | 453 | | _nodeOptions.DustLimitAmount, feeRatePerKw, firstPerCommitmentPoint, |
| 0 | 454 | | fundingAmount, fundingPubKey, htlcBasepoint, |
| 0 | 455 | | _nodeOptions.HtlcMinimumAmount, maxAcceptedHtlcs, maxHtlcValueInFlight, |
| 0 | 456 | | paymentBasepoint, pushAmount, revocationBasepoint, |
| 0 | 457 | | _nodeOptions.ToSelfDelay); |
| | 458 | |
|
| 0 | 459 | | return new OpenChannel1Message(payload, upfrontShutdownScriptTlv, channelTypeTlv); |
| | 460 | | } |
| | 461 | |
|
| | 462 | | /// <summary> |
| | 463 | | /// Create an OpenChannel2 message. |
| | 464 | | /// </summary> |
| | 465 | | /// <param name="temporaryChannelId">The temporary channel id.</param> |
| | 466 | | /// <param name="fundingFeeRatePerKw">The funding fee rate to open the channel.</param> |
| | 467 | | /// <param name="commitmentFeeRatePerKw">The commitment fee rate.</param> |
| | 468 | | /// <param name="fundingSatoshis">The amount of satoshis we're adding to the channel.</param> |
| | 469 | | /// <param name="fundingPubKey">The funding pubkey of the channel.</param> |
| | 470 | | /// <param name="revocationBasepoint">The revocation pubkey.</param> |
| | 471 | | /// <param name="paymentBasepoint">The payment pubkey.</param> |
| | 472 | | /// <param name="delayedPaymentBasepoint">The delayed payment pubkey.</param> |
| | 473 | | /// <param name="htlcBasepoint">The htlc pubkey.</param> |
| | 474 | | /// <param name="firstPerCommitmentPoint">The first per-commitment pubkey.</param> |
| | 475 | | /// <param name="secondPerCommitmentPoint">The second per-commitment pubkey.</param> |
| | 476 | | /// <param name="channelFlags">The flags for the channel.</param> |
| | 477 | | /// <param name="shutdownScriptPubkey">The shutdown script to be used when closing the channel.</param> |
| | 478 | | /// <param name="channelType">The type of the channel.</param> |
| | 479 | | /// <param name="requireConfirmedInputs">If we want confirmed inputs to open the channel.</param> |
| | 480 | | /// <returns>The OpenChannel2 message.</returns> |
| | 481 | | /// <seealso cref="OpenChannel2Message"/> |
| | 482 | | /// <seealso cref="ChannelId"/> |
| | 483 | | /// <seealso cref="CompactPubKey"/> |
| | 484 | | /// <seealso cref="ChannelFlags"/> |
| | 485 | | /// <seealso cref="BitcoinScript"/> |
| | 486 | | /// <seealso cref="OpenChannel2Payload"/> |
| | 487 | | public OpenChannel2Message CreateOpenChannel2Message(ChannelId temporaryChannelId, uint fundingFeeRatePerKw, |
| | 488 | | uint commitmentFeeRatePerKw, ulong fundingSatoshis, |
| | 489 | | CompactPubKey fundingPubKey, |
| | 490 | | CompactPubKey revocationBasepoint, |
| | 491 | | CompactPubKey paymentBasepoint, |
| | 492 | | CompactPubKey delayedPaymentBasepoint, |
| | 493 | | CompactPubKey htlcBasepoint, |
| | 494 | | CompactPubKey firstPerCommitmentPoint, |
| | 495 | | CompactPubKey secondPerCommitmentPoint, |
| | 496 | | ChannelFlags channelFlags, |
| | 497 | | BitcoinScript? shutdownScriptPubkey = null, |
| | 498 | | byte[]? channelType = null, |
| | 499 | | bool requireConfirmedInputs = false) |
| | 500 | | { |
| 0 | 501 | | var maxHtlcValueInFlight = |
| 0 | 502 | | LightningMoney.Satoshis(_nodeOptions.AllowUpToPercentageOfChannelFundsInFlight * fundingSatoshis / 100M); |
| | 503 | |
|
| 0 | 504 | | var payload = new OpenChannel2Payload(_bitcoinNetwork.ChainHash, channelFlags, commitmentFeeRatePerKw, |
| 0 | 505 | | delayedPaymentBasepoint, _nodeOptions.DustLimitAmount, |
| 0 | 506 | | firstPerCommitmentPoint, fundingSatoshis, fundingFeeRatePerKw, |
| 0 | 507 | | fundingPubKey, htlcBasepoint, _nodeOptions.HtlcMinimumAmount, |
| 0 | 508 | | _nodeOptions.Locktime, _nodeOptions.MaxAcceptedHtlcs, |
| 0 | 509 | | maxHtlcValueInFlight, paymentBasepoint, revocationBasepoint, |
| 0 | 510 | | secondPerCommitmentPoint, _nodeOptions.ToSelfDelay, temporaryChannelId); |
| | 511 | |
|
| 0 | 512 | | return new OpenChannel2Message(payload, |
| 0 | 513 | | shutdownScriptPubkey is null |
| 0 | 514 | | ? null |
| 0 | 515 | | : new UpfrontShutdownScriptTlv(shutdownScriptPubkey.Value), |
| 0 | 516 | | channelType is null |
| 0 | 517 | | ? null |
| 0 | 518 | | : new ChannelTypeTlv(channelType), |
| 0 | 519 | | requireConfirmedInputs ? new RequireConfirmedInputsTlv() : null); |
| | 520 | | } |
| | 521 | |
|
| | 522 | | /// <summary> |
| | 523 | | /// Creates an AcceptChannel1 message. |
| | 524 | | /// </summary> |
| | 525 | | /// <param name="channelReserveAmount">The reserve amount for the channel.</param> |
| | 526 | | /// <param name="channelTypeTlv">Optional parameter specifying the channel type.</param> |
| | 527 | | /// <param name="delayedPaymentBasepoint">The basepoint for the delayed payment key.</param> |
| | 528 | | /// <param name="firstPerCommitmentPoint">The first per-commitment point for the channel.</param> |
| | 529 | | /// <param name="fundingPubKey">Public key associated with the channel funding.</param> |
| | 530 | | /// <param name="htlcBasepoint">The basepoint for the HTLC key.</param> |
| | 531 | | /// <param name="maxAcceptedHtlcs">The maximum number of HTLCs to be accepted for this channel.</param> |
| | 532 | | /// <param name="maxHtlcValueInFlight">The maximum HTLC value that can be in flight.</param> |
| | 533 | | /// <param name="minimumDepth">The minimum confirmation depth required for the channel opening transaction.</param> |
| | 534 | | /// <param name="paymentBasepoint">The basepoint for the payment key.</param> |
| | 535 | | /// <param name="revocationBasepoint">The basepoint for the revocation key.</param> |
| | 536 | | /// <param name="temporaryChannelId">The temporary identifier for the channel negotiation.</param> |
| | 537 | | /// <param name="toSelfDelay">The delay in blocks before self outputs can be claimed.</param> |
| | 538 | | /// <param name="upfrontShutdownScriptTlv">Optional parameter specifying the upfront shutdown script TLV.</param> |
| | 539 | | /// <returns>The created AcceptChannel1 message.</returns> |
| | 540 | | /// <seealso cref="AcceptChannel1Message"/> |
| | 541 | | /// <seealso cref="AcceptChannel1Payload"/> |
| | 542 | | /// <seealso cref="ChannelId"/> |
| | 543 | | /// <seealso cref="LightningMoney"/> |
| | 544 | | /// <seealso cref="CompactPubKey"/> |
| | 545 | | /// <seealso cref="UpfrontShutdownScriptTlv"/> |
| | 546 | | /// <seealso cref="ChannelTypeTlv"/> |
| | 547 | | public AcceptChannel1Message CreateAcceptChannel1Message(LightningMoney channelReserveAmount, |
| | 548 | | ChannelTypeTlv? channelTypeTlv, |
| | 549 | | CompactPubKey delayedPaymentBasepoint, |
| | 550 | | CompactPubKey firstPerCommitmentPoint, |
| | 551 | | CompactPubKey fundingPubKey, CompactPubKey htlcBasepoint, |
| | 552 | | ushort maxAcceptedHtlcs, |
| | 553 | | LightningMoney maxHtlcValueInFlight, uint minimumDepth, |
| | 554 | | CompactPubKey paymentBasepoint, |
| | 555 | | CompactPubKey revocationBasepoint, |
| | 556 | | ChannelId temporaryChannelId, ushort toSelfDelay, |
| | 557 | | UpfrontShutdownScriptTlv? upfrontShutdownScriptTlv) |
| | 558 | | { |
| 0 | 559 | | var payload = new AcceptChannel1Payload(temporaryChannelId, channelReserveAmount, delayedPaymentBasepoint, |
| 0 | 560 | | _nodeOptions.DustLimitAmount, firstPerCommitmentPoint, fundingPubKey, |
| 0 | 561 | | htlcBasepoint, _nodeOptions.HtlcMinimumAmount, maxAcceptedHtlcs, |
| 0 | 562 | | maxHtlcValueInFlight, minimumDepth, paymentBasepoint, |
| 0 | 563 | | revocationBasepoint, toSelfDelay); |
| | 564 | |
|
| 0 | 565 | | return new AcceptChannel1Message(payload, upfrontShutdownScriptTlv, channelTypeTlv); |
| | 566 | | } |
| | 567 | |
|
| | 568 | | /// <summary> |
| | 569 | | /// Create an AcceptChannel2 message. |
| | 570 | | /// </summary> |
| | 571 | | /// <param name="temporaryChannelId">The temporary channel id.</param> |
| | 572 | | /// <param name="fundingSatoshis">The amount of satoshis we're adding to the channel.</param> |
| | 573 | | /// <param name="fundingPubKey">The funding pubkey of the channel.</param> |
| | 574 | | /// <param name="revocationBasepoint">The revocation pubkey.</param> |
| | 575 | | /// <param name="paymentBasepoint">The payment pubkey.</param> |
| | 576 | | /// <param name="delayedPaymentBasepoint">The delayed payment pubkey.</param> |
| | 577 | | /// <param name="htlcBasepoint">The htlc pubkey.</param> |
| | 578 | | /// <param name="firstPerCommitmentPoint">The first per-commitment pubkey.</param> |
| | 579 | | /// <param name="maxHtlcValueInFlight">Maximum HTLC value that can be in flight.</param> |
| | 580 | | /// <param name="shutdownScriptPubkey">The shutdown script to be used when closing the channel.</param> |
| | 581 | | /// <param name="channelType">The type of the channel.</param> |
| | 582 | | /// <param name="requireConfirmedInputs">If we want confirmed inputs to open the channel.</param> |
| | 583 | | /// <returns>The AcceptChannel2 message.</returns> |
| | 584 | | /// <seealso cref="AcceptChannel2Message"/> |
| | 585 | | /// <seealso cref="ChannelId"/> |
| | 586 | | /// <seealso cref="CompactPubKey"/> |
| | 587 | | /// <seealso cref="BitcoinScript"/> |
| | 588 | | /// <seealso cref="AcceptChannel2Payload"/> |
| | 589 | | public AcceptChannel2Message CreateAcceptChannel2Message(ChannelId temporaryChannelId, |
| | 590 | | LightningMoney fundingSatoshis, |
| | 591 | | CompactPubKey fundingPubKey, |
| | 592 | | CompactPubKey revocationBasepoint, |
| | 593 | | CompactPubKey paymentBasepoint, |
| | 594 | | CompactPubKey delayedPaymentBasepoint, |
| | 595 | | CompactPubKey htlcBasepoint, |
| | 596 | | CompactPubKey firstPerCommitmentPoint, |
| | 597 | | LightningMoney maxHtlcValueInFlight, |
| | 598 | | BitcoinScript? shutdownScriptPubkey = null, |
| | 599 | | byte[]? channelType = null, |
| | 600 | | bool requireConfirmedInputs = false) |
| | 601 | | { |
| 0 | 602 | | var payload = new AcceptChannel2Payload(delayedPaymentBasepoint, _nodeOptions.DustLimitAmount, |
| 0 | 603 | | firstPerCommitmentPoint, fundingSatoshis, fundingPubKey, |
| 0 | 604 | | htlcBasepoint, _nodeOptions.HtlcMinimumAmount, |
| 0 | 605 | | _nodeOptions.MaxAcceptedHtlcs, maxHtlcValueInFlight, |
| 0 | 606 | | _nodeOptions.MinimumDepth, paymentBasepoint, revocationBasepoint, |
| 0 | 607 | | temporaryChannelId, _nodeOptions.ToSelfDelay); |
| | 608 | |
|
| 0 | 609 | | return new AcceptChannel2Message(payload, |
| 0 | 610 | | shutdownScriptPubkey is null |
| 0 | 611 | | ? null |
| 0 | 612 | | : new UpfrontShutdownScriptTlv(shutdownScriptPubkey.Value), |
| 0 | 613 | | channelType is null |
| 0 | 614 | | ? null |
| 0 | 615 | | : new ChannelTypeTlv(channelType), |
| 0 | 616 | | requireConfirmedInputs ? new RequireConfirmedInputsTlv() : null); |
| | 617 | | } |
| | 618 | |
|
| | 619 | | /// <summary> |
| | 620 | | /// Create a FundingCreated message. |
| | 621 | | /// </summary> |
| | 622 | | /// <param name="temporaryChannelId">The temporary channel id.</param> |
| | 623 | | /// <param name="fundingTxId">The funding transaction id.</param> |
| | 624 | | /// <param name="fundingOutputIndex">The funding output index.</param> |
| | 625 | | /// <param name="signature">The signature for the funding transaction.</param> |
| | 626 | | /// <returns>The FundingCreated message.</returns> |
| | 627 | | /// <seealso cref="FundingCreatedMessage"/> |
| | 628 | | /// <seealso cref="ChannelId"/> |
| | 629 | | /// <seealso cref="CompactSignature"/> |
| | 630 | | /// <seealso cref="FundingCreatedPayload"/> |
| | 631 | | public FundingCreatedMessage CreatedFundingCreatedMessage(ChannelId temporaryChannelId, TxId fundingTxId, |
| | 632 | | ushort fundingOutputIndex, CompactSignature signature) |
| | 633 | | { |
| 0 | 634 | | var payload = new FundingCreatedPayload(temporaryChannelId, fundingTxId, fundingOutputIndex, signature); |
| | 635 | |
|
| 0 | 636 | | return new FundingCreatedMessage(payload); |
| | 637 | | } |
| | 638 | |
|
| | 639 | | /// <summary> |
| | 640 | | /// Create a FundingSigned message. |
| | 641 | | /// </summary> |
| | 642 | | /// <param name="channelId">The channel id.</param> |
| | 643 | | /// <param name="signature"></param> |
| | 644 | | /// <returns>The FundingSigned message.</returns> |
| | 645 | | /// <seealso cref="FundingCreatedMessage"/> |
| | 646 | | /// <seealso cref="ChannelId"/> |
| | 647 | | /// <seealso cref="CompactSignature"/> |
| | 648 | | /// <seealso cref="FundingCreatedPayload"/> |
| | 649 | | public FundingSignedMessage CreatedFundingSignedMessage(ChannelId channelId, CompactSignature signature) |
| | 650 | | { |
| 0 | 651 | | var payload = new FundingSignedPayload(channelId, signature); |
| | 652 | |
|
| 0 | 653 | | return new FundingSignedMessage(payload); |
| | 654 | | } |
| | 655 | |
|
| | 656 | | #endregion |
| | 657 | |
|
| | 658 | | #region Commitment |
| | 659 | |
|
| | 660 | | /// <summary> |
| | 661 | | /// Create an UpdateAddHtlc message. |
| | 662 | | /// </summary> |
| | 663 | | /// <param name="channelId">The channel id.</param> |
| | 664 | | /// <param name="id">The htlc id.</param> |
| | 665 | | /// <param name="amountMsat">The amount for this htlc.</param> |
| | 666 | | /// <param name="paymentHash">The htlc payment hash.</param> |
| | 667 | | /// <param name="cltvExpiry">The cltv expiry.</param> |
| | 668 | | /// <param name="onionRoutingPacket">The onion routing packet.</param> |
| | 669 | | /// <returns>The UpdateAddHtlc message.</returns> |
| | 670 | | /// <seealso cref="UpdateAddHtlcMessage"/> |
| | 671 | | /// <seealso cref="ChannelId"/> |
| | 672 | | /// <seealso cref="UpdateAddHtlcPayload"/> |
| | 673 | | public UpdateAddHtlcMessage CreateUpdateAddHtlcMessage(ChannelId channelId, ulong id, ulong amountMsat, |
| | 674 | | ReadOnlyMemory<byte> paymentHash, uint cltvExpiry, |
| | 675 | | ReadOnlyMemory<byte>? onionRoutingPacket = null) |
| | 676 | | { |
| 0 | 677 | | var payload = new UpdateAddHtlcPayload(amountMsat, channelId, cltvExpiry, id, paymentHash, onionRoutingPacket); |
| | 678 | |
|
| 0 | 679 | | return new UpdateAddHtlcMessage(payload); |
| | 680 | | } |
| | 681 | |
|
| | 682 | | /// <summary> |
| | 683 | | /// Create an UpdateFulfillHtlc message. |
| | 684 | | /// </summary> |
| | 685 | | /// <param name="channelId">The channel id.</param> |
| | 686 | | /// <param name="id">The htlc id.</param> |
| | 687 | | /// <param name="preimage">The preimage for this htlc.</param> |
| | 688 | | /// <returns>The UpdateFulfillHtlc message.</returns> |
| | 689 | | /// <seealso cref="UpdateFulfillHtlcMessage"/> |
| | 690 | | /// <seealso cref="ChannelId"/> |
| | 691 | | /// <seealso cref="UpdateFulfillHtlcPayload"/> |
| | 692 | | public UpdateFulfillHtlcMessage CreateUpdateFulfillHtlcMessage(ChannelId channelId, ulong id, |
| | 693 | | ReadOnlyMemory<byte> preimage) |
| | 694 | | { |
| 0 | 695 | | var payload = new UpdateFulfillHtlcPayload(channelId, id, preimage); |
| | 696 | |
|
| 0 | 697 | | return new UpdateFulfillHtlcMessage(payload); |
| | 698 | | } |
| | 699 | |
|
| | 700 | | /// <summary> |
| | 701 | | /// Create an UpdateFailHtlc message. |
| | 702 | | /// </summary> |
| | 703 | | /// <param name="channelId">The channel id.</param> |
| | 704 | | /// <param name="id">The htlc id.</param> |
| | 705 | | /// <param name="reason">The reason for failure.</param> |
| | 706 | | /// <returns>The UpdateFailHtlc message.</returns> |
| | 707 | | /// <seealso cref="UpdateFailHtlcMessage"/> |
| | 708 | | /// <seealso cref="ChannelId"/> |
| | 709 | | /// <seealso cref="UpdateFailHtlcPayload"/> |
| | 710 | | public UpdateFailHtlcMessage CreateUpdateFailHtlcMessage(ChannelId channelId, ulong id, ReadOnlyMemory<byte> reason) |
| | 711 | | { |
| 0 | 712 | | var payload = new UpdateFailHtlcPayload(channelId, id, reason); |
| | 713 | |
|
| 0 | 714 | | return new UpdateFailHtlcMessage(payload); |
| | 715 | | } |
| | 716 | |
|
| | 717 | | /// <summary> |
| | 718 | | /// Create a CommitmentSigned message. |
| | 719 | | /// </summary> |
| | 720 | | /// <param name="channelId">The channel id.</param> |
| | 721 | | /// <param name="signature">The signature for the commitment transaction.</param> |
| | 722 | | /// <param name="htlcSignatures">The signatures for each open htlc.</param> |
| | 723 | | /// <returns>The CommitmentSigned message.</returns> |
| | 724 | | /// <seealso cref="CommitmentSignedMessage"/> |
| | 725 | | /// <seealso cref="ChannelId"/> |
| | 726 | | /// <seealso cref="CompactSignature"/> |
| | 727 | | /// <seealso cref="CommitmentSignedPayload"/> |
| | 728 | | public CommitmentSignedMessage CreateCommitmentSignedMessage(ChannelId channelId, CompactSignature signature, |
| | 729 | | IEnumerable<CompactSignature> htlcSignatures) |
| | 730 | | { |
| 0 | 731 | | var payload = new CommitmentSignedPayload(channelId, htlcSignatures, signature); |
| | 732 | |
|
| 0 | 733 | | return new CommitmentSignedMessage(payload); |
| | 734 | | } |
| | 735 | |
|
| | 736 | | /// <summary> |
| | 737 | | /// Create a RevokeAndAck message. |
| | 738 | | /// </summary> |
| | 739 | | /// <param name="channelId">The channel id.</param> |
| | 740 | | /// <param name="perCommitmentSecret">The secret for the commitment transaction.</param> |
| | 741 | | /// <param name="nextPerCommitmentPoint">The next per commitment point.</param> |
| | 742 | | /// <returns>The RevokeAndAck message.</returns> |
| | 743 | | /// <seealso cref="RevokeAndAckMessage"/> |
| | 744 | | /// <seealso cref="ChannelId"/> |
| | 745 | | /// <seealso cref="CompactSignature"/> |
| | 746 | | /// <seealso cref="RevokeAndAckPayload"/> |
| | 747 | | public RevokeAndAckMessage CreateRevokeAndAckMessage(ChannelId channelId, ReadOnlyMemory<byte> perCommitmentSecret, |
| | 748 | | CompactPubKey nextPerCommitmentPoint) |
| | 749 | | { |
| 0 | 750 | | var payload = new RevokeAndAckPayload(channelId, nextPerCommitmentPoint, perCommitmentSecret); |
| | 751 | |
|
| 0 | 752 | | return new RevokeAndAckMessage(payload); |
| | 753 | | } |
| | 754 | |
|
| | 755 | | /// <summary> |
| | 756 | | /// Create a UpdateFee message. |
| | 757 | | /// </summary> |
| | 758 | | /// <param name="channelId">The channel id.</param> |
| | 759 | | /// <param name="feeratePerKw">The fee rate for the commitment transaction.</param> |
| | 760 | | /// <returns>The UpdateFee message.</returns> |
| | 761 | | /// <seealso cref="UpdateFeeMessage"/> |
| | 762 | | /// <seealso cref="ChannelId"/> |
| | 763 | | /// <seealso cref="UpdateFeePayload"/> |
| | 764 | | public UpdateFeeMessage CreateUpdateFeeMessage(ChannelId channelId, uint feeratePerKw) |
| | 765 | | { |
| 0 | 766 | | var payload = new UpdateFeePayload(channelId, feeratePerKw); |
| | 767 | |
|
| 0 | 768 | | return new UpdateFeeMessage(payload); |
| | 769 | | } |
| | 770 | |
|
| | 771 | | /// <summary> |
| | 772 | | /// Create an UpdateFailMalformedHtlc message. |
| | 773 | | /// </summary> |
| | 774 | | /// <param name="channelId">The channel id.</param> |
| | 775 | | /// <param name="id">The htlc id.</param> |
| | 776 | | /// <param name="sha256OfOnion">The sha256OfOnion for this htlc.</param> |
| | 777 | | /// <param name="failureCode">The failureCode.</param> |
| | 778 | | /// <returns>The UpdateFailMalformedHtlc message.</returns> |
| | 779 | | /// <seealso cref="UpdateFailMalformedHtlcMessage"/> |
| | 780 | | /// <seealso cref="ChannelId"/> |
| | 781 | | /// <seealso cref="UpdateFailMalformedHtlcPayload"/> |
| | 782 | | public UpdateFailMalformedHtlcMessage CreateUpdateFailMalformedHtlcMessage(ChannelId channelId, ulong id, |
| | 783 | | ReadOnlyMemory<byte> sha256OfOnion, |
| | 784 | | ushort failureCode) |
| | 785 | | { |
| 0 | 786 | | var payload = new UpdateFailMalformedHtlcPayload(channelId, failureCode, id, sha256OfOnion); |
| | 787 | |
|
| 0 | 788 | | return new UpdateFailMalformedHtlcMessage(payload); |
| | 789 | | } |
| | 790 | |
|
| | 791 | | /// <summary> |
| | 792 | | /// Create a ChannelReestablish message. |
| | 793 | | /// </summary> |
| | 794 | | /// <param name="channelId">The channel id.</param> |
| | 795 | | /// <param name="nextCommitmentNumber">The next commitment number.</param> |
| | 796 | | /// <param name="nextRevocationNumber">The next revocation number.</param> |
| | 797 | | /// <param name="yourLastPerCommitmentSecret">The peer's last per-commitment secret.</param> |
| | 798 | | /// <param name="myCurrentPerCommitmentPoint">Our current per commitment point.</param> |
| | 799 | | /// <returns>The ChannelReestablish message.</returns> |
| | 800 | | /// <seealso cref="ChannelReestablishMessage"/> |
| | 801 | | /// <seealso cref="ChannelId"/> |
| | 802 | | /// <seealso cref="ChannelReestablishPayload"/> |
| | 803 | | public ChannelReestablishMessage CreateChannelReestablishMessage(ChannelId channelId, ulong nextCommitmentNumber, |
| | 804 | | ulong nextRevocationNumber, |
| | 805 | | ReadOnlyMemory<byte> yourLastPerCommitmentSecret, |
| | 806 | | CompactPubKey myCurrentPerCommitmentPoint) |
| | 807 | | { |
| 0 | 808 | | var payload = new ChannelReestablishPayload(channelId, myCurrentPerCommitmentPoint, nextCommitmentNumber, |
| 0 | 809 | | nextRevocationNumber, yourLastPerCommitmentSecret); |
| | 810 | |
|
| 0 | 811 | | return new ChannelReestablishMessage(payload); |
| | 812 | | } |
| | 813 | |
|
| | 814 | | #endregion |
| | 815 | | } |