From bbd6b9780f96c61c0af1914bfd90b8136a90a532 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 15 Aug 2022 17:05:00 +0300 Subject: [PATCH] [#1683] adm: Minimize registration price Register NNS domain in one TX: 1. Set minimal (`1`) registration price; 2. Register domain; 3. Return registration price back. Signed-off-by: Pavel Karpy --- .../internal/modules/morph/initialize_nns.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go index 981850ad7..6b435ad90 100644 --- a/cmd/neofs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/neofs-adm/internal/modules/morph/initialize_nns.go @@ -129,12 +129,29 @@ func (c *initializeContext) nnsRegisterDomainScript(nnsHash, expectedHash util.U return nil, err } + res, err := invokeFunction(c.Client, nnsHash, "getPrice", nil, nil) + if err != nil || res.State != vmstate.Halt.String() || len(res.Stack) == 0 { + return nil, errors.New("could not get NNS's price") + } + + price, err := res.Stack[0].TryInteger() + if err != nil { + return nil, fmt.Errorf("unexpected `GetPrice` stack returned: %w", err) + } + bw := io.NewBufBinWriter() if ok { + // set minimal registration price + emit.AppCall(bw.BinWriter, nnsHash, "setPrice", callflag.All, 1) + + // register domain emit.AppCall(bw.BinWriter, nnsHash, "register", callflag.All, domain, c.CommitteeAcc.Contract.ScriptHash(), "ops@nspcc.ru", int64(3600), int64(600), int64(604800), int64(3600)) emit.Opcodes(bw.BinWriter, opcode.ASSERT) + + // set registration price back + emit.AppCall(bw.BinWriter, nnsHash, "setPrice", callflag.All, price) } else { s, err := nnsResolveHash(c.Client, nnsHash, domain) if err != nil {