Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow specification of sync wallet #111

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions client/cli/cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var syncCmd = &cobra.Command{
Use: "sync",
Short: "Publish a DID instance to the processing network",
Example: "algoid sync [DID name]",
Example: "algoid sync [did-name] [wallet-name]",
Aliases: []string{"publish", "update", "upload", "push"},
RunE: runSyncCmd,
}
Expand All @@ -37,7 +37,7 @@ func init() {
}

func runSyncCmd(_ *cobra.Command, args []string) error {
if len(args) != 1 {
if len(args) == 0 {
return errors.New("missing required parameters")
}

Expand All @@ -48,10 +48,17 @@ func runSyncCmd(_ *cobra.Command, args []string) error {
}

// Retrieve identifier
name := sanitize.Name(args[0])
id, err := st.Get(name)
didName := sanitize.Name(args[0])

walletName := didName

if len(args) > 1 {
walletName = sanitize.Name(args[1])
}

id, err := st.Get(didName)
if err != nil {
return fmt.Errorf("no available record under reference name: %s", name)
return fmt.Errorf("no available record under reference name: %s", didName)
}

// Get wallet account
Expand All @@ -61,7 +68,7 @@ func runSyncCmd(_ *cobra.Command, args []string) error {
}

// Decrypt wallet
seed, err := st.OpenWallet(name, wp)
seed, err := st.OpenWallet(walletName, wp)
if err != nil {
return err
}
Expand All @@ -85,14 +92,14 @@ func runSyncCmd(_ *cobra.Command, args []string) error {
// Submit request
log.Info("submitting request to the network")
if viper.GetBool("sync.delete") {
log.Infof("deleting: %s", name)
log.Infof("deleting: %s", didName)
if err = cl.DeleteDID(id, &account); err != nil {
return err
}
log.Info("DID instance deleted")
return nil
}
log.Infof("publishing: %s", name)
log.Infof("publishing: %s", didName)
if err := cl.PublishDID(id, &account); err != nil {
return err
}
Expand Down
Loading