github.com/ChainSafe/chainbridge-core@v1.4.2/chains/evm/cli/bridge/cancel-proposal.go (about) 1 package bridge 2 3 import ( 4 "fmt" 5 6 "github.com/ChainSafe/chainbridge-core/chains/evm/cli/flags" 7 "github.com/ChainSafe/chainbridge-core/chains/evm/cli/logger" 8 "github.com/ChainSafe/chainbridge-core/util" 9 "github.com/ethereum/go-ethereum/common" 10 "github.com/rs/zerolog/log" 11 "github.com/spf13/cobra" 12 ) 13 14 var cancelProposalCmd = &cobra.Command{ 15 Use: "cancel-proposal", 16 Short: "Cancel an expired proposal", 17 Long: "The cancel-proposal subcommand cancels an expired proposal", 18 PreRun: func(cmd *cobra.Command, args []string) { 19 logger.LoggerMetadata(cmd.Name(), cmd.Flags()) 20 }, 21 PersistentPreRunE: func(cmd *cobra.Command, args []string) error { 22 return util.CallPersistentPreRun(cmd, args) 23 }, 24 RunE: cancelProposal, 25 Args: func(cmd *cobra.Command, args []string) error { 26 err := ValidateCancelProposalFlags(cmd, args) 27 if err != nil { 28 return err 29 } 30 return nil 31 }, 32 } 33 34 func BindCancelProposalFlags(cmd *cobra.Command) { 35 cmd.Flags().StringVar(&Bridge, "bridge", "", "Bridge contract address") 36 cmd.Flags().StringVar(&DataHash, "data-hash", "", "Hash of proposal metadata") 37 cmd.Flags().Uint8Var(&DomainID, "domain", 0, "Domain ID of proposal to cancel") 38 cmd.Flags().Uint64Var(&DepositNonce, "deposit-nonce", 0, "Deposit nonce of proposal to cancel") 39 flags.MarkFlagsAsRequired(cmd, "bridge", "data-hash", "domain", "deposit-nonce") 40 } 41 42 func init() { 43 BindCancelProposalFlags(cancelProposalCmd) 44 } 45 46 func ValidateCancelProposalFlags(cmd *cobra.Command, args []string) error { 47 if !common.IsHexAddress(Bridge) { 48 return fmt.Errorf("invalid bridge address: %s", Bridge) 49 } 50 return nil 51 } 52 53 func cancelProposal(cmd *cobra.Command, args []string) error { 54 55 log.Debug().Msgf(` 56 Cancel propsal 57 Bridge address: %s 58 Chain ID: %d 59 Deposit nonce: %d 60 DataHash: %s 61 `, Bridge, DomainID, DepositNonce, DataHash) 62 return nil 63 } 64 65 /* 66 func cancelProposal(cctx *cli.Context) error { 67 url := cctx.String("url") 68 gasLimit := cctx.Uint64("gasLimit") 69 gasPrice := cctx.Uint64("gasPrice") 70 sender, err := cliutils.DefineSender(cctx) 71 if err != nil { 72 return err 73 } 74 bridgeAddress, err := cliutils.DefineBridgeAddress(cctx) 75 if err != nil { 76 return err 77 } 78 79 domainID := cctx.Uint64("domainId") 80 depositNonce := cctx.Uint64("depositNonce") 81 dataHash := cctx.String("dataHash") 82 dataHashBytes := utils.SliceTo32Bytes(common.Hex2Bytes(dataHash)) 83 84 ethClient, err := client.NewClient(url, false, sender, big.NewInt(0).SetUint64(gasLimit), big.NewInt(0).SetUint64(gasPrice), big.NewFloat(1)) 85 if err != nil { 86 return err 87 } 88 err = utils.CancelProposal(ethClient, bridgeAddress, uint8(domainID), depositNonce, dataHashBytes) 89 if err != nil { 90 return err 91 } 92 log.Info().Msgf("Setting proposal with domain ID %v and deposit nonce %v status to 'Cancelled", domainID, depositNonce) 93 return nil 94 } 95 */