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

[ioctl] Add INS register cmd #3903

Merged
merged 7 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
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
61 changes: 61 additions & 0 deletions ioctl/cmd/ins/ins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package ins

import (
"encoding/hex"

"github.com/spf13/cobra"
"golang.org/x/crypto/sha3"

"github.com/iotexproject/iotex-core/ioctl/config"
)

// IONode hash for io
var IONode, _ = hex.DecodeString("b2b692c69df4aa3b0a24634d20a3ba1b44c3299d09d6c4377577e20b09e68395")

// Multi-language support
var (
_insCmdShorts = map[config.Language]string{
config.English: "Manage INS of IoTeX blockchain",
config.Chinese: "管理IoTeX区块链上INS",
}
_flagInsEndPointUsages = map[config.Language]string{
config.English: "set endpoint for once",
config.Chinese: "一次设置端点", // this translation
}
_flagInsInsecureUsages = map[config.Language]string{
config.English: "insecure connection for once",
config.Chinese: "一次不安全连接", // this translation
}
)

// InsCmd represents the ins command
var InsCmd = &cobra.Command{
Use: "ins",
Short: config.TranslateInLang(_insCmdShorts, config.UILanguage),
}

func init() {
InsCmd.AddCommand(_insRegisterCmd)
InsCmd.PersistentFlags().StringVar(&config.ReadConfig.Endpoint, "endpoint",
config.ReadConfig.Endpoint, config.TranslateInLang(_flagInsEndPointUsages,
config.UILanguage))
InsCmd.PersistentFlags().BoolVar(&config.Insecure, "insecure", config.Insecure,
config.TranslateInLang(_flagInsInsecureUsages, config.UILanguage))
}

func nameHash(name string) (hash [32]byte, err error) {
ququzone marked this conversation as resolved.
Show resolved Hide resolved
sha := sha3.NewLegacyKeccak256()
if _, err = sha.Write(IONode); err != nil {
return
}
nameSha := sha3.NewLegacyKeccak256()
if _, err = nameSha.Write([]byte(name)); err != nil {
return
}
ququzone marked this conversation as resolved.
Show resolved Hide resolved
nameHash := nameSha.Sum(nil)
if _, err = sha.Write(nameHash); err != nil {
ququzone marked this conversation as resolved.
Show resolved Hide resolved
return
}
sha.Sum(hash[:0])
return
}
Loading