Skip to content

Commit

Permalink
Apply suggestions from PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
durkmurder committed Oct 11, 2023
1 parent 32dd1d2 commit 497bec2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
30 changes: 30 additions & 0 deletions model/flow/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ func (iy Identity) Checksum() Identifier {
return MakeID(iy)
}

// GetNodeID returns node ID for the identity. It is needed to satisfy GenericIdentity constraint.
func (iy IdentitySkeleton) GetNodeID() Identifier {
return iy.NodeID
}

// GetRole returns a node role for the identity. It is needed to satisfy GenericIdentity constraint.
func (iy IdentitySkeleton) GetRole() Role {
return iy.Role
}

// GetStakingPubKey returns staking public key for the identity. It is needed to satisfy GenericIdentity constraint.
func (iy IdentitySkeleton) GetStakingPubKey() crypto.PublicKey {
return iy.StakingPubKey
}

// GetNetworkPubKey returns network public key for the identity. It is needed to satisfy GenericIdentity constraint.
func (iy IdentitySkeleton) GetNetworkPubKey() crypto.PublicKey {
return iy.NetworkPubKey
}

// GetInitialWeight returns initial weight for the identity. It is needed to satisfy GenericIdentity constraint.
func (iy IdentitySkeleton) GetInitialWeight() uint64 {
return iy.InitialWeight
}

// GetSkeleton returns the skeleton part for the identity. It is needed to satisfy GenericIdentity constraint.
func (iy IdentitySkeleton) GetSkeleton() IdentitySkeleton {
return iy
}

type encodableIdentitySkeleton struct {
NodeID Identifier
Address string `json:",omitempty"`
Expand Down
33 changes: 4 additions & 29 deletions model/flow/identity_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,6 @@ type GenericIdentity interface {
GetSkeleton() IdentitySkeleton
}

func (iy IdentitySkeleton) GetNodeID() Identifier {
return iy.NodeID
}

func (iy IdentitySkeleton) GetRole() Role {
return iy.Role
}

func (iy IdentitySkeleton) GetStakingPubKey() crypto.PublicKey {
return iy.StakingPubKey
}

func (iy IdentitySkeleton) GetNetworkPubKey() crypto.PublicKey {
return iy.NetworkPubKey
}

func (iy IdentitySkeleton) GetInitialWeight() uint64 {
return iy.InitialWeight
}

func (iy IdentitySkeleton) GetSkeleton() IdentitySkeleton {
return iy
}

// IdentityFilter is a filter on identities. Mathematically, an IdentityFilter F
// can be described as a function F: 𝓘 → 𝐼, where 𝓘 denotes the set of all identities
// and 𝐼 ⊆ 𝓘. For an input identity i, F(i) returns true if and only if i passed the
Expand All @@ -85,14 +61,13 @@ type IdentityList = GenericIdentityList[Identity]
type GenericIdentityList[T GenericIdentity] []*T

// Filter will apply a filter to the identity list.
// The resulting list will only contain entries that match the filtering criteria.
func (il GenericIdentityList[T]) Filter(filter IdentityFilter[T]) GenericIdentityList[T] {
var dup GenericIdentityList[T]
IDLoop:
for _, identity := range il {
if !filter(identity) {
continue IDLoop
if filter(identity) {
dup = append(dup, identity)
}
dup = append(dup, identity)
}
return dup
}
Expand Down Expand Up @@ -146,7 +121,7 @@ func (il GenericIdentityList[T]) Selector() IdentityFilter[T] {
// Lookup converts the identity slice to a map using the NodeIDs as keys. This
// is useful when _repeatedly_ querying identities by their NodeIDs. The
// conversation from slice to map incurs cost O(n), for `n` the slice length.
// For a _single_ lookup, use method `ByNodeID(Identifier)` (avoiding conversion).
// For a _single_ lookup, use method `ByNodeID(Identifier)` (avoiding conversion).
func (il GenericIdentityList[T]) Lookup() map[Identifier]*T {
lookup := make(map[Identifier]*T, len(il))
for _, identity := range il {
Expand Down

0 comments on commit 497bec2

Please sign in to comment.