[#932] adm: Move DomainOf to util package

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2024-02-01 09:58:12 +03:00
parent 34fcab3498
commit fdeb99c52f
19 changed files with 36 additions and 38 deletions

View file

@ -85,7 +85,7 @@ func newPolicyContractInterface(cmd *cobra.Command) (*morph.ContractStorage, *ac
wallets, err := morphUtil.GetAlphabetWallets(v, walletDir)
commonCmd.ExitOnErr(cmd, "unable to get alphabet wallets: %w", err)
committeeAcc, err := morphUtil.GetWalletAccount(wallets[0], committeeAccountName)
committeeAcc, err := morphUtil.GetWalletAccount(wallets[0], morphUtil.CommitteeAccountName)
commonCmd.ExitOnErr(cmd, "can't find committee account: %w", err)
ac, err := morphUtil.NewActor(c, committeeAcc)
@ -97,7 +97,7 @@ func newPolicyContractInterface(cmd *cobra.Command) (*morph.ContractStorage, *ac
nnsCs, err := r.GetContractByID(1)
commonCmd.ExitOnErr(cmd, "can't get NNS contract state: %w", err)
ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, domainOf(policyContract))
ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(policyContract))
commonCmd.ExitOnErr(cmd, "unable to resolve policy contract hash: %w", err)
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)
}
nmHash, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, domainOf(netmapContract))
nmHash, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(netmapContract))
if err != nil {
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 {
h, err := morphUtil.NNSResolveHash(inv, nnsHash, domainOf(proxyContract))
h, err := morphUtil.NNSResolveHash(inv, nnsHash, morphUtil.DomainOf(proxyContract))
if err != nil {
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)
}
nmHash, err := util.NNSResolveHash(inv, cs.Hash, domainOf(netmapContract))
nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(netmapContract))
if err != nil {
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)
}
nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(netmapContract))
nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(netmapContract))
if err != nil {
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 {
return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err)
}
ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, domainOf(containerContract))
ch, err = morphUtil.NNSResolveHash(inv, nnsCs.Hash, morphUtil.DomainOf(containerContract))
if err != nil {
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)
}
ch, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, domainOf(containerContract))
ch, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, nnsCs.Hash, morphUtil.DomainOf(containerContract))
if err != nil {
return util.Uint160{}, fmt.Errorf("can't fetch container contract hash: %w", err)
}

View file

@ -89,7 +89,7 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error {
for _, ctrName := range contractList {
bw.Reset()
emit.AppCall(bw.BinWriter, cs.Hash, "resolve", callflag.ReadOnly,
domainOf(ctrName), int64(nns.TXT))
morphUtil.DomainOf(ctrName), int64(nns.TXT))
res, err := c.InvokeScript(bw.Bytes(), nil)
if err != nil {

View file

@ -28,7 +28,7 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("can't get NNS contract info: %w", err)
}
nmHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(netmapContract))
nmHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(netmapContract))
if err != nil {
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)
}
ffsidHash, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(frostfsIDContract))
ffsidHash, err := morphUtil.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(frostfsIDContract))
if err != nil {
return nil, fmt.Errorf("can't get proxy contract hash: %w", err)
}

View file

