[#888] neofs-adm: allow to work with multiple NNS versions
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
6571f9214f
commit
31b3c71457
2 changed files with 17 additions and 10 deletions
|
@ -78,9 +78,8 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
for i := 0; i < irSize; i++ {
|
for i := 0; i < irSize; i++ {
|
||||||
ctrHash := "hash is invalid"
|
ctrHash := "hash is invalid"
|
||||||
bs, err := alphaRes.Stack[i].TryBytes()
|
if h, err := parseNNSResolveResult(alphaRes.Stack[i]); err == nil {
|
||||||
if err == nil {
|
ctrHash = h.StringLE()
|
||||||
ctrHash = string(bs) // hashes are stored as hex-encoded LE string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = tw.Write([]byte(fmt.Sprintf("alphabet %d:\t%s\n", i, ctrHash)))
|
_, _ = 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 {
|
for i := range contractList {
|
||||||
ctrHash := "hash is invalid"
|
ctrHash := "hash is invalid"
|
||||||
bs, err := res.Stack[i].TryBytes()
|
if h, err := parseNNSResolveResult(res.Stack[i]); err == nil {
|
||||||
if err == nil {
|
ctrHash = h.StringLE()
|
||||||
ctrHash = string(bs) // hashes are stored as hex-encoded LE string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%s\n", contractList[i], ctrHash)))
|
_, _ = tw.Write([]byte(fmt.Sprintf("%s:\t%s\n", contractList[i], ctrHash)))
|
||||||
|
|
|
@ -139,11 +139,20 @@ func nnsResolveHash(c *client.Client, nnsHash util.Uint160, domain string) (util
|
||||||
if len(result.Stack) == 0 {
|
if len(result.Stack) == 0 {
|
||||||
return util.Uint160{}, errors.New("result stack is empty")
|
return util.Uint160{}, errors.New("result stack is empty")
|
||||||
}
|
}
|
||||||
arr, ok := result.Stack[len(result.Stack)-1].Value().([]stackitem.Item)
|
return parseNNSResolveResult(result.Stack[len(result.Stack)-1])
|
||||||
if !ok || len(arr) == 0 {
|
}
|
||||||
return util.Uint160{}, errors.New("malformed response")
|
|
||||||
|
// 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 {
|
if err != nil {
|
||||||
return util.Uint160{}, errors.New("malformed response")
|
return util.Uint160{}, errors.New("malformed response")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue