@@ -16,7 +16,6 @@ import (
1616 "github.com/decred/dcrd/dcrutil/v4"
1717 "github.com/decred/dcrd/wire"
1818 "github.com/decred/vspd/rpc"
19- "github.com/gin-gonic/gin"
2019)
2120
2221func currentVoteVersion (params * chaincfg.Params ) uint32 {
@@ -106,22 +105,22 @@ func validPolicyOption(policy string) error {
106105 }
107106}
108107
109- func validateSignature (hash , commitmentAddress , signature , message string , c * gin. Context ) error {
108+ func validateSignature (hash , commitmentAddress , signature , message string ) error {
110109 firstErr := dcrutil .VerifyMessage (commitmentAddress , signature , message , cfg .NetParams )
111110 if firstErr != nil {
112111 // Don't return an error straight away if sig validation fails -
113112 // first check if we have an alternate sign address for this ticket.
114113 altSigData , err := db .AltSignAddrData (hash )
115114 if err != nil {
116- return fmt .Errorf ("db.AltSignAddrData failed (ticketHash=%s) : %v" , hash , err )
115+ return fmt .Errorf ("db.AltSignAddrData failed: %v" , err )
117116 }
118117
119118 // If we have no alternate sign address, or if validating with the
120119 // alt sign addr fails, return an error to the client.
121120 if altSigData == nil || dcrutil .VerifyMessage (altSigData .AltSignAddr , signature , message , cfg .NetParams ) != nil {
122- return fmt .Errorf ("Bad signature (clientIP=%s, ticketHash=%s)" , c . ClientIP (), hash )
121+ return fmt .Errorf ("bad signature" )
123122 }
124- return firstErr
123+
125124 }
126125 return nil
127126}
@@ -152,55 +151,48 @@ func isValidTicket(tx *wire.MsgTx) error {
152151// validateTicketHash ensures the provided ticket hash is a valid ticket hash.
153152// A ticket hash should be 64 chars (MaxHashStringSize) and should parse into
154153// a chainhash.Hash without error.
155- func validateTicketHash (c * gin. Context , hash string ) ( bool , error ) {
154+ func validateTicketHash (hash string ) error {
156155 if len (hash ) != chainhash .MaxHashStringSize {
157- return false , fmt .Errorf ("Incorrect hash length (clientIP=%s) : got %d, expected %d" , c . ClientIP () , len (hash ), chainhash .MaxHashStringSize )
156+ return fmt .Errorf ("incorrect hash length: got %d, expected %d" , len (hash ), chainhash .MaxHashStringSize )
158157
159158 }
160159 _ , err := chainhash .NewHashFromStr (hash )
161160 if err != nil {
162- return false , fmt .Errorf ("Invalid hash (clientIP=%s) : %v" , c . ClientIP () , err )
161+ return fmt .Errorf ("invalid hash: %v" , err )
163162
164163 }
165164
166- return true , nil
165+ return nil
167166}
168167
169168// getCommitmentAddress gets the commitment address of the provided ticket hash
170169// from the chain.
171- func getCommitmentAddress (c * gin. Context , hash string ) (string , bool , error ) {
170+ func getCommitmentAddress (hash string , dcrdClient * rpc. DcrdRPC ) (string , error ) {
172171 var commitmentAddress string
173- dcrdClient := c .MustGet (dcrdKey ).(* rpc.DcrdRPC )
174- dcrdErr := c .MustGet (dcrdErrorKey )
175- if dcrdErr != nil {
176- return commitmentAddress , false , fmt .Errorf ("could not get dcrd client: %v" , dcrdErr .(error ))
177-
178- }
179-
180172 resp , err := dcrdClient .GetRawTransaction (hash )
181173 if err != nil {
182- return commitmentAddress , false , fmt .Errorf ("dcrd.GetRawTransaction for ticket failed (ticketHash=%s) : %v" , hash , err )
174+ return commitmentAddress , fmt .Errorf ("dcrd.GetRawTransaction for ticket failed: %v" , err )
183175
184176 }
185177
186178 msgTx , err := decodeTransaction (resp .Hex )
187179 if err != nil {
188- return commitmentAddress , false , fmt .Errorf ("Failed to decode ticket hex (ticketHash=%s) : %v" , hash , err )
180+ return commitmentAddress , fmt .Errorf ("Failed to decode ticket hex: %v" , err )
189181
190182 }
191183
192184 err = isValidTicket (msgTx )
193185 if err != nil {
194- return commitmentAddress , true , fmt .Errorf ("Invalid ticket (clientIP=%s, ticketHash=%s) : %v " , c . ClientIP (), hash , err )
186+ return commitmentAddress , fmt .Errorf ("Invalid ticket: %w " , errInvalidTicket )
195187
196188 }
197189
198190 addr , err := stake .AddrFromSStxPkScrCommitment (msgTx .TxOut [1 ].PkScript , cfg .NetParams )
199191 if err != nil {
200- return commitmentAddress , false , fmt .Errorf ("AddrFromSStxPkScrCommitment error (ticketHash=%s) : %v" , hash , err )
192+ return commitmentAddress , fmt .Errorf ("AddrFromSStxPkScrCommitment error: %v" , err )
201193
202194 }
203195
204196 commitmentAddress = addr .String ()
205- return commitmentAddress , false , nil
197+ return commitmentAddress , nil
206198}
0 commit comments