github.com/decred/politeia@v1.4.0/politeiawww/cmd/cmswww/newdcccomment.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 "encoding/hex" 9 10 v1 "github.com/decred/politeia/politeiawww/api/www/v1" 11 "github.com/decred/politeia/politeiawww/cmd/shared" 12 ) 13 14 // NewDCCCommentCmd submits a new dcc comment. 15 type NewDCCCommentCmd 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 *NewDCCCommentCmd) 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.NewDCCComment(nc) 52 if err != nil { 53 return err 54 } 55 56 // Print response details 57 return shared.PrintJSON(ncr) 58 } 59 60 // newDCCCommentHelpMsg is the output of the help command when 'newcomment' is 61 // specified. 62 const newDCCCommentHelpMsg = `newcomment "token" "comment" 63 64 Comment on proposal as logged in user. 65 66 Arguments: 67 1. token (string, required) DCC censorship token 68 2. comment (string, required) Comment 69 3. parentID (string, required if replying to comment) Id of commment 70 71 Request: 72 { 73 "token": (string) Censorship token 74 "parentid": (string) Id of comment (defaults to '0' (top-level comment)) 75 "comment": (string) Comment 76 "signature": (string) Signature of comment (token+parentID+comment) 77 "publickey": (string) Public key of user commenting 78 } 79 80 Response: 81 { 82 "comment": { 83 "token": (string) Censorship token 84 "parentid": (string) Id of comment (defaults to '0' (top-level)) 85 "comment": (string) Comment 86 "signature": (string) Signature of token+parentID+comment 87 "publickey": (string) Public key of user 88 "commentid": (string) Id of the comment 89 "receipt": (string) Server signature of the comment signature 90 "timestamp": (int64) Received UNIX timestamp 91 "resultvotes": (int64) Vote score 92 "censored": (bool) If comment has been censored 93 "userid": (string) User id 94 "username": (string) Username 95 } 96 }`