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-03-18 02:51:30 +03:00
|
|
|
//Next revocation to use
|
|
|
|
NextRevocationHash [20]byte
|
2016-04-11 10:55:48 +03:00
|
|
|
Revocation [20]byte
|
2016-01-05 19:19:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error {
|
2016-04-11 10:55:48 +03:00
|
|
|
// NextRevocationHash(20)
|
|
|
|
// Revocation(20)
|
2016-01-05 19:19:22 +03:00
|
|
|
err := readElements(r,
|
2016-03-18 02:51:30 +03:00
|
|
|
&c.NextRevocationHash,
|
2016-04-11 10:55:48 +03:00
|
|
|
&c.Revocation,
|
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,
|
2016-03-18 02:51:30 +03:00
|
|
|
c.NextRevocationHash,
|
2016-04-11 10:55:48 +03:00
|
|
|
c.Revocation,
|
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") +
|
2016-03-18 02:51:30 +03:00
|
|
|
fmt.Sprintf("NextRevocationHash:\t%x\n", c.NextRevocationHash) +
|
2016-04-11 10:55:48 +03:00
|
|
|
fmt.Sprintf("Revocation:\t%x\n", c.Revocation) +
|
2016-01-05 19:19:22 +03:00
|
|
|
fmt.Sprintf("--- End CommitRevocation ---\n")
|
|
|
|
}
|