Skip to content

Commit

Permalink
Fix: return 404 on unknown network on invalid address (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Apr 9, 2021
1 parent 434f12b commit 4928852
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 26 deletions.
9 changes: 6 additions & 3 deletions cmd/api/handlers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
// @Produce json
// @Success 200 {object} AccountInfo
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/account/{network}/{address} [get]
func (ctx *Context) GetInfo(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down Expand Up @@ -135,11 +136,12 @@ func (ctx *Context) GetBatchTokenBalances(c *gin.Context) {
// @Produce json
// @Success 200 {object} TokenBalances
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/account/{network}/{address}/token_balances [get]
func (ctx *Context) GetAccountTokenBalances(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var queryParams tokenBalanceRequest
Expand Down Expand Up @@ -230,11 +232,12 @@ func (ctx *Context) getAccountBalances(network, address string, req tokenBalance
// @Produce json
// @Success 200 {object} map[string]int64
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/account/{network}/{address}/count [get]
func (ctx *Context) GetAccountTokenBalancesGroupedCount(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
res, err := ctx.TokenBalances.CountByContract(req.Network, req.Address)
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/handlers/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
// @Success 200 {object} Contract
// @Success 204 {object} gin.H
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address} [get]
func (ctx *Context) GetContract(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down
9 changes: 6 additions & 3 deletions cmd/api/handlers/entrypoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
// @Produce json
// @Success 200 {array} EntrypointSchema
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/entrypoints [get]
func (ctx *Context) GetEntrypoints(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
script, err := ctx.getScript(req.Address, req.Network, "")
Expand Down Expand Up @@ -71,11 +72,12 @@ func (ctx *Context) GetEntrypoints(c *gin.Context) {
// @Produce json
// @Success 200 {object} gin.H
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/entrypoints/data [post]
func (ctx *Context) GetEntrypointData(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var reqData getEntrypointDataRequest
Expand Down Expand Up @@ -113,11 +115,12 @@ func (ctx *Context) GetEntrypointData(c *gin.Context) {
// @Produce json
// @Success 200 {object} EntrypointSchema
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/entrypoints/schema [get]
func (ctx *Context) GetEntrypointSchema(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/api/handlers/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import (
// @Produce json
// @Success 200 {array} Operation
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/mempool [get]
func (ctx *Context) GetMempool(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/api/handlers/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
// @Produce json
// @Success 200 {array} Migration
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/migrations [get]
func (ctx *Context) GetContractMigrations(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/api/handlers/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ import (
// @Produce json
// @Success 200 {object} OperationResponse
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/operations [get]
func (ctx *Context) GetContractOperations(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/api/handlers/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
// @Produce json
// @Success 200 {object} SameContractsResponse
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/same [get]
func (ctx *Context) GetSameContracts(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down Expand Up @@ -67,11 +68,12 @@ func (ctx *Context) GetSameContracts(c *gin.Context) {
// @Produce json
// @Success 200 {object} SimilarContractsResponse
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/similar [get]
func (ctx *Context) GetSimilarContracts(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/api/handlers/run_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// RunOperation -
func (ctx *Context) RunOperation(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var reqRunOp runOperationRequest
Expand Down Expand Up @@ -135,11 +135,12 @@ func (ctx *Context) RunOperation(c *gin.Context) {
// @Produce json
// @Success 200 {array} Operation
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/entrypoints/trace [post]
func (ctx *Context) RunCode(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var reqRunCode runCodeRequest
Expand Down
12 changes: 8 additions & 4 deletions cmd/api/handlers/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
// @Produce json
// @Success 200 {array} ast.MiguelNode
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/storage [get]
func (ctx *Context) GetContractStorage(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down Expand Up @@ -86,11 +87,12 @@ func (ctx *Context) GetContractStorage(c *gin.Context) {
// @Success 200 {string} string
// @Success 204 {string} string
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/storage/raw [get]
func (ctx *Context) GetContractStorageRaw(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var sReq storageRequest
Expand Down Expand Up @@ -135,11 +137,12 @@ func (ctx *Context) GetContractStorageRaw(c *gin.Context) {
// @Success 200 {object} gin.H
// @Success 204 {object} gin.H
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/storage/rich [get]
func (ctx *Context) GetContractStorageRich(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var sReq storageRequest
Expand Down Expand Up @@ -192,11 +195,12 @@ func (ctx *Context) GetContractStorageRich(c *gin.Context) {
// @Produce json
// @Success 200 {object} EntrypointSchema
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/storage/schema [get]
func (ctx *Context) GetContractStorageSchema(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var ssReq storageSchemaRequest
Expand Down
12 changes: 8 additions & 4 deletions cmd/api/handlers/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ func (ctx *Context) GetFAByVersion(c *gin.Context) {
// @Produce json
// @Success 200 {object} TransferResponse
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/tokens/{network}/transfers/{address} [get]
func (ctx *Context) GetFA12OperationsForAddress(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down Expand Up @@ -282,11 +283,12 @@ func (ctx *Context) contractToTokens(contracts []contract.Contract, network, ver
// @Produce json
// @Success 200 {array} TokenMetadata
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/tokens [get]
func (ctx *Context) GetContractTokens(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var pageReq tokenRequest
Expand Down Expand Up @@ -328,11 +330,12 @@ func (ctx *Context) GetContractTokens(c *gin.Context) {
// @Produce json
// @Success 200 {object} CountResponse
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/tokens/count [get]
func (ctx *Context) GetContractTokensCount(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
count, err := ctx.TokenMetadata.Count([]tokenmetadata.GetContext{{
Expand Down Expand Up @@ -387,11 +390,12 @@ func (ctx *Context) getTokensWithSupply(getCtx tokenmetadata.GetContext, size, o
// @Produce json
// @Success 200 {array} gin.H
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/tokens/holders [get]
func (ctx *Context) GetTokenHolders(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var reqArgs byTokenIDRequest
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/handlers/transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
// @Produce json
// @Success 200 {object} TransferResponse
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/{network}/{address}/transfers [get]
func (ctx *Context) GetContractTransfers(c *gin.Context) {
var contractRequest getContractRequest
if err := c.BindUri(&contractRequest); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&contractRequest); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var req getContractTransfers
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/handlers/tzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
// @Success 200 {object} TZIPResponse
// @Success 204 {object} gin.H
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/account/{network}/{address}/metadata [get]
func (ctx *Context) GetMetadata(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
tzip, err := ctx.TZIP.Get(req.Network, req.Address)
Expand Down
6 changes: 4 additions & 2 deletions cmd/api/handlers/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ var (
// @Produce json
// @Success 200 {array} ViewSchema
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/views/schema [get]
func (ctx *Context) GetViewsSchema(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}

Expand Down Expand Up @@ -97,11 +98,12 @@ func (ctx *Context) GetViewsSchema(c *gin.Context) {
// @Produce json
// @Success 200 {array} ast.MiguelNode
// @Failure 400 {object} Error
// @Failure 404 {object} Error
// @Failure 500 {object} Error
// @Router /v1/contract/{network}/{address}/views/execute [post]
func (ctx *Context) ExecuteView(c *gin.Context) {
var req getContractRequest
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusBadRequest) {
if err := c.BindUri(&req); ctx.handleError(c, err, http.StatusNotFound) {
return
}
var execView executeViewRequest
Expand Down

0 comments on commit 4928852

Please sign in to comment.