github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/client/cmd_wallet_cancel_request.go (about)

     1  package client
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/keybase/cli"
     7  	"github.com/keybase/client/go/libcmdline"
     8  	"github.com/keybase/client/go/libkb"
     9  	"github.com/keybase/client/go/protocol/stellar1"
    10  	"golang.org/x/net/context"
    11  )
    12  
    13  type CmdWalletCancelRequest struct {
    14  	libkb.Contextified
    15  	ID string
    16  }
    17  
    18  func newCmdWalletCancelRequest(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
    19  	cmd := &CmdWalletCancelRequest{
    20  		Contextified: libkb.NewContextified(g),
    21  	}
    22  	return cli.Command{
    23  		Name:         "cancel-request",
    24  		Usage:        "Cancel payment request",
    25  		ArgumentHelp: "<request id>",
    26  		Action: func(c *cli.Context) {
    27  			cl.ChooseCommand(cmd, "cancel-request", c)
    28  		},
    29  	}
    30  }
    31  
    32  func (c *CmdWalletCancelRequest) ParseArgv(ctx *cli.Context) error {
    33  	if len(ctx.Args()) != 1 {
    34  		return errors.New("cancel-request needs request id as the argument")
    35  	}
    36  
    37  	c.ID = ctx.Args()[0]
    38  	return nil
    39  }
    40  
    41  func (c *CmdWalletCancelRequest) Run() (err error) {
    42  	defer transformStellarCLIError(&err)
    43  	cli, err := GetWalletClient(c.G())
    44  	if err != nil {
    45  		return err
    46  	}
    47  
    48  	requestID, err := stellar1.KeybaseRequestIDFromString(c.ID)
    49  	if err != nil {
    50  		return err
    51  	}
    52  
    53  	return cli.CancelRequestLocal(context.Background(), stellar1.CancelRequestLocalArg{
    54  		ReqID: requestID,
    55  	})
    56  }
    57  
    58  func (c *CmdWalletCancelRequest) GetUsage() libkb.Usage {
    59  	return libkb.Usage{
    60  		Config:    true,
    61  		API:       true,
    62  		KbKeyring: true,
    63  	}
    64  }