forked from TrueCloudLab/frostfs-node
[#883] adm: Support proxy accounts
Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
419b07e8b8
commit
ac0821a1a5
2 changed files with 102 additions and 0 deletions
68
cmd/frostfs-adm/internal/modules/morph/proxy.go
Normal file
68
cmd/frostfs-adm/internal/modules/morph/proxy.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package morph
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
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 := newInitializeContext(cmd, viper.GetViper())
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't to 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 := nnsResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, proxyContract+".frostfs")
|
||||
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
|
||||
}
|
|
@ -241,6 +241,26 @@ var (
|
|||
},
|
||||
Run: listNetmapCandidatesNodes,
|
||||
}
|
||||
|
||||
proxyAddAccountCmd = &cobra.Command{
|
||||
Use: "proxy-add-account",
|
||||
Short: "Adds account to proxy contract",
|
||||
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||
_ = viper.BindPFlag(alphabetWalletsFlag, cmd.Flags().Lookup(alphabetWalletsFlag))
|
||||
_ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag))
|
||||
},
|
||||
Run: addProxyAccount,
|
||||
}
|
||||
|
||||
proxyRemoveAccountCmd = &cobra.Command{
|
||||
Use: "proxy-remove-account",
|
||||
Short: "Remove from proxy contract",
|
||||
PreRun: func(cmd *cobra.Command, _ []string) {
|
||||
_ = viper.BindPFlag(alphabetWalletsFlag, cmd.Flags().Lookup(alphabetWalletsFlag))
|
||||
_ = viper.BindPFlag(endpointFlag, cmd.Flags().Lookup(endpointFlag))
|
||||
},
|
||||
Run: removeProxyAccount,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -267,6 +287,20 @@ func init() {
|
|||
initAddRuleChainCmd()
|
||||
initRemoveRuleChainCmd()
|
||||
initListRuleChainsCmd()
|
||||
initProxyAddAccount()
|
||||
initProxyRemoveAccount()
|
||||
}
|
||||
|
||||
func initProxyAddAccount() {
|
||||
RootCmd.AddCommand(proxyAddAccountCmd)
|
||||
proxyAddAccountCmd.Flags().StringP(endpointFlag, endpointFlagShort, "", endpointFlagDesc)
|
||||
proxyAddAccountCmd.Flags().String(accountAddressFlag, "", "Wallet address string")
|
||||
}
|
||||
|
||||
func initProxyRemoveAccount() {
|
||||
RootCmd.AddCommand(proxyRemoveAccountCmd)
|
||||
proxyRemoveAccountCmd.Flags().StringP(endpointFlag, endpointFlagShort, "", endpointFlagDesc)
|
||||
proxyRemoveAccountCmd.Flags().String(accountAddressFlag, "", "Wallet address string")
|
||||
}
|
||||
|
||||
func initNetmapCandidatesCmd() {
|
||||
|
|
Loading…
Reference in a new issue