From 4ccacb89e8f5ae64f35c4529085926b0bef5ffb3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 1 Sep 2022 11:53:01 +0300 Subject: [PATCH] [#1748] neofs-adm: Set custom contract hashes as N3 address Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/deploy.go | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cmd/neofs-adm/internal/modules/morph/deploy.go b/cmd/neofs-adm/internal/modules/morph/deploy.go index 90392b439..a04a56385 100644 --- a/cmd/neofs-adm/internal/modules/morph/deploy.go +++ b/cmd/neofs-adm/internal/modules/morph/deploy.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neo-go/cli/cmdargs" "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" "github.com/nspcc-dev/neo-go/pkg/core/state" + "github.com/nspcc-dev/neo-go/pkg/encoding/address" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" @@ -117,13 +118,13 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { emit.AppCall(bw.BinWriter, nnsCs.Hash, "setPrice", callflag.All, 1) start := bw.Len() - newRecord := false + needRecord := false ok, err := c.nnsRootRegistered(nnsCs.Hash, zone) if err != nil { return err } else if !ok { - newRecord = true + needRecord = true emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All, zone, c.CommitteeAcc.Contract.ScriptHash(), @@ -134,23 +135,21 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { domain, c.CommitteeAcc.Contract.ScriptHash(), "ops@nspcc.ru", int64(3600), int64(600), int64(defaultExpirationTime), int64(3600)) emit.Opcodes(bw.BinWriter, opcode.ASSERT) - - emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All, - domain, int64(nns.TXT), cs.Hash.StringLE()) } else { s, ok, err := c.nnsRegisterDomainScript(nnsCs.Hash, cs.Hash, domain) if err != nil { return err } - if !ok { - newRecord = true - if len(s) != 0 { - bw.WriteBytes(s) - } - emit.AppCall(w.BinWriter, nnsCs.Hash, "addRecord", callflag.All, - domain, int64(nns.TXT), cs.Hash.StringLE()) + needRecord = !ok + if len(s) != 0 { + bw.WriteBytes(s) } } + if needRecord { + emit.AppCall(bw.BinWriter, nnsCs.Hash, "addRecord", callflag.All, + domain, int64(nns.TXT), address.Uint160ToString(cs.Hash)) + } + if bw.Err != nil { panic(fmt.Errorf("BUG: can't create deployment script: %w", w.Err)) } else if bw.Len() != start { @@ -158,7 +157,7 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { emit.Opcodes(w.BinWriter, opcode.LDSFLD0, opcode.PUSH1, opcode.PACK) emit.AppCallNoArgs(w.BinWriter, nnsCs.Hash, "setPrice", callflag.All) - if newRecord { + if needRecord { c.Command.Printf("NNS: Set %s -> %s\n", domain, cs.Hash.StringLE()) } }