github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/cmdproposalbillingstatuschanges.go (about)

     1  // Copyright (c) 2021 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	piv1 "github.com/decred/politeia/politeiawww/api/pi/v1"
     9  	pclient "github.com/decred/politeia/politeiawww/client"
    10  )
    11  
    12  // cmdProposalBillingStatusChanges returns the billing status changes of a
    13  // proposal.
    14  type cmdProposalBillingStatusChanges struct {
    15  	Args struct {
    16  		Tokens []string `positional-arg-name:"tokens" required:"true"`
    17  	} `positional-args:"true"`
    18  }
    19  
    20  // Execute executes the cmdProposalBillingStatusChanges command.
    21  //
    22  // This function satisfies the go-flags Commander interface.
    23  func (c *cmdProposalBillingStatusChanges) Execute(args []string) error {
    24  	// Setup client
    25  	opts := pclient.Opts{
    26  		HTTPSCert:  cfg.HTTPSCert,
    27  		Cookies:    cfg.Cookies,
    28  		HeaderCSRF: cfg.CSRF,
    29  		Verbose:    cfg.Verbose,
    30  		RawJSON:    cfg.RawJSON,
    31  	}
    32  	pc, err := pclient.New(cfg.Host, opts)
    33  	if err != nil {
    34  		return err
    35  	}
    36  
    37  	// Setup request
    38  	bscs := piv1.BillingStatusChanges{
    39  		Tokens: c.Args.Tokens,
    40  	}
    41  
    42  	// Send request
    43  	bscsr, err := pc.PiBillingStatusChanges(bscs)
    44  	if err != nil {
    45  		return err
    46  	}
    47  
    48  	// Print billing status changes for all tokens
    49  	for t, bscs := range bscsr.BillingStatusChanges {
    50  		printf("Proposal %v\n", t)
    51  		if len(bscs) > 0 {
    52  			for i, bsc := range bscs {
    53  				printBillingStatusChange(bsc)
    54  				if i != len(bscs)-1 {
    55  					printf("  -----\n")
    56  				}
    57  			}
    58  		} else {
    59  			printf("  No billing status changes\n")
    60  		}
    61  		printf("\n")
    62  	}
    63  
    64  	return nil
    65  }
    66  
    67  // proposalBillingStatusChangesHelpMsg is printed to stdout by the help command.
    68  const proposalBillingStatusChangesHelpMsg = `proposalbillingstatuschanges "tokens..."
    69  
    70  Return the billing status changes for a page of propsoals.
    71  
    72  Arguments:
    73  1. tokens   (string, required)   Proposal censorship tokens
    74  `