Browse Source

Merge pull request #518 from hermeznetwork/fix/api-recommended-fee

Fix api resopnse format for recommended fee
feature/sql-semaphore1
Alberto Elias 3 years ago
committed by GitHub
parent
commit
cea3af4291
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions
  1. +15
    -0
      api/handlers.go
  2. +5
    -0
      api/swagger.yml
  3. +3
    -3
      common/fee.go

+ 15
- 0
api/handlers.go

@ -7,7 +7,9 @@ import (
"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 @@ const (
// 2^64 /2 -1
maxInt64 = 9223372036854775807
// Error for duplicated key
errDuplicatedKey = "Item already exists"
)
var (
@ -33,6 +38,15 @@ var (
)
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 retSQLErr(err error, c *gin.Context) {
}
func retBadReq(err error, c *gin.Context) {
log.Warn("HTTP API Bad request error", "err", err)
c.JSON(http.StatusBadRequest, errorMsg{
Message: err.Error(),
})

+ 5
- 0
api/swagger.yml

@ -2193,6 +2193,11 @@ components:
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.

+ 3
- 3
common/fee.go

@ -22,9 +22,9 @@ var FeeFactorLsh60 [256]*big.Int
// 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.

Loading…
Cancel
Save