lnwire: add new 'PushSatoshis' field to SingleFundingRequest
This commit adds a new paramter to the initial channel creation: ‘PushSatoshis’. This new field allows the funder of a channel to push over a certain amount to the responder as part of the initial channel state. This ability creates a new streamlined UX of finalizing a payment as a part of the channel creation.
This commit is contained in:
parent
d3612ac00a
commit
35776a9906
@ -45,6 +45,10 @@ type SingleFundingRequest struct {
|
|||||||
// to commit to the channel.
|
// to commit to the channel.
|
||||||
FundingAmount btcutil.Amount
|
FundingAmount btcutil.Amount
|
||||||
|
|
||||||
|
// PushSatoshis is the number of satoshis that will be pushed to the
|
||||||
|
// responder as a part of the first commitment state.
|
||||||
|
PushSatoshis btcutil.Amount
|
||||||
|
|
||||||
// CsvDelay is the number of blocks to use for the relative time lock
|
// CsvDelay is the number of blocks to use for the relative time lock
|
||||||
// in the pay-to-self output of both commitment transactions.
|
// in the pay-to-self output of both commitment transactions.
|
||||||
CsvDelay uint32
|
CsvDelay uint32
|
||||||
@ -80,7 +84,7 @@ type SingleFundingRequest struct {
|
|||||||
func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64,
|
func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64,
|
||||||
fee btcutil.Amount, amt btcutil.Amount, delay uint32, ck,
|
fee btcutil.Amount, amt btcutil.Amount, delay uint32, ck,
|
||||||
cdp *btcec.PublicKey, deliveryScript PkScript,
|
cdp *btcec.PublicKey, deliveryScript PkScript,
|
||||||
dustLimit btcutil.Amount) *SingleFundingRequest {
|
dustLimit btcutil.Amount, pushSat btcutil.Amount) *SingleFundingRequest {
|
||||||
|
|
||||||
return &SingleFundingRequest{
|
return &SingleFundingRequest{
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
@ -93,6 +97,7 @@ func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64,
|
|||||||
ChannelDerivationPoint: cdp,
|
ChannelDerivationPoint: cdp,
|
||||||
DeliveryPkScript: deliveryScript,
|
DeliveryPkScript: deliveryScript,
|
||||||
DustLimit: dustLimit,
|
DustLimit: dustLimit,
|
||||||
|
PushSatoshis: pushSat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +123,7 @@ func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error {
|
|||||||
&c.CoinType,
|
&c.CoinType,
|
||||||
&c.FeePerKb,
|
&c.FeePerKb,
|
||||||
&c.FundingAmount,
|
&c.FundingAmount,
|
||||||
|
&c.PushSatoshis,
|
||||||
&c.CsvDelay,
|
&c.CsvDelay,
|
||||||
&c.CommitmentKey,
|
&c.CommitmentKey,
|
||||||
&c.ChannelDerivationPoint,
|
&c.ChannelDerivationPoint,
|
||||||
@ -152,6 +158,7 @@ func (c *SingleFundingRequest) Encode(w io.Writer, pver uint32) error {
|
|||||||
c.CoinType,
|
c.CoinType,
|
||||||
c.FeePerKb,
|
c.FeePerKb,
|
||||||
c.FundingAmount,
|
c.FundingAmount,
|
||||||
|
c.PushSatoshis,
|
||||||
c.CsvDelay,
|
c.CsvDelay,
|
||||||
c.CommitmentKey,
|
c.CommitmentKey,
|
||||||
c.ChannelDerivationPoint,
|
c.ChannelDerivationPoint,
|
||||||
@ -176,12 +183,12 @@ func (c *SingleFundingRequest) Command() uint32 {
|
|||||||
// SingleFundingRequest. This is calculated by summing the max length of all
|
// SingleFundingRequest. This is calculated by summing the max length of all
|
||||||
// the fields within a SingleFundingRequest. To enforce a maximum
|
// the fields within a SingleFundingRequest. To enforce a maximum
|
||||||
// DeliveryPkScript size, the size of a P2PKH public key script is used.
|
// DeliveryPkScript size, the size of a P2PKH public key script is used.
|
||||||
// Therefore, the final breakdown is: 8 + 1 + 8 + 8 + 8 + 4 + 33 + 33 + 25 + 8 =
|
// Therefore, the final breakdown is: 8 + 1 + 8 + 8 + 8 + 4 + 33 + 33 + 25 + 8
|
||||||
// 166.
|
// + 9 = 166.
|
||||||
//
|
//
|
||||||
// This is part of the lnwire.Message interface.
|
// This is part of the lnwire.Message interface.
|
||||||
func (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32 {
|
func (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32 {
|
||||||
return 166
|
return 174
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate examines each populated field within the SingleFundingRequest for
|
// Validate examines each populated field within the SingleFundingRequest for
|
||||||
@ -247,6 +254,7 @@ func (c *SingleFundingRequest) String() string {
|
|||||||
fmt.Sprintf("CoinType:\t\t\t%d\n", c.CoinType) +
|
fmt.Sprintf("CoinType:\t\t\t%d\n", c.CoinType) +
|
||||||
fmt.Sprintf("FeePerKb:\t\t\t%s\n", c.FeePerKb.String()) +
|
fmt.Sprintf("FeePerKb:\t\t\t%s\n", c.FeePerKb.String()) +
|
||||||
fmt.Sprintf("FundingAmount:\t\t\t%s\n", c.FundingAmount.String()) +
|
fmt.Sprintf("FundingAmount:\t\t\t%s\n", c.FundingAmount.String()) +
|
||||||
|
fmt.Sprintf("PushSatoshis:\t\t%v\n", c.PushSatoshis) +
|
||||||
fmt.Sprintf("CsvDelay:\t\t\t%d\n", c.CsvDelay) +
|
fmt.Sprintf("CsvDelay:\t\t\t%d\n", c.CsvDelay) +
|
||||||
fmt.Sprintf("ChannelDerivationPoint:\t\t\t%x\n", serializedPubkey) +
|
fmt.Sprintf("ChannelDerivationPoint:\t\t\t%x\n", serializedPubkey) +
|
||||||
fmt.Sprintf("DeliveryPkScript:\t\t\t%x\n", c.DeliveryPkScript) +
|
fmt.Sprintf("DeliveryPkScript:\t\t\t%x\n", c.DeliveryPkScript) +
|
||||||
|
@ -11,7 +11,7 @@ func TestSingleFundingRequestWire(t *testing.T) {
|
|||||||
cdp := pubKey
|
cdp := pubKey
|
||||||
delivery := PkScript(bytes.Repeat([]byte{0x02}, 25))
|
delivery := PkScript(bytes.Repeat([]byte{0x02}, 25))
|
||||||
sfr := NewSingleFundingRequest(20, 21, 22, 23, 5, 5, cdp, cdp,
|
sfr := NewSingleFundingRequest(20, 21, 22, 23, 5, 5, cdp, cdp,
|
||||||
delivery, 540)
|
delivery, 540, 10000)
|
||||||
|
|
||||||
// Next encode the SFR message into an empty bytes buffer.
|
// Next encode the SFR message into an empty bytes buffer.
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
Loading…
Reference in New Issue
Block a user