diff --git a/methods.go b/methods.go index 15dec60..74dbb44 100644 --- a/methods.go +++ b/methods.go @@ -5,7 +5,6 @@ import ( "context" "crypto/ed25519" "encoding/base64" - "encoding/binary" "encoding/hex" "encoding/json" "errors" @@ -60,8 +59,17 @@ func feeAddress(c *gin.Context) { // signature - signmessage signature using the ticket commitment address // - message = "vsp v3 getfeeaddress ticketHash" + dec := json.NewDecoder(c.Request.Body) + + var feeAddressRequest FeeAddressRequest + err := dec.Decode(&feeAddressRequest) + if err != nil { + c.AbortWithError(http.StatusBadRequest, errors.New("invalid json")) + return + } + // ticketHash - ticketHashStr := c.Param("ticketHash") + ticketHashStr := feeAddressRequest.TicketHash if len(ticketHashStr) != chainhash.MaxHashStringSize { c.AbortWithError(http.StatusBadRequest, errors.New("invalid ticket hash")) return @@ -73,7 +81,7 @@ func feeAddress(c *gin.Context) { } // signature - sanity check signature is in base64 encoding - signature := c.Param("signature") + signature := feeAddressRequest.Signature if _, err = base64.StdEncoding.DecodeString(signature); err != nil { c.AbortWithError(http.StatusBadRequest, errors.New("invalid signature")) return @@ -174,31 +182,25 @@ func payFee(c *gin.Context) { // votingKey - WIF private key for ticket stakesubmission address // voteBits - voting preferences in little endian - votingKey := c.Param("votingKey") + dec := json.NewDecoder(c.Request.Body) + + var payFeeRequest PayFeeRequest + err := dec.Decode(&payFeeRequest) + if err != nil { + c.AbortWithError(http.StatusBadRequest, errors.New("invalid json")) + return + } + + votingKey := payFeeRequest.VotingKey votingWIF, err := dcrutil.DecodeWIF(votingKey, cfg.netParams.PrivateKeyID) if err != nil { c.AbortWithError(http.StatusInternalServerError, err) return } - - feeTxStr := c.Param("feeTx") - feeTxBytes, err := hex.DecodeString(feeTxStr) - if err != nil { - c.AbortWithError(http.StatusInternalServerError, errors.New("invalid transaction")) - return - } - - voteBitsStr := c.Param("voteBits") - voteBitsBytes, err := hex.DecodeString(voteBitsStr) - if err != nil || len(voteBitsBytes) != 2 { - c.AbortWithError(http.StatusInternalServerError, errors.New("invalid votebits")) - return - } - - voteBits := binary.LittleEndian.Uint16(voteBitsBytes) + voteBits := payFeeRequest.VoteBits feeTx := wire.NewMsgTx() - err = feeTx.FromBytes(feeTxBytes) + err = feeTx.FromBytes(payFeeRequest.Hex) if err != nil { c.AbortWithError(http.StatusInternalServerError, errors.New("unable to deserialize transaction")) return diff --git a/responses.go b/responses.go index 2357fb2..4e7804f 100644 --- a/responses.go +++ b/responses.go @@ -10,6 +10,11 @@ type feeResponse struct { Fee float64 `json:"fee"` } +type FeeAddressRequest struct { + TicketHash string `json:"ticketHash"` + Signature string `json:"signature"` +} + type feeAddressResponse struct { Timestamp int64 `json:"timestamp"` TicketHash string `json:"ticketHash"` @@ -17,6 +22,12 @@ type feeAddressResponse struct { FeeAddress string `json:"feeAddress"` } +type PayFeeRequest struct { + Hex []byte `json:"feeTx"` + VotingKey string `json:"votingKey"` + VoteBits uint16 `json:"voteBits"` +} + type payFeeResponse struct { Timestamp int64 `json:"timestamp"` TxHash string `json:"txHash"` diff --git a/router.go b/router.go index b1b6236..e335759 100644 --- a/router.go +++ b/router.go @@ -12,9 +12,9 @@ func newRouter() *gin.Engine { api.Use() { router.GET("/fee", fee) - router.GET("/feeaddress", feeAddress) + router.POST("/feeaddress", feeAddress) router.GET("/pubkey", pubKey) - router.GET("/payfee", payFee) + router.POST("/payfee", payFee) } return router