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

adm: never use GetContractStateByID(1) to retrieve NNS hash #2841

Merged
merged 1 commit into from
May 6, 2024
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
31 changes: 8 additions & 23 deletions cmd/neofs-adm/internal/modules/morph/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"math/big"

"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
"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/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
Expand All @@ -19,7 +18,7 @@
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
"github.com/nspcc-dev/neofs-contract/contracts/nns"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -42,7 +41,7 @@
dumpStorage, _ = cmd.Flags().GetBool(dumpBalancesStorageFlag)
dumpAlphabet, _ = cmd.Flags().GetBool(dumpBalancesAlphabetFlag)
dumpProxy, _ = cmd.Flags().GetBool(dumpBalancesProxyFlag)
nnsCs *state.Contract
nnsReader *nns.ContractReader

Check warning on line 44 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L44

Added line #L44 was not covered by tests
nmHash util.Uint160
)

Expand All @@ -54,12 +53,13 @@
inv := invoker.New(c, nil)

if dumpStorage || dumpAlphabet || dumpProxy {
nnsCs, err = c.GetContractStateByID(1)
carpawell marked this conversation as resolved.
Show resolved Hide resolved
nnsHash, err := nns.InferHash(c)

Check warning on line 56 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L56

Added line #L56 was not covered by tests
if err != nil {
return fmt.Errorf("can't get NNS contract info: %w", err)
return fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 58 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L58

Added line #L58 was not covered by tests
}
nnsReader = nns.NewReader(inv, nnsHash)

Check warning on line 60 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L60

Added line #L60 was not covered by tests

nmHash, err = nnsResolveHash(inv, nnsCs.Hash, netmapContract+".neofs")
nmHash, err = nnsReader.ResolveFSContract(nns.NameNetmap)

Check warning on line 62 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L62

Added line #L62 was not covered by tests
if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err)
}
Expand Down Expand Up @@ -109,7 +109,7 @@
}

if dumpProxy {
h, err := nnsResolveHash(inv, nnsCs.Hash, proxyContract+".neofs")
h, err := nnsReader.ResolveFSContract(nns.NameProxy)

Check warning on line 112 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L112

Added line #L112 was not covered by tests
if err != nil {
return fmt.Errorf("can't get hash of the proxy contract: %w", err)
}
Expand All @@ -124,23 +124,8 @@
if dumpAlphabet {
alphaList := make([]accBalancePair, len(irList))

b := smartcontract.NewBuilder()
for i := range alphaList {
b.InvokeMethod(nnsCs.Hash, "resolve", getAlphabetNNSDomain(i), int64(nns.TXT))
}

script, err := b.Script()
if err != nil {
return fmt.Errorf("resolving alphabet hashes script: %w", err)
}

alphaRes, err := c.InvokeScript(script, nil)
if err != nil {
return fmt.Errorf("can't fetch info from NNS: %w", err)
}

for i := range alphaList {
h, err := parseNNSResolveResult(alphaRes.Stack[i])
h, err := nnsReader.ResolveFSContract(getAlphabetNNSDomain(i))

Check warning on line 128 in cmd/neofs-adm/internal/modules/morph/balance.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/balance.go#L128

Added line #L128 was not covered by tests
if err != nil {
return fmt.Errorf("can't fetch the alphabet contract #%d hash: %w", i, err)
}
Expand Down
15 changes: 9 additions & 6 deletions cmd/neofs-adm/internal/modules/morph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -28,12 +29,13 @@

inv := invoker.New(c, nil)

cs, err := c.GetContractStateByID(1)
nnsHash, err := nns.InferHash(c)

Check warning on line 32 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L32

Added line #L32 was not covered by tests
if err != nil {
return fmt.Errorf("can't get NNS contract info: %w", err)
return fmt.Errorf("can't find NNS hash: %w", err)

Check warning on line 34 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L34

Added line #L34 was not covered by tests
}
nnsReader := nns.NewReader(inv, nnsHash)

Check warning on line 36 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L36

Added line #L36 was not covered by tests

nmHash, err := nnsResolveHash(inv, cs.Hash, netmapContract+".neofs")
nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap)

Check warning on line 38 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L38

Added line #L38 was not covered by tests
if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err)
}
Expand Down Expand Up @@ -102,12 +104,13 @@
return fmt.Errorf("can't initialize context: %w", err)
}

