github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/cmdproposalinv.go (about) 1 // Copyright (c) 2020-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 rcv1 "github.com/decred/politeia/politeiawww/api/records/v1" 9 pclient "github.com/decred/politeia/politeiawww/client" 10 ) 11 12 // cmdProposalInv retrieves the censorship record tokens of all proposals in 13 // the inventory, categorized by status. 14 type cmdProposalInv struct { 15 Args struct { 16 State string `positional-arg-name:"state"` 17 Status string `positional-arg-name:"status"` 18 Page uint32 `positional-arg-name:"page"` 19 } `positional-args:"true" optional:"true"` 20 } 21 22 // Execute executes the cmdProposalInv command. 23 // 24 // This function satisfies the go-flags Commander interface. 25 func (c *cmdProposalInv) Execute(args []string) error { 26 _, err := proposalInv(c) 27 if err != nil { 28 return err 29 } 30 return nil 31 } 32 33 // proposalInv retrieves the proposal inventory. This function has been pulled 34 // out of the Execute method so that it can be used in test commands. 35 func proposalInv(c *cmdProposalInv) (*rcv1.InventoryReply, error) { 36 // Setup client 37 opts := pclient.Opts{ 38 HTTPSCert: cfg.HTTPSCert, 39 Cookies: cfg.Cookies, 40 HeaderCSRF: cfg.CSRF, 41 Verbose: cfg.Verbose, 42 RawJSON: cfg.RawJSON, 43 } 44 pc, err := pclient.New(cfg.Host, opts) 45 if err != nil { 46 return nil, err 47 } 48 49 // Setup state 50 var state rcv1.RecordStateT 51 if c.Args.State != "" { 52 // Parse state. This can be either the numeric state code or the 53 // human readable equivalent. 54 state, err = parseRecordState(c.Args.State) 55 if err != nil { 56 return nil, err 57 } 58 } 59 60 // Setup status and page number 61 var status rcv1.RecordStatusT 62 if c.Args.Status != "" { 63 // Parse status. This can be either the numeric status code or the 64 // human readable equivalent. 65 status, err = parseRecordStatus(c.Args.Status) 66 if err != nil { 67 return nil, err 68 } 69 70 // If a status was given but no page number was give, default 71 // to page number 1. 72 if c.Args.Page == 0 { 73 c.Args.Page = 1 74 } 75 } 76 77 // Get inventory 78 i := rcv1.Inventory{ 79 State: state, 80 Status: status, 81 Page: c.Args.Page, 82 } 83 ir, err := pc.RecordInventory(i) 84 if err != nil { 85 return nil, err 86 } 87 88 // Print inventory 89 printJSON(ir) 90 91 return ir, nil 92 } 93 94 // proposalInvHelpMsg is printed to stdout by the help command. 95 const proposalInvHelpMsg = `proposalinv 96 97 Inventory returns the tokens of the records in the inventory, categorized by 98 record state and record status. The tokens are ordered by the timestamp of 99 their most recent status change, sorted from newest to oldest. 100 101 The status and page arguments can be provided to request a specific page of 102 record tokens. 103 104 If no status is specified then a page of tokens for each status are returned. 105 The state and page arguments will be ignored. 106 107 Valid states: 108 (1) unvetted 109 (2) vetted 110 111 Valid statuses: 112 (2) public 113 (3) censored 114 (4) abandoned 115 116 Arguments: 117 1. state (string, optional) State of tokens being requested. 118 2. status (string, optional) Status of tokens being requested. 119 3. page (uint32, optional) Page number. 120 `