Skip to content

Commit

Permalink
use for range loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kc1116 committed Apr 2, 2024
1 parent 884fdbf commit 6aacb01
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions cmd/util/cmd/epochs/cmd/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,13 @@ func extractRecoverEpochArgs(snapshot *inmem.Snapshot) []cadence.Value {
}
log.Info().Msg("")

collectors.Map(func(identity flow.Identity) flow.Identity {
if _, ok := internalNodesMap[identity.NodeID]; ok {
internalCollectors = append(internalCollectors, &identity)
for _, collector := range collectors {
if _, ok := internalNodesMap[collector.NodeID]; ok {
internalCollectors = append(internalCollectors, collector)
} else {
partnerCollectors = append(partnerCollectors, &identity)
partnerCollectors = append(partnerCollectors, collector)
}
return identity
})
}

currentEpochDKG, err := epoch.DKG()
if err != nil {
Expand All @@ -156,25 +155,25 @@ func extractRecoverEpochArgs(snapshot *inmem.Snapshot) []cadence.Value {

dkgPubKeys := make([]cadence.Value, 0)
nodeIds := make([]cadence.Value, 0)
ids.Map(func(identity flow.Identity) flow.Identity {
if identity.GetRole() == flow.RoleConsensus {
dkgPubKey, keyShareErr := currentEpochDKG.KeyShare(identity.GetNodeID())

for _, id := range ids {
if id.GetRole() == flow.RoleConsensus {
dkgPubKey, keyShareErr := currentEpochDKG.KeyShare(id.GetNodeID())
if keyShareErr != nil {
log.Fatal().Err(keyShareErr).Msg(fmt.Sprintf("failed to get dkg pub key share for node: %s", identity.GetNodeID()))
log.Fatal().Err(keyShareErr).Msg(fmt.Sprintf("failed to get dkg pub key share for node: %s", id.GetNodeID()))
}
dkgPubKeyCdc, cdcErr := cadence.NewString(dkgPubKey.String())
if cdcErr != nil {
log.Fatal().Err(cdcErr).Msg(fmt.Sprintf("failed to get dkg pub key cadence string for node: %s", identity.GetNodeID()))
log.Fatal().Err(cdcErr).Msg(fmt.Sprintf("failed to get dkg pub key cadence string for node: %s", id.GetNodeID()))
}
dkgPubKeys = append(dkgPubKeys, dkgPubKeyCdc)
}
nodeIdCdc, err := cadence.NewString(identity.GetNodeID().String())
nodeIdCdc, err := cadence.NewString(id.GetNodeID().String())
if err != nil {
log.Fatal().Err(err).Msg(fmt.Sprintf("failed to convert node ID to cadence string: %s", identity.GetNodeID()))
log.Fatal().Err(err).Msg(fmt.Sprintf("failed to convert node ID to cadence string: %s", id.GetNodeID()))
}
nodeIds = append(nodeIds, nodeIdCdc)
return identity
})
}

// @TODO: cluster qcs are converted into flow.ClusterQCVoteData types,
// we need a corresponding type in cadence on the FlowClusterQC contract
Expand Down

0 comments on commit 6aacb01

Please sign in to comment.