diff --git a/cmd/neofs-adm/internal/modules/morph/dump.go b/cmd/neofs-adm/internal/modules/morph/dump.go index b16b820c00..8f88beed3b 100644 --- a/cmd/neofs-adm/internal/modules/morph/dump.go +++ b/cmd/neofs-adm/internal/modules/morph/dump.go @@ -78,9 +78,8 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { for i := 0; i < irSize; i++ { ctrHash := "hash is invalid" - bs, err := alphaRes.Stack[i].TryBytes() - if err == nil { - ctrHash = string(bs) // hashes are stored as hex-encoded LE string + if h, err := parseNNSResolveResult(alphaRes.Stack[i]); err == nil { + ctrHash = h.StringLE() } _, _ = tw.Write([]byte(fmt.Sprintf("alphabet %d:\t%s\n", i, ctrHash))) @@ -89,9 +88,8 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { for i := range contractList { ctrHash := "hash is invalid" - bs, err := res.Stack[i].TryBytes() - if err == nil { - ctrHash = string(bs) // hashes are stored as hex-encoded LE string + if h, err := parseNNSResolveResult(res.Stack[i]); err == nil { + ctrHash = h.StringLE() } _, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%s\n", contractList[i], ctrHash))) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go index e1de223ed4..07aca04130 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go @@ -139,11 +139,20 @@ func nnsResolveHash(c *client.Client, nnsHash util.Uint160, domain string) (util if len(result.Stack) == 0 { return util.Uint160{}, errors.New("result stack is empty") } - arr, ok := result.Stack[len(result.Stack)-1].Value().([]stackitem.Item) - if !ok || len(arr) == 0 { - return util.Uint160{}, errors.New("malformed response") + return parseNNSResolveResult(result.Stack[len(result.Stack)-1]) +} + +// parseNNSResolveResult parses the result of resolving NNS record. +// It works with multiple formats (corresponding to multiple NNS versions). +// If array of hashes is provided, it returns only the first one. +func parseNNSResolveResult(res stackitem.Item) (util.Uint160, error) { + if arr, ok := res.Value().([]stackitem.Item); ok { + if len(arr) == 0 { + return util.Uint160{}, errors.New("NNS record is missing") + } + res = arr[0] } - bs, err := arr[0].TryBytes() + bs, err := res.TryBytes() if err != nil { return util.Uint160{}, errors.New("malformed response") }