Skip to content

Commit

Permalink
Refactoring: remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Sep 26, 2023
1 parent db123b1 commit 6cdd7eb
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 466 deletions.
95 changes: 4 additions & 91 deletions cmd/api/handlers/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,63 +26,6 @@ import (
"github.com/tidwall/gjson"
)

// GetContractOperations godoc
// @Summary Get contract operations
// @Description Get contract operations
// @Tags contract
// @ID get-contract-operations
// @Param network path string true "Network"
// @Param address path string true "KT address" minlength(36) maxlength(36)
// @Param last_id query string false "Last operation ID"
// @Param from query integer false "Timestamp"
// @Param to query integer false "Timestamp"
// @Param size query integer false "Expected OPG count" mininum(1)
// @Param status query string false "Comma-separated operations statuses"
// @Param entrypoints query string false "Comma-separated called entrypoints list"
// @Param with_storage_diff query bool false "Include storage diff to operations or not"
// @Accept json
// @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 GetContractOperations() gin.HandlerFunc {
return func(c *gin.Context) {
ctx := c.MustGet("context").(*config.Context)

var req getAccountRequest
if err := c.BindUri(&req); handleError(c, ctx.Storage, err, http.StatusNotFound) {
return
}

var filtersReq operationsRequest
if err := c.BindQuery(&filtersReq); handleError(c, ctx.Storage, err, http.StatusBadRequest) {
return
}

account, err := ctx.Accounts.Get(c.Request.Context(), req.Address)
if handleError(c, ctx.Storage, err, http.StatusNotFound) {
return
}

filters := prepareFilters(filtersReq)
ops, err := ctx.Operations.GetByAccount(c.Request.Context(), account, filtersReq.Size, filters)
if handleError(c, ctx.Storage, err, 0) {
return
}

resp, err := PrepareOperations(c.Request.Context(), ctx, ops.Operations, filtersReq.WithStorageDiff)
if handleError(c, ctx.Storage, err, 0) {
return
}
c.SecureJSON(http.StatusOK, OperationResponse{
Operations: resp,
LastID: ops.LastID,
})
}
}

// GetOperation godoc
// @Summary Get operation group
// @Description Get operation group by hash
Expand Down Expand Up @@ -207,12 +150,12 @@ func GetImplicitOperation() gin.HandlerFunc {
return
}

op, err := ctx.Operations.GetImplicitOperation(c.Request.Context(), req.Counter)
operations, err := ctx.Operations.GetByHashAndCounter(c.Request.Context(), nil, req.Counter)
if handleError(c, ctx.Storage, err, 0) {
return
}

