|
| 1 | +package chancloser |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/btcsuite/btcd/btcec/v2" |
| 5 | + "github.com/btcsuite/btcd/btcutil" |
| 6 | + "github.com/btcsuite/btcd/wire" |
| 7 | + "github.com/lightningnetwork/lnd/fn" |
| 8 | + "github.com/lightningnetwork/lnd/lnwallet" |
| 9 | + "github.com/lightningnetwork/lnd/lnwire" |
| 10 | + "github.com/lightningnetwork/lnd/tlv" |
| 11 | +) |
| 12 | + |
| 13 | +// CloseOutput represents an output that should be included in the close |
| 14 | +// transaction. |
| 15 | +type CloseOutput struct { |
| 16 | + // Amt is the amount of the output. |
| 17 | + Amt btcutil.Amount |
| 18 | + |
| 19 | + // DustLimit is the dust limit for the local node. |
| 20 | + DustLimit btcutil.Amount |
| 21 | + |
| 22 | + // PkScript is the script that should be used to pay to the output. |
| 23 | + PkScript []byte |
| 24 | + |
| 25 | + // ShutdownRecords is the set of custom records that may result in |
| 26 | + // extra close outputs being added. |
| 27 | + ShutdownRecords lnwire.CustomRecords |
| 28 | +} |
| 29 | + |
| 30 | +// AuxShutdownReq is used to request a set of extra custom records to include |
| 31 | +// in the shutdown message. |
| 32 | +type AuxShutdownReq struct { |
| 33 | + // ChanPoint is the channel point of the channel that is being shut |
| 34 | + // down. |
| 35 | + ChanPoint wire.OutPoint |
| 36 | + |
| 37 | + // ShortChanID is the short channel ID of the channel that is being |
| 38 | + // closed. |
| 39 | + ShortChanID lnwire.ShortChannelID |
| 40 | + |
| 41 | + // Initiator is true if the local node is the initiator of the channel. |
| 42 | + Initiator bool |
| 43 | + |
| 44 | + // InternalKey is the internal key for the shutdown addr. This will |
| 45 | + // only be set for taproot shutdown addrs. |
| 46 | + InternalKey fn.Option[btcec.PublicKey] |
| 47 | + |
| 48 | + // CommitBlob is the blob that was included in the last commitment. |
| 49 | + CommitBlob fn.Option[tlv.Blob] |
| 50 | + |
| 51 | + // FundingBlob is the blob that was included in the funding state. |
| 52 | + FundingBlob fn.Option[tlv.Blob] |
| 53 | +} |
| 54 | + |
| 55 | +// AuxCloseDesc is used to describe the channel close that is being performed. |
| 56 | +type AuxCloseDesc struct { |
| 57 | + AuxShutdownReq |
| 58 | + |
| 59 | + // CloseFee is the closing fee to be paid for this state. |
| 60 | + CloseFee btcutil.Amount |
| 61 | + |
| 62 | + // CommitFee is the fee that was paid for the last commitment. |
| 63 | + CommitFee btcutil.Amount |
| 64 | + |
| 65 | + // LocalCloseOutput is the output that the local node should be paid |
| 66 | + // to. This is None if the local party will not have an output on the |
| 67 | + // co-op close transaction. |
| 68 | + LocalCloseOutput fn.Option[CloseOutput] |
| 69 | + |
| 70 | + // RemoteCloseOutput is the output that the remote node should be paid |
| 71 | + // to. This will be None if the remote party will not have an output on |
| 72 | + // the co-op close transaction. |
| 73 | + RemoteCloseOutput fn.Option[CloseOutput] |
| 74 | +} |
| 75 | + |
| 76 | +// AuxCloseOutputs is used to specify extra outputs that should be used when |
| 77 | +// constructing the co-op close transaction. |
| 78 | +type AuxCloseOutputs struct { |
| 79 | + // ExtraCloseOutputs is a set of extra outputs that should be included |
| 80 | + // in the close transaction. |
| 81 | + ExtraCloseOutputs []lnwallet.CloseOutput |
| 82 | + |
| 83 | + // CustomSort is a custom function that can be used to sort the |
| 84 | + // transaction outputs. If this isn't set, then the default BIP-69 |
| 85 | + // sorting is used. |
| 86 | + CustomSort lnwallet.CloseSortFunc |
| 87 | +} |
| 88 | + |
| 89 | +// AuxChanCloser is used to allow an external caller to modify the co-op close |
| 90 | +// transaction. |
| 91 | +type AuxChanCloser interface { |
| 92 | + // ShutdownBlob returns the set of custom records that should be |
| 93 | + // included in the shutdown message. |
| 94 | + ShutdownBlob(req AuxShutdownReq) (fn.Option[lnwire.CustomRecords], |
| 95 | + error) |
| 96 | + |
| 97 | + // AuxCloseOutputs returns the set of custom outputs that should be used |
| 98 | + // to construct the co-op close transaction. |
| 99 | + AuxCloseOutputs(desc AuxCloseDesc) (fn.Option[AuxCloseOutputs], error) |
| 100 | + |
| 101 | + // FinalizeClose is called after the close transaction has been agreed |
| 102 | + // upon. |
| 103 | + FinalizeClose(desc AuxCloseDesc, closeTx *wire.MsgTx) error |
| 104 | +} |
0 commit comments