github.com/decred/politeia@v1.4.0/politeiawww/cmd/cmswww/newcomment.go (about) 1 // Copyright (c) 2017-2020 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 "encoding/hex" 9 10 v1 "github.com/decred/politeia/politeiawww/api/www/v1" 11 "github.com/decred/politeia/politeiawww/cmd/shared" 12 ) 13 14 // NewCommentCmd submits a new proposal comment. 15 type NewCommentCmd struct { 16 Args struct { 17 Token string `positional-arg-name:"token" required:"true"` // Censorship token 18 Comment string `positional-arg-name:"comment" required:"true"` // Comment text 19 ParentID string `positional-arg-name:"parentID"` // Comment parent ID 20 } `positional-args:"true"` 21 } 22 23 // Execute executes the new comment command. 24 func (cmd *NewCommentCmd) Execute(args []string) error { 25 token := cmd.Args.Token 26 comment := cmd.Args.Comment 27 parentID := cmd.Args.ParentID 28 29 // Check for user identity 30 if cfg.Identity == nil { 31 return shared.ErrUserIdentityNotFound 32 } 33 34 // Setup new comment request 35 sig := cfg.Identity.SignMessage([]byte(token + parentID + comment)) 36 nc := &v1.NewComment{ 37 Token: token, 38 ParentID: parentID, 39 Comment: comment, 40 Signature: hex.EncodeToString(sig[:]), 41 PublicKey: hex.EncodeToString(cfg.Identity.Public.Key[:]), 42 } 43 44 // Print request details 45 err := shared.PrintJSON(nc) 46 if err != nil { 47 return err 48 } 49 50 // Send request 51 ncr, err := client.WWWNewComment(nc) 52 if err != nil { 53 return err 54 } 55 56 // Print response details 57 return shared.PrintJSON(ncr) 58 } 59 60 // newCommentHelpMsg is the output of the help command when 'newcomment' is 61 // specified. 62 const newCommentHelpMsg = `newcomment "token" "comment" 63 Comment on proposal as logged in user. 64 Arguments: 65 1. token (string, required) Proposal censorship token 66 2. comment (string, required) Comment 67 3. parentID (string, required if replying to comment) Id of commment 68 Request: 69 { 70 "token": (string) Censorship token 71 "parentid": (string) Id of comment (defaults to '0' (top-level comment)) 72 "comment": (string) Comment 73 "signature": (string) Signature of comment (token+parentID+comment) 74 "publickey": (string) Public key of user commenting 75 } 76 Response: 77 { 78 "comment": { 79 "token": (string) Censorship token 80 "parentid": (string) Id of comment (defaults to '0' (top-level)) 81 "comment": (string) Comment 82 "signature": (string) Signature of token+parentID+comment 83 "publickey": (string) Public key of user 84 "commentid": (string) Id of the comment 85 "receipt": (string) Server signature of the comment signature 86 "timestamp": (int64) Received UNIX timestamp 87 "resultvotes": (int64) Vote score 88 "upvotes": (uint64) Pro votes 89 "downvotes": (uint64) Contra votes 90 "censored": (bool) If comment has been censored 91 "userid": (string) User id 92 "username": (string) Username 93 } 94 }`