arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Fix api resopnse format for recommended fee
Arnau B arnaubennassar5@gmail.com
Mon, 01 Feb 2021 12:23:20 +0100
commit

dd1657847e69ce12770491f4d894146acc398a3f

parent

8cc23b9fb243028fbc7216facc8e2be92c87dadb

3 files changed, 23 insertions(+), 3 deletions(-)

jump to
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.