2016-05-23 08:25:42 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/roasbeef/btcd/btcec"
|
|
|
|
"github.com/roasbeef/btcd/wire"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SingleFundingComplete is the message Alice sends to Bob once she is able to
|
|
|
|
// fully assemble the funding transaction, and both versions of the commitment
|
|
|
|
// transaction. The purpose of this message is to present Bob with the items
|
|
|
|
// required for him to generate a signature for Alice's version of the
|
|
|
|
// commitment transaction.
|
|
|
|
type SingleFundingComplete struct {
|
2017-04-17 01:22:20 +03:00
|
|
|
// PendingChannelID serves to uniquely identify the future channel
|
|
|
|
// created by the initiated single funder workflow.
|
|
|
|
PendingChannelID [32]byte
|
2016-05-23 08:25:42 +03:00
|
|
|
|
|
|
|
// FundingOutPoint is the outpoint (txid:index) of the funding
|
|
|
|
// transaction. With this value, Bob will be able to generate a
|
|
|
|
// signature for Alice's version of the commitment transaction.
|
2017-02-16 15:34:44 +03:00
|
|
|
FundingOutPoint wire.OutPoint
|
2016-05-23 08:25:42 +03:00
|
|
|
|
2016-05-31 01:45:44 +03:00
|
|
|
// CommitSignature is Alice's signature for Bob's version of the
|
2016-05-23 08:25:42 +03:00
|
|
|
// commitment transaction.
|
2016-05-31 01:45:44 +03:00
|
|
|
CommitSignature *btcec.Signature
|
2016-06-30 21:49:58 +03:00
|
|
|
|
|
|
|
// RevocationKey is the initial key to be used for the revocation
|
|
|
|
// clause within the self-output of the initiators's commitment
|
|
|
|
// transaction. Once an initial new state is created, the initiator
|
2017-01-13 08:01:50 +03:00
|
|
|
// will send a preimage which will allow the initiator to sweep the
|
2016-06-30 21:49:58 +03:00
|
|
|
// initiator's funds if the violate the contract.
|
|
|
|
RevocationKey *btcec.PublicKey
|
2016-11-15 06:03:55 +03:00
|
|
|
|
|
|
|
// StateHintObsfucator is the set of bytes used by the initiator to
|
|
|
|
// obsfucate the state number encoded within the sequence number for
|
|
|
|
// the commitment transaction's only input. The initiator generates
|
|
|
|
// this value by hashing the 0th' state derived from the revocation PRF
|
|
|
|
// an additional time.
|
2017-01-05 10:55:52 +03:00
|
|
|
StateHintObsfucator [6]byte
|
2016-05-31 01:45:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSingleFundingComplete creates, and returns a new empty
|
|
|
|
// SingleFundingResponse.
|
2017-04-17 01:22:20 +03:00
|
|
|
func NewSingleFundingComplete(pChanID [32]byte, fundingPoint wire.OutPoint,
|
2016-11-15 06:03:55 +03:00
|
|
|
commitSig *btcec.Signature, revokeKey *btcec.PublicKey,
|
2017-01-05 10:55:52 +03:00
|
|
|
obsfucator [6]byte) *SingleFundingComplete {
|
2016-05-31 01:45:44 +03:00
|
|
|
|
|
|
|
return &SingleFundingComplete{
|
2017-04-17 01:22:20 +03:00
|
|
|
PendingChannelID: pChanID,
|
2016-11-15 06:03:55 +03:00
|
|
|
FundingOutPoint: fundingPoint,
|
|
|
|
CommitSignature: commitSig,
|
|
|
|
RevocationKey: revokeKey,
|
|
|
|
StateHintObsfucator: obsfucator,
|
2016-05-31 01:45:44 +03:00
|
|
|
}
|
2016-05-23 08:25:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decode deserializes the serialized SingleFundingComplete stored in the passed
|
|
|
|
// io.Reader into the target SingleFundingComplete using the deserialization
|
|
|
|
// rules defined by the passed protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (s *SingleFundingComplete) Decode(r io.Reader, pver uint32) error {
|
2017-02-23 21:59:50 +03:00
|
|
|
return readElements(r,
|
2017-04-17 01:22:20 +03:00
|
|
|
s.PendingChannelID[:],
|
2016-05-23 08:25:42 +03:00
|
|
|
&s.FundingOutPoint,
|
2016-06-30 21:49:58 +03:00
|
|
|
&s.CommitSignature,
|
2016-11-15 06:03:55 +03:00
|
|
|
&s.RevocationKey,
|
2017-02-16 15:34:44 +03:00
|
|
|
s.StateHintObsfucator[:])
|
2016-05-23 08:25:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target SingleFundingComplete into the passed io.Writer
|
|
|
|
// implementation. Serialization will observe the rules defined by the passed
|
|
|
|
// protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (s *SingleFundingComplete) Encode(w io.Writer, pver uint32) error {
|
2017-02-23 21:59:50 +03:00
|
|
|
return writeElements(w,
|
2017-04-17 01:22:20 +03:00
|
|
|
s.PendingChannelID[:],
|
2016-05-23 08:25:42 +03:00
|
|
|
s.FundingOutPoint,
|
2016-06-30 21:49:58 +03:00
|
|
|
s.CommitSignature,
|
2016-11-15 06:03:55 +03:00
|
|
|
s.RevocationKey,
|
2017-02-16 15:34:44 +03:00
|
|
|
s.StateHintObsfucator[:])
|
2016-05-23 08:25:42 +03:00
|
|
|
}
|
|
|
|
|
2017-04-20 01:57:43 +03:00
|
|
|
// MsgType returns the uint32 code which uniquely identifies this message as a
|
2017-01-31 08:45:02 +03:00
|
|
|
// SingleFundingComplete on the wire.
|
2016-05-23 08:25:42 +03:00
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 01:57:43 +03:00
|
|
|
func (s *SingleFundingComplete) MsgType() MessageType {
|
|
|
|
return MsgSingleFundingComplete
|
2016-05-23 08:25:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// MaxPayloadLength returns the maximum allowed payload length for a
|
|
|
|
// SingleFundingComplete. This is calculated by summing the max length of all
|
2017-04-17 01:22:20 +03:00
|
|
|
// the fields within a SingleFundingComplete.
|
2016-05-23 08:25:42 +03:00
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
|
|
|
func (s *SingleFundingComplete) MaxPayloadLength(uint32) uint32 {
|
2017-04-17 01:22:20 +03:00
|
|
|
// 32 + 36 + 64 + 33 + 6
|
|
|
|
return 171
|
2016-05-23 08:25:42 +03:00
|
|
|
}
|