Skip to content

Commit

Permalink
feat: allow specification of sync wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-p committed Jun 10, 2024
1 parent 170891b commit 52f98d0
Showing 1 changed file with 15 additions and 8 deletions.
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

0 comments on commit 52f98d0

Please sign in to comment.