cleanup payfee (#35)
This commit is contained in:
parent
80e7983d4e
commit
f50b0aba56
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@ -63,7 +64,7 @@ func feeAddress(c *gin.Context) {
|
|||||||
|
|
||||||
var feeAddressRequest FeeAddressRequest
|
var feeAddressRequest FeeAddressRequest
|
||||||
if err := c.ShouldBindJSON(&feeAddressRequest); err != nil {
|
if err := c.ShouldBindJSON(&feeAddressRequest); err != nil {
|
||||||
log.Warnf("Bad request from %s", c.ClientIP())
|
log.Warnf("Bad feeaddress request from %s: %v", c.ClientIP(), err)
|
||||||
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -133,7 +134,7 @@ func feeAddress(c *gin.Context) {
|
|||||||
var resp dcrdtypes.TxRawResult
|
var resp dcrdtypes.TxRawResult
|
||||||
err = walletClient.Call(ctx, "getrawtransaction", &resp, txHash.String(), 1)
|
err = walletClient.Call(ctx, "getrawtransaction", &resp, txHash.String(), 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("Could not retrieve tx for %s", c.ClientIP())
|
log.Warnf("Could not retrieve tx %s for %s: %v", txHash, c.ClientIP(), err)
|
||||||
sendErrorResponse("unknown transaction", http.StatusBadRequest, c)
|
sendErrorResponse("unknown transaction", http.StatusBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -243,7 +244,7 @@ func feeAddress(c *gin.Context) {
|
|||||||
func payFee(c *gin.Context) {
|
func payFee(c *gin.Context) {
|
||||||
var payFeeRequest PayFeeRequest
|
var payFeeRequest PayFeeRequest
|
||||||
if err := c.ShouldBindJSON(&payFeeRequest); err != nil {
|
if err := c.ShouldBindJSON(&payFeeRequest); err != nil {
|
||||||
log.Warnf("Bad request from %s", c.ClientIP())
|
log.Warnf("Bad payfee request from %s: %v", c.ClientIP(), err)
|
||||||
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -251,18 +252,25 @@ func payFee(c *gin.Context) {
|
|||||||
votingKey := payFeeRequest.VotingKey
|
votingKey := payFeeRequest.VotingKey
|
||||||
votingWIF, err := dcrutil.DecodeWIF(votingKey, cfg.NetParams.PrivateKeyID)
|
votingWIF, err := dcrutil.DecodeWIF(votingKey, cfg.NetParams.PrivateKeyID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to decode WIF: %v", err)
|
log.Warnf("Failed to decode WIF: %v", err)
|
||||||
sendErrorResponse("error decoding WIF", http.StatusInternalServerError, c)
|
sendErrorResponse("error decoding WIF", http.StatusBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
voteBits := payFeeRequest.VoteBits
|
voteBits := payFeeRequest.VoteBits
|
||||||
|
|
||||||
feeTx := wire.NewMsgTx()
|
feeTxBytes, err := hex.DecodeString(payFeeRequest.Hex)
|
||||||
err = feeTx.FromBytes(payFeeRequest.Hex)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to deserialize tx: %v", err)
|
log.Warnf("Failed to decode tx: %v", err)
|
||||||
sendErrorResponse("unable to deserialize transaction", http.StatusInternalServerError, c)
|
sendErrorResponse("failed to decode transaction", http.StatusBadRequest, c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
feeTx := wire.NewMsgTx()
|
||||||
|
err = feeTx.FromBytes(feeTxBytes)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("Failed to deserialize tx: %v", err)
|
||||||
|
sendErrorResponse("unable to deserialize transaction", http.StatusBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,8 +308,8 @@ findAddress:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if feeAddr == "" {
|
if feeAddr == "" {
|
||||||
log.Errorf("feeTx did not include any payments")
|
log.Warnf("feeTx did not include any payments")
|
||||||
sendErrorResponse("feeTx did not include any payments", http.StatusInternalServerError, c)
|
sendErrorResponse("feeTx did not include any payments", http.StatusBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,16 +370,16 @@ findAddress:
|
|||||||
ctx := c.Request.Context()
|
ctx := c.Request.Context()
|
||||||
var resp dcrdtypes.TxRawResult
|
var resp dcrdtypes.TxRawResult
|
||||||
|
|
||||||
err = walletClient.Call(ctx, "getrawtransaction", &resp, ticketHash.String(), true)
|
err = walletClient.Call(ctx, "getrawtransaction", &resp, ticketHash.String(), 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("GetRawTransaction failed: %v", err)
|
log.Errorf("GetRawTransaction failed: %v", err)
|
||||||
sendErrorResponse("dcrwallet RPC error", http.StatusInternalServerError, c)
|
sendErrorResponse("dcrwallet RPC error", http.StatusInternalServerError, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = walletClient.Call(ctx, "addticket", nil, resp.Hex)
|
err = walletClient.Call(ctx, "addtransaction", nil, resp.BlockHash, resp.Hex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("AddTicket failed: %v", err)
|
log.Errorf("AddTransaction failed: %v", err)
|
||||||
sendErrorResponse("dcrwallet RPC error", http.StatusInternalServerError, c)
|
sendErrorResponse("dcrwallet RPC error", http.StatusInternalServerError, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -393,7 +401,7 @@ findAddress:
|
|||||||
}
|
}
|
||||||
|
|
||||||
var res string
|
var res string
|
||||||
err = walletClient.Call(ctx, "sendrawtransaction", &res, hex.NewEncoder(feeTxBuf), false)
|
err = walletClient.Call(ctx, "sendrawtransaction", &res, hex.EncodeToString(feeTxBuf.Bytes()), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("SendRawTransaction failed: %v", err)
|
log.Errorf("SendRawTransaction failed: %v", err)
|
||||||
sendErrorResponse("dcrwallet RPC error", http.StatusInternalServerError, c)
|
sendErrorResponse("dcrwallet RPC error", http.StatusInternalServerError, c)
|
||||||
@ -417,7 +425,7 @@ findAddress:
|
|||||||
func setVoteBits(c *gin.Context) {
|
func setVoteBits(c *gin.Context) {
|
||||||
var setVoteBitsRequest SetVoteBitsRequest
|
var setVoteBitsRequest SetVoteBitsRequest
|
||||||
if err := c.ShouldBindJSON(&setVoteBitsRequest); err != nil {
|
if err := c.ShouldBindJSON(&setVoteBitsRequest); err != nil {
|
||||||
log.Warnf("Bad request from %s", c.ClientIP())
|
log.Warnf("Bad setvotebits request from %s: %v", c.ClientIP(), err)
|
||||||
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -483,7 +491,7 @@ func setVoteBits(c *gin.Context) {
|
|||||||
func ticketStatus(c *gin.Context) {
|
func ticketStatus(c *gin.Context) {
|
||||||
var ticketStatusRequest TicketStatusRequest
|
var ticketStatusRequest TicketStatusRequest
|
||||||
if err := c.ShouldBindJSON(&ticketStatusRequest); err != nil {
|
if err := c.ShouldBindJSON(&ticketStatusRequest); err != nil {
|
||||||
log.Warnf("Bad request from %s", c.ClientIP())
|
log.Warnf("Bad ticketstatus request from %s: %v", c.ClientIP(), err)
|
||||||
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
sendErrorResponse(err.Error(), http.StatusBadRequest, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ type feeAddressResponse struct {
|
|||||||
|
|
||||||
type PayFeeRequest struct {
|
type PayFeeRequest struct {
|
||||||
Timestamp int64 `json:"timestamp" binding:"required"`
|
Timestamp int64 `json:"timestamp" binding:"required"`
|
||||||
Hex []byte `json:"feeTx" binding:"required"`
|
Hex string `json:"feeTx" binding:"required"`
|
||||||
VotingKey string `json:"votingKey" binding:"required"`
|
VotingKey string `json:"votingKey" binding:"required"`
|
||||||
VoteBits uint16 `json:"voteBits" binding:"required"`
|
VoteBits uint16 `json:"voteBits" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user