From 00a0045d9a50faca916461bdbb3d0de261aceb86 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 24 Oct 2023 13:06:30 +0300 Subject: [PATCH] [#750] adm: Drop deprecated GetContract*() Signed-off-by: Evgenii Stratonikov --- .../internal/modules/morph/balance.go | 4 +++- cmd/frostfs-adm/internal/modules/morph/config.go | 7 +++++-- .../internal/modules/morph/container.go | 13 ++++++++----- cmd/frostfs-adm/internal/modules/morph/deploy.go | 3 ++- .../internal/modules/morph/dump_hashes.go | 4 +++- cmd/frostfs-adm/internal/modules/morph/epoch.go | 4 +++- .../internal/modules/morph/initialize.go | 4 +++- .../internal/modules/morph/initialize_deploy.go | 16 +++++++++++----- .../internal/modules/morph/initialize_nns.go | 4 +++- .../internal/modules/morph/local_client.go | 15 --------------- .../internal/modules/morph/n3client.go | 2 -- .../internal/modules/morph/netmap_candidates.go | 4 +++- .../internal/modules/morph/remove_node.go | 4 +++- 13 files changed, 47 insertions(+), 37 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/balance.go b/cmd/frostfs-adm/internal/modules/morph/balance.go index 6debc50b..9b706c7b 100644 --- a/cmd/frostfs-adm/internal/modules/morph/balance.go +++ b/cmd/frostfs-adm/internal/modules/morph/balance.go @@ -16,6 +16,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/rpcclient/gas" "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/rolemgmt" "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" @@ -56,7 +57,8 @@ func dumpBalances(cmd *cobra.Command, _ []string) error { inv := invoker.New(c, nil) if dumpStorage || dumpAlphabet || dumpProxy { - nnsCs, err = c.GetContractStateByID(1) + r := management.NewReader(inv) + nnsCs, err = r.GetContractByID(1) if err != nil { return fmt.Errorf("can't get NNS contract info: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/config.go b/cmd/frostfs-adm/internal/modules/morph/config.go index a86829aa..3c4029bc 100644 --- a/cmd/frostfs-adm/internal/modules/morph/config.go +++ b/cmd/frostfs-adm/internal/modules/morph/config.go @@ -13,6 +13,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap" "github.com/nspcc-dev/neo-go/pkg/io" "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" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/vm/emit" @@ -29,8 +30,9 @@ func dumpNetworkConfig(cmd *cobra.Command, _ []string) error { } inv := invoker.New(c, nil) + r := management.NewReader(inv) - cs, err := c.GetContractStateByID(1) + cs, err := r.GetContractByID(1) if err != nil { return fmt.Errorf("can't get NNS contract info: %w", err) } @@ -87,7 +89,8 @@ func setConfigCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't initialize context: %w", err) } - cs, err := wCtx.Client.GetContractStateByID(1) + r := management.NewReader(wCtx.ReadOnlyInvoker) + cs, err := r.GetContractByID(1) if err != nil { return fmt.Errorf("can't get NNS contract info: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/container.go b/cmd/frostfs-adm/internal/modules/morph/container.go index 687d7e84..f3faa304 100644 --- a/cmd/frostfs-adm/internal/modules/morph/container.go +++ b/cmd/frostfs-adm/internal/modules/morph/container.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/hash" "github.com/nspcc-dev/neo-go/pkg/io" "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" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/util" @@ -22,14 +23,15 @@ import ( var errInvalidContainerResponse = errors.New("invalid response from container contract") -func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker, c Client) (util.Uint160, error) { +func getContainerContractHash(cmd *cobra.Command, inv *invoker.Invoker) (util.Uint160, error) { s, err := cmd.Flags().GetString(containerContractFlag) var ch util.Uint160 if err == nil { ch, err = util.Uint160DecodeStringLE(s) } if err != nil { - nnsCs, err := c.GetContractStateByID(1) + r := management.NewReader(inv) + nnsCs, err := r.GetContractByID(1) if err != nil { return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err) } @@ -78,7 +80,7 @@ func dumpContainers(cmd *cobra.Command, _ []string) error { inv := invoker.New(c, nil) - ch, err := getContainerContractHash(cmd, inv, c) + ch, err := getContainerContractHash(cmd, inv) if err != nil { return fmt.Errorf("unable to get contaract hash: %w", err) } @@ -168,7 +170,7 @@ func listContainers(cmd *cobra.Command, _ []string) error { inv := invoker.New(c, nil) - ch, err := getContainerContractHash(cmd, inv, c) + ch, err := getContainerContractHash(cmd, inv) if err != nil { return fmt.Errorf("unable to get contaract hash: %w", err) } @@ -298,7 +300,8 @@ func parseContainers(filename string) ([]Container, error) { } func fetchContainerContractHash(wCtx *initializeContext) (util.Uint160, error) { - nnsCs, err := wCtx.Client.GetContractStateByID(1) + r := management.NewReader(wCtx.ReadOnlyInvoker) + nnsCs, err := r.GetContractByID(1) if err != nil { return util.Uint160{}, fmt.Errorf("can't get NNS contract state: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/deploy.go b/cmd/frostfs-adm/internal/modules/morph/deploy.go index a4b94543..54b50671 100644 --- a/cmd/frostfs-adm/internal/modules/morph/deploy.go +++ b/cmd/frostfs-adm/internal/modules/morph/deploy.go @@ -76,7 +76,8 @@ func deployContractCmd(cmd *cobra.Command, args []string) error { return err } - nnsCs, err := c.Client.GetContractStateByID(1) + r := management.NewReader(c.ReadOnlyInvoker) + nnsCs, err := r.GetContractByID(1) if err != nil { return fmt.Errorf("can't fetch NNS contract state: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go b/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go index 69db5c7b..585de6d6 100644 --- a/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go +++ b/cmd/frostfs-adm/internal/modules/morph/dump_hashes.go @@ -11,6 +11,7 @@ import ( morphClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client" "github.com/nspcc-dev/neo-go/pkg/io" "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" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/util" @@ -36,7 +37,8 @@ func dumpContractHashes(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't create N3 client: %w", err) } - cs, err := c.GetContractStateByID(1) + r := management.NewReader(invoker.New(c, nil)) + cs, err := r.GetContractByID(1) if err != nil { return err } diff --git a/cmd/frostfs-adm/internal/modules/morph/epoch.go b/cmd/frostfs-adm/internal/modules/morph/epoch.go index a96efa43..453e984b 100644 --- a/cmd/frostfs-adm/internal/modules/morph/epoch.go +++ b/cmd/frostfs-adm/internal/modules/morph/epoch.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/nspcc-dev/neo-go/pkg/io" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/management" "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/util" @@ -20,7 +21,8 @@ func forceNewEpochCmd(cmd *cobra.Command, _ []string) error { return fmt.Errorf("can't to initialize context: %w", err) } - cs, err := wCtx.Client.GetContractStateByID(1) + r := management.NewReader(wCtx.ReadOnlyInvoker) + cs, err := r.GetContractByID(1) if err != nil { return fmt.Errorf("can't get NNS contract info: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize.go b/cmd/frostfs-adm/internal/modules/morph/initialize.go index dec1fba2..4184e1a8 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize.go @@ -15,6 +15,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/management" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" @@ -312,7 +313,8 @@ func (c *initializeContext) nnsContractState() (*state.Contract, error) { return c.nnsCs, nil } - cs, err := c.Client.GetContractStateByID(1) + r := management.NewReader(c.ReadOnlyInvoker) + cs, err := r.GetContractByID(1) if err != nil { return nil, err } diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go index a7cd537b..6896b4ff 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_deploy.go @@ -94,7 +94,10 @@ func (c *initializeContext) deployNNS(method string) error { h := cs.Hash nnsCs, err := c.nnsContractState() - if err == nil { + if err != nil { + return err + } + if nnsCs != nil { if nnsCs.NEF.Checksum == cs.NEF.Checksum { if method == deployMethodName { c.Command.Println("NNS contract is already deployed.") @@ -366,8 +369,9 @@ func (c *initializeContext) deployContracts() error { } func (c *initializeContext) isUpdated(ctrHash util.Uint160, cs *contractState) bool { - realCs, err := c.Client.GetContractStateByHash(ctrHash) - return err == nil && realCs.NEF.Checksum == cs.NEF.Checksum + r := management.NewReader(c.ReadOnlyInvoker) + realCs, err := r.GetContract(ctrHash) + return err == nil && realCs != nil && realCs.NEF.Checksum == cs.NEF.Checksum } func (c *initializeContext) getContract(ctrName string) *contractState { @@ -536,7 +540,8 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an case containerContract: // In case if NNS is updated multiple times, we can't calculate // it's actual hash based on local data, thus query chain. - nnsCs, err := c.Client.GetContractStateByID(1) + r := management.NewReader(c.ReadOnlyInvoker) + nnsCs, err := r.GetContractByID(1) if err != nil { panic("NNS is not yet deployed") } @@ -590,7 +595,8 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an } func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, error) { - cs, err := c.Client.GetContractStateByID(1) + r := management.NewReader(c.ReadOnlyInvoker) + cs, err := r.GetContractByID(1) if err != nil { return nil, fmt.Errorf("NNS is not yet deployed: %w", err) } diff --git a/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go b/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go index 6758b4dd..1bf4c4be 100644 --- a/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go +++ b/cmd/frostfs-adm/internal/modules/morph/initialize_nns.go @@ -15,6 +15,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/rpcclient" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/management" nnsClient "github.com/nspcc-dev/neo-go/pkg/rpcclient/nns" "github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" @@ -30,7 +31,8 @@ const defaultExpirationTime = 10 * 365 * 24 * time.Hour / time.Second const frostfsOpsEmail = "ops@frostfs.info" func (c *initializeContext) setNNS() error { - nnsCs, err := c.Client.GetContractStateByID(1) + r := management.NewReader(c.ReadOnlyInvoker) + nnsCs, err := r.GetContractByID(1) if err != nil { return err } diff --git a/cmd/frostfs-adm/internal/modules/morph/local_client.go b/cmd/frostfs-adm/internal/modules/morph/local_client.go index 84cf40e9..cd094ca2 100644 --- a/cmd/frostfs-adm/internal/modules/morph/local_client.go +++ b/cmd/frostfs-adm/internal/modules/morph/local_client.go @@ -118,21 +118,6 @@ func (l *localClient) GetBlockCount() (uint32, error) { return l.bc.BlockHeight(), nil } -func (l *localClient) GetContractStateByID(id int32) (*state.Contract, error) { - h, err := l.bc.GetContractScriptHash(id) - if err != nil { - return nil, err - } - return l.GetContractStateByHash(h) -} - -func (l *localClient) GetContractStateByHash(h util.Uint160) (*state.Contract, error) { - if cs := l.bc.GetContractState(h); cs != nil { - return cs, nil - } - return nil, storage.ErrKeyNotFound -} - func (l *localClient) GetNativeContracts() ([]state.NativeContract, error) { return l.bc.GetNatives(), nil } diff --git a/cmd/frostfs-adm/internal/modules/morph/n3client.go b/cmd/frostfs-adm/internal/modules/morph/n3client.go index 77f207c9..7ba5a7ce 100644 --- a/cmd/frostfs-adm/internal/modules/morph/n3client.go +++ b/cmd/frostfs-adm/internal/modules/morph/n3client.go @@ -28,8 +28,6 @@ type Client interface { invoker.RPCInvoke GetBlockCount() (uint32, error) - GetContractStateByID(int32) (*state.Contract, error) - GetContractStateByHash(util.Uint160) (*state.Contract, error) GetNativeContracts() ([]state.NativeContract, error) GetApplicationLog(util.Uint256, *trigger.Type) (*result.ApplicationLog, error) GetVersion() (*result.Version, error) diff --git a/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go b/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go index 222b9902..30f7c69c 100644 --- a/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go +++ b/cmd/frostfs-adm/internal/modules/morph/netmap_candidates.go @@ -5,6 +5,7 @@ import ( commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/management" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -14,8 +15,9 @@ func listNetmapCandidatesNodes(cmd *cobra.Command, _ []string) { commonCmd.ExitOnErr(cmd, "can't create N3 client: %w", err) inv := invoker.New(c, nil) + r := management.NewReader(inv) - cs, err := c.GetContractStateByID(1) + cs, err := r.GetContractByID(1) commonCmd.ExitOnErr(cmd, "can't get NNS contract info: %w", err) nmHash, err := nnsResolveHash(inv, cs.Hash, netmapContract+".frostfs") diff --git a/cmd/frostfs-adm/internal/modules/morph/remove_node.go b/cmd/frostfs-adm/internal/modules/morph/remove_node.go index df67433c..ba7bb90f 100644 --- a/cmd/frostfs-adm/internal/modules/morph/remove_node.go +++ b/cmd/frostfs-adm/internal/modules/morph/remove_node.go @@ -7,6 +7,7 @@ import ( netmapcontract "git.frostfs.info/TrueCloudLab/frostfs-contract/netmap" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/io" + "github.com/nspcc-dev/neo-go/pkg/rpcclient/management" "github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/spf13/cobra" @@ -33,7 +34,8 @@ func removeNodesCmd(cmd *cobra.Command, args []string) error { } defer wCtx.close() - cs, err := wCtx.Client.GetContractStateByID(1) + r := management.NewReader(wCtx.ReadOnlyInvoker) + cs, err := r.GetContractByID(1) if err != nil { return fmt.Errorf("can't get NNS contract info: %w", err) }