Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelkrolevets committed Nov 6, 2023
1 parent 4180dec commit 94edf54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions cli/initiator/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package initiator
import (
"encoding/hex"
"fmt"
e2m_core "github.com/bloxapp/eth2-key-manager/core"
"os"

e2m_core "github.com/bloxapp/eth2-key-manager/core"
"github.com/spf13/cobra"
"go.uber.org/zap"

Expand Down Expand Up @@ -74,9 +74,9 @@ var StartDKG = &cobra.Command{
if err != nil {
logger.Warn("Failed writing deposit data file: ", zap.Error(err))
}
keysharesFinalPath := fmt.Sprintf("%s/keyshares-%v-%v.json", cli_utils.OutputPath, depositData.PubKey, hex.EncodeToString(id[:]))
logger.Info("💾 Writing keyshares payload to file", zap.String("path", keysharesFinalPath))
err = utils.WriteJSON(keysharesFinalPath, keyShares)
// Save results
logger.Info("💾 Writing keyshares payload to file")
err = cli_utils.WriteKeyShares(id, keyShares.Payload.PublicKey, keyShares)
if err != nil {
logger.Warn("Failed writing keyshares file: ", zap.Error(err))
}
Expand Down
7 changes: 2 additions & 5 deletions cli/initiator/reshare.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package initiator

import (
"encoding/hex"
"fmt"

"github.com/spf13/cobra"
Expand All @@ -10,7 +9,6 @@ import (
cli_utils "github.com/bloxapp/ssv-dkg/cli/utils"
"github.com/bloxapp/ssv-dkg/pkgs/crypto"
"github.com/bloxapp/ssv-dkg/pkgs/initiator"
"github.com/bloxapp/ssv-dkg/pkgs/utils"
)

func init() {
Expand Down Expand Up @@ -70,9 +68,8 @@ var StartReshare = &cobra.Command{
logger.Fatal("😥 Failed to initiate DKG ceremony: ", zap.Error(err))
}
// Save results
keysharesFinalPath := fmt.Sprintf("%s/keyshares-reshared-%v-%v.json", cli_utils.OutputPath, keyShares.Payload.PublicKey, hex.EncodeToString(id[:]))
logger.Info("💾 Writing keyshares payload to file", zap.String("path", keysharesFinalPath))
err = utils.WriteJSON(keysharesFinalPath, keyShares)
logger.Info("💾 Writing keyshares payload to file")
err = cli_utils.WriteKeyShares(id, keyShares.Payload.PublicKey, keyShares)
if err != nil {
logger.Warn("Failed writing keyshares file: ", zap.Error(err))
}
Expand Down
9 changes: 9 additions & 0 deletions cli/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,12 @@ func GetOperatorDB() (basedb.Options, error) {
}
return DBOptions, nil
}

func WriteKeyShares(id [24]byte, PubKey string, keyShares *initiator.KeyShares) error {
keysharesFinalPath := fmt.Sprintf("%s/keyshares-%v-%v.json", OutputPath, PubKey, hex.EncodeToString(id[:]))
err := utils.WriteJSON(keysharesFinalPath, keyShares)
if err != nil {
return err
}
return nil
}

0 comments on commit 94edf54

Please sign in to comment.