From b0fefcb21fcde69ecc8985ddbf79dac708ad72fe Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 23 Mar 2023 09:35:25 +0300 Subject: [PATCH] [#161] adm: Refactor deposit-notary command Resolve funlen linter for depositNotary function Signed-off-by: Dmitrii Stepanov --- .../internal/modules/morph/notary.go | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/cmd/frostfs-adm/internal/modules/morph/notary.go b/cmd/frostfs-adm/internal/modules/morph/notary.go index 24cfd7d14..2459f127b 100644 --- a/cmd/frostfs-adm/internal/modules/morph/notary.go +++ b/cmd/frostfs-adm/internal/modules/morph/notary.go @@ -9,10 +9,12 @@ 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/encoding/address" + "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" "github.com/nspcc-dev/neo-go/pkg/rpcclient/actor" "github.com/nspcc-dev/neo-go/pkg/rpcclient/gas" "github.com/nspcc-dev/neo-go/pkg/rpcclient/nep17" "github.com/nspcc-dev/neo-go/pkg/rpcclient/notary" + "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -22,18 +24,10 @@ import ( // https://github.com/nspcc-dev/neo-go/blob/master/pkg/core/native/notary.go#L48 const defaultNotaryDepositLifetime = 5760 -// nolint: funlen func depositNotary(cmd *cobra.Command, _ []string) error { - p, err := cmd.Flags().GetString(storageWalletFlag) + w, err := openWallet(cmd) if err != nil { return err - } else if p == "" { - return fmt.Errorf("missing wallet path (use '--%s ')", storageWalletFlag) - } - - w, err := wallet.NewWalletFromFile(p) - if err != nil { - return fmt.Errorf("can't open wallet: %v", err) } accHash := w.GetChangeAddress() @@ -81,6 +75,10 @@ func depositNotary(cmd *cobra.Command, _ []string) error { } } + return transferGas(cmd, acc, accHash, gasAmount, till) +} + +func transferGas(cmd *cobra.Command, acc *wallet.Account, accHash util.Uint160, gasAmount fixedn.Fixed8, till int64) error { c, err := getN3Client(viper.GetViper()) if err != nil { return err @@ -120,3 +118,18 @@ func depositNotary(cmd *cobra.Command, _ []string) error { return awaitTx(cmd, c, []hashVUBPair{{hash: txHash, vub: vub}}) } + +func openWallet(cmd *cobra.Command) (*wallet.Wallet, error) { + p, err := cmd.Flags().GetString(storageWalletFlag) + if err != nil { + return nil, err + } else if p == "" { + return nil, fmt.Errorf("missing wallet path (use '--%s ')", storageWalletFlag) + } + + w, err := wallet.NewWalletFromFile(p) + if err != nil { + return nil, fmt.Errorf("can't open wallet: %v", err) + } + return w, nil +}