forked from TrueCloudLab/frostfs-node
[#932] adm: Move contract name constants to util
package
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
fdeb99c52f
commit
ba00fc4971
15 changed files with 66 additions and 68 deletions
|
@ -35,36 +35,23 @@ import (
|
|||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const (
|
||||
nnsContract = "nns"
|
||||
frostfsContract = "frostfs" // not deployed in side-chain.
|
||||
processingContract = "processing" // not deployed in side-chain.
|
||||
alphabetContract = "alphabet"
|
||||
balanceContract = "balance"
|
||||
containerContract = "container"
|
||||
frostfsIDContract = "frostfsid"
|
||||
netmapContract = "netmap"
|
||||
policyContract = "policy"
|
||||
proxyContract = "proxy"
|
||||
)
|
||||
|
||||
const frostfsIDAdminConfigKey = "frostfsid.admin"
|
||||
|
||||
var (
|
||||
contractList = []string{
|
||||
balanceContract,
|
||||
containerContract,
|
||||
frostfsIDContract,
|
||||
netmapContract,
|
||||
policyContract,
|
||||
proxyContract,
|
||||
morphUtil.BalanceContract,
|
||||
morphUtil.ContainerContract,
|
||||
morphUtil.FrostfsIDContract,
|
||||
morphUtil.NetmapContract,
|
||||
morphUtil.PolicyContract,
|
||||
morphUtil.ProxyContract,
|
||||
}
|
||||
|
||||
fullContractList = append([]string{
|
||||
frostfsContract,
|
||||
processingContract,
|
||||
nnsContract,
|
||||
alphabetContract,
|
||||
morphUtil.FrostfsContract,
|
||||
morphUtil.ProcessingContract,
|
||||
morphUtil.NNSContract,
|
||||
morphUtil.AlphabetContract,
|
||||
}, contractList...)
|
||||
|
||||
netmapConfigKeys = []string{
|
||||
|
@ -93,7 +80,7 @@ const (
|
|||
)
|
||||
|
||||
func (c *initializeContext) deployNNS(method string) error {
|
||||
cs := c.getContract(nnsContract)
|
||||
cs := c.getContract(morphUtil.NNSContract)
|
||||
h := cs.Hash
|
||||
|
||||
nnsCs, err := c.nnsContractState()
|
||||
|
@ -126,7 +113,7 @@ func (c *initializeContext) deployNNS(method string) error {
|
|||
|
||||
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", morphUtil.NNSContract, err)
|
||||
}
|
||||
|
||||
if err := c.multiSignAndSend(tx, morphUtil.CommitteeAccountName); err != nil {
|
||||
|
@ -137,7 +124,7 @@ func (c *initializeContext) deployNNS(method string) error {
|
|||
}
|
||||
|
||||
func (c *initializeContext) updateContracts() error {
|
||||
alphaCs := c.getContract(alphabetContract)
|
||||
alphaCs := c.getContract(morphUtil.AlphabetContract)
|
||||
|
||||
nnsCs, err := c.nnsContractState()
|
||||
if err != nil {
|
||||
|
@ -296,7 +283,7 @@ func (c *initializeContext) deployAlphabetAccounts(nnsHash util.Uint160, w *io2.
|
|||
}
|
||||
|
||||
func (c *initializeContext) deployContracts() error {
|
||||
alphaCs := c.getContract(alphabetContract)
|
||||
alphaCs := c.getContract(morphUtil.AlphabetContract)
|
||||
|
||||
var keysParam []any
|
||||
|
||||
|
@ -422,7 +409,7 @@ func (c *initializeContext) readContracts(names []string) error {
|
|||
}
|
||||
|
||||
for _, ctrName := range names {
|
||||
if ctrName != alphabetContract {
|
||||
if ctrName != morphUtil.AlphabetContract {
|
||||
cs := c.Contracts[ctrName]
|
||||
cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(),
|
||||
cs.NEF.Checksum, cs.Manifest.Name)
|
||||
|
@ -524,19 +511,19 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
items := make([]any, 0, 6)
|
||||
|
||||
switch ctrName {
|
||||
case frostfsContract:
|
||||
case morphUtil.FrostfsContract:
|
||||
items = append(items,
|
||||
c.Contracts[processingContract].Hash,
|
||||
c.Contracts[morphUtil.ProcessingContract].Hash,
|
||||
keysParam,
|
||||
smartcontract.Parameter{})
|
||||
case processingContract:
|
||||
items = append(items, c.Contracts[frostfsContract].Hash)
|
||||
case morphUtil.ProcessingContract:
|
||||
items = append(items, c.Contracts[morphUtil.FrostfsContract].Hash)
|
||||
return items[1:], nil // no notary info
|
||||
case balanceContract:
|
||||
case morphUtil.BalanceContract:
|
||||
items = append(items,
|
||||
c.Contracts[netmapContract].Hash,
|
||||
c.Contracts[containerContract].Hash)
|
||||
case containerContract:
|
||||
c.Contracts[morphUtil.NetmapContract].Hash,
|
||||
c.Contracts[morphUtil.ContainerContract].Hash)
|
||||
case morphUtil.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)
|
||||
|
@ -545,12 +532,12 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
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[morphUtil.NetmapContract].Hash,
|
||||
c.Contracts[morphUtil.BalanceContract].Hash,
|
||||
c.Contracts[morphUtil.FrostfsIDContract].Hash,
|
||||
nnsCs.Hash,
|
||||
"container")
|
||||
case frostfsIDContract:
|
||||
case morphUtil.FrostfsIDContract:
|
||||
var (
|
||||
h util.Uint160
|
||||
found bool
|
||||
|
@ -569,9 +556,9 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
if found {
|
||||
items = append(items, h)
|
||||
} else {
|
||||
items = append(items, c.Contracts[proxyContract].Hash)
|
||||
items = append(items, c.Contracts[morphUtil.ProxyContract].Hash)
|
||||
}
|
||||
case netmapContract:
|
||||
case morphUtil.NetmapContract:
|
||||
md := getDefaultNetmapContractConfigMap()
|
||||
if method == updateMethodName {
|
||||
if err := c.mergeNetmapConfig(md); err != nil {
|
||||
|
@ -585,14 +572,14 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
|
|||
}
|
||||
|
||||
items = append(items,
|
||||
c.Contracts[balanceContract].Hash,
|
||||
c.Contracts[containerContract].Hash,
|
||||
c.Contracts[morphUtil.BalanceContract].Hash,
|
||||
c.Contracts[morphUtil.ContainerContract].Hash,
|
||||
keysParam,
|
||||
configParam)
|
||||
case proxyContract:
|
||||
case morphUtil.ProxyContract:
|
||||
items = nil
|
||||
case policyContract:
|
||||
items = append(items, c.Contracts[proxyContract].Hash)
|
||||
case morphUtil.PolicyContract:
|
||||
items = append(items, c.Contracts[morphUtil.ProxyContract].Hash)
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid contract name: %s", ctrName))
|
||||
}
|
||||
|
@ -605,7 +592,7 @@ func (c *initializeContext) getFrostfsIDAdminFromContract() (util.Uint160, bool,
|
|||
if err != nil {
|
||||
return util.Uint160{}, false, fmt.Errorf("get nns contract: %w", err)
|
||||
}
|
||||
fidHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(frostfsIDContract))
|
||||
fidHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(morphUtil.FrostfsIDContract))
|
||||
if err != nil {
|
||||
return util.Uint160{}, false, fmt.Errorf("resolve frostfsid contract hash: %w", err)
|
||||
}
|
||||
|
@ -634,7 +621,7 @@ func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item,
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("get nns contract: %w", err)
|
||||
}
|
||||
nmHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(netmapContract))
|
||||
nmHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(morphUtil.NetmapContract))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't get netmap contract hash: %w", err)
|
||||
}
|
||||
|
@ -667,8 +654,8 @@ func (c *initializeContext) mergeNetmapConfig(md map[string]any) error {
|
|||
|
||||
func (c *initializeContext) getAlphabetDeployItems(i, n int) []any {
|
||||
items := make([]any, 5)
|
||||
items[0] = c.Contracts[netmapContract].Hash
|
||||
items[1] = c.Contracts[proxyContract].Hash
|
||||
items[0] = c.Contracts[morphUtil.NetmapContract].Hash
|
||||
items[1] = c.Contracts[morphUtil.ProxyContract].Hash
|
||||
items[2] = innerring.GlagoliticLetter(i).String()
|
||||
items[3] = int64(i)
|
||||
items[4] = int64(n)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue