forked from TrueCloudLab/frostfs-node
[#1748] neofs-adm: Allow to parse hashes in multiple formats
NEO NNS proposal uses addresses. We should eventually use the same, but must stay compatible now. Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
4ccacb89e8
commit
d4ac5bdb97
1 changed files with 23 additions and 9 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
|
@ -256,17 +257,30 @@ func nnsResolveKey(c Client, nnsHash util.Uint160, domain string) (*keys.PublicK
|
||||||
// It works with multiple formats (corresponding to multiple NNS versions).
|
// It works with multiple formats (corresponding to multiple NNS versions).
|
||||||
// If array of hashes is provided, it returns only the first one.
|
// If array of hashes is provided, it returns only the first one.
|
||||||
func parseNNSResolveResult(res stackitem.Item) (util.Uint160, error) {
|
func parseNNSResolveResult(res stackitem.Item) (util.Uint160, error) {
|
||||||
if arr, ok := res.Value().([]stackitem.Item); ok {
|
arr, ok := res.Value().([]stackitem.Item)
|
||||||
if len(arr) == 0 {
|
if !ok {
|
||||||
|
arr = []stackitem.Item{res}
|
||||||
|
}
|
||||||
|
if _, ok := res.Value().(stackitem.Null); ok || len(arr) == 0 {
|
||||||
return util.Uint160{}, errors.New("NNS record is missing")
|
return util.Uint160{}, errors.New("NNS record is missing")
|
||||||
}
|
}
|
||||||
res = arr[0]
|
for i := range arr {
|
||||||
}
|
bs, err := arr[i].TryBytes()
|
||||||
bs, err := res.TryBytes()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return util.Uint160{}, errors.New("malformed response")
|
continue
|
||||||
}
|
}
|
||||||
return util.Uint160DecodeStringLE(string(bs))
|
|
||||||
|
h, err := util.Uint160DecodeStringLE(string(bs))
|
||||||
|
if err == nil {
|
||||||
|
return h, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
h, err = address.StringToUint160(string(bs))
|
||||||
|
if err == nil {
|
||||||
|
return h, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return util.Uint160{}, errors.New("no valid hashes are found")
|
||||||
}
|
}
|
||||||
|
|
||||||
var errNNSIsAvailableInvalid = errors.New("`isAvailable`: invalid response")
|
var errNNSIsAvailableInvalid = errors.New("`isAvailable`: invalid response")
|
||||||
|
|
Loading…
Reference in a new issue