frostfs-node/cmd/neofs-adm/internal/modules/morph/policy.go
Evgenii Stratonikov 82fda42316 [#1294] neofs-adm: Use Global scope where needed
Provide explicit argument to `sendCommitteeTx` signifying whether a tx
should try to use group signer.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-04-05 18:23:14 +03:00

59 lines
1.5 KiB
Go

package morph
import (
"fmt"
"strconv"
"strings"
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
execFeeParam = "ExecFeeFactor"
storagePriceParam = "StoragePrice"
setFeeParam = "FeePerByte"
)
func setPolicyCmd(cmd *cobra.Command, args []string) error {
wCtx, err := newInitializeContext(cmd, viper.GetViper())
if err != nil {
return fmt.Errorf("can't to initialize context: %w", err)
}
policyHash, err := wCtx.Client.GetNativeContractHash(nativenames.Policy)
if err != nil {
return fmt.Errorf("can't get policy contract hash: %w", err)
}
bw := io.NewBufBinWriter()
for i := range args {
kv := strings.SplitN(args[i], "=", 2)
if len(kv) != 2 {
return fmt.Errorf("invalid parameter format, must be Parameter=Value")
}
switch kv[0] {
case execFeeParam, storagePriceParam, setFeeParam:
default:
return fmt.Errorf("parameter must be one of %s, %s and %s", execFeeParam, storagePriceParam, setFeeParam)
}
value, err := strconv.ParseUint(kv[1], 10, 32)
if err != nil {
return fmt.Errorf("can't parse parameter value '%s': %w", args[1], err)
}
emit.AppCall(bw.BinWriter, policyHash, "set"+kv[0], callflag.All, int64(value))
}
if err := wCtx.sendCommitteeTx(bw.Bytes(), -1, false); err != nil {
return err
}
return wCtx.awaitTx()
}