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 CommitRevocation 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
|
|
|
// Height of the commitment
|
|
|
|
// You should have the most recent commitment height stored locally
|
|
|
|
// This should be validated!
|
|
|
|
// This is used for shachain.
|
|
|
|
// Each party increments their own CommitmentHeight, they can differ for
|
|
|
|
// each part of the Commitment.
|
2016-01-05 19:19:22 +03:00
|
|
|
CommitmentHeight uint64
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Revocation to use
|
2016-01-05 19:19:22 +03:00
|
|
|
RevocationProof [20]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error {
|
2016-01-17 04:14:35 +03:00
|
|
|
// ChannelID(8)
|
|
|
|
// CommitmentHeight(8)
|
|
|
|
// RevocationProof(20)
|
2016-01-05 19:19:22 +03:00
|
|
|
err := readElements(r,
|
|
|
|
&c.ChannelID,
|
|
|
|
&c.CommitmentHeight,
|
|
|
|
&c.RevocationProof,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Creates a new CommitRevocation
|
2016-01-05 19:19:22 +03:00
|
|
|
func NewCommitRevocation() *CommitRevocation {
|
|
|
|
return &CommitRevocation{}
|
|
|
|
}
|
|
|
|
|
2016-01-17 04:14:35 +03:00
|
|
|
// Serializes the item from the CommitRevocation struct
|
|
|
|
// Writes the data to w
|
2016-01-05 19:19:22 +03:00
|
|
|
func (c *CommitRevocation) Encode(w io.Writer, pver uint32) error {
|
|
|
|
err := writeElements(w,
|
|
|
|
c.ChannelID,
|
|
|
|
c.CommitmentHeight,
|
|
|
|
c.RevocationProof,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CommitRevocation) Command() uint32 {
|
|
|
|
return CmdCommitRevocation
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CommitRevocation) MaxPayloadLength(uint32) uint32 {
|
|
|
|
return 36
|
|
|
|
}
|
|
|
|
|
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 *CommitRevocation) 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 *CommitRevocation) String() string {
|
|
|
|
return fmt.Sprintf("\n--- Begin CommitRevocation ---\n") +
|
|
|
|
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
|
|
|
|
fmt.Sprintf("CommitmentHeight:\t%d\n", c.CommitmentHeight) +
|
|
|
|
fmt.Sprintf("RevocationProof:\t%x\n", c.RevocationProof) +
|
|
|
|
fmt.Sprintf("--- End CommitRevocation ---\n")
|
|
|
|
}
|