Simplified the commitment messages

This commit is contained in:
Joseph Poon 2016-04-11 00:55:48 -07:00
parent 10d52611cd
commit 5218dca5b6
2 changed files with 10 additions and 47 deletions

@ -8,24 +8,17 @@ import (
// Multiple Clearing Requests are possible by putting this inside an array of
// clearing requests
type CommitRevocation struct {
// We can use a different data type for this if necessary...
ChannelID uint64
// Revocation to use
RevocationProof [20]byte
//Next revocation to use
NextRevocationHash [20]byte
Revocation [20]byte
}
func (c *CommitRevocation) Decode(r io.Reader, pver uint32) error {
// ChannelID(8)
// CommitmentHeight(8)
// RevocationProof(20)
// NextRevocationHash(20)
// Revocation(20)
err := readElements(r,
&c.ChannelID,
&c.RevocationProof,
&c.NextRevocationHash,
&c.Revocation,
)
if err != nil {
return err
@ -43,9 +36,8 @@ func NewCommitRevocation() *CommitRevocation {
// Writes the data to w
func (c *CommitRevocation) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.RevocationProof,
c.NextRevocationHash,
c.Revocation,
)
if err != nil {
return err
@ -70,8 +62,7 @@ func (c *CommitRevocation) Validate() error {
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) +
fmt.Sprintf("NextRevocationHash:\t%x\n", c.NextRevocationHash) +
fmt.Sprintf("Revocation:\t%x\n", c.Revocation) +
fmt.Sprintf("--- End CommitRevocation ---\n")
}

@ -10,25 +10,9 @@ import (
// Multiple Clearing Requests are possible by putting this inside an array of
// clearing requests
type CommitSignature struct {
// We can use a different data type for this if necessary...
ChannelID uint64
// 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.
//FIXME This might be superfluous
CommitmentHeight uint64
// List of HTLC Keys which are updated from all parties
//UpdatedHTLCKeys []uint64
LastCommittedKeyAlice HTLCKey
LastCommittedKeyBob HTLCKey
// Hash of the revocation to use
RevocationHash [20]byte
HighestPosition uint64
// Total miners' fee that was used
Fee btcutil.Amount
@ -44,11 +28,7 @@ func (c *CommitSignature) Decode(r io.Reader, pver uint32) error {
// Fee(8)
// RequesterCommitSig(73max+2)
err := readElements(r,
&c.ChannelID,
&c.CommitmentHeight,
&c.LastCommittedKeyAlice,
&c.LastCommittedKeyBob,
&c.RevocationHash,
&c.HighestPosition,
&c.Fee,
&c.CommitSig,
)
@ -68,11 +48,7 @@ func NewCommitSignature() *CommitSignature {
// Writes the data to w
func (c *CommitSignature) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
c.CommitmentHeight,
c.LastCommittedKeyAlice,
c.LastCommittedKeyBob,
c.RevocationHash,
c.HighestPosition,
c.Fee,
c.CommitSig,
)
@ -115,11 +91,7 @@ func (c *CommitSignature) String() string {
}
return fmt.Sprintf("\n--- Begin CommitSignature ---\n") +
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
fmt.Sprintf("CommitmentHeight:\t%d\n", c.CommitmentHeight) +
fmt.Sprintf("LastCommittedKeyAlice:\t%d\n", c.LastCommittedKeyAlice) +
fmt.Sprintf("LastCommittedKeyBob:\t%d\n", c.LastCommittedKeyBob) +
fmt.Sprintf("RevocationHash:\t\t%x\n", c.RevocationHash) +
fmt.Sprintf("HighestPosition:\t%d\n", c.HighestPosition) +
fmt.Sprintf("Fee:\t\t\t%s\n", c.Fee.String()) +
fmt.Sprintf("CommitSig:\t\t%x\n", serializedSig) +
fmt.Sprintf("--- End CommitSignature ---\n")