cs, err := wCtx.Client.GetContractStateByID(1)
nnsHash, err := nns.InferHash(wCtx.Client)

Check warning on line 107 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L107

Added line #L107 was not covered by tests
if err != nil {
return fmt.Errorf("can't get NNS contract info: %w", err)
return fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 109 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L109

Added line #L109 was not covered by tests
}
nnsReader := nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash)

Check warning on line 111 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L111

Added line #L111 was not covered by tests

nmHash, err := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, netmapContract+".neofs")
nmHash, err := nnsReader.ResolveFSContract(nns.NameNetmap)

Check warning on line 113 in cmd/neofs-adm/internal/modules/morph/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/config.go#L113

Added line #L113 was not covered by tests
if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err)
}
Expand Down
18 changes: 11 additions & 7 deletions cmd/neofs-adm/internal/modules/morph/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -27,13 +28,15 @@
ch, err = util.Uint160DecodeStringLE(s)
}
if err != nil {
nnsCs, err := c.GetContractStateByID(1)
nnsHash, err := nns.InferHash(c)

Check warning on line 31 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L31

Added line #L31 was not covered by tests
if err != nil {
return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err)
return ch, fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 33 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L33

Added line #L33 was not covered by tests
}
ch, err = nnsResolveHash(inv, nnsCs.Hash, containerContract+".neofs")
nnsReader := nns.NewReader(inv, nnsHash)

Check warning on line 35 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L35

Added line #L35 was not covered by tests

ch, err = nnsReader.ResolveFSContract(nns.NameContainer)

Check warning on line 37 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L37

Added line #L37 was not covered by tests
if err != nil {
return util.Uint160{}, err
return ch, fmt.Errorf("can't fetch container contract hash: %w", err)

Check warning on line 39 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L39

Added line #L39 was not covered by tests
}
}
return ch, nil
Expand Down Expand Up @@ -168,12 +171,13 @@
}
defer wCtx.close()

nnsCs, err := wCtx.Client.GetContractStateByID(1)
nnsHash, err := nns.InferHash(wCtx.Client)

Check warning on line 174 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L174

Added line #L174 was not covered by tests
if err != nil {
return fmt.Errorf("can't get NNS contract state: %w", err)
return fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 176 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L176

Added line #L176 was not covered by tests
}
nnsReader := nns.NewReader(wCtx.ReadOnlyInvoker, nnsHash)

Check warning on line 178 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L178

Added line #L178 was not covered by tests

ch, err := nnsResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, containerContract+".neofs")
ch, err := nnsReader.ResolveFSContract(nns.NameContainer)

Check warning on line 180 in cmd/neofs-adm/internal/modules/morph/container.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/container.go#L180

Added line #L180 was not covered by tests
if err != nil {
return fmt.Errorf("can't fetch container contract hash: %w", err)
}
Expand Down
28 changes: 14 additions & 14 deletions cmd/neofs-adm/internal/modules/morph/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neofs-contract/contracts/nns"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -76,9 +76,9 @@
return err
}

nnsCs, err := c.Client.GetContractStateByID(1)
nnsHash, err := nns.InferHash(c.Client)

Check warning on line 79 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L79

Added line #L79 was not covered by tests
if err != nil {
return fmt.Errorf("can't fetch NNS contract state: %w", err)
return fmt.Errorf("can't fetch NNS contract hash: %w", err)

Check warning on line 81 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L81

Added line #L81 was not covered by tests
}

