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
|
|
|
// Revocation to use
|
2016-01-05 19:19:22 +03:00
|
|
|
RevocationProof [20]byte
|
2016-03-18 02:51:30 +03:00
|
|
|
|
|
|
|
//Next revocation to use
|
|
|
|
NextRevocationHash [20]byte
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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.RevocationProof,
|
2016-03-18 02:51:30 +03:00
|
|
|
&c.NextRevocationHash,
|
2016-01-05 19:19:22 +03:00
|
|
|
)
|
|
|
|
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.RevocationProof,
|
2016-03-18 02:51:30 +03:00
|
|
|
c.NextRevocationHash,
|
2016-01-05 19:19:22 +03:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CommitRevocation) Command() uint32 {
|
|
|
|
return CmdCommitRevocation
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CommitRevocation) MaxPayloadLength(uint32) uint32 {
|
2016-03-18 02:51:30 +03:00
|
|
|
return 48
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
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("RevocationProof:\t%x\n", c.RevocationProof) +
|
2016-03-18 02:51:30 +03:00
|
|
|
fmt.Sprintf("NextRevocationHash:\t%x\n", c.NextRevocationHash) +
|
2016-01-05 19:19:22 +03:00
|
|
|
fmt.Sprintf("--- End CommitRevocation ---\n")
|
|
|
|
}
|