Skip to content

Commit

Permalink
feat: Add disable-gas-policy in wasp-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed Aug 15, 2023
1 parent 0b0a9c1 commit 4bad149
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/wasp-cli/chain/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Init(rootCmd *cobra.Command) {
chainCmd.AddCommand(initRotateCmd())
chainCmd.AddCommand(initRotateWithDKGCmd())
chainCmd.AddCommand(initChangeAccessNodesCmd())
chainCmd.AddCommand(initDisableGasPolicyCmd())
chainCmd.AddCommand(initPermissionlessAccessNodesCmd())
chainCmd.AddCommand(initAddChainCmd())
chainCmd.AddCommand(initRegisterERC20NativeTokenCmd())
Expand Down
66 changes: 66 additions & 0 deletions tools/wasp-cli/chain/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
package chain

import (
"context"

"github.com/spf13/cobra"

"github.com/iotaledger/wasp/clients/apiclient"
"github.com/iotaledger/wasp/clients/apiextensions"
"github.com/iotaledger/wasp/clients/chainclient"
"github.com/iotaledger/wasp/packages/cryptolib"
"github.com/iotaledger/wasp/packages/kv/dict"
"github.com/iotaledger/wasp/packages/util"
"github.com/iotaledger/wasp/packages/vm/core/governance"
"github.com/iotaledger/wasp/packages/vm/gas"
"github.com/iotaledger/wasp/tools/wasp-cli/cli/cliclients"
"github.com/iotaledger/wasp/tools/wasp-cli/cli/config"
"github.com/iotaledger/wasp/tools/wasp-cli/log"
"github.com/iotaledger/wasp/tools/wasp-cli/waspcmd"
)
Expand Down Expand Up @@ -65,3 +74,60 @@ func initChangeAccessNodesCmd() *cobra.Command {

return cmd
}

func initDisableGasPolicyCmd() *cobra.Command {
var offLedger bool
var node string
var chain string

cmd := &cobra.Command{
Use: "disable-gas-policy",
Short: "set token charged by each gas to free.",
Args: cobra.MinimumNArgs(2),
Run: func(cmd *cobra.Command, args []string) {
node = waspcmd.DefaultWaspNodeFallback(node)
chain = defaultChainFallback(chain)
client := cliclients.WaspClient(node)

callGovView := func(viewName string) dict.Dict {
result, _, err := client.ChainsApi.CallView(context.Background(), config.GetChain(chain).String()).
ContractCallViewRequest(apiclient.ContractCallViewRequest{
ContractName: governance.Contract.Name,
FunctionName: viewName,
}).Execute() //nolint:bodyclose // false positive
log.Check(err)

resultDict, err := apiextensions.APIJsonDictToDict(*result)
log.Check(err)
return resultDict
}

feePolicyBytes := callGovView(governance.ViewGetFeePolicy.Name).Get(governance.ParamFeePolicyBytes)
feePolicy := gas.MustFeePolicyFromBytes(feePolicyBytes)
feePolicy.GasPerToken = util.Ratio32{}

params := chainclient.PostRequestParams{
Args: dict.Dict{
governance.VarGasFeePolicyBytes: feePolicy.Bytes(),
},
}

postRequest(
node,
chain,
governance.Contract.Name,
governance.FuncSetFeePolicy.Name,
params,
offLedger,
true)
},
}

waspcmd.WithWaspNodeFlag(cmd, &node)
withChainFlag(cmd, &chain)
cmd.Flags().BoolVarP(&offLedger, "off-ledger", "o", false,
"post an off-ledger request",
)

return cmd
}

0 comments on commit 4bad149

Please sign in to comment.