Skip to content

Commit

Permalink
maintainence(lib/babe): refactor code to use epochHandler for control…
Browse files Browse the repository at this point in the history
… of epoch logic (#2151)
  • Loading branch information
noot authored Jan 28, 2022
1 parent 9e360a5 commit 656fd8d
Show file tree
Hide file tree
Showing 18 changed files with 1,011 additions and 635 deletions.
15 changes: 15 additions & 0 deletions dot/types/authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package types

import (
"encoding/binary"
"fmt"
"io"

"github.com/ChainSafe/gossamer/lib/common"
Expand Down Expand Up @@ -74,6 +75,16 @@ func (a *Authority) ToRaw() *AuthorityRaw {
return raw
}

// DeepCopy creates a deep copy of the Authority
func (a *Authority) DeepCopy() *Authority {
pk := a.Key.Encode()
pkCopy, _ := sr25519.NewPublicKey(pk[:])
return &Authority{
Key: pkCopy,
Weight: a.Weight,
}
}

// FromRawSr25519 sets the Authority given AuthorityRaw. It converts the byte representations of
// the authority public keys into a sr25519.PublicKey.
func (a *Authority) FromRawSr25519(raw *AuthorityRaw) error {
Expand All @@ -93,6 +104,10 @@ type AuthorityRaw struct {
Weight uint64
}

func (a *AuthorityRaw) String() string {
return fmt.Sprintf("AuthorityRaw Key=0x%x Weight=%d", a.Key, a.Weight)
}

// AuthoritiesToRaw converts an array of Authority in an array of AuthorityRaw
func AuthoritiesToRaw(auths []Authority) []AuthorityRaw {
raw := make([]AuthorityRaw, len(auths))
Expand Down
6 changes: 6 additions & 0 deletions dot/types/consensus_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package types

import (
"fmt"

"github.com/ChainSafe/gossamer/pkg/scale"
)

Expand Down Expand Up @@ -70,6 +72,10 @@ type NextEpochData struct {
// Index Returns VDT index
func (d NextEpochData) Index() uint { return 1 }

func (d NextEpochData) String() string {
return fmt.Sprintf("NextEpochData Authorities=%v Randomness=%v", d.Authorities, d.Randomness)
}

// ToEpochData returns the NextEpochData as EpochData
func (d *NextEpochData) ToEpochData() (*EpochData, error) {
auths, err := BABEAuthorityRawToAuthority(d.Authorities)
Expand Down
Loading

0 comments on commit 656fd8d

Please sign in to comment.