[#1748] neofs-adm: Remove addRecord
from nnsRegisterDomainScript
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
eb5e1121c5
commit
9290a7e1fe
3 changed files with 37 additions and 28 deletions
|
@ -138,13 +138,17 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
|
|||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
|
||||
domain, int64(nns.TXT), cs.Hash.StringLE())
|
||||
} 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 {
|
||||
return err
|
||||
}
|
||||
if len(s) != 0 {
|
||||
if !ok {
|
||||
newRecord = true
|
||||
bw.WriteBytes(s)
|
||||
if len(s) != 0 {
|
||||
bw.WriteBytes(s)
|
||||
}
|
||||
emit.AppCall(w.BinWriter, nnsCs.Hash, "addRecord", callflag.All,
|
||||
domain, int64(nns.TXT), cs.Hash.StringLE())
|
||||
}
|
||||
}
|
||||
if bw.Err != nil {
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"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/vmstate"
|
||||
"github.com/nspcc-dev/neofs-contract/nns"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring"
|
||||
morphClient "github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -263,13 +264,17 @@ func (c *initializeContext) updateContracts() error {
|
|||
if method == deployMethodName {
|
||||
// same actions are done in initializeContext.setNNS, can be unified
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
if script != nil {
|
||||
totalGasCost += defaultRegisterSysfee + native.GASFactor
|
||||
w.WriteBytes(script)
|
||||
if !ok {
|
||||
if script != nil {
|
||||
totalGasCost += defaultRegisterSysfee + native.GASFactor
|
||||
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())
|
||||
}
|
||||
|
|
|
@ -126,24 +126,24 @@ func getAlphabetNNSDomain(i int) string {
|
|||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
bw := io.NewBufBinWriter()
|
||||
if ok {
|
||||
bw := io.NewBufBinWriter()
|
||||
var price *big.Int
|
||||
if setPrice {
|
||||
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")
|
||||
return nil, false, 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)
|
||||
return nil, false, fmt.Errorf("unexpected `GetPrice` stack returned: %w", err)
|
||||
}
|
||||
|
||||
// set minimal registration price
|
||||
|
@ -160,32 +160,32 @@ func (c *initializeContext) nnsRegisterDomainScript(nnsHash, expectedHash util.U
|
|||
// set registration price back
|
||||
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
|
||||
|
||||
if bw.Err != nil {
|
||||
panic(bw.Err)
|
||||
}
|
||||
return bw.Bytes(), false, nil
|
||||
}
|
||||
|
||||
emit.AppCall(bw.BinWriter, nnsHash, "addRecord", callflag.All,
|
||||
domain, int64(nns.TXT), expectedHash.StringLE())
|
||||
|
||||
if bw.Err != nil {
|
||||
panic(bw.Err)
|
||||
s, err := nnsResolveHash(c.Client, nnsHash, domain)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return bw.Bytes(), nil
|
||||
return nil, s == expectedHash, nil
|
||||
}
|
||||
|
||||
func (c *initializeContext) nnsRegisterDomain(nnsHash, expectedHash util.Uint160, domain string) error {
|
||||
script, err := c.nnsRegisterDomainScript(nnsHash, expectedHash, domain, true)
|
||||
if script == nil {
|
||||
script, ok, err := c.nnsRegisterDomainScript(nnsHash, expectedHash, domain, true)
|
||||
if ok || err != nil {
|
||||
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)
|
||||
return c.sendCommitteeTx(script, sysFee, true)
|
||||
return c.sendCommitteeTx(w.Bytes(), sysFee, true)
|
||||
}
|
||||
|
||||
func (c *initializeContext) nnsRootRegistered(nnsHash util.Uint160, zone string) (bool, error) {
|
||||
|
|
Loading…
Reference in a new issue