lnwire: remove obsolete dual funder messages
This commit is contained in:
parent
82ea6ebf78
commit
bdc22e67fa
@ -1,237 +0,0 @@
|
|||||||
package lnwire
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
"github.com/roasbeef/btcutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FundingRequest struct {
|
|
||||||
ReservationID uint64
|
|
||||||
|
|
||||||
ChannelType uint8
|
|
||||||
|
|
||||||
RequesterFundingAmount btcutil.Amount
|
|
||||||
RequesterReserveAmount btcutil.Amount
|
|
||||||
MinFeePerKb btcutil.Amount
|
|
||||||
|
|
||||||
// The funding requester can request payment
|
|
||||||
// This wallet only allows positive values,
|
|
||||||
// which is a payment to the responder
|
|
||||||
// (This can be used to fund the Reserve)
|
|
||||||
// If the responder disagrees, then the funding request fails
|
|
||||||
// THIS VALUE GOES INTO THE RESPONDER'S FUNDING AMOUNT
|
|
||||||
// total requester input value = RequesterFundingAmount + PaymentAmount + "Total Change" + Fees(?)
|
|
||||||
// RequesterFundingAmount = "Available Balance" + RequesterReserveAmount
|
|
||||||
// Payment SHOULD NOT be acknowledged until the minimum confirmation has elapsed
|
|
||||||
// (Due to double-spend risks the recipient will not want to acknolwedge confirmation until later)
|
|
||||||
// This is to make a payment as part of opening the channel
|
|
||||||
PaymentAmount btcutil.Amount
|
|
||||||
|
|
||||||
// Minimum number of confirmations to validate transaction
|
|
||||||
MinDepth uint32
|
|
||||||
|
|
||||||
// Should double-check the total funding later
|
|
||||||
MinTotalFundingAmount btcutil.Amount
|
|
||||||
|
|
||||||
// CLTV/CSV lock-time to use
|
|
||||||
LockTime uint32
|
|
||||||
|
|
||||||
// Who pays the fees
|
|
||||||
// 0: (default) channel initiator
|
|
||||||
// 1: split
|
|
||||||
// 2: channel responder
|
|
||||||
FeePayer uint8
|
|
||||||
|
|
||||||
RevocationHash [32]byte
|
|
||||||
Pubkey *btcec.PublicKey
|
|
||||||
DeliveryPkScript PkScript // *MUST* be either P2PKH or P2SH
|
|
||||||
ChangePkScript PkScript // *MUST* be either P2PKH or P2SH
|
|
||||||
|
|
||||||
Inputs []*wire.TxIn
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingRequest) Decode(r io.Reader, pver uint32) error {
|
|
||||||
// Reservation ID (8)
|
|
||||||
// Channel Type (1)
|
|
||||||
// Funding Amount (8)
|
|
||||||
// Channel Minimum Capacity (8)
|
|
||||||
// Revocation Hash (20)
|
|
||||||
// Commitment Pubkey (32)
|
|
||||||
// Reserve Amount (8)
|
|
||||||
// Minimum Transaction Fee Per Kb (8)
|
|
||||||
// PaymentAmount (8)
|
|
||||||
// MinDepth (4)
|
|
||||||
// LockTime (4)
|
|
||||||
// FeePayer (1)
|
|
||||||
// DeliveryPkScript (final delivery)
|
|
||||||
// First byte length then pkscript
|
|
||||||
// ChangePkScript (change for extra from inputs)
|
|
||||||
// First byte length then pkscript
|
|
||||||
// Inputs: Create the TxIns
|
|
||||||
// First byte is number of inputs
|
|
||||||
// For each input, it's 32bytes txin & 4bytes index
|
|
||||||
err := readElements(r,
|
|
||||||
&c.ReservationID,
|
|
||||||
&c.ChannelType,
|
|
||||||
&c.RequesterFundingAmount,
|
|
||||||
&c.MinTotalFundingAmount,
|
|
||||||
&c.RevocationHash,
|
|
||||||
&c.Pubkey,
|
|
||||||
&c.RequesterReserveAmount,
|
|
||||||
&c.MinFeePerKb,
|
|
||||||
&c.PaymentAmount,
|
|
||||||
&c.MinDepth,
|
|
||||||
&c.LockTime,
|
|
||||||
&c.FeePayer,
|
|
||||||
&c.DeliveryPkScript,
|
|
||||||
&c.ChangePkScript,
|
|
||||||
&c.Inputs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a new FundingRequest
|
|
||||||
func NewFundingRequest() *FundingRequest {
|
|
||||||
return &FundingRequest{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serializes the item from the FundingRequest struct
|
|
||||||
// Writes the data to w
|
|
||||||
func (c *FundingRequest) Encode(w io.Writer, pver uint32) error {
|
|
||||||
// Channel Type
|
|
||||||
// Funding Amont
|
|
||||||
// Channel Minimum Capacity
|
|
||||||
// Revocation Hash
|
|
||||||
// Commitment Pubkey
|
|
||||||
// Reserve Amount
|
|
||||||
// Minimum Transaction Fee Per KB
|
|
||||||
// LockTime
|
|
||||||
// FeePayer
|
|
||||||
// DeliveryPkScript
|
|
||||||
// ChangePkScript
|
|
||||||
// Inputs: Append the actual Txins
|
|
||||||
err := writeElements(w,
|
|
||||||
c.ReservationID,
|
|
||||||
c.ChannelType,
|
|
||||||
c.RequesterFundingAmount,
|
|
||||||
c.MinTotalFundingAmount,
|
|
||||||
c.RevocationHash,
|
|
||||||
c.Pubkey,
|
|
||||||
c.RequesterReserveAmount,
|
|
||||||
c.MinFeePerKb,
|
|
||||||
c.PaymentAmount,
|
|
||||||
c.MinDepth,
|
|
||||||
c.LockTime,
|
|
||||||
c.FeePayer,
|
|
||||||
c.DeliveryPkScript,
|
|
||||||
c.ChangePkScript,
|
|
||||||
c.Inputs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingRequest) Command() uint32 {
|
|
||||||
return CmdFundingRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingRequest) MaxPayloadLength(uint32) uint32 {
|
|
||||||
// 110 (base size) + 26 (pkscript) + 26 (pkscript) + 1 (numTxes) + 127*36(127 inputs * sha256+idx)
|
|
||||||
return 4735
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
|
||||||
func (c *FundingRequest) Validate() error {
|
|
||||||
// No negative values
|
|
||||||
if c.RequesterFundingAmount < 0 {
|
|
||||||
return fmt.Errorf("RequesterFundingAmount cannot be negative")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.RequesterReserveAmount < 0 {
|
|
||||||
return fmt.Errorf("RequesterReserveAmount cannot be negative")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.MinFeePerKb < 0 {
|
|
||||||
return fmt.Errorf("MinFeePerKb cannot be negative")
|
|
||||||
}
|
|
||||||
if c.MinTotalFundingAmount < 0 {
|
|
||||||
return fmt.Errorf("MinTotalFundingAmount cannot be negative")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validation of what makes sense...
|
|
||||||
if c.MinTotalFundingAmount < c.RequesterFundingAmount {
|
|
||||||
return fmt.Errorf("Requester's minimum too low.")
|
|
||||||
}
|
|
||||||
if c.RequesterFundingAmount < c.RequesterReserveAmount {
|
|
||||||
return fmt.Errorf("Reserve must be below Funding Amount")
|
|
||||||
}
|
|
||||||
|
|
||||||
// This wallet only allows payment from the requester to responder
|
|
||||||
if c.PaymentAmount < 0 {
|
|
||||||
return fmt.Errorf("This wallet requieres payment to be greater than zero.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure there's not more than 127 inputs
|
|
||||||
if len(c.Inputs) > 127 {
|
|
||||||
return fmt.Errorf("Too many inputs")
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeliveryPkScript is either P2SH or P2PKH
|
|
||||||
if !isValidPkScript(c.DeliveryPkScript) {
|
|
||||||
// TODO(roasbeef): move into actual error
|
|
||||||
return fmt.Errorf("Valid delivery public key scripts MUST be: " +
|
|
||||||
"P2PKH, P2WKH, P2SH, or P2WSH.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChangePkScript is either P2SH or P2PKH
|
|
||||||
if !isValidPkScript(c.ChangePkScript) {
|
|
||||||
return fmt.Errorf("Valid change public key script MUST be: " +
|
|
||||||
"P2PKH, P2WKH, P2SH, or P2WSH.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// We're good!
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingRequest) String() string {
|
|
||||||
var inputs string
|
|
||||||
for i, in := range c.Inputs {
|
|
||||||
inputs += fmt.Sprintf("\n Slice\t%d\n", i)
|
|
||||||
if &in != nil {
|
|
||||||
inputs += fmt.Sprintf("\tHash\t%s\n", in.PreviousOutPoint.Hash)
|
|
||||||
inputs += fmt.Sprintf("\tIndex\t%d\n", in.PreviousOutPoint.Index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var serializedPubkey []byte
|
|
||||||
if &c.Pubkey != nil && c.Pubkey.X != nil {
|
|
||||||
serializedPubkey = c.Pubkey.SerializeCompressed()
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("\n--- Begin FundingRequest ---\n") +
|
|
||||||
fmt.Sprintf("ReservationID:\t\t\t%d\n", c.ReservationID) +
|
|
||||||
fmt.Sprintf("ChannelType:\t\t\t%x\n", c.ChannelType) +
|
|
||||||
fmt.Sprintf("RequesterFundingAmount:\t\t%s\n", c.RequesterFundingAmount.String()) +
|
|
||||||
fmt.Sprintf("RequesterReserveAmount:\t\t%s\n", c.RequesterReserveAmount.String()) +
|
|
||||||
fmt.Sprintf("MinFeePerKb:\t\t\t%s\n", c.MinFeePerKb.String()) +
|
|
||||||
fmt.Sprintf("PaymentAmount:\t\t\t%s\n", c.PaymentAmount.String()) +
|
|
||||||
fmt.Sprintf("MinDepth:\t\t\t%d\n", c.MinDepth) +
|
|
||||||
fmt.Sprintf("MinTotalFundingAmount\t\t%s\n", c.MinTotalFundingAmount.String()) +
|
|
||||||
fmt.Sprintf("LockTime\t\t\t%d\n", c.LockTime) +
|
|
||||||
fmt.Sprintf("FeePayer\t\t\t%x\n", c.FeePayer) +
|
|
||||||
fmt.Sprintf("RevocationHash\t\t\t%x\n", c.RevocationHash) +
|
|
||||||
fmt.Sprintf("Pubkey\t\t\t\t%x\n", serializedPubkey) +
|
|
||||||
fmt.Sprintf("DeliveryPkScript\t\t%x\n", c.DeliveryPkScript) +
|
|
||||||
fmt.Sprintf("Inputs:") +
|
|
||||||
inputs +
|
|
||||||
fmt.Sprintf("--- End FundingRequest ---\n")
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
package lnwire
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/roasbeef/btcutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFundingRequestEncodeDecode(t *testing.T) {
|
|
||||||
// funding request
|
|
||||||
fr := &FundingRequest{
|
|
||||||
ReservationID: uint64(12345678),
|
|
||||||
ChannelType: uint8(0),
|
|
||||||
RequesterFundingAmount: btcutil.Amount(100000000),
|
|
||||||
RequesterReserveAmount: btcutil.Amount(131072),
|
|
||||||
MinFeePerKb: btcutil.Amount(20000),
|
|
||||||
MinTotalFundingAmount: btcutil.Amount(150000000),
|
|
||||||
LockTime: uint32(4320), // 30 block-days
|
|
||||||
FeePayer: uint8(0),
|
|
||||||
PaymentAmount: btcutil.Amount(1234567),
|
|
||||||
MinDepth: uint32(6),
|
|
||||||
RevocationHash: revHash,
|
|
||||||
Pubkey: pubKey,
|
|
||||||
DeliveryPkScript: deliveryPkScript,
|
|
||||||
ChangePkScript: changePkScript,
|
|
||||||
Inputs: inputs,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next encode the FR message into an empty bytes buffer.
|
|
||||||
var b bytes.Buffer
|
|
||||||
if err := fr.Encode(&b, 0); err != nil {
|
|
||||||
t.Fatalf("unable to encode FundingRequest: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deserialize the encoded FR message into a new empty struct.
|
|
||||||
fr2 := &FundingRequest{}
|
|
||||||
if err := fr2.Decode(&b, 0); err != nil {
|
|
||||||
t.Fatalf("unable to decode FundingRequest: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert equality of the two instances.
|
|
||||||
if !reflect.DeepEqual(fr, fr2) {
|
|
||||||
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
||||||
fr, fr2)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,210 +0,0 @@
|
|||||||
package lnwire
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
"github.com/roasbeef/btcutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FundingResponse struct {
|
|
||||||
ChannelType uint8
|
|
||||||
|
|
||||||
ReservationID uint64
|
|
||||||
|
|
||||||
ResponderFundingAmount btcutil.Amount // Responder's funding amount
|
|
||||||
ResponderReserveAmount btcutil.Amount // Responder's reserve amount
|
|
||||||
MinFeePerKb btcutil.Amount // Lock-in min fee
|
|
||||||
|
|
||||||
// Minimum depth
|
|
||||||
MinDepth uint32
|
|
||||||
|
|
||||||
// CLTV/CSV lock-time to use
|
|
||||||
LockTime uint32
|
|
||||||
|
|
||||||
// Who pays the fees
|
|
||||||
// 0: (default) channel initiator
|
|
||||||
// 1: split
|
|
||||||
// 2: channel responder
|
|
||||||
FeePayer uint8
|
|
||||||
|
|
||||||
RevocationHash [32]byte
|
|
||||||
Pubkey *btcec.PublicKey
|
|
||||||
CommitSig *btcec.Signature // Requester's Commitment
|
|
||||||
DeliveryPkScript PkScript // *MUST* be either P2PKH or P2SH
|
|
||||||
ChangePkScript PkScript // *MUST* be either P2PKH or P2SH
|
|
||||||
|
|
||||||
Inputs []*wire.TxIn
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingResponse) Decode(r io.Reader, pver uint32) error {
|
|
||||||
// ReservationID (8)
|
|
||||||
// Channel Type (1)
|
|
||||||
// Funding Amount (8)
|
|
||||||
// Revocation Hash (20)
|
|
||||||
// Commitment Pubkey (32)
|
|
||||||
// Reserve Amount (8)
|
|
||||||
// Minimum Transaction Fee Per Kb (8)
|
|
||||||
// MinDepth (4)
|
|
||||||
// LockTime (4)
|
|
||||||
// FeePayer (1)
|
|
||||||
// DeliveryPkScript (final delivery)
|
|
||||||
// First byte length then pkscript
|
|
||||||
// ChangePkScript (change for extra from inputs)
|
|
||||||
// First byte length then pkscript
|
|
||||||
// CommitSig
|
|
||||||
// First byte length then sig
|
|
||||||
// Inputs: Create the TxIns
|
|
||||||
// First byte is number of inputs
|
|
||||||
// For each input, it's 32bytes txin & 4bytes index
|
|
||||||
err := readElements(r,
|
|
||||||
&c.ReservationID,
|
|
||||||
&c.ChannelType,
|
|
||||||
&c.ResponderFundingAmount,
|
|
||||||
&c.RevocationHash,
|
|
||||||
&c.Pubkey,
|
|
||||||
&c.ResponderReserveAmount,
|
|
||||||
&c.MinFeePerKb,
|
|
||||||
&c.MinDepth,
|
|
||||||
&c.LockTime,
|
|
||||||
&c.FeePayer,
|
|
||||||
&c.DeliveryPkScript,
|
|
||||||
&c.ChangePkScript,
|
|
||||||
&c.CommitSig,
|
|
||||||
&c.Inputs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a new FundingResponse
|
|
||||||
func NewFundingResponse() *FundingResponse {
|
|
||||||
return &FundingResponse{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serializes the item from the FundingResponse struct
|
|
||||||
// Writes the data to w
|
|
||||||
func (c *FundingResponse) Encode(w io.Writer, pver uint32) error {
|
|
||||||
// ReservationID (8)
|
|
||||||
// Channel Type (1)
|
|
||||||
// Funding Amount (8)
|
|
||||||
// Revocation Hash (20)
|
|
||||||
// Commitment Pubkey (32)
|
|
||||||
// Reserve Amount (8)
|
|
||||||
// Minimum Transaction Fee Per Kb (8)
|
|
||||||
// LockTime (4)
|
|
||||||
// FeePayer (1)
|
|
||||||
// DeliveryPkScript (final delivery)
|
|
||||||
// ChangePkScript (change for extra from inputs)
|
|
||||||
// CommitSig
|
|
||||||
// Inputs
|
|
||||||
err := writeElements(w,
|
|
||||||
c.ReservationID,
|
|
||||||
c.ChannelType,
|
|
||||||
c.ResponderFundingAmount,
|
|
||||||
c.RevocationHash,
|
|
||||||
c.Pubkey,
|
|
||||||
c.ResponderReserveAmount,
|
|
||||||
c.MinFeePerKb,
|
|
||||||
c.MinDepth,
|
|
||||||
c.LockTime,
|
|
||||||
c.FeePayer,
|
|
||||||
c.DeliveryPkScript,
|
|
||||||
c.ChangePkScript,
|
|
||||||
c.CommitSig,
|
|
||||||
c.Inputs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingResponse) Command() uint32 {
|
|
||||||
return CmdFundingResponse
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingResponse) MaxPayloadLength(uint32) uint32 {
|
|
||||||
// 86 (base size) + 26 (pkscript) + 26 (pkscript) + 74sig + 1 (numTxes) + 127*36(127 inputs * sha256+idx)
|
|
||||||
return 4785
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
|
||||||
func (c *FundingResponse) Validate() error {
|
|
||||||
// No negative values
|
|
||||||
if c.ResponderFundingAmount < 0 {
|
|
||||||
return fmt.Errorf("ResponderFundingAmount cannot be negative")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.ResponderReserveAmount < 0 {
|
|
||||||
return fmt.Errorf("ResponderReserveAmount cannot be negative")
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.MinFeePerKb < 0 {
|
|
||||||
return fmt.Errorf("MinFeePerKb cannot be negative")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validation of what makes sense...
|
|
||||||
if c.ResponderFundingAmount < c.ResponderReserveAmount {
|
|
||||||
return fmt.Errorf("Reserve must be below Funding Amount")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure there's not more than 127 inputs
|
|
||||||
if len(c.Inputs) > 127 {
|
|
||||||
return fmt.Errorf("Too many inputs")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delivery PkScript is either P2SH or P2PKH
|
|
||||||
if !isValidPkScript(c.DeliveryPkScript) {
|
|
||||||
return fmt.Errorf("Valid delivery public key scripts MUST be: " +
|
|
||||||
"P2PKH, P2WKH, P2SH, or P2WSH.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change PkScript is either P2SH or P2PKH
|
|
||||||
if !isValidPkScript(c.ChangePkScript) {
|
|
||||||
// TODO(roasbeef): move into actual error
|
|
||||||
return fmt.Errorf("Valid change public key scripts MUST be: " +
|
|
||||||
"P2PKH, P2WKH, P2SH, or P2WSH.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// We're good!
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingResponse) String() string {
|
|
||||||
var inputs string
|
|
||||||
for i, in := range c.Inputs {
|
|
||||||
inputs += fmt.Sprintf("\n Slice\t%d\n", i)
|
|
||||||
if &in != nil {
|
|
||||||
inputs += fmt.Sprintf("\tHash\t%s\n", in.PreviousOutPoint.Hash)
|
|
||||||
inputs += fmt.Sprintf("\tIndex\t%d\n", in.PreviousOutPoint.Index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var serializedPubkey []byte
|
|
||||||
if &c.Pubkey != nil && c.Pubkey.X != nil {
|
|
||||||
serializedPubkey = c.Pubkey.SerializeCompressed()
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("\n--- Begin FundingResponse ---\n") +
|
|
||||||
fmt.Sprintf("ChannelType:\t\t\t%x\n", c.ChannelType) +
|
|
||||||
fmt.Sprintf("ReservationID:\t\t\t%d\n", c.ReservationID) +
|
|
||||||
fmt.Sprintf("ResponderFundingAmount:\t\t%s\n", c.ResponderFundingAmount.String()) +
|
|
||||||
fmt.Sprintf("ResponderReserveAmount:\t\t%s\n", c.ResponderReserveAmount.String()) +
|
|
||||||
fmt.Sprintf("MinFeePerKb:\t\t\t%s\n", c.MinFeePerKb.String()) +
|
|
||||||
fmt.Sprintf("MinDepth:\t\t\t%d\n", c.MinDepth) +
|
|
||||||
fmt.Sprintf("LockTime\t\t\t%d\n", c.LockTime) +
|
|
||||||
fmt.Sprintf("FeePayer\t\t\t%x\n", c.FeePayer) +
|
|
||||||
fmt.Sprintf("RevocationHash\t\t\t%x\n", c.RevocationHash) +
|
|
||||||
fmt.Sprintf("Pubkey\t\t\t\t%x\n", serializedPubkey) +
|
|
||||||
fmt.Sprintf("CommitSig\t\t\t%x\n", c.CommitSig.Serialize()) +
|
|
||||||
fmt.Sprintf("DeliveryPkScript\t\t%x\n", c.DeliveryPkScript) +
|
|
||||||
fmt.Sprintf("ChangePkScript\t\t%x\n", c.ChangePkScript) +
|
|
||||||
fmt.Sprintf("Inputs:") +
|
|
||||||
inputs +
|
|
||||||
fmt.Sprintf("--- End FundingResponse ---\n")
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package lnwire
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/roasbeef/btcutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFundingResponseEncodeDecode(t *testing.T) {
|
|
||||||
copy(revocationHash[:], revocationHashBytes)
|
|
||||||
|
|
||||||
// funding response
|
|
||||||
fr := &FundingResponse{
|
|
||||||
ChannelType: uint8(1),
|
|
||||||
ReservationID: uint64(12345678),
|
|
||||||
ResponderFundingAmount: btcutil.Amount(100000000),
|
|
||||||
ResponderReserveAmount: btcutil.Amount(131072),
|
|
||||||
MinFeePerKb: btcutil.Amount(20000),
|
|
||||||
MinDepth: uint32(6),
|
|
||||||
LockTime: uint32(4320), // 30 block-days
|
|
||||||
FeePayer: uint8(1),
|
|
||||||
RevocationHash: revHash,
|
|
||||||
Pubkey: pubKey,
|
|
||||||
CommitSig: commitSig,
|
|
||||||
DeliveryPkScript: deliveryPkScript,
|
|
||||||
ChangePkScript: changePkScript,
|
|
||||||
Inputs: inputs,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next encode the FR message into an empty bytes buffer.
|
|
||||||
var b bytes.Buffer
|
|
||||||
if err := fr.Encode(&b, 0); err != nil {
|
|
||||||
t.Fatalf("unable to encode HTLCAddRequest: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deserialize the encoded FR message into a new empty struct.
|
|
||||||
fr2 := &FundingResponse{}
|
|
||||||
if err := fr2.Decode(&b, 0); err != nil {
|
|
||||||
t.Fatalf("unable to decode FundingResponse: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert equality of the two instances.
|
|
||||||
if !reflect.DeepEqual(fr, fr2) {
|
|
||||||
t.Fatalf("encode/decode error messages don't match %#v vs %#v",
|
|
||||||
fr, fr2)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
package lnwire
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FundingSignAccept struct {
|
|
||||||
ReservationID uint64
|
|
||||||
|
|
||||||
CommitSig *btcec.Signature // Requester's Commitment
|
|
||||||
FundingTXSigs []*btcec.Signature
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingSignAccept) Decode(r io.Reader, pver uint32) error {
|
|
||||||
// ReservationID (8)
|
|
||||||
// CommitSig (73)
|
|
||||||
// First byte length then sig
|
|
||||||
// FundingTXSigs
|
|
||||||
// First byte is number of FundingTxSigs
|
|
||||||
// Sorted list of the requester's input signatures
|
|
||||||
// (originally provided in the Funding Request)
|
|
||||||
err := readElements(r,
|
|
||||||
&c.ReservationID,
|
|
||||||
&c.CommitSig,
|
|
||||||
&c.FundingTXSigs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a new FundingSignAccept
|
|
||||||
func NewFundingSignAccept() *FundingSignAccept {
|
|
||||||
return &FundingSignAccept{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serializes the item from the FundingSignAccept struct
|
|
||||||
// Writes the data to w
|
|
||||||
func (c *FundingSignAccept) Encode(w io.Writer, pver uint32) error {
|
|
||||||
// ReservationID
|
|
||||||
// CommitSig
|
|
||||||
// FundingTxSigs
|
|
||||||
err := writeElements(w,
|
|
||||||
c.ReservationID,
|
|
||||||
c.CommitSig,
|
|
||||||
c.FundingTXSigs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingSignAccept) Command() uint32 {
|
|
||||||
return CmdFundingSignAccept
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingSignAccept) MaxPayloadLength(uint32) uint32 {
|
|
||||||
// 8 (base size) + 73 + (73maxSigSize*127maxInputs)
|
|
||||||
return 9352
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
|
||||||
func (c *FundingSignAccept) Validate() error {
|
|
||||||
// We're good!
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingSignAccept) String() string {
|
|
||||||
var sigs string
|
|
||||||
for i, in := range c.FundingTXSigs {
|
|
||||||
sigs += fmt.Sprintf("\n Slice\t%d\n", i)
|
|
||||||
if in != nil {
|
|
||||||
sigs += fmt.Sprintf("\tSig\t%x\n", in.Serialize())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var serializedSig []byte
|
|
||||||
if &c.CommitSig != nil && c.CommitSig.R != nil {
|
|
||||||
serializedSig = c.CommitSig.Serialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("\n--- Begin FundingSignAccept ---\n") +
|
|
||||||
fmt.Sprintf("ReservationID:\t\t%d\n", c.ReservationID) +
|
|
||||||
fmt.Sprintf("CommitSig\t\t%x\n", serializedSig) +
|
|
||||||
fmt.Sprintf("FundingTxSigs:") +
|
|
||||||
sigs +
|
|
||||||
fmt.Sprintf("--- End FundingSignAccept ---\n")
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package lnwire
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// funding sign accept
|
|
||||||
fundingSignAccept = &FundingSignAccept{
|
|
||||||
ReservationID: uint64(12345678),
|
|
||||||
CommitSig: commitSig,
|
|
||||||
FundingTXSigs: ptrFundingTXSigs,
|
|
||||||
}
|
|
||||||
fundingSignAcceptSerializedString = "0000000000bc614e4630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
|
||||||
fundingSignAcceptSerializedMessage = "0709110b000000dc000000df0000000000bc614e4630440220333835e58e958f5e92b4ff4e6fa2470dac88094c97506b4d6d1f4e23e52cb481022057483ac18d6b9c9c14f0c626694c9ccf8b27b3dbbedfdf6b6c9a9fa9f427a1df02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFundingSignAcceptEncodeDecode(t *testing.T) {
|
|
||||||
// All of these types being passed are of the message interface type
|
|
||||||
// Test serialization, runs: message.Encode(b, 0)
|
|
||||||
// Returns bytes
|
|
||||||
// Compares the expected serialized string from the original
|
|
||||||
s := SerializeTest(t, fundingSignAccept, fundingSignAcceptSerializedString, filename)
|
|
||||||
|
|
||||||
// Test deserialization, runs: message.Decode(s, 0)
|
|
||||||
// Makes sure the deserialized struct is the same as the original
|
|
||||||
newMessage := NewFundingSignAccept()
|
|
||||||
DeserializeTest(t, s, newMessage, fundingSignAccept)
|
|
||||||
|
|
||||||
// Test message using Message interface
|
|
||||||
// Serializes into buf: WriteMessage(buf, message, uint32(1), wire.TestNet3)
|
|
||||||
// Deserializes into msg: _, msg, _ , err := ReadMessage(buf, uint32(1), wire.TestNet3)
|
|
||||||
MessageSerializeDeserializeTest(t, fundingSignAccept, fundingSignAcceptSerializedMessage)
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
package lnwire
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
|
||||||
"github.com/roasbeef/btcd/wire"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FundingSignComplete struct {
|
|
||||||
ReservationID uint64
|
|
||||||
|
|
||||||
TxID *wire.ShaHash
|
|
||||||
FundingTXSigs []*btcec.Signature
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingSignComplete) Decode(r io.Reader, pver uint32) error {
|
|
||||||
// ReservationID (8)
|
|
||||||
// TxID (32)
|
|
||||||
// FundingTXSigs
|
|
||||||
// First byte is number of FundingTxSigs
|
|
||||||
// Sorted list of the requester's input signatures
|
|
||||||
// (originally provided in the Funding Request)
|
|
||||||
err := readElements(r,
|
|
||||||
&c.ReservationID,
|
|
||||||
&c.TxID,
|
|
||||||
&c.FundingTXSigs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a new FundingSignComplete
|
|
||||||
func NewFundingSignComplete() *FundingSignComplete {
|
|
||||||
return &FundingSignComplete{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Serializes the item from the FundingSignComplete struct
|
|
||||||
// Writes the data to w
|
|
||||||
func (c *FundingSignComplete) Encode(w io.Writer, pver uint32) error {
|
|
||||||
err := writeElements(w,
|
|
||||||
c.ReservationID,
|
|
||||||
c.TxID,
|
|
||||||
c.FundingTXSigs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingSignComplete) Command() uint32 {
|
|
||||||
return CmdFundingSignComplete
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingSignComplete) MaxPayloadLength(uint32) uint32 {
|
|
||||||
// 8 (base size) + 32 + (73maxSigSize*127maxInputs)
|
|
||||||
return 9311
|
|
||||||
}
|
|
||||||
|
|
||||||
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
|
||||||
func (c *FundingSignComplete) Validate() error {
|
|
||||||
// We're good!
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *FundingSignComplete) String() string {
|
|
||||||
var sigs string
|
|
||||||
for i, in := range c.FundingTXSigs {
|
|
||||||
sigs += fmt.Sprintf("\n Slice\t%d\n", i)
|
|
||||||
if in != nil {
|
|
||||||
sigs += fmt.Sprintf("\tSig\t%x\n", in.Serialize())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("\n--- Begin FundingSignComplete ---\n") +
|
|
||||||
fmt.Sprintf("ReservationID:\t\t%d\n", c.ReservationID) +
|
|
||||||
fmt.Sprintf("TxID\t\t%s\n", c.TxID.String()) +
|
|
||||||
fmt.Sprintf("FundingTxSigs:") +
|
|
||||||
sigs +
|
|
||||||
fmt.Sprintf("--- End FundingSignComplete ---\n")
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package lnwire
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// funding response
|
|
||||||
fundingSignComplete = &FundingSignComplete{
|
|
||||||
ReservationID: uint64(12345678),
|
|
||||||
TxID: txid,
|
|
||||||
FundingTXSigs: ptrFundingTXSigs,
|
|
||||||
}
|
|
||||||
fundingSignCompleteSerializedString = "0000000000bc614efd95c6e5c9d5bcf9cfc7231b6a438e46c518c724d0b04b75cc8fddf84a254e3a02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
|
||||||
fundingSignCompleteSerializedMessage = "0709110b000000e6000000b80000000000bc614efd95c6e5c9d5bcf9cfc7231b6a438e46c518c724d0b04b75cc8fddf84a254e3a02473045022100e7946d057c0b4cc4d3ea525ba156b429796858ebc543d75a6c6c2cbca732db6902202fea377c1f9fb98cd103cf5a4fba276a074b378d4227d15f5fa6439f1a6685bb4630440220235ee55fed634080089953048c3e3f7dc3a154fd7ad18f31dc08e05b7864608a02203bdd7d4e4d9a8162d4b511faf161f0bb16c45181187125017cd0c620c53876ca"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestFundingSignCompleteEncodeDecode(t *testing.T) {
|
|
||||||
// All of these types being passed are of the message interface type
|
|
||||||
// Test serialization, runs: message.Encode(b, 0)
|
|
||||||
// Returns bytes
|
|
||||||
// Compares the expected serialized string from the original
|
|
||||||
s := SerializeTest(t, fundingSignComplete, fundingSignCompleteSerializedString, filename)
|
|
||||||
|
|
||||||
// Test deserialization, runs: message.Decode(s, 0)
|
|
||||||
// Makes sure the deserialized struct is the same as the original
|
|
||||||
newMessage := NewFundingSignComplete()
|
|
||||||
DeserializeTest(t, s, newMessage, fundingSignComplete)
|
|
||||||
|
|
||||||
// Test message using Message interface
|
|
||||||
// Serializes into buf: WriteMessage(buf, message, uint32(1), wire.TestNet3)
|
|
||||||
// Deserializes into msg: _, msg, _ , err := ReadMessage(buf, uint32(1), wire.TestNet3)
|
|
||||||
MessageSerializeDeserializeTest(t, fundingSignComplete, fundingSignCompleteSerializedMessage)
|
|
||||||
}
|
|
@ -22,12 +22,6 @@ const MaxMessagePayload = 1024 * 1024 * 32 // 32MB
|
|||||||
|
|
||||||
// Commands used in lightning message headers which detail the type of message.
|
// Commands used in lightning message headers which detail the type of message.
|
||||||
const (
|
const (
|
||||||
// Commands for opening a channel funded by both parties (dual funder).
|
|
||||||
CmdFundingRequest = uint32(200)
|
|
||||||
CmdFundingResponse = uint32(210)
|
|
||||||
CmdFundingSignAccept = uint32(220)
|
|
||||||
CmdFundingSignComplete = uint32(230)
|
|
||||||
|
|
||||||
// Commands for opening a channel funded by one party (single funder).
|
// Commands for opening a channel funded by one party (single funder).
|
||||||
CmdSingleFundingRequest = uint32(100)
|
CmdSingleFundingRequest = uint32(100)
|
||||||
CmdSingleFundingResponse = uint32(110)
|
CmdSingleFundingResponse = uint32(110)
|
||||||
@ -72,14 +66,6 @@ func makeEmptyMessage(command uint32) (Message, error) {
|
|||||||
var msg Message
|
var msg Message
|
||||||
|
|
||||||
switch command {
|
switch command {
|
||||||
case CmdFundingRequest:
|
|
||||||
msg = &FundingRequest{}
|
|
||||||
case CmdFundingResponse:
|
|
||||||
msg = &FundingResponse{}
|
|
||||||
case CmdFundingSignAccept:
|
|
||||||
msg = &FundingSignAccept{}
|
|
||||||
case CmdFundingSignComplete:
|
|
||||||
msg = &FundingSignComplete{}
|
|
||||||
case CmdSingleFundingRequest:
|
case CmdSingleFundingRequest:
|
||||||
msg = &SingleFundingRequest{}
|
msg = &SingleFundingRequest{}
|
||||||
case CmdSingleFundingResponse:
|
case CmdSingleFundingResponse:
|
||||||
|
Loading…
Reference in New Issue
Block a user