@ -25,11 +25,6 @@ import (
"golang.org/x/sync/errgroup"
)
const (
singleAccountName = "single"
committeeAccountName = "committee"
)
func generateAlphabetCreds(cmd *cobra.Command, _ []string) error {
// alphabet size is not part of the config
size, err := cmd.Flags().GetUint(alphabetSizeFlag)
@ -87,7 +82,7 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er
if err != nil {
return nil, fmt.Errorf("can't create wallet: %w", err)
}
if err := w.CreateAccount(singleAccountName, password); err != nil {
if err := w.CreateAccount(morphUtil.SingleAccountName, password); err != nil {
return nil, fmt.Errorf("can't create account: %w", err)
}
@ -106,7 +101,7 @@ func initializeWallets(v *viper.Viper, walletDir string, size int) ([]string, er
i := i
ps := pubs.Copy()
errG.Go(func() error {
if err := addMultisigAccount(wallets[i], majCount, committeeAccountName, passwords[i], ps); err != nil {
if err := addMultisigAccount(wallets[i], majCount, morphUtil.CommitteeAccountName, passwords[i], ps); err != nil {
return fmt.Errorf("can't create committee account: %w", err)
}
if err := addMultisigAccount(wallets[i], bftCount, morphUtil.ConsensusAccountName, passwords[i], ps); err != nil {
@ -182,7 +177,7 @@ func refillGas(cmd *cobra.Command, gasFlag string, createWallet bool) (err error
}
if label == "" {
label = singleAccountName
label = morphUtil.SingleAccountName
}
if err := w.CreateAccount(label, password); err != nil {

View file

@ -90,10 +90,10 @@ func TestGenerateAlphabet(t *testing.T) {
switch a.Label {
case util.ConsensusAccountName:
require.Equal(t, smartcontract.GetDefaultHonestNodeCount(size), len(a.Contract.Parameters))
case committeeAccountName:
case util.CommitteeAccountName:
require.Equal(t, smartcontract.GetMajorityHonestNodeCount(size), len(a.Contract.Parameters))
default:
require.Equal(t, singleAccountName, a.Label)
require.Equal(t, util.SingleAccountName, a.Label)
}
}
}()

View file

@ -122,7 +122,7 @@ func newInitializeContext(cmd *cobra.Command, v *viper.Viper) (*initializeContex
return nil, err
}
committeeAcc, err := morphUtil.GetWalletAccount(wallets[0], committeeAccountName)
committeeAcc, err := morphUtil.GetWalletAccount(wallets[0], morphUtil.CommitteeAccountName)
if err != nil {
return nil, fmt.Errorf("can't find committee account: %w", err)
}
@ -237,7 +237,7 @@ func getContractsPath(cmd *cobra.Command, needContracts bool) (string, error) {
func createWalletAccounts(wallets []*wallet.Wallet) ([]*wallet.Account, error) {
accounts := make([]*wallet.Account, len(wallets))
for i, w := range wallets {
acc, err := morphUtil.GetWalletAccount(w, singleAccountName)
acc, err := morphUtil.GetWalletAccount(w, morphUtil.SingleAccountName)
if err != nil {
return nil, fmt.Errorf("wallet %s is invalid (no single account): %w", w.Path(), err)
}
@ -346,7 +346,7 @@ func (c *initializeContext) sendMultiTx(script []byte, tryGroup bool, withConsen
return fmt.Errorf("could not perform test invocation: %w", err)
}
if err := c.multiSign(tx, committeeAccountName); err != nil {
if err := c.multiSign(tx, morphUtil.CommitteeAccountName); err != nil {
return err
}
if withConsensus {

View file

@ -92,10 +92,6 @@ const (
deployMethodName = "deploy"
)
func domainOf(contract string) string {
return contract + ".frostfs"
}
func (c *initializeContext) deployNNS(method string) error {
cs := c.getContract(nnsContract)
h := cs.Hash
@ -133,7 +129,7 @@ func (c *initializeContext) deployNNS(method string) error {
return fmt.Errorf("failed to create deploy tx for %s: %w", nnsContract, err)
}
if err := c.multiSignAndSend(tx, committeeAccountName); err != nil {
if err := c.multiSignAndSend(tx, morphUtil.CommitteeAccountName); err != nil {
return fmt.Errorf("can't send deploy transaction: %w", err)
}
@ -203,7 +199,7 @@ func (c *initializeContext) deployOrUpdateContracts(w *io2.BufBinWriter, nnsHash
cs := c.getContract(ctrName)
method := updateMethodName
ctrHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, nnsHash, domainOf(ctrName))
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
@ -609,7 +605,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, domainOf(frostfsIDContract))
fidHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(frostfsIDContract))
if err != nil {
return util.Uint160{}, false, fmt.Errorf("resolve frostfsid contract hash: %w", err)
}
@ -638,7 +634,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, domainOf(netmapContract))
nmHash, err := morphUtil.NNSResolveHash(c.ReadOnlyInvoker, cs.Hash, morphUtil.DomainOf(netmapContract))
if err != nil {
return nil, fmt.Errorf("can't get netmap contract hash: %w", err)
}

View file

@ -68,7 +68,7 @@ func (c *initializeContext) registerCandidateRange(start, end int) error {
if err != nil {
return fmt.Errorf("can't create tx: %w", err)
}
if err := c.multiSign(tx, committeeAccountName); err != nil {
if err := c.multiSign(tx, morphUtil.CommitteeAccountName); err != nil {
return fmt.Errorf("can't sign a transaction: %w", err)
}

View file

@ -113,7 +113,7 @@ func generateTestData(t *testing.T, dir string, size int) error {
return fmt.Errorf("wallet doesn't exist: %w", err)
}
for _, acc := range w.Accounts {
if acc.Label == singleAccountName {
if acc.Label == util.SingleAccountName {
pub, ok := vm.ParseSignatureContract(acc.Contract.Script)
if !ok {
return fmt.Errorf("could not parse signature script for %s", acc.Address)

View file

@ -161,7 +161,7 @@ func (c *initializeContext) transferGASToProxy() error {
return err
}
if err := c.multiSignAndSend(tx, committeeAccountName); err != nil {
if err := c.multiSignAndSend(tx, morphUtil.CommitteeAccountName); err != nil {
return err
}

View file

@ -21,7 +21,7 @@ func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) {
cs, err := r.GetContractByID(1)
commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err)
nmHash, err := util.NNSResolveHash(inv, cs.Hash, domainOf(netmapContract))
nmHash, err := util.NNSResolveHash(inv, cs.Hash, util.DomainOf(netmapContract))
commonCmd.ExitOnErr(cmd, "can't get netmap contract hash: %w", err)
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)
}
proxyHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(proxyContract))
proxyHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(proxyContract))
if err != nil {
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)
}
nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, domainOf(netmapContract))
nmHash, err := util.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util.DomainOf(netmapContract))
if err != nil {
return fmt.Errorf("can't get netmap contract hash: %w", err)
}

View file

@ -14,4 +14,7 @@ const (
EndpointFlagShort = "r"
AlphabetWalletsFlag = "alphabet-wallets"
AlphabetWalletsFlagDesc = "Path to alphabet wallets dir"
SingleAccountName = "single"
CommitteeAccountName = "committee"
)

View file

@ -140,3 +140,7 @@ func NNSResolveHash(inv *invoker.Invoker, nnsHash util.Uint160, domain string) (
}
return ParseNNSResolveResult(item)
}
func DomainOf(contract string) string {
return contract + ".frostfs"
}