-
Notifications
You must be signed in to change notification settings - Fork 324
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
Showing
4 changed files
with
134 additions
and
0 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
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
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,60 @@ | ||
package did | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl/cmd/action" | ||
"github.com/iotexproject/iotex-core/ioctl/config" | ||
"github.com/iotexproject/iotex-core/ioctl/output" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Multi-language support | ||
var ( | ||
_serviceaddCmdShorts = map[config.Language]string{ | ||
config.English: "Add service to DID document using private key from wallet", | ||
config.Chinese: "用钱包中的私钥向DID document添加服务", | ||
} | ||
_serviceaddCmdUses = map[config.Language]string{ | ||
config.English: "serviceadd [-s SIGNER] RESOLVER_ENDPOINT TAG TYPE SERVICE_ENDPOINT", | ||
config.Chinese: "serviceadd [-s 签署人] Resolver端点 标签 类型 服务端点", | ||
} | ||
) | ||
|
||
// _didServiceAddCmd represents service add command | ||
var _didServiceAddCmd = &cobra.Command{ | ||
Use: config.TranslateInLang(_serviceaddCmdUses, config.UILanguage), | ||
Short: config.TranslateInLang(_serviceaddCmdShorts, config.UILanguage), | ||
Args: cobra.ExactArgs(4), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.SilenceUsage = true | ||
err := addService(args) | ||
return output.PrintError(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
action.RegisterWriteCommand(_didServiceAddCmd) | ||
} | ||
|
||
func addService(args []string) error { | ||
endpoint := args[0] | ||
|
||
signature, _, addr, err := signPermit(endpoint) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
serviceReq := &ServiceAddRequest{ | ||
Signature: *signature, | ||
Tag: args[1], | ||
Type: args[2], | ||
ServiceEndpoint: args[3], | ||
} | ||
serviceBytes, err := json.Marshal(&serviceReq) | ||
if err != nil { | ||
return output.NewError(output.ConvertError, "failed to encode request", err) | ||
} | ||
|
||
return postToResolver(endpoint+"/did/"+addr+"/service", serviceBytes) | ||
} |
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,58 @@ | ||
package did | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl/cmd/action" | ||
"github.com/iotexproject/iotex-core/ioctl/config" | ||
"github.com/iotexproject/iotex-core/ioctl/output" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Multi-language support | ||
var ( | ||
_serviceremoveCmdShorts = map[config.Language]string{ | ||
config.English: "Remove service to DID document using private key from wallet", | ||
config.Chinese: "用钱包中的私钥从DID document移除服务", | ||
} | ||
_serviceremoveCmdUses = map[config.Language]string{ | ||
config.English: "serviceremove [-s SIGNER] RESOLVER_ENDPOINT TAG", | ||
config.Chinese: "serviceremove [-s 签署人] Resolver端点 标签", | ||
} | ||
) | ||
|
||
// _didServiceRemoveCmd represents service remove command | ||
var _didServiceRemoveCmd = &cobra.Command{ | ||
Use: config.TranslateInLang(_serviceremoveCmdUses, config.UILanguage), | ||
Short: config.TranslateInLang(_serviceremoveCmdShorts, config.UILanguage), | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cmd.SilenceUsage = true | ||
err := removeService(args) | ||
return output.PrintError(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
action.RegisterWriteCommand(_didServiceRemoveCmd) | ||
} | ||
|
||
func removeService(args []string) error { | ||
endpoint := args[0] | ||
|
||
signature, _, addr, err := signPermit(endpoint) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
serviceReq := &ServiceRemoveRequest{ | ||
Signature: *signature, | ||
Tag: args[1], | ||
} | ||
serviceBytes, err := json.Marshal(&serviceReq) | ||
if err != nil { | ||
return output.NewError(output.ConvertError, "failed to encode request", err) | ||
} | ||
|
||
return postToResolver(endpoint+"/did/"+addr+"/service/delete", serviceBytes) | ||
} |