@@ -16,7 +16,6 @@ import (
16
16
"github.com/decred/dcrd/dcrutil/v4"
17
17
"github.com/decred/dcrd/wire"
18
18
"github.com/decred/vspd/rpc"
19
- "github.com/gin-gonic/gin"
20
19
)
21
20
22
21
func currentVoteVersion (params * chaincfg.Params ) uint32 {
@@ -106,22 +105,22 @@ func validPolicyOption(policy string) error {
106
105
}
107
106
}
108
107
109
- func validateSignature (hash , commitmentAddress , signature , message string , c * gin. Context ) error {
108
+ func validateSignature (hash , commitmentAddress , signature , message string ) error {
110
109
firstErr := dcrutil .VerifyMessage (commitmentAddress , signature , message , cfg .NetParams )
111
110
if firstErr != nil {
112
111
// Don't return an error straight away if sig validation fails -
113
112
// first check if we have an alternate sign address for this ticket.
114
113
altSigData , err := db .AltSignAddrData (hash )
115
114
if err != nil {
116
- return fmt .Errorf ("db.AltSignAddrData failed (ticketHash=%s) : %v" , hash , err )
115
+ return fmt .Errorf ("db.AltSignAddrData failed: %v" , err )
117
116
}
118
117
119
118
// If we have no alternate sign address, or if validating with the
120
119
// alt sign addr fails, return an error to the client.
121
120
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" )
123
122
}
124
- return firstErr
123
+
125
124
}
126
125
return nil
127
126
}
@@ -152,55 +151,48 @@ func isValidTicket(tx *wire.MsgTx) error {
152
151
// validateTicketHash ensures the provided ticket hash is a valid ticket hash.
153
152
// A ticket hash should be 64 chars (MaxHashStringSize) and should parse into
154
153
// a chainhash.Hash without error.
155
- func validateTicketHash (c * gin. Context , hash string ) ( bool , error ) {
154
+ func validateTicketHash (hash string ) error {
156
155
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 )
158
157
159
158
}
160
159
_ , err := chainhash .NewHashFromStr (hash )
161
160
if err != nil {
162
- return false , fmt .Errorf ("Invalid hash (clientIP=%s) : %v" , c . ClientIP () , err )
161
+ return fmt .Errorf ("invalid hash: %v" , err )
163
162
164
163
}
165
164
166
- return true , nil
165
+ return nil
167
166
}
168
167
169
168
// getCommitmentAddress gets the commitment address of the provided ticket hash
170
169
// from the chain.
171
- func getCommitmentAddress (c * gin. Context , hash string ) (string , bool , error ) {
170
+ func getCommitmentAddress (hash string , dcrdClient * rpc. DcrdRPC ) (string , error ) {
172
171
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
-
180
172
resp , err := dcrdClient .GetRawTransaction (hash )
181
173
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 )
183
175
184
176
}
185
177
186
178
msgTx , err := decodeTransaction (resp .Hex )
187
179
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 )
189
181
190
182
}
191
183
192
184
err = isValidTicket (msgTx )
193
185
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 )
195
187
196
188
}
197
189
198
190
addr , err := stake .AddrFromSStxPkScrCommitment (msgTx .TxOut [1 ].PkScript , cfg .NetParams )
199
191
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 )
201
193
202
194
}
203
195
204
196
commitmentAddress = addr .String ()
205
- return commitmentAddress , false , nil
197
+ return commitmentAddress , nil
206
198
}
0 commit comments