callHash := management.Hash
Expand All @@ -87,7 +87,7 @@
domain := ctrName + "." + zone
isUpdate, _ := cmd.Flags().GetBool(updateFlag)
if isUpdate {
cs.Hash, err = nnsResolveHash(c.ReadOnlyInvoker, nnsCs.Hash, domain)
cs.Hash, err = nnsResolveHash(c.ReadOnlyInvoker, nnsHash, domain)

Check warning on line 90 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L90

Added line #L90 was not covered by tests
if err != nil {
return fmt.Errorf("can't fetch contract hash from NNS: %w", err)
}
Expand All @@ -113,28 +113,28 @@
if !isUpdate {
bw := io.NewBufBinWriter()
emit.Instruction(bw.BinWriter, opcode.INITSSLOT, []byte{1})
emit.AppCall(bw.BinWriter, nnsCs.Hash, "getPrice", callflag.All)
emit.AppCall(bw.BinWriter, nnsHash, "getPrice", callflag.All)

Check warning on line 116 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L116

Added line #L116 was not covered by tests
emit.Opcodes(bw.BinWriter, opcode.STSFLD0)
emit.AppCall(bw.BinWriter, nnsCs.Hash, "setPrice", callflag.All, 1)
emit.AppCall(bw.BinWriter, nnsHash, "setPrice", callflag.All, 1)

Check warning on line 118 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L118

Added line #L118 was not covered by tests

start := bw.Len()
needRecord := false

ok, err := c.nnsRootRegistered(nnsCs.Hash, zone)
ok, err := c.nnsRootRegistered(nnsHash, zone)

Check warning on line 123 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L123

Added line #L123 was not covered by tests
if err != nil {
return err
} else if !ok {
needRecord = true

emit.AppCall(bw.BinWriter, nnsCs.Hash, "registerTLD", callflag.All,
emit.AppCall(bw.BinWriter, nnsHash, "registerTLD", callflag.All,

Check warning on line 129 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L129

Added line #L129 was not covered by tests
zone,
"[email protected]", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All,

Check warning on line 132 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L132

Added line #L132 was not covered by tests
domain, c.CommitteeAcc.Contract.ScriptHash(),
"[email protected]", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600))
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
} else {
s, ok, err := c.nnsRegisterDomainScript(nnsCs.Hash, cs.Hash, domain)
s, ok, err := c.nnsRegisterDomainScript(nnsHash, cs.Hash, domain)

Check warning on line 137 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L137

Added line #L137 was not covered by tests
if err != nil {
return err
}
Expand All @@ -144,17 +144,17 @@
}
}
if needRecord {
emit.AppCall(bw.BinWriter, nnsCs.Hash, "deleteRecords", callflag.All, domain, int64(nns.TXT))
emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
domain, int64(nns.TXT), address.Uint160ToString(cs.Hash))
emit.AppCall(bw.BinWriter, nnsHash, "deleteRecords", callflag.All, domain, nns.TXT)
emit.AppCall(bw.BinWriter, nnsHash, "addRecord", callflag.All,
domain, nns.TXT, address.Uint160ToString(cs.Hash))

Check warning on line 149 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L147-L149

Added lines #L147 - L149 were not covered by tests
}

