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
This commit is contained in:
1 parent
58f0bfe252
commit
f3849f5c10
23 files changed
+1286
-5
No files matched your search
@@ -0,0 +1,71 @@
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
//Multiple Clearing Requests are possible by putting this inside an array of
|
||||
//clearing requests
|
||||
type HTLCTimeoutRequest struct {
|
||||
//We can use a different data type for this if necessary...
|
||||
ChannelID uint64
|
||||
|
||||
//ID of this request
|
||||
StagingID uint64
|
||||
}
|
||||
|
||||
func (c *HTLCTimeoutRequest) Decode(r io.Reader, pver uint32) error {
|
||||
//ChannelID(8)
|
||||
//StagingID(8)
|
||||
err := readElements(r,
|
||||
&c.ChannelID,
|
||||
&c.StagingID,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
//Creates a new HTLCTimeoutRequest
|
||||
func NewHTLCTimeoutRequest() *HTLCTimeoutRequest {
|
||||
return &HTLCTimeoutRequest{}
|
||||
}
|
||||
|
||||
//Serializes the item from the HTLCTimeoutRequest struct
|
||||
//Writes the data to w
|
||||
func (c *HTLCTimeoutRequest) Encode(w io.Writer, pver uint32) error {
|
||||
err := writeElements(w,
|
||||
c.ChannelID,
|
||||
c.StagingID,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *HTLCTimeoutRequest) Command() uint32 {
|
||||
return CmdHTLCTimeoutRequest
|
||||
}
|
||||
|
||||
func (c *HTLCTimeoutRequest) MaxPayloadLength(uint32) uint32 {
|
||||
//16
|
||||
return 16
|
||||
}
|
||||
|
||||
//Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
|
||||
func (c *HTLCTimeoutRequest) Validate() error {
|
||||
//We're good!
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *HTLCTimeoutRequest) String() string {
|
||||
return fmt.Sprintf("\n--- Begin HTLCTimeoutRequest ---\n") +
|
||||
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +
|
||||
fmt.Sprintf("StagingID:\t%d\n", c.StagingID) +
|
||||
fmt.Sprintf("--- End HTLCTimeoutRequest ---\n")
|
||||
}
|
||||
Reference in new issue
Block a user