forked from TrueCloudLab/frostfs-node
[#932] adm: Move const
to package constants
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
814c411f4a
commit
e2cee4cf09
29 changed files with 140 additions and 114 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
"github.com/nspcc-dev/neo-go/cli/cmdargs"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||
|
@ -84,7 +85,7 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
callHash := management.Hash
|
||||
method := util.DeployMethodName
|
||||
method := constants.DeployMethodName
|
||||
zone, _ := cmd.Flags().GetString(commonflags.CustomZoneFlag)
|
||||
domain := ctrName + "." + zone
|
||||
isUpdate, _ := cmd.Flags().GetBool(updateFlag)
|
||||
|
@ -94,7 +95,7 @@ func deployContractCmd(cmd *cobra.Command, args []string) error {
|
|||
return fmt.Errorf("can't fetch contract hash from NNS: %w", err)
|
||||
}
|
||||
callHash = cs.Hash
|
||||
method = util.UpdateMethodName
|
||||
method = constants.UpdateMethodName
|
||||
} else {
|
||||
cs.Hash = state.CreateContractHash(
|
||||
c.CommitteeAcc.Contract.ScriptHash(),
|
||||
|
@ -147,12 +148,12 @@ func registerNNS(nnsCs *state.Contract, c *util.InitializeContext, zone string,
|
|||
|
||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
||||
zone, c.CommitteeAcc.Contract.ScriptHash(),
|
||||
util.FrostfsOpsEmail, int64(3600), int64(600), int64(util.DefaultExpirationTime), int64(3600))
|
||||
constants.FrostfsOpsEmail, int64(3600), int64(600), int64(constants.DefaultExpirationTime), int64(3600))
|
||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||
|
||||
emit.AppCall(bw.BinWriter, nnsCs.Hash, "register", callflag.All,
|
||||
domain, c.CommitteeAcc.Contract.ScriptHash(),
|
||||
util.FrostfsOpsEmail, int64(3600), int64(600), int64(util.DefaultExpirationTime), int64(3600))
|
||||
constants.FrostfsOpsEmail, int64(3600), int64(600), int64(constants.DefaultExpirationTime), int64(3600))
|
||||
emit.Opcodes(bw.BinWriter, opcode.ASSERT)
|
||||
} else {
|
||||
s, ok, err := c.NNSRegisterDomainScript(nnsCs.Hash, cs.Hash, domain)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/commonflags"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
|
@ -51,7 +52,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
|||
return dumpCustomZoneHashes(cmd, cs.Hash, zone, c)
|
||||
}
|
||||
|
||||
infos := []contractDumpInfo{{name: morphUtil.NNSContract, hash: cs.Hash}}
|
||||
infos := []contractDumpInfo{{name: constants.NNSContract, hash: cs.Hash}}
|
||||
|
||||
irSize := 0
|
||||
for ; irSize < lastGlagoliticLetter; irSize++ {
|
||||
|
@ -87,7 +88,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
for _, ctrName := range morphUtil.ContractList {
|
||||
for _, ctrName := range constants.ContractList {
|
||||
bw.Reset()
|
||||
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
|
||||
morphUtil.DomainOf(ctrName), int64(nns.TXT))
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/common"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-contract/nns"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
morphUtil "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
||||
morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||
|
@ -29,7 +30,7 @@ func updateContracts(cmd *cobra.Command, _ []string) error {
|
|||
return fmt.Errorf("initialization error: %w", err)
|
||||
}
|
||||
|
||||
if err := morphUtil.DeployNNS(wCtx, morphUtil.UpdateMethodName); err != nil {
|
||||
if err := morphUtil.DeployNNS(wCtx, constants.UpdateMethodName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,7 @@ func updateContracts(cmd *cobra.Command, _ []string) error {
|
|||
}
|
||||
|
||||
func updateContractsInternal(c *morphUtil.InitializeContext) error {
|
||||
alphaCs := c.GetContract(morphUtil.AlphabetContract)
|
||||
alphaCs := c.GetContract(constants.AlphabetContract)
|
||||
|
||||
nnsCs, err := c.NNSContractState()
|
||||
if err != nil {
|
||||
|
@ -116,7 +117,7 @@ func deployAlphabetAccounts(c *morphUtil.InitializeContext, nnsHash neoUtil.Uint
|
|||
emit.Opcodes(w.BinWriter, opcode.LDSFLD0)
|
||||
emit.Int(w.BinWriter, 3)
|
||||
emit.Opcodes(w.BinWriter, opcode.PACK)
|
||||
emit.AppCallNoArgs(w.BinWriter, ctrHash, morphUtil.UpdateMethodName, callflag.All)
|
||||
emit.AppCallNoArgs(w.BinWriter, ctrHash, constants.UpdateMethodName, callflag.All)
|
||||
}
|
||||
if err := c.SendCommitteeTx(w.Bytes(), false); err != nil {
|
||||
if !strings.Contains(err.Error(), common.ErrAlreadyUpdated) {
|
||||
|
@ -134,15 +135,15 @@ func deployOrUpdateContracts(c *morphUtil.InitializeContext, w *io2.BufBinWriter
|
|||
emit.Opcodes(w.BinWriter, opcode.STSFLD0)
|
||||
emit.AppCall(w.BinWriter, nnsHash, "setPrice", callflag.All, 1)
|
||||
|
||||
for _, ctrName := range morphUtil.ContractList {
|
||||
for _, ctrName := range constants.ContractList {
|
||||
cs := c.GetContract(ctrName)
|
||||
|
||||
method := morphUtil.UpdateMethodName
|
||||
method := constants.UpdateMethodName
|
||||
ctrHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, nnsHash, morphUtil.DomainOf(ctrName))
|
||||
if err != nil {
|
||||
if errors.Is(err, errMissingNNSRecord) {
|
||||
// if contract not found we deploy it instead of update
|
||||
method = morphUtil.DeployMethodName
|
||||
method = constants.DeployMethodName
|
||||
} else {
|
||||
return fmt.Errorf("can't resolve hash for contract update: %w", err)
|
||||
}
|
||||
|
@ -154,18 +155,18 @@ func deployOrUpdateContracts(c *morphUtil.InitializeContext, w *io2.BufBinWriter
|
|||
}
|
||||
|
||||
invokeHash := management.Hash
|
||||
if method == morphUtil.UpdateMethodName {
|
||||
if method == constants.UpdateMethodName {
|
||||
invokeHash = ctrHash
|
||||
}
|
||||
|
||||
args, err := morphUtil.GetContractDeployData(c, ctrName, keysParam, morphUtil.UpdateMethodName)
|
||||
args, err := morphUtil.GetContractDeployData(c, ctrName, keysParam, constants.UpdateMethodName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: getting update params: %v", ctrName, err)
|
||||
}
|
||||
params := morphUtil.GetContractDeployParameters(cs, args)
|
||||
res, err := c.CommitteeAct.MakeCall(invokeHash, method, params...)
|
||||
if err != nil {
|
||||
if method != morphUtil.UpdateMethodName || !strings.Contains(err.Error(), common.ErrAlreadyUpdated) {
|
||||
if method != constants.UpdateMethodName || !strings.Contains(err.Error(), common.ErrAlreadyUpdated) {
|
||||
return fmt.Errorf("deploy contract: %w", err)
|
||||
}
|
||||
c.Command.Printf("%s contract is already updated.\n", ctrName)
|
||||
|
@ -174,7 +175,7 @@ func deployOrUpdateContracts(c *morphUtil.InitializeContext, w *io2.BufBinWriter
|
|||
|
||||
w.WriteBytes(res.Script)
|
||||
|
||||
if method == morphUtil.DeployMethodName {
|
||||
if method == constants.DeployMethodName {
|
||||
// same actions are done in InitializeContext.setNNS, can be unified
|
||||
domain := ctrName + ".frostfs"
|
||||
script, ok, err := c.NNSRegisterDomainScript(nnsHash, cs.Hash, domain)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue