Class MessageFactory
- Namespace
- NLightning.Bolts.Factories
- Assembly
- NLightning.Bolts.dll
Factory for creating messages.
public static class MessageFactory
- Inheritance
-
MessageFactory
- Inherited Members
Methods
CreateAcceptChannel2Message(ChannelId, ulong, PubKey, PubKey, PubKey, PubKey, PubKey, PubKey, Script?, byte[]?, bool)
Create a AcceptChannel2 message.
public static IMessage CreateAcceptChannel2Message(ChannelId temporaryChannelId, ulong fundingSatoshis, PubKey fundingPubKey, PubKey revocationBasepoint, PubKey paymentBasepoint, PubKey delayedPaymentBasepoint, PubKey htlcBasepoint, PubKey firstPerCommitmentPoint, Script? shutdownScriptPubkey = null, byte[]? channelType = null, bool requireConfirmedInputs = false)
Parameters
temporaryChannelId
ChannelIdThe temporary channel id.
fundingSatoshis
ulongThe amount of satoshis we're adding to the channel.
fundingPubKey
PubKeyThe funding pubkey of the channel.
revocationBasepoint
PubKeyThe revocation pubkey.
paymentBasepoint
PubKeyThe payment pubkey.
delayedPaymentBasepoint
PubKeyThe delayed payment pubkey.
htlcBasepoint
PubKeyThe htlc pubkey.
firstPerCommitmentPoint
PubKeyThe first per commitment pubkey.
shutdownScriptPubkey
ScriptThe shutdown script to be used when closing the channel.
channelType
byte[]The type of the channel.
requireConfirmedInputs
boolIf we want confirmed inputs to open the channel.
Returns
- IMessage
The AcceptChannel2 message.
- See Also
-
PubKeyScript
CreateChannelReadyMessage(ChannelId, PubKey, ShortChannelId?)
Create a ChannelReady message.
public static IMessage CreateChannelReadyMessage(ChannelId channelId, PubKey secondPerCommitmentPoint, ShortChannelId? shortChannelId = null)
Parameters
channelId
ChannelIdThe channel id.
secondPerCommitmentPoint
PubKeyThe second per commitment point.
shortChannelId
ShortChannelId?The channel's shortChannelId.
Returns
- IMessage
The ChannelReady message.
- See Also
-
PubKey
CreateChannelReestablishMessage(ChannelId, ulong, ulong, ReadOnlyMemory<byte>, PubKey)
Create a ChannelReestablish message.
public static IMessage CreateChannelReestablishMessage(ChannelId channelId, ulong nextCommitmentNumber, ulong nextRevocationNumber, ReadOnlyMemory<byte> yourLastPerCommitmentSecret, PubKey myCurrentPerCommitmentPoint)
Parameters
channelId
ChannelIdThe channel id.
nextCommitmentNumber
ulongThe next commitment number.
nextRevocationNumber
ulongThe next revocation number.
yourLastPerCommitmentSecret
ReadOnlyMemory<byte>The peer last per commitment secret.
myCurrentPerCommitmentPoint
PubKeyOur current per commitment point.
Returns
- IMessage
The ChannelReestablish message.
- See Also
CreateClosingSignedMessage(ChannelId, ulong, ECDSASignature, ulong, ulong)
Create a ClosingSigned message.
public static IMessage CreateClosingSignedMessage(ChannelId channelId, ulong feeSatoshis, ECDSASignature signature, ulong minFeeSatoshis, ulong maxFeeSatoshis)
Parameters
channelId
ChannelIdThe channel id.
feeSatoshis
ulongThe fee we want them to pay for closing the channel.
signature
ECDSASignatureThe signature for closing the channel.
minFeeSatoshis
ulongThe min fee we will accept them to pay to close the channel.
maxFeeSatoshis
ulongThe max fee we will accept them to pay to close the channel.
Returns
- IMessage
The ClosingSigned message.
- See Also
-
ECDSASignature
CreateCommitmentSignedMessage(ChannelId, ECDSASignature, IEnumerable<ECDSASignature>)
Create a CommitmentSigned message.
public static IMessage CreateCommitmentSignedMessage(ChannelId channelId, ECDSASignature signature, IEnumerable<ECDSASignature> htlcSignatures)
Parameters
channelId
ChannelIdThe channel id.
signature
ECDSASignatureThe signature for the commitment transaction.
htlcSignatures
IEnumerable<ECDSASignature>The signatures for each open htlc.
Returns
- IMessage
The CommitmentSigned message.
- See Also
-
ECDSASignature
CreateCommitmentSignedMessage(ChannelId, ReadOnlyMemory<byte>, PubKey)
Create a RevokeAndAck message.
public static IMessage CreateCommitmentSignedMessage(ChannelId channelId, ReadOnlyMemory<byte> perCommitmentSecret, PubKey nextPerCommitmentPoint)
Parameters
channelId
ChannelIdThe channel id.
perCommitmentSecret
ReadOnlyMemory<byte>The secret for the commitment transaction.
nextPerCommitmentPoint
PubKeyThe next per commitment point.
Returns
- IMessage
The RevokeAndAck message.
- See Also
-
ECDSASignature
CreateErrorMessage(byte[], ChannelId?)
Create a Error message.
public static IMessage CreateErrorMessage(byte[] data, ChannelId? channelId)
Parameters
Returns
- IMessage
The Error message.
- See Also
CreateErrorMessage(string, ChannelId?)
Create a Error message.
public static IMessage CreateErrorMessage(string message, ChannelId? channelId)
Parameters
Returns
- IMessage
The Error message.
- See Also
CreateInitMessage(NodeOptions)
Create an Init message.
public static IMessage CreateInitMessage(NodeOptions options)
Parameters
options
NodeOptionsThe node options.
Returns
- IMessage
The Init message.
- See Also
CreateOpenChannel2Message(ChannelId, uint, uint, ulong, PubKey, PubKey, PubKey, PubKey, PubKey, PubKey, PubKey, ChannelFlags, Script?, byte[]?, bool)
Create a OpenChannel2 message.
public static IMessage CreateOpenChannel2Message(ChannelId temporaryChannelId, uint fundingFeeRatePerKw, uint commitmentFeeRatePerKw, ulong fundingSatoshis, PubKey fundingPubKey, PubKey revocationBasepoint, PubKey paymentBasepoint, PubKey delayedPaymentBasepoint, PubKey htlcBasepoint, PubKey firstPerCommitmentPoint, PubKey secondPerCommitmentPoint, ChannelFlags channelFlags, Script? shutdownScriptPubkey = null, byte[]? channelType = null, bool requireConfirmedInputs = false)
Parameters
temporaryChannelId
ChannelIdThe temporary channel id.
fundingFeeRatePerKw
uintThe funding fee rate to open the channel.
commitmentFeeRatePerKw
uintThe commitment fee rate.
fundingSatoshis
ulongThe amount of satoshis we're adding to the channel.
fundingPubKey
PubKeyThe funding pubkey of the channel.
revocationBasepoint
PubKeyThe revocation pubkey.
paymentBasepoint
PubKeyThe payment pubkey.
delayedPaymentBasepoint
PubKeyThe delayed payment pubkey.
htlcBasepoint
PubKeyThe htlc pubkey.
firstPerCommitmentPoint
PubKeyThe first per commitment pubkey.
secondPerCommitmentPoint
PubKeyThe second per commitment pubkey.
channelFlags
ChannelFlagsThe flags for the channel.
shutdownScriptPubkey
ScriptThe shutdown script to be used when closing the channel.
channelType
byte[]The type of the channel.
requireConfirmedInputs
boolIf we want confirmed inputs to open the channel.
Returns
- IMessage
The OpenChannel2 message.
- See Also
-
PubKeyScript
CreatePingMessage()
Create a Ping message.
public static IMessage CreatePingMessage()
Returns
- IMessage
The Ping message.
- See Also
CreatePongMessage(ushort)
Create a Pong message.
public static IMessage CreatePongMessage(ushort bytesLen)
Parameters
bytesLen
ushortThe number of bytes in the pong payload.
Returns
- IMessage
The Pong message.
- See Also
CreateShutdownMessage(ChannelId, Script)
Create a Shutdown message.
public static IMessage CreateShutdownMessage(ChannelId channelId, Script scriptPubkey)
Parameters
channelId
ChannelIdThe channel id.
scriptPubkey
ScriptThe Script to send closing funds to.
Returns
- IMessage
The Shutdown message.
- See Also
-
Script
CreateStfuMessage(ChannelId, bool)
Create a Stfu message.
public static IMessage CreateStfuMessage(ChannelId channelId, bool initiator)
Parameters
Returns
- IMessage
The Stfu message.
- See Also
CreateTxAbortMessage(ChannelId, byte[])
Create a TxAbort message.
public static IMessage CreateTxAbortMessage(ChannelId channelId, byte[] data)
Parameters
Returns
- IMessage
The TxAbort message.
- See Also
CreateTxAckRbfMessage(ChannelId, long, bool)
Create a TxAckRbf message.
public static IMessage CreateTxAckRbfMessage(ChannelId channelId, long fundingOutputContrubution, bool requireConfirmedInputs)
Parameters
channelId
ChannelIdThe channel id.
fundingOutputContrubution
longThe output contribution.
requireConfirmedInputs
boolHow many confirmed inputs we need.
Returns
- IMessage
The TxAckRbf message.
- See Also
CreateTxAddInputMessage(ChannelId, ulong, byte[], uint, uint)
Create a TxAddInput message.
public static IMessage CreateTxAddInputMessage(ChannelId channelId, ulong serialId, byte[] prevTx, uint prevTxVout, uint sequence)
Parameters
channelId
ChannelIdThe channel id.
serialId
ulongThe serial id.
prevTx
byte[]The previous transaction.
prevTxVout
uintThe previous transaction vout.
sequence
uintThe sequence number.
Returns
- IMessage
The TxAddInput message.
- See Also
CreateTxAddOutputMessage(ChannelId, ulong, ulong, byte[])
Create a TxAddOutput message.
public static IMessage CreateTxAddOutputMessage(ChannelId channelId, ulong serialId, ulong sats, byte[] script)
Parameters
channelId
ChannelIdThe channel id.
serialId
ulongThe serial id.
sats
ulongThe number of satoshis.
script
byte[]The script.
Returns
- IMessage
The TxAddOutput message.
- See Also
CreateTxCompleteMessage(ChannelId)
Create a TxComplete message.
public static IMessage CreateTxCompleteMessage(ChannelId channelId)
Parameters
channelId
ChannelIdThe channel id.
Returns
- IMessage
The TxComplete message.
- See Also
CreateTxInitRbfMessage(ChannelId, uint, uint, long, bool)
Create a TxInitRbf message.
public static IMessage CreateTxInitRbfMessage(ChannelId channelId, uint locktime, uint feerate, long fundingOutputContrubution, bool requireConfirmedInputs)
Parameters
channelId
ChannelIdThe channel id.
locktime
uintThe locktime.
feerate
uintThe feerate
fundingOutputContrubution
longThe output contribution.
requireConfirmedInputs
boolHow many confirmed inputs we need.
Returns
- IMessage
The TxInitRbf message.
- See Also
CreateTxRemoveInputMessage(ChannelId, ulong)
Create a TxRemoveInput message.
public static IMessage CreateTxRemoveInputMessage(ChannelId channelId, ulong serialId)
Parameters
Returns
- IMessage
The TxRemoveInput message.
- See Also
CreateTxRemoveOutputMessage(ChannelId, ulong)
Create a TxRemoveOutput message.
public static IMessage CreateTxRemoveOutputMessage(ChannelId channelId, ulong serialId)
Parameters
Returns
- IMessage
The TxRemoveOutput message.
- See Also
CreateTxSignaturesMessage(ChannelId, byte[], List<Witness>)
Create a TxSignatures message.
public static IMessage CreateTxSignaturesMessage(ChannelId channelId, byte[] txId, List<Witness> witnesses)
Parameters
channelId
ChannelIdThe channel id.
txId
byte[]The transaction id.
witnesses
List<Witness>The witnesses.
Returns
- IMessage
The TxSignatures message.
- See Also
CreateUpdateAddHtlcMessage(ChannelId, ulong, ulong, ReadOnlyMemory<byte>, uint, ReadOnlyMemory<byte>?)
Create a UpdateAddHtlc message.
public static IMessage CreateUpdateAddHtlcMessage(ChannelId channelId, ulong id, ulong amountMsat, ReadOnlyMemory<byte> paymentHash, uint cltvExpiry, ReadOnlyMemory<byte>? onionRoutingPacket = null)
Parameters
channelId
ChannelIdThe channel id.
id
ulongThe htlc id.
amountMsat
ulongThe amount for this htlc.
paymentHash
ReadOnlyMemory<byte>The htlc payment hash.
cltvExpiry
uintThe cltv expiry.
onionRoutingPacket
ReadOnlyMemory<byte>?The onion routing packet.
Returns
- IMessage
The UpdateAddHtlc message.
- See Also
CreateUpdateFailHtlcMessage(ChannelId, ulong, ReadOnlyMemory<byte>)
Create a UpdateFailHtlc message.
public static IMessage CreateUpdateFailHtlcMessage(ChannelId channelId, ulong id, ReadOnlyMemory<byte> reason)
Parameters
channelId
ChannelIdThe channel id.
id
ulongThe htlc id.
reason
ReadOnlyMemory<byte>The reason for failure.
Returns
- IMessage
The UpdateFailHtlc message.
- See Also
CreateUpdateFailMalformedHtlcMessage(ChannelId, ulong, ReadOnlyMemory<byte>, ushort)
Create a UpdateFailMalformedHtlc message.
public static IMessage CreateUpdateFailMalformedHtlcMessage(ChannelId channelId, ulong id, ReadOnlyMemory<byte> sha256OfOnion, ushort failureCode)
Parameters
channelId
ChannelIdThe channel id.
id
ulongThe htlc id.
sha256OfOnion
ReadOnlyMemory<byte>The sha256OfOnion for this htlc.
failureCode
ushortThe failureCode.
Returns
- IMessage
The UpdateFailMalformedHtlc message.
- See Also
CreateUpdateFeeMessage(ChannelId, uint)
Create a UpdateFee message.
public static IMessage CreateUpdateFeeMessage(ChannelId channelId, uint feeratePerKw)
Parameters
Returns
- IMessage
The UpdateFee message.
- See Also
CreateUpdateFulfillHtlcMessage(ChannelId, ulong, ReadOnlyMemory<byte>)
Create a UpdateFulfillHtlc message.
public static IMessage CreateUpdateFulfillHtlcMessage(ChannelId channelId, ulong id, ReadOnlyMemory<byte> preimage)
Parameters
channelId
ChannelIdThe channel id.
id
ulongThe htlc id.
preimage
ReadOnlyMemory<byte>The preimage for this htlc.
Returns
- IMessage
The UpdateFulfillHtlc message.
- See Also
CreateWarningMessage(byte[], ChannelId?)
Create a Warning message.
public static IMessage CreateWarningMessage(byte[] data, ChannelId? channelId)
Parameters
Returns
- IMessage
The Warning message.
- See Also
CreateWarningMessage(string, ChannelId?)
Create a Warning message.
public static IMessage CreateWarningMessage(string message, ChannelId? channelId)
Parameters
Returns
- IMessage
The Warning message.
- See Also
DeserializeMessageAsync(MemoryStream)
Deserialize a message from a stream.
public static Task<IMessage> DeserializeMessageAsync(MemoryStream stream)
Parameters
stream
MemoryStreamThe stream to deserialize from.
Returns
Exceptions
- InvalidMessageException
Unknown message type