[#932] adm: Move contract name constants to util package

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2024-02-01 10:06:05 +03:00
parent fdeb99c52f
commit ba00fc4971
15 changed files with 66 additions and 68 deletions

View file

@ -97,7 +97,7 @@ func newPolicyContractInterface(cmd *cobra.Command) (*morph.ContractStorage, *ac
nnsCs, err := r.GetContractByID(1) nnsCs, err := r.GetContractByID(1)
commonCmd.ExitOnErr(cmd, "can't get NNS contract state: %w", err) commonCmd.ExitOnErr(cmd, "can't get NNS contract state: %w", err)
ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(policyContract)) ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(morphUtil.PolicyContract))
commonCmd.ExitOnErr(cmd, "unable to resolve policy contract hash: %w", err) commonCmd.ExitOnErr(cmd, "unable to resolve policy contract hash: %w", err)
return morph.NewContractStorage(ac, ch), ac return morph.NewContractStorage(ac, ch), ac

View file

@ -64,7 +64,7 @@ func dumpBalances(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't get NNS contract info: %w", err) return fmt.Errorf("can't get NNS contract info: %w", err)
} }
nmHash, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(netmapContract)) nmHash, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(morphUtil.NetmapContract))
if err != nil { if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err) return fmt.Errorf("can't get netmap contract hash: %w", err)
} }
@ -137,7 +137,7 @@ func printStorageNodeBalances(cmd *cobra.Command, inv *invoker.Invoker, nmHash u
} }
func printProxyContractBalance(cmd *cobra.Command, inv *invoker.Invoker, nnsHash util.Uint160) error { func printProxyContractBalance(cmd *cobra.Command, inv *invoker.Invoker, nnsHash util.Uint160) error {
h, err := morphUtil.NNSResolveHash(inv, nnsHash, morphUtil.DomainOf(proxyContract)) h, err := morphUtil.NNSResolveHash(inv, nnsHash, morphUtil.DomainOf(morphUtil.ProxyContract))
if err != nil { if err != nil {
return fmt.Errorf("can't get hash of the proxy contract: %w", err) return fmt.Errorf("can't get hash of the proxy contract: %w", err)
} }

View file

@ -38,7 +38,7 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't get NNS contract info: %w", err) return fmt.Errorf("can't get NNS contract info: %w", err)
} }
nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(netmapContract)) nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(util.NetmapContract))
if err != nil { if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err) return fmt.Errorf("can't get netmap contract hash: %w", err)
} }
@ -96,7 +96,7 @@ func setConfigCmd(cmd *cobra.Command, args []string) error {
return fmt.Errorf("can't get NNS contract info: %w", err) return fmt.Errorf("can't get NNS contract info: %w", err)
} }
nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(netmapContract)) nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(util.NetmapContract))
if err != nil { if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err) return fmt.Errorf("can't get netmap contract hash: %w", err)
} }

View file

@ -36,7 +36,7 @@ func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker) (util.Ui
if err != nil { if err != nil {
return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err) return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err)
} }
ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(containerContract)) ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(morphUtil.ContainerContract))
if err != nil { if err != nil {
return util.Uint160{}, err return util.Uint160{}, err
} }
@ -307,7 +307,7 @@ func fetchContainerContractHash(wCtx *initializeContext) (util.Uint160, error) {
return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err) return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err)
} }
ch, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, morphUtil.DomainOf(containerContract)) ch, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, morphUtil.DomainOf(morphUtil.ContainerContract))
if err != nil { if err != nil {
return util.Uint160{}, fmt.Errorf("can't fetch container contract hash: %w", err) return util.Uint160{}, fmt.Errorf("can't fetch container contract hash: %w", err)
} }

View file

