Ekaterina Lebedeva
56eeb630b6
All checks were successful
DCO action / DCO (pull_request) Successful in 13m23s
Tests and linters / gopls check (pull_request) Successful in 16m29s
Tests and linters / Lint (pull_request) Successful in 17m2s
Build / Build Components (1.21) (pull_request) Successful in 16m26s
Build / Build Components (1.22) (pull_request) Successful in 16m21s
Vulncheck / Vulncheck (pull_request) Successful in 16m40s
Tests and linters / Staticcheck (pull_request) Successful in 19m9s
Pre-commit hooks / Pre-commit (pull_request) Successful in 21m37s
Tests and linters / Tests with -race (pull_request) Successful in 22m33s
Tests and linters / Tests (1.22) (pull_request) Successful in 3m46s
Tests and linters / Tests (1.21) (pull_request) Successful in 3m51s
Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
70 lines
2.1 KiB
Go
70 lines
2.1 KiB
Go
package proxy
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"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/encoding/address"
|
|
"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/util"
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
const (
|
|
accountAddressFlag = "account"
|
|
)
|
|
|
|
func addProxyAccount(cmd *cobra.Command, _ []string) {
|
|
acc, _ := cmd.Flags().GetString(accountAddressFlag)
|
|
addr, err := address.StringToUint160(acc)
|
|
commonCmd.ExitOnErr(cmd, "invalid account: %w", err)
|
|
err = processAccount(cmd, addr, "addAccount")
|
|
commonCmd.ExitOnErr(cmd, "processing error: %w", err)
|
|
}
|
|
|
|
func removeProxyAccount(cmd *cobra.Command, _ []string) {
|
|
acc, _ := cmd.Flags().GetString(accountAddressFlag)
|
|
addr, err := address.StringToUint160(acc)
|
|
commonCmd.ExitOnErr(cmd, "invalid account: %w", err)
|
|
err = processAccount(cmd, addr, "removeAccount")
|
|
commonCmd.ExitOnErr(cmd, "processing error: %w", err)
|
|
}
|
|
|
|
func processAccount(cmd *cobra.Command, addr util.Uint160, method string) error {
|
|
wCtx, err := helper.NewInitializeContext(cmd, viper.GetViper())
|
|
if err != nil {
|
|
return fmt.Errorf("can't initialize context: %w", err)
|
|
}
|
|
|
|
r := management.NewReader(wCtx.ReadOnlyInvoker)
|
|
cs, err := r.GetContractByID(1)
|
|
if err != nil {
|
|
return fmt.Errorf("can't get NNS contract info: %w", err)
|
|
}
|
|
|
|
proxyHash, err := helper.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, helper.DomainOf(constants.ProxyContract))
|
|
if err != nil {
|
|
return fmt.Errorf("can't get proxy contract hash: %w", err)
|
|
}
|
|
|
|
bw := io.NewBufBinWriter()
|
|
emit.AppCall(bw.BinWriter, proxyHash, method, callflag.All, addr)
|
|
|
|
if err := wCtx.SendConsensusTx(bw.Bytes()); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err = wCtx.AwaitTx(); err != nil {
|
|
return err
|
|
}
|
|
|
|
cmd.Println("Proxy contract has been updated")
|
|
|
|
return nil
|
|
}
|