github.com/decred/politeia@v1.4.0/politeiawww/cmd/cmswww/invoicedetails.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  // InvoiceDetailsCmd retrieves the details of a invoice.
    15  type InvoiceDetailsCmd struct {
    16  	Args struct {
    17  		Token   string `positional-arg-name:"token" required:"true"` // Censorship token
    18  		Version string `positional-arg-name:"version"`               // Proposal version
    19  	} `positional-args:"true"`
    20  }
    21  
    22  // Execute executes the invoice details command.
    23  func (cmd *InvoiceDetailsCmd) Execute(args []string) error {
    24  	// Get server's public key
    25  	vr, err := client.Version()
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	// Get invoice
    31  	idr, err := client.InvoiceDetails(cmd.Args.Token,
    32  		&v1.InvoiceDetails{
    33  			Version: cmd.Args.Version,
    34  		})
    35  	if err != nil {
    36  		return err
    37  	}
    38  
    39  	// Verify invoice censorship record
    40  	err = verifyInvoice(idr.Invoice, vr.PubKey)
    41  	if err != nil {
    42  		return fmt.Errorf("unable to verify invoice %v: %v",
    43  			idr.Invoice.CensorshipRecord.Token, err)
    44  	}
    45  
    46  	// Print invoice details
    47  	return shared.PrintJSON(idr)
    48  }
    49  
    50  // invoiceDetailsHelpMsg is the output for the help command when
    51  // 'invoicedetails' is specified.
    52  const invoiceDetailsHelpMsg = `invoicedetails "token"
    53  
    54  Get a invoice.
    55  
    56  Arguments:
    57  1. token      (string, required)   Censorship token
    58  
    59  Result:
    60  {
    61    "invoice": {
    62      "name":          (string)  Suggested short invoice name 
    63      "state":         (PropStateT)  Current state of invoice
    64      "status":        (PropStatusT)  Current status of invoice
    65      "timestamp":     (int64)  Timestamp of last update of invoice
    66      "userid":        (string)  ID of user who submitted invoice
    67      "username":      (string)  Username of user who submitted invoice
    68      "publickey":     (string)  Public key used to sign invoice
    69      "signature":     (string)  Signature of merkle root
    70      "files": [
    71        {
    72          "name":      (string)  Filename 
    73          "mime":      (string)  Mime type 
    74          "digest":    (string)  File digest 
    75          "payload":   (string)  File payload 
    76        }
    77      ],
    78      "numcomments":   (uint)  Number of comments on the invoice
    79      "version": 		 (string)  Version of invoice
    80      "censorshiprecord": {	
    81        "token":       (string)  Censorship token
    82        "merkle":      (string)  Merkle root of invoice
    83        "signature":   (string)  Server side signature of []byte(Merkle+Token)
    84      }
    85    }
    86  }`