lnd.xprv/lnwire/htlc_addaccept.go
Joseph Poon f3849f5c10 Structs for Wire Protocol HTLCs and Commitments
* Structs and wire messages for HTLCs
* Wire protocol for a state machine with no blocking(!!!)
  (I will write the state machine)
  TL;DR: Can do multiple HTLC modifications in-flight, dead simple wire
  protocol. Both sides can update their Commitments unliaterally without
  waiting for the other party's signature. Will have basic/preliminary
  notes in the README
* Added **swp to .gitignore because of vim annoyances
2016-01-14 23:56:10 -08:00

71 lines
1.3 KiB
Go

package lnwire
import (
"fmt"
"io"
)
type HTLCAddAccept struct {
ChannelID uint64
StagingID uint64
}
func (c *HTLCAddAccept) Decode(r io.Reader, pver uint32) error {
//ChannelID(8)
//CommitmentHeight(8)
//NextResponderCommitmentRevocationHash(20)
//ResponderRevocationPreimage(20)
//ResponderCommitSig(2+73max)
err := readElements(r,
&c.ChannelID,
&c.StagingID,
)
if err != nil {
return err
}
return nil
}
//Creates a new HTLCAddAccept
func NewHTLCAddAccept() *HTLCAddAccept {
return &HTLCAddAccept{}
}
//Serializes the item from the HTLCAddAccept struct
//Writes the data to w
func (c *HTLCAddAccept) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.StagingID,
)
if err != nil {
return err
}
return nil
}
func (c *HTLCAddAccept) Command() uint32 {
return CmdHTLCAddAccept
}
func (c *HTLCAddAccept) MaxPayloadLength(uint32) uint32 {
//16 base size
return 16
}
//Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
func (c *HTLCAddAccept) Validate() error {
//We're good!
return nil
}
func (c *HTLCAddAccept) String() string {
return fmt.Sprintf("\n--- Begin HTLCAddAccept ---\n") +
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
fmt.Sprintf("StagingID:\t\t%d\n", c.StagingID) +
fmt.Sprintf("--- End HTLCAddAccept ---\n")
}