Include ticket hex in feeaddress request.
This commit is contained in:
parent
1131e15ff1
commit
27e49e5e69
@ -108,16 +108,18 @@ func withWalletClients(wallets rpc.WalletConnect) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureTicketBroadcast will parse ticket hash and ticket hex from the request
|
// broadcastTicket will parse ticket hash and ticket hex from the request body,
|
||||||
// body, and ensure the local dcrd instance can retrieve information about that
|
// and ensure the local dcrd instance can retrieve information about the ticket.
|
||||||
// ticket. If no info can be found, the ticket hex will be broadcast.
|
// If no info can be found, the ticket hex will be broadcast.
|
||||||
func ensureTicketBroadcast() gin.HandlerFunc {
|
func broadcastTicket() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
funcName := "broadcastTicket"
|
||||||
|
|
||||||
// Read request bytes and then replace the request reader for
|
// Read request bytes and then replace the request reader for
|
||||||
// downstream handlers to use.
|
// downstream handlers to use.
|
||||||
reqBytes, err := ioutil.ReadAll(c.Request.Body)
|
reqBytes, err := ioutil.ReadAll(c.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Error reading request from %s: %v", c.ClientIP(), err)
|
log.Warnf("%s: Error reading request (clientIP=%s): %v", funcName, c.ClientIP(), err)
|
||||||
sendErrorWithMsg(err.Error(), errBadRequest, c)
|
sendErrorWithMsg(err.Error(), errBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -127,7 +129,7 @@ func ensureTicketBroadcast() gin.HandlerFunc {
|
|||||||
// Parse request and ensure ticket hash and hex are included.
|
// Parse request and ensure ticket hash and hex are included.
|
||||||
var request ticketRequest
|
var request ticketRequest
|
||||||
if err := binding.JSON.BindBody(reqBytes, &request); err != nil {
|
if err := binding.JSON.BindBody(reqBytes, &request); err != nil {
|
||||||
log.Warnf("Bad request from %s: %v", c.ClientIP(), err)
|
log.Warnf("%s: Bad request (clientIP=%s): %v", funcName, c.ClientIP(), err)
|
||||||
sendErrorWithMsg(err.Error(), errBadRequest, c)
|
sendErrorWithMsg(err.Error(), errBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -135,21 +137,23 @@ func ensureTicketBroadcast() gin.HandlerFunc {
|
|||||||
// Ensure the provided hex is a valid ticket.
|
// Ensure the provided hex is a valid ticket.
|
||||||
msgTx, err := decodeTransaction(request.TicketHex)
|
msgTx, err := decodeTransaction(request.TicketHex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("decodeTransaction error: %v", err)
|
log.Errorf("%s: Failed to decode ticket hex (ticketHash=%s): %v", funcName, request.TicketHash, err)
|
||||||
sendErrorWithMsg("cannot decode ticket hex", errBadRequest, c)
|
sendErrorWithMsg("cannot decode ticket hex", errBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = isValidTicket(msgTx)
|
err = isValidTicket(msgTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Invalid ticket from %s: %v", c.ClientIP(), err)
|
log.Warnf("%s: Invalid ticket (clientIP=%s, ticketHash=%s): %v",
|
||||||
|
funcName, c.ClientIP(), request.TicketHash, err)
|
||||||
sendError(errInvalidTicket, c)
|
sendError(errInvalidTicket, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure hex matches hash.
|
// Ensure hex matches hash.
|
||||||
if msgTx.TxHash().String() != request.TicketHash {
|
if msgTx.TxHash().String() != request.TicketHash {
|
||||||
log.Warnf("Ticket hex/hash mismatch from %s", c.ClientIP())
|
log.Warnf("%s: Ticket hex/hash mismatch (clientIP=%s, ticketHash=%s)",
|
||||||
|
funcName, c.ClientIP(), request.TicketHash)
|
||||||
sendErrorWithMsg("ticket hex does not match hash", errBadRequest, c)
|
sendErrorWithMsg("ticket hex does not match hash", errBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -160,7 +164,7 @@ func ensureTicketBroadcast() gin.HandlerFunc {
|
|||||||
// ticket.
|
// ticket.
|
||||||
_, err = dcrdClient.GetRawTransaction(request.TicketHash)
|
_, err = dcrdClient.GetRawTransaction(request.TicketHash)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// No error means dcrd knows the ticket, we are done here.
|
// No error means dcrd already knows the ticket, we are done here.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,15 +172,17 @@ func ensureTicketBroadcast() gin.HandlerFunc {
|
|||||||
// hex, so we can broadcast it here.
|
// hex, so we can broadcast it here.
|
||||||
var e *wsrpc.Error
|
var e *wsrpc.Error
|
||||||
if errors.As(err, &e) && e.Code == rpc.ErrNoTxInfo {
|
if errors.As(err, &e) && e.Code == rpc.ErrNoTxInfo {
|
||||||
log.Debugf("Broadcasting ticket with hash %s", request.TicketHash)
|
log.Debugf("%s: Broadcasting ticket (ticketHash=%s)", funcName, request.TicketHash)
|
||||||
err = dcrdClient.SendRawTransaction(request.TicketHex)
|
err = dcrdClient.SendRawTransaction(request.TicketHex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("SendRawTransaction error: %v", err)
|
log.Errorf("%s: dcrd.SendRawTransaction for ticket failed (ticketHash=%s): %v",
|
||||||
|
funcName, request.TicketHash, err)
|
||||||
sendError(errInternalError, c)
|
sendError(errInternalError, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("GetRawTransaction error: %v", err)
|
log.Errorf("%s: dcrd.GetRawTransaction for ticket failed (ticketHash=%s): %v",
|
||||||
|
funcName, request.TicketHash, err)
|
||||||
sendError(errInternalError, c)
|
sendError(errInternalError, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -190,7 +190,7 @@ func router(debugMode bool, cookieSecret []byte, dcrd rpc.DcrdConnect, wallets r
|
|||||||
|
|
||||||
api := router.Group("/api")
|
api := router.Group("/api")
|
||||||
api.GET("/vspinfo", vspInfo)
|
api.GET("/vspinfo", vspInfo)
|
||||||
api.POST("/feeaddress", withDcrdClient(dcrd), ensureTicketBroadcast(), vspAuth(), feeAddress)
|
api.POST("/feeaddress", withDcrdClient(dcrd), broadcastTicket(), vspAuth(), feeAddress)
|
||||||
api.GET("/ticketstatus", withDcrdClient(dcrd), vspAuth(), ticketStatus)
|
api.GET("/ticketstatus", withDcrdClient(dcrd), vspAuth(), ticketStatus)
|
||||||
api.POST("/payfee", withDcrdClient(dcrd), vspAuth(), payFee)
|
api.POST("/payfee", withDcrdClient(dcrd), vspAuth(), payFee)
|
||||||
api.POST("/setvotechoices", withDcrdClient(dcrd), withWalletClients(wallets), vspAuth(), setVoteChoices)
|
api.POST("/setvotechoices", withDcrdClient(dcrd), withWalletClients(wallets), vspAuth(), setVoteChoices)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user