Add funcName to middleware logs
This commit is contained in:
parent
f42d3ee62f
commit
2c91a9bf9d
@ -110,11 +110,13 @@ func withWalletClients(wallets rpc.WalletConnect) gin.HandlerFunc {
|
|||||||
// use.
|
// use.
|
||||||
func vspAuth() gin.HandlerFunc {
|
func vspAuth() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
funcName := "vspAuth"
|
||||||
|
|
||||||
// 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 from %s: %v", funcName, c.ClientIP(), err)
|
||||||
sendErrorWithMsg(err.Error(), errBadRequest, c)
|
sendErrorWithMsg(err.Error(), errBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -124,7 +126,7 @@ func vspAuth() gin.HandlerFunc {
|
|||||||
// Parse request and ensure there is a ticket hash included.
|
// Parse request and ensure there is a ticket hash included.
|
||||||
var request ticketHashRequest
|
var request ticketHashRequest
|
||||||
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 from %s: %v", funcName, c.ClientIP(), err)
|
||||||
sendErrorWithMsg(err.Error(), errBadRequest, c)
|
sendErrorWithMsg(err.Error(), errBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -134,13 +136,13 @@ func vspAuth() gin.HandlerFunc {
|
|||||||
// A ticket hash should be 64 chars (MaxHashStringSize) and should parse
|
// A ticket hash should be 64 chars (MaxHashStringSize) and should parse
|
||||||
// into a chainhash.Hash without error.
|
// into a chainhash.Hash without error.
|
||||||
if len(hash) != chainhash.MaxHashStringSize {
|
if len(hash) != chainhash.MaxHashStringSize {
|
||||||
log.Errorf("Invalid hash from %s: incorrect length", c.ClientIP())
|
log.Errorf("%s: Invalid hash from %s: incorrect length", funcName, c.ClientIP())
|
||||||
sendErrorWithMsg("invalid ticket hash", errBadRequest, c)
|
sendErrorWithMsg("invalid ticket hash", errBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = chainhash.NewHashFromStr(hash)
|
_, err = chainhash.NewHashFromStr(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Invalid hash from %s: %v", c.ClientIP(), err)
|
log.Errorf("%s: Invalid hash from %s: %v", funcName, c.ClientIP(), err)
|
||||||
sendErrorWithMsg("invalid ticket hash", errBadRequest, c)
|
sendErrorWithMsg("invalid ticket hash", errBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -148,7 +150,7 @@ func vspAuth() gin.HandlerFunc {
|
|||||||
// Check if this ticket already appears in the database.
|
// Check if this ticket already appears in the database.
|
||||||
ticket, ticketFound, err := db.GetTicketByHash(hash)
|
ticket, ticketFound, err := db.GetTicketByHash(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GetTicketByHash error: %v", err)
|
log.Errorf("%s: GetTicketByHash error: %v", funcName, err)
|
||||||
sendError(errInternalError, c)
|
sendError(errInternalError, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -163,28 +165,28 @@ func vspAuth() gin.HandlerFunc {
|
|||||||
|
|
||||||
resp, err := dcrdClient.GetRawTransaction(hash)
|
resp, err := dcrdClient.GetRawTransaction(hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GetRawTransaction error: %v", err)
|
log.Errorf("%s: GetRawTransaction error: %v", funcName, err)
|
||||||
sendError(errInternalError, c)
|
sendError(errInternalError, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msgTx, err := decodeTransaction(resp.Hex)
|
msgTx, err := decodeTransaction(resp.Hex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("decodeTransaction error: %v", err)
|
log.Errorf("%s: decodeTransaction error: %v", funcName, err)
|
||||||
sendError(errInternalError, c)
|
sendError(errInternalError, 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 from %s: %v", funcName, c.ClientIP(), err)
|
||||||
sendError(errInvalidTicket, c)
|
sendError(errInvalidTicket, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
addr, err := stake.AddrFromSStxPkScrCommitment(msgTx.TxOut[1].PkScript, cfg.NetParams)
|
addr, err := stake.AddrFromSStxPkScrCommitment(msgTx.TxOut[1].PkScript, cfg.NetParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("AddrFromSStxPkScrCommitment error: %v", err)
|
log.Errorf("%s: AddrFromSStxPkScrCommitment error: %v", funcName, err)
|
||||||
sendError(errInternalError, c)
|
sendError(errInternalError, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -195,7 +197,7 @@ func vspAuth() gin.HandlerFunc {
|
|||||||
// Validate request signature to ensure ticket ownership.
|
// Validate request signature to ensure ticket ownership.
|
||||||
err = validateSignature(reqBytes, commitmentAddress, c)
|
err = validateSignature(reqBytes, commitmentAddress, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Bad signature from %s: %v", c.ClientIP(), err)
|
log.Warnf("%s: Bad signature from %s: %v", funcName, c.ClientIP(), err)
|
||||||
sendError(errBadSignature, c)
|
sendError(errBadSignature, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user