From ac8e20f3c1dbd2702924d490a8891894608634fe Mon Sep 17 00:00:00 2001 From: Jamie Holdstock Date: Wed, 30 Dec 2020 12:36:06 +0000 Subject: [PATCH] Use actual request in response, dont reserialize. (#220) Reserializing the client request can result in different bytes because the order of iteration over a map is not guaranteed to be the same every time. --- webapi/getfeeaddress.go | 4 ++-- webapi/payfee.go | 2 +- webapi/setvotechoices.go | 2 +- webapi/ticketstatus.go | 2 +- webapi/types.go | 30 +++++++++++++++--------------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/webapi/getfeeaddress.go b/webapi/getfeeaddress.go index d75588e..66e4195 100644 --- a/webapi/getfeeaddress.go +++ b/webapi/getfeeaddress.go @@ -147,7 +147,7 @@ func feeAddress(c *gin.Context) { } sendJSONResponse(feeAddressResponse{ Timestamp: now.Unix(), - Request: request, + Request: reqBytes, FeeAddress: ticket.FeeAddress, FeeAmount: ticket.FeeAmount, Expiration: ticket.FeeExpiration, @@ -200,7 +200,7 @@ func feeAddress(c *gin.Context) { sendJSONResponse(feeAddressResponse{ Timestamp: now.Unix(), - Request: request, + Request: reqBytes, FeeAddress: newAddress, FeeAmount: int64(fee), Expiration: expire, diff --git a/webapi/payfee.go b/webapi/payfee.go index ba6abda..85643d8 100644 --- a/webapi/payfee.go +++ b/webapi/payfee.go @@ -276,7 +276,7 @@ findAddress: // Send success response to client. resp, respSig := sendJSONResponse(payFeeResponse{ Timestamp: time.Now().Unix(), - Request: request, + Request: reqBytes, }, c) // Store a record of the vote choice change. diff --git a/webapi/setvotechoices.go b/webapi/setvotechoices.go index ef2a912..9b057df 100644 --- a/webapi/setvotechoices.go +++ b/webapi/setvotechoices.go @@ -134,7 +134,7 @@ func setVoteChoices(c *gin.Context) { // Send success response to client. resp, respSig := sendJSONResponse(setVoteChoicesResponse{ Timestamp: time.Now().Unix(), - Request: request, + Request: reqBytes, }, c) // Store a record of the vote choice change. diff --git a/webapi/ticketstatus.go b/webapi/ticketstatus.go index 3f61504..7840a2c 100644 --- a/webapi/ticketstatus.go +++ b/webapi/ticketstatus.go @@ -36,7 +36,7 @@ func ticketStatus(c *gin.Context) { sendJSONResponse(ticketStatusResponse{ Timestamp: time.Now().Unix(), - Request: request, + Request: reqBytes, TicketConfirmed: ticket.Confirmed, FeeTxStatus: string(ticket.FeeTxStatus), FeeTxHash: ticket.FeeTxHash, diff --git a/webapi/types.go b/webapi/types.go index 034e538..b48b3f7 100644 --- a/webapi/types.go +++ b/webapi/types.go @@ -25,11 +25,11 @@ type feeAddressRequest struct { } type feeAddressResponse struct { - Timestamp int64 `json:"timestamp"` - FeeAddress string `json:"feeaddress"` - FeeAmount int64 `json:"feeamount"` - Expiration int64 `json:"expiration"` - Request feeAddressRequest `json:"request"` + Timestamp int64 `json:"timestamp"` + FeeAddress string `json:"feeaddress"` + FeeAmount int64 `json:"feeamount"` + Expiration int64 `json:"expiration"` + Request []byte `json:"request"` } type payFeeRequest struct { @@ -41,8 +41,8 @@ type payFeeRequest struct { } type payFeeResponse struct { - Timestamp int64 `json:"timestamp"` - Request payFeeRequest `json:"request"` + Timestamp int64 `json:"timestamp"` + Request []byte `json:"request"` } type setVoteChoicesRequest struct { @@ -52,8 +52,8 @@ type setVoteChoicesRequest struct { } type setVoteChoicesResponse struct { - Timestamp int64 `json:"timestamp"` - Request setVoteChoicesRequest `json:"request"` + Timestamp int64 `json:"timestamp"` + Request []byte `json:"request"` } type ticketStatusRequest struct { @@ -61,10 +61,10 @@ type ticketStatusRequest struct { } type ticketStatusResponse struct { - Timestamp int64 `json:"timestamp"` - TicketConfirmed bool `json:"ticketconfirmed"` - FeeTxStatus string `json:"feetxstatus"` - FeeTxHash string `json:"feetxhash"` - VoteChoices map[string]string `json:"votechoices"` - Request ticketStatusRequest `json:"request"` + Timestamp int64 `json:"timestamp"` + TicketConfirmed bool `json:"ticketconfirmed"` + FeeTxStatus string `json:"feetxstatus"` + FeeTxHash string `json:"feetxhash"` + VoteChoices map[string]string `json:"votechoices"` + Request []byte `json:"request"` }