[#1006] neofs-adm: skip missing entries in dump-hashes

We have `subnet` contract in list, but it isn't currently deployed.
This commit skips missing NNS entries to handle such situation. In
future we may optimize this to be done in 1 round-trip.

As a nice side-effect, dump-hashes for notary-enabled environment works
even if notary is disabled -- it just prints zero hash for proxy
contract.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-12-03 12:01:30 +03:00 committed by Alex Vanin
parent 4ad2961c51
commit a5e952cc72

View file

@ -42,21 +42,6 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
infos := []contractDumpInfo{{name: nnsContract, hash: cs.Hash}}
bw := io.NewBufBinWriter()
for _, ctrName := range contractList {
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
ctrName+".neofs", int64(nns.TXT))
}
res, err := c.InvokeScript(bw.Bytes(), nil)
if err != nil {
return fmt.Errorf("can't fetch info from NNS: %w", err)
}
if len(res.Stack) != len(contractList) {
return errors.New("invalid response from NNS contract: length mismatch")
}
irSize := 0
for ; irSize < lastGlagoliticLetter; irSize++ {
ok, err := c.NNSIsAvailable(cs.Hash, getAlphabetNNSDomain(irSize))
@ -68,6 +53,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
}
buf := bytes.NewBuffer(nil)
bw := io.NewBufBinWriter()
if irSize != 0 {
bw.Reset()
@ -91,10 +77,21 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
}
}
for i := range contractList {
info := contractDumpInfo{name: contractList[i]}
if h, err := parseNNSResolveResult(res.Stack[i]); err == nil {
info.hash = h
for _, ctrName := range contractList {
bw.Reset()
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
ctrName+".neofs", int64(nns.TXT))
res, err := c.InvokeScript(bw.Bytes(), nil)
if err != nil {
return fmt.Errorf("can't fetch info from NNS: %w", err)
}
info := contractDumpInfo{name: ctrName}
if len(res.Stack) != 0 {
if h, err := parseNNSResolveResult(res.Stack[0]); err == nil {
info.hash = h
}
}
infos = append(infos, info)
}
@ -108,7 +105,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
}
}
res, err = c.InvokeScript(bw.Bytes(), nil)
res, err := c.InvokeScript(bw.Bytes(), nil)
if err != nil {
return fmt.Errorf("can't fetch info from NNS: %w", err)
}