2023-12-21 09:26:47 +00:00
|
|
|
package morph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2024-02-01 06:43:51 +00:00
|
|
|
util2 "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-adm/internal/modules/morph/util"
|
2023-12-21 09:26:47 +00:00
|
|
|
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 {
|
2024-02-01 11:30:59 +00:00
|
|
|
wCtx, err := NewInitializeContext(cmd, viper.GetViper())
|
2023-12-21 09:26:47 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2024-02-01 07:06:05 +00:00
|
|
|
proxyHash, err := util2.NNSResolveHash(wCtx.ReadOnlyInvoker, cs.Hash, util2.DomainOf(util2.ProxyContract))
|
2023-12-21 09:26:47 +00:00
|
|
|
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)
|
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
if err := wCtx.SendConsensusTx(bw.Bytes()); err != nil {
|
2023-12-21 09:26:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-02-01 11:30:59 +00:00
|
|
|
if err = wCtx.AwaitTx(); err != nil {
|
2023-12-21 09:26:47 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Println("Proxy contract has been updated")
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|