2022-04-04 15:36:10 +00:00
|
|
|
package morph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2022-11-23 14:44:03 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/policy"
|
2022-04-04 15:36:10 +00:00
|
|
|
"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)
|
|
|
|
}
|
|
|
|
|
|
|
|
bw := io.NewBufBinWriter()
|
|
|
|
for i := range args {
|
2023-02-27 14:19:35 +00:00
|
|
|
k, v, found := strings.Cut(args[i], "=")
|
|
|
|
if !found {
|
2022-04-04 15:36:10 +00:00
|
|
|
return fmt.Errorf("invalid parameter format, must be Parameter=Value")
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:19:35 +00:00
|
|
|
switch k {
|
2022-04-04 15:36:10 +00:00
|
|
|
case execFeeParam, storagePriceParam, setFeeParam:
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("parameter must be one of %s, %s and %s", execFeeParam, storagePriceParam, setFeeParam)
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:19:35 +00:00
|
|
|
value, err := strconv.ParseUint(v, 10, 32)
|
2022-04-04 15:36:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("can't parse parameter value '%s': %w", args[1], err)
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:19:35 +00:00
|
|
|
emit.AppCall(bw.BinWriter, policy.Hash, "set"+k, callflag.All, int64(value))
|
2022-04-04 15:36:10 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 19:31:32 +00:00
|
|
|
if err := wCtx.sendCommitteeTx(bw.Bytes(), false); err != nil {
|
2022-04-04 15:36:10 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return wCtx.awaitTx()
|
|
|
|
}
|