Merge pull request #518 from hermeznetwork/fix/api-recommended-fee Fix api resopnse format for recommended fee
Alberto Elias hi@albertoelias.me
Mon, 01 Feb 2021 15:04:15 +0000
3 files changed,
23 insertions(+),
3 deletions(-)
M
api/handlers.go
→
api/handlers.go
@@ -7,7 +7,9 @@ "net/http"
"github.com/gin-gonic/gin" "github.com/hermeznetwork/hermez-node/db/historydb" + "github.com/hermeznetwork/hermez-node/log" "github.com/hermeznetwork/tracerr" + "github.com/lib/pq" ) const (@@ -25,6 +27,9 @@ maxUint32 = 4294967295
// 2^64 /2 -1 maxInt64 = 9223372036854775807 + + // Error for duplicated key + errDuplicatedKey = "Item already exists" ) var (@@ -33,6 +38,15 @@ ErrNillBidderAddr = errors.New("biderAddr can not be nil")
) func retSQLErr(err error, c *gin.Context) { + log.Warn("HTTP API SQL request error", "err", err) + if sqlErr, ok := tracerr.Unwrap(err).(*pq.Error); ok { + // https://www.postgresql.org/docs/current/errcodes-appendix.html + if sqlErr.Code == "23505" { + c.JSON(http.StatusInternalServerError, errorMsg{ + Message: errDuplicatedKey, + }) + } + } if tracerr.Unwrap(err) == sql.ErrNoRows { c.JSON(http.StatusNotFound, errorMsg{ Message: err.Error(),@@ -45,6 +59,7 @@ }
} func retBadReq(err error, c *gin.Context) { + log.Warn("HTTP API Bad request error", "err", err) c.JSON(http.StatusBadRequest, errorMsg{ Message: err.Error(), })
M
api/swagger.yml
→
api/swagger.yml
@@ -2193,6 +2193,11 @@ type: number
description: Recommended fee if the destination account of the transaction doesn't exist, but the coordinator has the ability to create a valid account associated to a BJJ public key controlled by the receiver. Note that these kind of accounts are not associated with an Ethereum address and therefore can only operate in L2. minimum: 0 example: 0.5 + required: + - existingAccount + - createAccount + - createAccountInternal + additionalProperties: false Token: type: object description: Hermez Network compatible and registered token.
M
common/fee.go
→
common/fee.go
@@ -22,9 +22,9 @@ // RecommendedFee is the recommended fee to pay in USD per transaction set by
// the coordinator according to the tx type (if the tx requires to create an // account and register, only register or he account already esists) type RecommendedFee struct { - ExistingAccount float64 - CreatesAccount float64 - CreatesAccountAndRegister float64 + ExistingAccount float64 `json:"existingAccount"` + CreatesAccount float64 `json:"createAccount"` + CreatesAccountAndRegister float64 `json:"createAccountInternal"` } // FeeSelector is used to select a percentage from the FeePlan.