2016-01-05 19:19:22 +03:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Multiple Clearing Requests are possible by putting this inside an array of
|
|
|
|
// clearing requests
|
2016-01-05 19:19:22 +03:00
|
|
|
type HTLCSettleRequest struct {
|
2016-01-17 04:14:35 +03:00
|
|
|
// We can use a different data type for this if necessary...
|
2016-01-05 19:19:22 +03:00
|
|
|
ChannelID uint64
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// ID of this request
|
2016-01-15 04:02:23 +03:00
|
|
|
HTLCKey HTLCKey
|
2016-01-05 19:19:22 +03:00
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Redemption Proofs (R-Values)
|
2016-01-05 19:19:22 +03:00
|
|
|
RedemptionProofs []*[20]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HTLCSettleRequest) Decode(r io.Reader, pver uint32) error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// ChannelID(8)
|
|
|
|
// HTLCKey(8)
|
|
|
|
// Expiry(4)
|
|
|
|
// Amount(4)
|
|
|
|
// NextHop(20)
|
|
|
|
// ContractType(1)
|
|
|
|
// RedemptionHashes (numOfHashes * 20 + numOfHashes)
|
|
|
|
// Blob(2+blobsize)
|
2016-01-05 19:19:22 +03:00
|
|
|
err := readElements(r,
|
|
|
|
&c.ChannelID,
|
2016-01-15 04:02:23 +03:00
|
|
|
&c.HTLCKey,
|
2016-01-05 19:19:22 +03:00
|
|
|
&c.RedemptionProofs,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Creates a new HTLCSettleRequest
|
2016-01-05 19:19:22 +03:00
|
|
|
func NewHTLCSettleRequest() *HTLCSettleRequest {
|
|
|
|
return &HTLCSettleRequest{}
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Serializes the item from the HTLCSettleRequest struct
|
|
|
|
// Writes the data to w
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCSettleRequest) Encode(w io.Writer, pver uint32) error {
|
|
|
|
err := writeElements(w,
|
|
|
|
c.ChannelID,
|
2016-01-15 04:02:23 +03:00
|
|
|
c.HTLCKey,
|
2016-01-05 19:19:22 +03:00
|
|
|
c.RedemptionProofs,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HTLCSettleRequest) Command() uint32 {
|
|
|
|
return CmdHTLCSettleRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HTLCSettleRequest) MaxPayloadLength(uint32) uint32 {
|
2016-01-17 04:14:35 +03:00
|
|
|
// 21*15+16
|
2016-01-05 19:19:22 +03:00
|
|
|
return 331
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *HTLCSettleRequest) Validate() error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// We're good!
|
2016-01-05 19:19:22 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *HTLCSettleRequest) String() string {
|
|
|
|
var redemptionProofs string
|
|
|
|
for i, rh := range c.RedemptionProofs {
|
|
|
|
redemptionProofs += fmt.Sprintf("\n\tSlice\t%d\n", i)
|
|
|
|
redemptionProofs += fmt.Sprintf("\t\tRedemption Proof: %x\n", *rh)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("\n--- Begin HTLCSettleRequest ---\n") +
|
|
|
|
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +
|
2016-01-15 04:02:23 +03:00
|
|
|
fmt.Sprintf("HTLCKey:\t%d\n", c.HTLCKey) +
|
2016-01-05 19:19:22 +03:00
|
|
|
fmt.Sprintf("RedemptionHashes:") +
|
|
|
|
redemptionProofs +
|
|
|
|
fmt.Sprintf("--- End HTLCSettleRequest ---\n")
|
|
|
|
}
|