github.com/decred/politeia@v1.4.0/politeiawww/cmd/cmswww/supportopposedcc.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 "fmt" 10 11 v1 "github.com/decred/politeia/politeiawww/api/cms/v1" 12 "github.com/decred/politeia/politeiawww/cmd/shared" 13 ) 14 15 // SupportOpposeDCCCmd allows a user to support a DCC proposal. 16 type SupportOpposeDCCCmd struct { 17 Args struct { 18 Vote string `positional-arg-name:"vote"` 19 Token string `positional-arg-name:"token"` 20 } `positional-args:"true" required:"true"` 21 } 22 23 // Execute executes the support DCC command. 24 func (cmd *SupportOpposeDCCCmd) Execute(args []string) error { 25 token := cmd.Args.Token 26 vote := cmd.Args.Vote 27 28 if vote != "aye" && vote != "nay" { 29 return fmt.Errorf("invalid request: you must either vote aye or nay") 30 } 31 32 if token == "" { 33 return fmt.Errorf("invalid request: you must specify dcc " + 34 "token") 35 } 36 37 // Check for user identity 38 if cfg.Identity == nil { 39 return shared.ErrUserIdentityNotFound 40 } 41 42 sig := cfg.Identity.SignMessage([]byte(token + vote)) 43 sd := v1.SupportOpposeDCC{ 44 Vote: vote, 45 Token: token, 46 PublicKey: hex.EncodeToString(cfg.Identity.Public.Key[:]), 47 Signature: hex.EncodeToString(sig[:]), 48 } 49 50 // Print request details 51 err := shared.PrintJSON(sd) 52 if err != nil { 53 return err 54 } 55 56 // Send request 57 sdr, err := client.SupportOpposeDCC(sd) 58 if err != nil { 59 return fmt.Errorf("SupportOpposeDCC: %v", err) 60 } 61 62 // Print response details 63 err = shared.PrintJSON(sdr) 64 if err != nil { 65 return err 66 } 67 68 return nil 69 }