github.com/decred/politeia@v1.4.0/politeiawww/cmd/cmswww/admininvoices.go (about)

     1  // Copyright (c) 2017-2019 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  	"fmt"
     9  
    10  	v1 "github.com/decred/politeia/politeiawww/api/cms/v1"
    11  	"github.com/decred/politeia/politeiawww/cmd/shared"
    12  )
    13  
    14  // InvoicesCmd gets all invoices by month/year and/or status.
    15  type InvoicesCmd struct {
    16  	Args struct {
    17  		Month  int `long:"month"`
    18  		Year   int `long:"year"`
    19  		Status int `long:"status"`
    20  	}
    21  }
    22  
    23  // Execute executes the admin invoices command.
    24  func (cmd *InvoicesCmd) Execute(args []string) error {
    25  	// Get server public key
    26  	vr, err := client.Version()
    27  	if err != nil {
    28  		return err
    29  	}
    30  
    31  	// Get admin invoices
    32  	uir, err := client.Invoices(
    33  		&v1.Invoices{
    34  			Month:  uint16(cmd.Args.Month),
    35  			Year:   uint16(cmd.Args.Year),
    36  			Status: v1.InvoiceStatusT(cmd.Args.Status),
    37  		})
    38  	if err != nil {
    39  		return err
    40  	}
    41  
    42  	// Verify invoice censorship records
    43  	for _, p := range uir.Invoices {
    44  		err := verifyInvoice(p, vr.PubKey)
    45  		if err != nil {
    46  			return fmt.Errorf("unable to verify invoice %v: %v",
    47  				p.CensorshipRecord.Token, err)
    48  		}
    49  	}
    50  
    51  	// Print user invoices
    52  	return shared.PrintJSON(uir)
    53  }
    54  
    55  // userProposalsHelpMsg is the output of the help command when 'userinvoices'
    56  // is specified.
    57  const adminInvoicesHelpMsg = `userinvoices "userID" 
    58  
    59  Fetch all invoices submitted by a specific user.
    60  
    61  Arguments:
    62  1. userID      (string, required)   User id
    63  
    64  Result:
    65  {
    66    "invoices": [
    67  		{
    68  			...
    69      }
    70    ]
    71  }`