resp, err := PrepareOperations(c.Request.Context(), ctx, []operation.Operation{op}, false)
resp, err := PrepareOperations(c.Request.Context(), ctx, operations, false)
if handleError(c, ctx.Storage, err, 0) {
return
}
Expand Down Expand Up @@ -402,8 +345,8 @@ func GetByHashAndCounter() gin.HandlerFunc {
var opg []operation.Operation
var foundContext *config.Context

ctx, err := ctxs.Get(modelTypes.NewNetwork(args.Network))
if err == nil {
network := modelTypes.NewNetwork(args.Network)
if ctx, ok := ctxs[network]; ok {
opg, err = ctx.Operations.GetByHashAndCounter(c.Request.Context(), hash, req.Counter)
if handleError(c, ctx.Storage, err, 0) {
return
Expand Down Expand Up @@ -447,36 +390,6 @@ func getOperationFromMempool(c context.Context, ctx *config.Context, hash string
}
}

func prepareFilters(req operationsRequest) map[string]interface{} {
filters := map[string]interface{}{}

if req.LastID != "" {
filters["last_id"] = req.LastID
}

if req.From > 0 {
filters["from"] = req.From / 1000
}

if req.To > 0 {
filters["to"] = req.To / 1000
}

if req.Status != "" {
statusList := make([]modelTypes.OperationStatus, 0)
for _, item := range strings.Split(req.Status, ",") {
status := modelTypes.NewOperationStatus(item)
statusList = append(statusList, status)
}
filters["status"] = statusList
}

if req.Entrypoints != "" {
filters["entrypoints"] = strings.Split(req.Entrypoints, ",")
}
return filters
}

func formatErrors(errs []*tezerrors.Error, op *Operation) error {
for i := range errs {
if err := errs[i].Format(); err != nil {
Expand Down
10 changes: 0 additions & 10 deletions cmd/api/handlers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ type OauthParams struct {
Provider string `uri:"provider"`
}

type operationsRequest struct {
LastID string `form:"last_id" binding:"omitempty,numeric"`
From uint `form:"from" binding:"omitempty"`
To uint `form:"to" binding:"omitempty,gtfield=From"`
Size uint64 `form:"size" binding:"min=0"`
Status string `form:"status" binding:"omitempty,status"`
Entrypoints string `form:"entrypoints" binding:"omitempty,excludesall=\"'"`
WithStorageDiff bool `form:"with_storage_diff"`
}

type opgForAddressRequest struct {
LastID int64 `form:"last_id" binding:"omitempty"`
Size uint64 `form:"size" binding:"min=0"`
Expand Down
1 change: 0 additions & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ func (api *app) makeRouter() {
{
contract.GET("", handlers.ContextsMiddleware(api.Contexts), handlers.GetContract())
contract.GET("code", handlers.GetContractCode())
contract.GET("operations", handlers.GetContractOperations())
contract.GET("opg", handlers.GetOperationGroups())
contract.GET("migrations", handlers.GetContractMigrations())
contract.GET("global_constants", handlers.GetContractGlobalConstants())
Expand Down
118 changes: 0 additions & 118 deletions internal/models/mock/operation/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions internal/models/operation/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ package operation

import (
"context"

"github.com/baking-bad/bcdhub/internal/models/account"
)

//go:generate mockgen -source=$GOFILE -destination=../mock/operation/mock.go -package=operation -typed
type Repository interface {
GetByAccount(ctx context.Context, acc account.Account, size uint64, filters map[string]interface{}) (Pageable, error)
// Last - get last operation by `filters` with not empty deffated_storage.
Last(ctx context.Context, filter map[string]interface{}, lastID int64) (Operation, error)
GetByHash(ctx context.Context, hash []byte) ([]Operation, error)
GetByHashAndCounter(ctx context.Context, hash []byte, counter int64) ([]Operation, error)
GetImplicitOperation(ctx context.Context, counter int64) (Operation, error)
OPG(ctx context.Context, address string, size, lastID int64) ([]OPG, error)
Origination(ctx context.Context, accountID int64) (Operation, error)

// GetOperations - get operation by `filter`. `Size` - if 0 - return all, else certain `size` operations.
// `Sort` - sort by time and content index by desc
Get(ctx context.Context, filter map[string]interface{}, size int64, sort bool) ([]Operation, error)
GetByID(ctx context.Context, id int64) (Operation, error)

ListEvents(ctx context.Context, accountID int64, size, offset int64) ([]Operation, error)
EventsCount(ctx context.Context, accountID int64) (int, error)
}
15 changes: 0 additions & 15 deletions internal/parsers/stacktrace/stacktrace.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package stacktrace

import (
"context"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -173,17 +172,3 @@ func (st *StackTrace) print(arr []int64, depth int, builder io.StringWriter) err
}
return nil
}

// Fill -
func (st *StackTrace) Fill(ctx context.Context, repo operation.Repository, op operation.Operation) error {
ops, err := repo.Get(ctx, map[string]interface{}{
"hash": op.Hash,
}, 0, true)
if err != nil {
return err
}
for i := range ops {
st.Add(ops[i])
}
return nil
}
Loading

0 comments on commit 6cdd7eb

Please sign in to comment.