@ -50,7 +50,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
return dumpCustomZoneHashes(cmd, cs.Hash, zone, c) return dumpCustomZoneHashes(cmd, cs.Hash, zone, c)
} }
infos := []contractDumpInfo{{name: nnsContract, hash: cs.Hash}} infos := []contractDumpInfo{{name: morphUtil.NNSContract, hash: cs.Hash}}
irSize := 0 irSize := 0
for ; irSize < lastGlagoliticLetter; irSize++ { for ; irSize < lastGlagoliticLetter; irSize++ {

View file

@ -28,7 +28,7 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't get NNS contract info: %w", err) return fmt.Errorf("can't get NNS contract info: %w", err)
} }
nmHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(netmapContract)) nmHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(util2.NetmapContract))
if err != nil { if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err) return fmt.Errorf("can't get netmap contract hash: %w", err)
} }

View file

@ -431,7 +431,7 @@ func newFrostfsIDClient(cmd *cobra.Command) (*frostfsidClient, error) {
return nil, fmt.Errorf("can't get NNS contract info: %w", err) return nil, fmt.Errorf("can't get NNS contract info: %w", err)
} }
ffsidHash, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(frostfsIDContract)) ffsidHash, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(morphUtil.FrostfsIDContract))
if err != nil { if err != nil {
return nil, fmt.Errorf("can't get proxy contract hash: %w", err) return nil, fmt.Errorf("can't get proxy contract hash: %w", err)
} }

View file