if bw.Err != nil {
panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err))
} else if bw.Len() != start {
w.WriteBytes(bw.Bytes())
emit.Opcodes(w.BinWriter, opcode.LDSFLD0, opcode.PUSH1, opcode.PACK)
emit.AppCallNoArgs(w.BinWriter, nnsCs.Hash, "setPrice", callflag.All)
emit.AppCallNoArgs(w.BinWriter, nnsHash, "setPrice", callflag.All)

Check warning on line 157 in cmd/neofs-adm/internal/modules/morph/deploy.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/deploy.go#L157

Added line #L157 was not covered by tests

if needRecord {
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
Expand Down
66 changes: 17 additions & 49 deletions cmd/neofs-adm/internal/modules/morph/dump_hashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
"github.com/nspcc-dev/neofs-contract/contracts/nns"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -39,76 +39,44 @@
return fmt.Errorf("can't create N3 client: %w", err)
}

cs, err := c.GetContractStateByID(1)
inv := invoker.New(c, nil)
nnsHash, err := nns.InferHash(c)

Check warning on line 43 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L42-L43

Added lines #L42 - L43 were not covered by tests
if err != nil {
return err
return fmt.Errorf("can't get NNS contract hash: %w", err)

Check warning on line 45 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L45

Added line #L45 was not covered by tests
}
nnsReader := nns.NewReader(inv, nnsHash)

Check warning on line 47 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L47

Added line #L47 was not covered by tests

zone, _ := cmd.Flags().GetString(customZoneFlag)
if zone != "" {
return dumpCustomZoneHashes(cmd, cs.Hash, zone, c)
return dumpCustomZoneHashes(cmd, nnsHash, zone, c)

Check warning on line 51 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L51

Added line #L51 was not covered by tests
}

infos := []contractDumpInfo{{name: nnsContract, hash: cs.Hash}}
infos := []contractDumpInfo{{name: nnsContract, hash: nnsHash}}

Check warning on line 54 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L54

Added line #L54 was not covered by tests

irSize := 0
for ; irSize < lastGlagoliticLetter; irSize++ {
ok, err := nnsIsAvailable(c, cs.Hash, getAlphabetNNSDomain(irSize))
ok, err := nnsReader.IsAvailable(getAlphabetNNSDomain(irSize) + "." + nns.ContractTLD)

Check warning on line 58 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L58

Added line #L58 was not covered by tests
if err != nil {
return err
} else if ok {
break
}
}

b := smartcontract.NewBuilder()

if irSize != 0 {
b.Reset()
for i := 0; i < irSize; i++ {
b.InvokeMethod(cs.Hash, "resolve", getAlphabetNNSDomain(i), int64(nns.TXT))
}

script, err := b.Script()
if err != nil {
return fmt.Errorf("resolving alphabet hashes script: %w", err)
}

alphaRes, err := c.InvokeScript(script, nil)
if err != nil {
return fmt.Errorf("can't fetch info from NNS: %w", err)
}

for i := 0; i < irSize; i++ {
info := contractDumpInfo{name: fmt.Sprintf("alphabet %d", i)}
if h, err := parseNNSResolveResult(alphaRes.Stack[i]); err == nil {
info.hash = h
}
infos = append(infos, info)
}
var contracts = make([]string, 0, irSize+len(contractList))
for i := 0; i < irSize; i++ {
contracts = append(contracts, getAlphabetNNSDomain(i))

Check warning on line 68 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L66-L68

Added lines #L66 - L68 were not covered by tests
}

for _, ctrName := range contractList {
b.Reset()
b.InvokeMethod(cs.Hash, "resolve", ctrName+".neofs", int64(nns.TXT))

script, err := b.Script()
if err != nil {
return fmt.Errorf("resolving neofs contract hashes script: %w", err)
}
contracts = append(contracts, ctrName)

Check warning on line 71 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L71

Added line #L71 was not covered by tests
}

res, err := c.InvokeScript(script, nil)
for _, ctrName := range contracts {
h, err := nnsReader.ResolveFSContract(ctrName)

Check warning on line 75 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L74-L75

Added lines #L74 - L75 were not covered by tests
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
}
return fmt.Errorf("can't resolve %s contract: %w", ctrName, err)

Check warning on line 77 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L77

Added line #L77 was not covered by tests
}
infos = append(infos, info)
infos = append(infos, contractDumpInfo{name: ctrName, hash: h})

Check warning on line 79 in cmd/neofs-adm/internal/modules/morph/dump_hashes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_hashes.go#L79

Added line #L79 was not covered by tests
}

fillContractVersion(cmd, c, infos)
Expand Down
10 changes: 5 additions & 5 deletions cmd/neofs-adm/internal/modules/morph/dump_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"time"

"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nep11"
"github.com/nspcc-dev/neofs-contract/rpc/nns"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -28,12 +28,12 @@
if err != nil {
return fmt.Errorf("can't create N3 client: %w", err)
}
cs, err := c.GetContractStateByID(1) // NNS.
nnsHash, err := nns.InferHash(c)

Check warning on line 31 in cmd/neofs-adm/internal/modules/morph/dump_names.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_names.go#L31

Added line #L31 was not covered by tests
if err != nil {
return err
}
var n11r = nep11.NewNonDivisibleReader(invoker.New(c, nil), cs.Hash)
tokIter, err := n11r.Tokens()
var nnsReader = nns.NewReader(invoker.New(c, nil), nnsHash)
tokIter, err := nnsReader.Tokens()

Check warning on line 36 in cmd/neofs-adm/internal/modules/morph/dump_names.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_names.go#L35-L36

Added lines #L35 - L36 were not covered by tests
if err != nil {
return err
}
Expand All @@ -48,7 +48,7 @@
if zone != "" && !strings.HasSuffix(name, "."+zone) {
continue
}
props, err := n11r.Properties(toks[i])
props, err := nnsReader.Properties(toks[i])

Check warning on line 51 in cmd/neofs-adm/internal/modules/morph/dump_names.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-adm/internal/modules/morph/dump_names.go#L51

Added line #L51 was not covered by tests
if err != nil {
cmd.PrintErrf("Error getting properties for %s: %v\n", name, err)
continue
Expand Down
Loading
Loading