lnd.xprv/lnwire/commit_revocation.go

69 lines
1.4 KiB
Go
Raw Normal View History

package lnwire
import (
"fmt"
"io"
)
// Multiple Clearing Requests are possible by putting this inside an array of
// clearing requests
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
}
func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error {
2016-04-11 10:55:48 +03:00
// NextRevocationHash(20)
// Revocation(20)
err := readElements(r,
2016-03-18 02:51:30 +03:00
&c.NextRevocationHash,
2016-04-11 10:55:48 +03:00
&c.Revocation,
)
if err != nil {
return err
}
return nil
}
// Creates a new CommitRevocation
func NewCommitRevocation() *CommitRevocation {
return &CommitRevocation{}
}
// Serializes the item from the CommitRevocation struct
// Writes the data to w
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,
)
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
}
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
func (c *CommitRevocation) Validate() error {
// We're good!
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) +
fmt.Sprintf("--- End CommitRevocation ---\n")
}