@ -35,36 +35,23 @@ import (
"github.com/spf13/viper" "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" const frostfsIDAdminConfigKey = "frostfsid.admin"
var ( var (
contractList = []string{ contractList = []string{
balanceContract, morphUtil.BalanceContract,
containerContract, morphUtil.ContainerContract,
frostfsIDContract, morphUtil.FrostfsIDContract,
netmapContract, morphUtil.NetmapContract,
policyContract, morphUtil.PolicyContract,
proxyContract, morphUtil.ProxyContract,
} }
fullContractList = append([]string{ fullContractList = append([]string{
frostfsContract, morphUtil.FrostfsContract,
processingContract, morphUtil.ProcessingContract,
nnsContract, morphUtil.NNSContract,
alphabetContract, morphUtil.AlphabetContract,
}, contractList...) }, contractList...)
netmapConfigKeys = []string{ netmapConfigKeys = []string{
@ -93,7 +80,7 @@ const (
) )
func (c *initializeContext) deployNNS(method string) error { func (c *initializeContext) deployNNS(method string) error {
cs := c.getContract(nnsContract) cs := c.getContract(morphUtil.NNSContract)
h := cs.Hash h := cs.Hash
nnsCs, err := c.nnsContractState() nnsCs, err := c.nnsContractState()
@ -126,7 +113,7 @@ func (c *initializeContext) deployNNS(method string) error {
tx, err := c.CommitteeAct.MakeCall(invokeHash, method, params...) tx, err := c.CommitteeAct.MakeCall(invokeHash, method, params...)
if err != nil { 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 { 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 { func (c *initializeContext) updateContracts() error {
alphaCs := c.getContract(alphabetContract) alphaCs := c.getContract(morphUtil.AlphabetContract)
nnsCs, err := c.nnsContractState() nnsCs, err := c.nnsContractState()
if err != nil { if err != nil {
@ -296,7 +283,7 @@ func (c *initializeContext) deployAlphabetAccounts(nnsHash util.Uint160, w *io2.
} }
func (c *initializeContext) deployContracts() error { func (c *initializeContext) deployContracts() error {
alphaCs := c.getContract(alphabetContract) alphaCs := c.getContract(morphUtil.AlphabetContract)
var keysParam []any var keysParam []any
@ -422,7 +409,7 @@ func (c *initializeContext) readContracts(names []string) error {
} }
for _, ctrName := range names { for _, ctrName := range names {
if ctrName != alphabetContract { if ctrName != morphUtil.AlphabetContract {
cs := c.Contracts[ctrName] cs := c.Contracts[ctrName]
cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(), cs.Hash = state.CreateContractHash(c.CommitteeAcc.Contract.ScriptHash(),
cs.NEF.Checksum, cs.Manifest.Name) cs.NEF.Checksum, cs.Manifest.Name)
@ -524,19 +511,19 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
items := make([]any, 0, 6) items := make([]any, 0, 6)
switch ctrName { switch ctrName {
case frostfsContract: case morphUtil.FrostfsContract:
items = append(items, items = append(items,
c.Contracts[processingContract].Hash, c.Contracts[morphUtil.ProcessingContract].Hash,
keysParam, keysParam,
smartcontract.Parameter{}) smartcontract.Parameter{})
case processingContract: case morphUtil.ProcessingContract:
items = append(items, c.Contracts[frostfsContract].Hash) items = append(items, c.Contracts[morphUtil.FrostfsContract].Hash)
return items[1:], nil // no notary info return items[1:], nil // no notary info
case balanceContract: case morphUtil.BalanceContract:
items = append(items, items = append(items,
c.Contracts[netmapContract].Hash, c.Contracts[morphUtil.NetmapContract].Hash,
c.Contracts[containerContract].Hash) c.Contracts[morphUtil.ContainerContract].Hash)
case containerContract: case morphUtil.ContainerContract:
// In case if NNS is updated multiple times, we can't calculate // In case if NNS is updated multiple times, we can't calculate
// it's actual hash based on local data, thus query chain. // it's actual hash based on local data, thus query chain.
r := management.NewReader(c.ReadOnlyInvoker) 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) return nil, fmt.Errorf("get nns contract: %w", err)
} }
items = append(items, items = append(items,
c.Contracts[netmapContract].Hash, c.Contracts[morphUtil.NetmapContract].Hash,
c.Contracts[balanceContract].Hash, c.Contracts[morphUtil.BalanceContract].Hash,
c.Contracts[frostfsIDContract].Hash, c.Contracts[morphUtil.FrostfsIDContract].Hash,
nnsCs.Hash, nnsCs.Hash,
"container") "container")
case frostfsIDContract: case morphUtil.FrostfsIDContract:
var ( var (
h util.Uint160 h util.Uint160
found bool found bool
@ -569,9 +556,9 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
if found { if found {
items = append(items, h) items = append(items, h)
} else { } else {
items = append(items, c.Contracts[proxyContract].Hash) items = append(items, c.Contracts[morphUtil.ProxyContract].Hash)
} }
case netmapContract: case morphUtil.NetmapContract:
md := getDefaultNetmapContractConfigMap() md := getDefaultNetmapContractConfigMap()
if method == updateMethodName { if method == updateMethodName {
if err := c.mergeNetmapConfig(md); err != nil { if err := c.mergeNetmapConfig(md); err != nil {
@ -585,14 +572,14 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
} }
items = append(items, items = append(items,
c.Contracts[balanceContract].Hash, c.Contracts[morphUtil.BalanceContract].Hash,
c.Contracts[containerContract].Hash, c.Contracts[morphUtil.ContainerContract].Hash,
keysParam, keysParam,
configParam) configParam)
case proxyContract: case morphUtil.ProxyContract:
items = nil items = nil
case policyContract: case morphUtil.PolicyContract:
items = append(items, c.Contracts[proxyContract].Hash) items = append(items, c.Contracts[morphUtil.ProxyContract].Hash)
default: default:
panic(fmt.Sprintf("invalid contract name: %s", ctrName)) panic(fmt.Sprintf("invalid contract name: %s", ctrName))
} }
@ -605,7 +592,7 @@ func (c *initializeContext) getFrostfsIDAdminFromContract() (util.Uint160, bool,
if err != nil { if err != nil {
return util.Uint160{}, false, fmt.Errorf("get nns contract: %w", err) 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 { if err != nil {
return util.Uint160{}, false, fmt.Errorf("resolve frostfsid contract hash: %w", err) 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 { if err != nil {
return nil, fmt.Errorf("get nns contract: %w", err) 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 { if err != nil {
return nil, fmt.Errorf("can't get netmap contract hash: %w", err) 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 { func (c *initializeContext) getAlphabetDeployItems(i, n int) []any {
items := make([]any, 5) items := make([]any, 5)
items[0] = c.Contracts[netmapContract].Hash items[0] = c.Contracts[morphUtil.NetmapContract].Hash
items[1] = c.Contracts[proxyContract].Hash items[1] = c.Contracts[morphUtil.ProxyContract].Hash
items[2] = innerring.GlagoliticLetter(i).String() items[2] = innerring.GlagoliticLetter(i).String()
items[3] = int64(i) items[3] = int64(i)
items[4] = int64(n) items[4] = int64(n)

View file

@ -55,7 +55,7 @@ func (c *initializeContext) setNNS() error {
} }
} }
alphaCs := c.getContract(alphabetContract) alphaCs := c.getContract(morphUtil.AlphabetContract)
for i, acc := range c.Accounts { for i, acc := range c.Accounts {
alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name) alphaCs.Hash = state.CreateContractHash(acc.Contract.ScriptHash(), alphaCs.NEF.Checksum, alphaCs.Manifest.Name)
@ -139,7 +139,7 @@ func (c *initializeContext) emitUpdateNNSGroupScript(bw *io.BufBinWriter, nnsHas
} }
func getAlphabetNNSDomain(i int) string { func getAlphabetNNSDomain(i int) string {
return alphabetContract + strconv.FormatUint(uint64(i), 10) + ".frostfs" return morphUtil.AlphabetContract + strconv.FormatUint(uint64(i), 10) + ".frostfs"
} }
// wrapRegisterScriptWithPrice wraps a given script with `getPrice`/`setPrice` calls for NNS. // wrapRegisterScriptWithPrice wraps a given script with `getPrice`/`setPrice` calls for NNS.

View file

@ -123,7 +123,7 @@ func (c *initializeContext) transferNEOToAlphabetContracts() error {
return err return err
} }
cs := c.getContract(alphabetContract) cs := c.getContract(morphUtil.AlphabetContract)
amount := initialAlphabetNEOAmount / len(c.Wallets) amount := initialAlphabetNEOAmount / len(c.Wallets)
bw := io.NewBufBinWriter() bw := io.NewBufBinWriter()

View file

@ -144,7 +144,7 @@ func (c *initializeContext) multiSign(tx *transaction.Transaction, accType strin
} }
func (c *initializeContext) transferGASToProxy() error { func (c *initializeContext) transferGASToProxy() error {
proxyCs := c.getContract(proxyContract) proxyCs := c.getContract(morphUtil.ProxyContract)
r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash) r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash)
bal, err := r.BalanceOf(proxyCs.Hash) bal, err := r.BalanceOf(proxyCs.Hash)

View file

@ -21,7 +21,7 @@ func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) {
cs, err := r.GetContractByID(1) cs, err := r.GetContractByID(1)
commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err) commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err)
nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(netmapContract)) nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(util.NetmapContract))
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err) commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
res, err := inv.Call(nmHash, "netmapCandidates") res, err := inv.Call(nmHash, "netmapCandidates")

View file

@ -47,7 +47,7 @@ func processAccount(cmd *cobra.Command, addr util.Uint160, method string) error
return fmt.Errorf("can't get NNS contract info: %w", err) return fmt.Errorf("can't get NNS contract info: %w", err)
} }
proxyHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(proxyContract)) proxyHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(util2.ProxyContract))
if err != nil { if err != nil {
return fmt.Errorf("can't get proxy contract hash: %w", err) return fmt.Errorf("can't get proxy contract hash: %w", err)
} }

View file

@ -41,7 +41,7 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error {
return fmt.Errorf("can't get NNS contract info: %w", err) return fmt.Errorf("can't get NNS contract info: %w", err)
} }
nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(netmapContract)) nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(util.NetmapContract))
if err != nil { if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err) return fmt.Errorf("can't get netmap contract hash: %w", err)
} }

View file

@ -17,4 +17,15 @@ const (
SingleAccountName = "single" SingleAccountName = "single"
CommitteeAccountName = "committee" CommitteeAccountName = "committee"
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"
) )