From 78188afee66776216fb9aa3946dc08a89dbe450d Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Wed, 30 Oct 2024 17:39:02 +0300 Subject: [PATCH] [#XX] adm: Make `NewLocalActor` receive accout name * Some RPC-clients for contracts require different wallet account types. Since, `Policy` contract gets `consensus` accounts while `NNS` gets `committee` accounts. Signed-off-by: Airat Arifullin --- .../internal/modules/morph/ape/ape_util.go | 2 +- .../internal/modules/morph/helper/actor.go | 15 +++++++++++++-- .../internal/modules/morph/nns/helper.go | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go b/cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go index d4aedda2e..f4373c535 100644 --- a/cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go +++ b/cmd/frostfs-adm/internal/modules/morph/ape/ape_util.go @@ -139,7 +139,7 @@ func newPolicyContractInterface(cmd *cobra.Command) (*morph.ContractStorage, *he c, err := helper.GetN3Client(viper.GetViper()) commonCmd.ExitOnErr(cmd, "unable to create NEO rpc client: %w", err) - ac, err := helper.NewLocalActor(cmd, c) + ac, err := helper.NewLocalActor(cmd, c, constants.ConsensusAccountName) commonCmd.ExitOnErr(cmd, "can't create actor: %w", err) var ch util.Uint160 diff --git a/cmd/frostfs-adm/internal/modules/morph/helper/actor.go b/cmd/frostfs-adm/internal/modules/morph/helper/actor.go index 1ca246f9f..e4cd5d2cc 100644 --- a/cmd/frostfs-adm/internal/modules/morph/helper/actor.go +++ b/cmd/frostfs-adm/internal/modules/morph/helper/actor.go @@ -29,9 +29,18 @@ type LocalActor struct { rpcInvoker invoker.RPCInvoke } +func checkAccountName(accName string) error { + switch accName { + case constants.CommitteeAccountName, constants.ConsensusAccountName, constants.SingleAccountName: + default: + return fmt.Errorf("unknown account name: %s", accName) + } + return nil +} + // NewLocalActor create LocalActor with accounts form provided wallets. // In case of empty wallets provided created actor with dummy account only for read operation. -func NewLocalActor(cmd *cobra.Command, c actor.RPCActor) (*LocalActor, error) { +func NewLocalActor(cmd *cobra.Command, c actor.RPCActor, accName string) (*LocalActor, error) { walletDir := config.ResolveHomePath(viper.GetString(commonflags.AlphabetWalletsFlag)) var act *actor.Actor var accounts []*wallet.Account @@ -49,11 +58,13 @@ func NewLocalActor(cmd *cobra.Command, c actor.RPCActor) (*LocalActor, error) { return nil, err } } else { + commonCmd.ExitOnErr(cmd, "%w", checkAccountName(accName)) + wallets, err := GetAlphabetWallets(viper.GetViper(), walletDir) commonCmd.ExitOnErr(cmd, "unable to get alphabet wallets: %w", err) for _, w := range wallets { - acc, err := GetWalletAccount(w, constants.CommitteeAccountName) + acc, err := GetWalletAccount(w, accName) //constants.CommitteeAccountName) commonCmd.ExitOnErr(cmd, "can't find committee account: %w", err) accounts = append(accounts, acc) } diff --git a/cmd/frostfs-adm/internal/modules/morph/nns/helper.go b/cmd/frostfs-adm/internal/modules/morph/nns/helper.go index 0eaa5ac58..de439acd1 100644 --- a/cmd/frostfs-adm/internal/modules/morph/nns/helper.go +++ b/cmd/frostfs-adm/internal/modules/morph/nns/helper.go @@ -2,6 +2,7 @@ package nns import ( client "git.frostfs.info/TrueCloudLab/frostfs-contract/rpcclient/nns" + "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/helper" commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" "github.com/nspcc-dev/neo-go/pkg/rpcclient/management" @@ -15,7 +16,7 @@ func getRPCClient(cmd *cobra.Command) (*client.Contract, *helper.LocalActor, uti c, err := helper.GetN3Client(v) commonCmd.ExitOnErr(cmd, "unable to create NEO rpc client: %w", err) - ac, err := helper.NewLocalActor(cmd, c) + ac, err := helper.NewLocalActor(cmd, c, constants.CommitteeAccountName) commonCmd.ExitOnErr(cmd, "can't create actor: %w", err) r := management.NewReader(ac.Invoker)