forked from TrueCloudLab/frostfs-node
[#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 <carpawell@nspcc.ru>
This commit is contained in:
parent
d57c57010f
commit
bbd6b9780f
1 changed files with 17 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue