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
|
@ -3,6 +3,7 @@ package util
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/constants"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/management"
|
||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||
|
@ -18,7 +19,7 @@ func getFrostfsIDAdminFromContract(roInvoker *invoker.Invoker) (util.Uint160, bo
|
|||
if err != nil {
|
||||
return util.Uint160{}, false, fmt.Errorf("get nns contract: %w", err)
|
||||
}
|
||||
fidHash, err := NNSResolveHash(roInvoker, cs.Hash, DomainOf(FrostfsIDContract))
|
||||
fidHash, err := NNSResolveHash(roInvoker, cs.Hash, DomainOf(constants.FrostfsIDContract))
|
||||
if err != nil {
|
||||
return util.Uint160{}, false, fmt.Errorf("resolve frostfsid contract hash: %w", err)
|
||||
}
|
||||
|
@ -45,19 +46,19 @@ func GetContractDeployData(c *InitializeContext, ctrName string, keysParam []any
|
|||
items := make([]any, 0, 6)
|
||||
|
||||
switch ctrName {
|
||||
case FrostfsContract:
|
||||
case constants.FrostfsContract:
|
||||
items = append(items,
|
||||
c.Contracts[ProcessingContract].Hash,
|
||||
c.Contracts[constants.ProcessingContract].Hash,
|
||||
keysParam,
|
||||
smartcontract.Parameter{})
|
||||
case ProcessingContract:
|
||||
items = append(items, c.Contracts[FrostfsContract].Hash)
|
||||
case constants.ProcessingContract:
|
||||
items = append(items, c.Contracts[constants.FrostfsContract].Hash)
|
||||
return items[1:], nil // no notary info
|
||||
case BalanceContract:
|
||||
case constants.BalanceContract:
|
||||
items = append(items,
|
||||
c.Contracts[NetmapContract].Hash,
|
||||
c.Contracts[ContainerContract].Hash)
|
||||
case ContainerContract:
|
||||
c.Contracts[constants.NetmapContract].Hash,
|
||||
c.Contracts[constants.ContainerContract].Hash)
|
||||
case constants.ContainerContract:
|
||||
// In case if NNS is updated multiple times, we can't calculate
|
||||
// it's actual hash based on local data, thus query chain.
|
||||
r := management.NewReader(c.ReadOnlyInvoker)
|
||||
|
@ -66,21 +67,21 @@ func GetContractDeployData(c *InitializeContext, ctrName string, keysParam []any
|
|||
return nil, fmt.Errorf("get nns contract: %w", err)
|
||||
}
|
||||
items = append(items,
|
||||
c.Contracts[NetmapContract].Hash,
|
||||
c.Contracts[BalanceContract].Hash,
|
||||
c.Contracts[FrostfsIDContract].Hash,
|
||||
c.Contracts[constants.NetmapContract].Hash,
|
||||
c.Contracts[constants.BalanceContract].Hash,
|
||||
c.Contracts[constants.FrostfsIDContract].Hash,
|
||||
nnsCs.Hash,
|
||||
"container")
|
||||
case FrostfsIDContract:
|
||||
case constants.FrostfsIDContract:
|
||||
var (
|
||||
h util.Uint160
|
||||
found bool
|
||||
err error
|
||||
)
|
||||
if method == UpdateMethodName {
|
||||
if method == constants.UpdateMethodName {
|
||||
h, found, err = getFrostfsIDAdminFromContract(c.ReadOnlyInvoker)
|
||||
}
|
||||
if method != UpdateMethodName || err == nil && !found {
|
||||
if method != constants.UpdateMethodName || err == nil && !found {
|
||||
h, found, err = GetFrostfsIDAdmin(viper.GetViper())
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -90,11 +91,11 @@ func GetContractDeployData(c *InitializeContext, ctrName string, keysParam []any
|
|||
if found {
|
||||
items = append(items, h)
|
||||
} else {
|
||||
items = append(items, c.Contracts[ProxyContract].Hash)
|
||||
items = append(items, c.Contracts[constants.ProxyContract].Hash)
|
||||
}
|
||||
case NetmapContract:
|
||||
case constants.NetmapContract:
|
||||
md := GetDefaultNetmapContractConfigMap()
|
||||
if method == UpdateMethodName {
|
||||
if method == constants.UpdateMethodName {
|
||||
if err := MergeNetmapConfig(c.ReadOnlyInvoker, md); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -106,14 +107,14 @@ func GetContractDeployData(c *InitializeContext, ctrName string, keysParam []any
|
|||
}
|
||||
|
||||
items = append(items,
|
||||
c.Contracts[BalanceContract].Hash,
|
||||
c.Contracts[ContainerContract].Hash,
|
||||
c.Contracts[constants.BalanceContract].Hash,
|
||||
c.Contracts[constants.ContainerContract].Hash,
|
||||
keysParam,
|
||||
configParam)
|
||||
case ProxyContract:
|
||||
case constants.ProxyContract:
|
||||
items = nil
|
||||
case PolicyContract:
|
||||
items = append(items, c.Contracts[ProxyContract].Hash)
|
||||
case constants.PolicyContract:
|
||||
items = append(items, c.Contracts[constants.ProxyContract].Hash)
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid contract name: %s", ctrName))
|
||||
}
|
||||
|
@ -125,7 +126,7 @@ func GetContractDeployParameters(cs *ContractState, deployData []any) []any {
|
|||
}
|
||||
|
||||
func DeployNNS(c *InitializeContext, method string) error {
|
||||
cs := c.GetContract(NNSContract)
|
||||
cs := c.GetContract(constants.NNSContract)
|
||||
h := cs.Hash
|
||||
|
||||
nnsCs, err := c.NNSContractState()
|
||||
|
@ -134,7 +135,7 @@ func DeployNNS(c *InitializeContext, method string) error {
|
|||
}
|
||||
if nnsCs != nil {
|
||||
if nnsCs.NEF.Checksum == cs.NEF.Checksum {
|
||||
if method == DeployMethodName {
|
||||
if method == constants.DeployMethodName {
|
||||
c.Command.Println("NNS contract is already deployed.")
|
||||
} else {
|
||||
c.Command.Println("NNS contract is already updated.")
|
||||
|
@ -152,16 +153,16 @@ func DeployNNS(c *InitializeContext, method string) error {
|
|||
params := GetContractDeployParameters(cs, nil)
|
||||
|
||||
invokeHash := management.Hash
|
||||
if method == UpdateMethodName {
|
||||
if method == constants.UpdateMethodName {
|
||||
invokeHash = nnsCs.Hash
|
||||
}
|
||||
|
||||
tx, err := c.CommitteeAct.MakeCall(invokeHash, method, params...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create deploy tx for %s: %w", NNSContract, err)
|
||||
return fmt.Errorf("failed to create deploy tx for %s: %w", constants.NNSContract, err)
|
||||
}
|
||||
|
||||
if err := c.MultiSignAndSend(tx, CommitteeAccountName); err != nil {
|
||||
if err := c.MultiSignAndSend(tx, constants.CommitteeAccountName); err != nil {
|
||||
return fmt.Errorf("can't send deploy transaction: %w", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue