[#1748] neofs-adm: Remove addRecord from nnsRegisterDomainScript

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-02 10:59:09 +03:00 committed by fyrchik
parent eb5e1121c5
commit 9290a7e1fe
3 changed files with 37 additions and 28 deletions

View file

@ -138,14 +138,18 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All, emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
domain, int64(nns.TXT), cs.Hash.StringLE()) domain, int64(nns.TXT), cs.Hash.StringLE())
} else { } else {
s, err := c.nnsRegisterDomainScript(nnsCs.Hash, cs.Hash, domain, false) s, ok, err := c.nnsRegisterDomainScript(nnsCs.Hash, cs.Hash, domain, false)
if err != nil { if err != nil {
return err return err
} }
if len(s) != 0 { if !ok {
newRecord = true newRecord = true
if len(s) != 0 {
bw.WriteBytes(s) bw.WriteBytes(s)
} }
emit.AppCall(w.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
domain, int64(nns.TXT), cs.Hash.StringLE())
}
} }
if bw.Err != nil { if bw.Err != nil {
panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err)) panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err))

View file

@ -26,6 +26,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
"github.com/nspcc-dev/neofs-contract/nns"
"github.com/nspcc-dev/neofs-node/pkg/innerring" "github.com/nspcc-dev/neofs-node/pkg/innerring"
morphClient "github.com/nspcc-dev/neofs-node/pkg/morph/client" morphClient "github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -263,14 +264,18 @@ func (c *initializeContext) updateContracts() error {
if method == deployMethodName { if method == deployMethodName {
// same actions are done in initializeContext.setNNS, can be unified // same actions are done in initializeContext.setNNS, can be unified
domain := ctrName + ".neofs" domain := ctrName + ".neofs"
script, err := c.nnsRegisterDomainScript(nnsHash, cs.Hash, domain, true) script, ok, err := c.nnsRegisterDomainScript(nnsHash, cs.Hash, domain, true)
if err != nil { if err != nil {
return err return err
} }
if !ok {
if script != nil { if script != nil {
totalGasCost += defaultRegisterSysfee + native.GASFactor totalGasCost += defaultRegisterSysfee + native.GASFactor
w.WriteBytes(script) w.WriteBytes(script)
} }
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
domain, int64(nns.TXT), cs.Hash.StringLE())
}
c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE()) c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE())
} }
} }

View file

@ -126,24 +126,24 @@ func getAlphabetNNSDomain(i int) string {
return alphabetContract + strconv.FormatUint(uint64(i), 10) + ".neofs" return alphabetContract + strconv.FormatUint(uint64(i), 10) + ".neofs"
} }
func (c *initializeContext) nnsRegisterDomainScript(nnsHash, expectedHash util.Uint160, domain string, setPrice bool) ([]byte, error) { func (c *initializeContext) nnsRegisterDomainScript(nnsHash, expectedHash util.Uint160, domain string, setPrice bool) ([]byte, bool, error) {
ok, err := nnsIsAvailable(c.Client, nnsHash, domain) ok, err := nnsIsAvailable(c.Client, nnsHash, domain)
if err != nil { if err != nil {
return nil, err return nil, false, err
} }
bw := io.NewBufBinWriter()
if ok { if ok {
bw := io.NewBufBinWriter()
var price *big.Int var price *big.Int
if setPrice { if setPrice {
res, err := invokeFunction(c.Client, nnsHash, "getPrice", nil, nil) res, err := invokeFunction(c.Client, nnsHash, "getPrice", nil, nil)
if err != nil || res.State != vmstate.Halt.String() || len(res.Stack) == 0 { if err != nil || res.State != vmstate.Halt.String() || len(res.Stack) == 0 {
return nil, errors.New("could not get NNS's price") return nil, false, errors.New("could not get NNS's price")
} }
price, err = res.Stack[0].TryInteger() price, err = res.Stack[0].TryInteger()
if err != nil { if err != nil {
return nil, fmt.Errorf("unexpected `GetPrice` stack returned: %w", err) return nil, false, fmt.Errorf("unexpected `GetPrice` stack returned: %w", err)
} }
// set minimal registration price // set minimal registration price
@ -160,32 +160,32 @@ func (c *initializeContext) nnsRegisterDomainScript(nnsHash, expectedHash util.U
// set registration price back // set registration price back
emit.AppCall(bw.BinWriter, nnsHash, "setPrice", callflag.All, price) emit.AppCall(bw.BinWriter, nnsHash, "setPrice", callflag.All, price)
} }
} else {
s, err := nnsResolveHash(c.Client, nnsHash, domain)
if err != nil {
return nil, err
}
if s == expectedHash {
return nil, nil
}
}
emit.AppCall(bw.BinWriter, nnsHash, "addRecord", callflag.All,
domain, int64(nns.TXT), expectedHash.StringLE())
if bw.Err != nil { if bw.Err != nil {
panic(bw.Err) panic(bw.Err)
} }
return bw.Bytes(), nil return bw.Bytes(), false, nil
}
s, err := nnsResolveHash(c.Client, nnsHash, domain)
if err != nil {
return nil, false, err
}
return nil, s == expectedHash, nil
} }
func (c *initializeContext) nnsRegisterDomain(nnsHash, expectedHash util.Uint160, domain string) error { func (c *initializeContext) nnsRegisterDomain(nnsHash, expectedHash util.Uint160, domain string) error {
script, err := c.nnsRegisterDomainScript(nnsHash, expectedHash, domain, true) script, ok, err := c.nnsRegisterDomainScript(nnsHash, expectedHash, domain, true)
if script == nil { if ok || err != nil {
return err return err
} }
w := io.NewBufBinWriter()
w.WriteBytes(script)
emit.AppCall(w.BinWriter, nnsHash, "addRecord", callflag.All,
domain, int64(nns.TXT), expectedHash.StringLE())
sysFee := int64(defaultRegisterSysfee + native.GASFactor) sysFee := int64(defaultRegisterSysfee + native.GASFactor)
return c.sendCommitteeTx(script, sysFee, true) return c.sendCommitteeTx(w.Bytes(), sysFee, true)
} }
func (c *initializeContext) nnsRootRegistered(nnsHash util.Uint160, zone string) (bool, error) { func (c *initializeContext) nnsRootRegistered(nnsHash util.Uint160, zone string) (bool, error) {