-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b710aa2
commit 4330d84
Showing
13 changed files
with
481 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/p2p-org/dkc/cmd/combine" | ||
"github.com/p2p-org/dkc/cmd/convert" | ||
"github.com/p2p-org/dkc/utils" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var combineCmd = &cobra.Command{ | ||
Use: "combine", | ||
Short: "Combine distributed wallets to keystore", | ||
Long: `Allow to combine distributed wallets to keystore`, | ||
var convertCmd = &cobra.Command{ | ||
Use: "convert", | ||
Short: "Convert from distributed|hd|nd wallet types to distributed or nd wallets types", | ||
Long: `Allow to convert wallets types between each other`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
utils.Log.Info().Msgf("starting DKC-%s", viper.Get("version")) | ||
utils.Log.Info().Msgf("using config file: %s", viper.ConfigFileUsed()) | ||
utils.LogCombine.Info().Msg("starting combine function") | ||
err := combine.Run() | ||
utils.LogCombine.Info().Msg("starting convert function") | ||
err := convert.Run() | ||
if err != nil { | ||
utils.LogCombine.Fatal().Err(nil).Send() | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(combineCmd) | ||
rootCmd.AddCommand(convertCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package convert | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/p2p-org/dkc/utils" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type dataIn struct { | ||
ctx context.Context | ||
InputW utils.W | ||
OutputW utils.W | ||
} | ||
|
||
func (d *dataIn) validate() error { | ||
if d.InputW.Path == d.OutputW.Path { | ||
return errors.New("timeout is required") | ||
} | ||
|
||
if d.InputW.Type == d.OutputW.Type { | ||
return errors.New("timeout is required") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func input(ctx context.Context) (*dataIn, error) { | ||
var err error | ||
data := &dataIn{ | ||
InputW: utils.W{}, | ||
OutputW: utils.W{}, | ||
} | ||
|
||
//Parse Input Config | ||
data.InputW, err = utils.ParseCfg("input") | ||
if err != nil { | ||
return nil, errors.New("timeout is required") | ||
} | ||
|
||
//Parse Output Config | ||
data.OutputW, err = utils.ParseCfg("output") | ||
if err != nil { | ||
return nil, errors.New("timeout is required") | ||
} | ||
|
||
return data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package convert | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/p2p-org/dkc/utils" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
func process(ctx context.Context, data *dataIn) error { | ||
//Init Stores | ||
iStore, err := utils.InputStoreInit(data.InputW.Type) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
oStore, err := utils.OutputStoreInit(data.OutputW.Type) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Get Wallets List From Input Store | ||
err = iStore.Load(data.ctx, data.InputW.Path, data.InputW.Passphrases, data.InputW.Peers) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Create Output Store | ||
err = oStore.Create(data.ctx, data.OutputW.Path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Convert Wallets | ||
eg := errgroup.Group{} | ||
|
||
for _, wallet := range iStore.GetWallets() { | ||
eg.Go(func() error { | ||
w, err := oStore.CreateWallet(wallet) | ||
if err != nil { | ||
return err | ||
} | ||
}) | ||
} | ||
|
||
// Only First Error Will Be Displayed | ||
err = eg.Wait() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package convert | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func Run() error { | ||
ctx := context.Background() | ||
dataIn, err := input(ctx) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to obtain input") | ||
} | ||
|
||
err = dataIn.validate() | ||
if err != nil { | ||
return errors.Wrap(err, "failed to obtain input") | ||
} | ||
|
||
err = process(ctx, dataIn) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to process") | ||
} | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
input: | ||
store: | ||
path: DISTRIBUTED_WALLETS | ||
wallet: | ||
type: distributed | ||
passphrases: | ||
path: ./input_wallet_passphrases.txt | ||
threshold: 2 | ||
peers: | ||
10: old1:9091 | ||
20: old2:9091 | ||
30: old3:9091 | ||
output: | ||
store: | ||
path: ND_WALLETS | ||
wallet: | ||
type: nd | ||
passphrases: | ||
path: ./output_wallet_passphrases.txt | ||
|
||
log-level: debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.