Skip to content

Commit

Permalink
cmd: Add --force switch to override reserve addr errs
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Dec 22, 2022
1 parent d8c913e commit e4aaa7b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ var (

// Check, if to address is known to be unspendable.
if toAddr != nil {
cobra.CheckErr(common.CheckAddressNotReserved(cfg, toAddr.String()))
common.CheckForceErr(common.CheckAddressNotReserved(cfg, toAddr.String()))
}

// Parse amount.
Expand Down Expand Up @@ -407,7 +407,7 @@ var (
cobra.CheckErr(common.CheckLocalAccountIsConsensusCapable(cfg, addrToCheck))

// Check, if to address is known to be unspendable.
cobra.CheckErr(common.CheckAddressNotReserved(cfg, addrToCheck))
common.CheckForceErr(common.CheckAddressNotReserved(cfg, addrToCheck))

// Parse amount.
// TODO: This should actually query the ParaTime (or config) to check what the consensus
Expand Down Expand Up @@ -493,7 +493,7 @@ var (
cobra.CheckErr(err)

// Check, if to address is known to be unspendable.
cobra.CheckErr(common.CheckAddressNotReserved(cfg, toAddr.String()))
common.CheckForceErr(common.CheckAddressNotReserved(cfg, toAddr.String()))

acc := common.LoadAccount(cfg, npa.AccountName)

Expand Down Expand Up @@ -855,12 +855,15 @@ func init() {

accountsDepositCmd.Flags().AddFlagSet(common.SelectorFlags)
accountsDepositCmd.Flags().AddFlagSet(common.TransactionFlags)
accountsDepositCmd.Flags().AddFlagSet(common.ForceFlag)

accountsWithdrawCmd.Flags().AddFlagSet(common.SelectorFlags)
accountsWithdrawCmd.Flags().AddFlagSet(common.TransactionFlags)
accountsWithdrawCmd.Flags().AddFlagSet(common.ForceFlag)

accountsTransferCmd.Flags().AddFlagSet(common.SelectorFlags)
accountsTransferCmd.Flags().AddFlagSet(common.TransactionFlags)
accountsTransferCmd.Flags().AddFlagSet(common.ForceFlag)

accountsBurnCmd.Flags().AddFlagSet(common.SelectorFlags)
accountsBurnCmd.Flags().AddFlagSet(common.TransactionFlags)
Expand Down
12 changes: 12 additions & 0 deletions cmd/common/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,24 @@ import (
)

var selectedHeight int64
var force bool

// HeightFlag is the flag for specifying block height.
var HeightFlag *flag.FlagSet

// ForceFlag is a force mode switch.
var ForceFlag *flag.FlagSet

// GetHeight returns the user-selected block height.
func GetHeight() int64 {
return selectedHeight
}

// IsForce returns force mode.
func IsForce() bool {
return force
}

// GetActualHeight returns the user-selected block height if explicitly
// specified, or the current latest height.
func GetActualHeight(
Expand All @@ -39,4 +48,7 @@ func GetActualHeight(
func init() {
HeightFlag = flag.NewFlagSet("", flag.ContinueOnError)
HeightFlag.Int64Var(&selectedHeight, "height", consensus.HeightLatest, "explicitly set block height to use")

ForceFlag = flag.NewFlagSet("", flag.ContinueOnError)
ForceFlag.BoolVarP(&force, "force", "f", false, "treat safety check errors as warnings")
}
17 changes: 17 additions & 0 deletions cmd/common/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package common

import (
"fmt"

"github.com/spf13/cobra"
)

// CheckForceErr treats error as warning, if --force is provided.
func CheckForceErr(err interface{}) {
if err != nil && IsForce() {
fmt.Printf("Warning: %s. Proceeding by force!\n", err)
return
}

cobra.CheckErr(err)
}

0 comments on commit e4aaa7b

Please sign in to comment.