From 3b256f34cb51620dbab8ed3001e57c55feac34f1 Mon Sep 17 00:00:00 2001 From: Zakhar Petukhov Date: Mon, 20 Jan 2025 20:56:41 +0800 Subject: [PATCH] remove useless method --- api/openapi.json | 32 ----- api/openapi.yml | 18 --- pkg/api/extra_currency_handlers.go | 4 - pkg/oas/oas_handlers_gen.go | 121 ------------------- pkg/oas/oas_json_gen.go | 106 ---------------- pkg/oas/oas_parameters_gen.go | 173 --------------------------- pkg/oas/oas_response_encoders_gen.go | 14 --- pkg/oas/oas_router_gen.go | 146 ++++++---------------- pkg/oas/oas_schemas_gen.go | 15 --- pkg/oas/oas_server_gen.go | 6 - pkg/oas/oas_unimplemented_gen.go | 9 -- pkg/oas/oas_validators_gen.go | 23 ---- 12 files changed, 35 insertions(+), 632 deletions(-) diff --git a/api/openapi.json b/api/openapi.json index b84beca8..55017165 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -8545,38 +8545,6 @@ ] } }, - "/v2/extra-currencies": { - "get": { - "description": "Get a list of all extra currencies in the blockchain.", - "operationId": "getExtraCurrencies", - "parameters": [ - { - "$ref": "#/components/parameters/limitQuery" - }, - { - "$ref": "#/components/parameters/offsetQuery" - } - ], - "responses": { - "200": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ExtraCurrencies" - } - } - }, - "description": "a list of extra currencies" - }, - "default": { - "$ref": "#/components/responses/Error" - } - }, - "tags": [ - "ExtraCurrency" - ] - } - }, "/v2/extra-currency/{id}": { "get": { "description": "Get extra currency info by id", diff --git a/api/openapi.yml b/api/openapi.yml index 38ddd66b..264dd425 100644 --- a/api/openapi.yml +++ b/api/openapi.yml @@ -1742,24 +1742,6 @@ paths: $ref: '#/components/schemas/EcPreview' 'default': $ref: '#/components/responses/Error' - /v2/extra-currencies: - get: - description: Get a list of all extra currencies in the blockchain. - operationId: getExtraCurrencies - tags: - - ExtraCurrency - parameters: - - $ref: '#/components/parameters/limitQuery' - - $ref: '#/components/parameters/offsetQuery' - responses: - '200': - description: a list of extra currencies - content: - application/json: - schema: - $ref: '#/components/schemas/ExtraCurrencies' - 'default': - $ref: '#/components/responses/Error' /v2/staking/nominator/{account_id}/pools: get: diff --git a/pkg/api/extra_currency_handlers.go b/pkg/api/extra_currency_handlers.go index 8fcf6eb5..9353a817 100644 --- a/pkg/api/extra_currency_handlers.go +++ b/pkg/api/extra_currency_handlers.go @@ -9,7 +9,3 @@ import ( func (h *Handler) GetExtraCurrencyInfo(ctx context.Context, params oas.GetExtraCurrencyInfoParams) (*oas.EcPreview, error) { return &oas.EcPreview{}, nil } - -func (h *Handler) GetExtraCurrencies(ctx context.Context, params oas.GetExtraCurrenciesParams) (*oas.ExtraCurrencies, error) { - return &oas.ExtraCurrencies{ExtraCurrencies: []oas.EcPreview{}}, nil -} diff --git a/pkg/oas/oas_handlers_gen.go b/pkg/oas/oas_handlers_gen.go index 3a5da6ec..5496811a 100644 --- a/pkg/oas/oas_handlers_gen.go +++ b/pkg/oas/oas_handlers_gen.go @@ -6765,127 +6765,6 @@ func (s *Server) handleGetEventRequest(args [1]string, argsEscaped bool, w http. } } -// handleGetExtraCurrenciesRequest handles getExtraCurrencies operation. -// -// Get a list of all extra currencies in the blockchain. -// -// GET /v2/extra-currencies -func (s *Server) handleGetExtraCurrenciesRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { - otelAttrs := []attribute.KeyValue{ - otelogen.OperationID("getExtraCurrencies"), - semconv.HTTPMethodKey.String("GET"), - semconv.HTTPRouteKey.String("/v2/extra-currencies"), - } - - // Start a span for this request. - ctx, span := s.cfg.Tracer.Start(r.Context(), "GetExtraCurrencies", - trace.WithAttributes(otelAttrs...), - serverSpanKind, - ) - defer span.End() - - // Run stopwatch. - startTime := time.Now() - defer func() { - elapsedDuration := time.Since(startTime) - // Use floating point division here for higher precision (instead of Millisecond method). - s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) - }() - - // Increment request counter. - s.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) - - var ( - recordError = func(stage string, err error) { - span.RecordError(err) - span.SetStatus(codes.Error, stage) - s.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) - } - err error - opErrContext = ogenerrors.OperationContext{ - Name: "GetExtraCurrencies", - ID: "getExtraCurrencies", - } - ) - params, err := decodeGetExtraCurrenciesParams(args, argsEscaped, r) - if err != nil { - err = &ogenerrors.DecodeParamsError{ - OperationContext: opErrContext, - Err: err, - } - recordError("DecodeParams", err) - s.cfg.ErrorHandler(ctx, w, r, err) - return - } - - var response *ExtraCurrencies - if m := s.cfg.Middleware; m != nil { - mreq := middleware.Request{ - Context: ctx, - OperationName: "GetExtraCurrencies", - OperationSummary: "", - OperationID: "getExtraCurrencies", - Body: nil, - Params: middleware.Parameters{ - { - Name: "limit", - In: "query", - }: params.Limit, - { - Name: "offset", - In: "query", - }: params.Offset, - }, - Raw: r, - } - - type ( - Request = struct{} - Params = GetExtraCurrenciesParams - Response = *ExtraCurrencies - ) - response, err = middleware.HookMiddleware[ - Request, - Params, - Response, - ]( - m, - mreq, - unpackGetExtraCurrenciesParams, - func(ctx context.Context, request Request, params Params) (response Response, err error) { - response, err = s.h.GetExtraCurrencies(ctx, params) - return response, err - }, - ) - } else { - response, err = s.h.GetExtraCurrencies(ctx, params) - } - if err != nil { - if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { - if err := encodeErrorResponse(errRes, w, span); err != nil { - recordError("Internal", err) - } - return - } - if errors.Is(err, ht.ErrNotImplemented) { - s.cfg.ErrorHandler(ctx, w, r, err) - return - } - if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { - recordError("Internal", err) - } - return - } - - if err := encodeGetExtraCurrenciesResponse(response, w, span); err != nil { - recordError("EncodeResponse", err) - if !errors.Is(err, ht.ErrInternalServerErrorResponse) { - s.cfg.ErrorHandler(ctx, w, r, err) - } - return - } -} - // handleGetExtraCurrencyInfoRequest handles getExtraCurrencyInfo operation. // // Get extra currency info by id. diff --git a/pkg/oas/oas_json_gen.go b/pkg/oas/oas_json_gen.go index 4ba73886..37dd3508 100644 --- a/pkg/oas/oas_json_gen.go +++ b/pkg/oas/oas_json_gen.go @@ -15690,112 +15690,6 @@ func (s *Event) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode implements json.Marshaler. -func (s *ExtraCurrencies) Encode(e *jx.Encoder) { - e.ObjStart() - s.encodeFields(e) - e.ObjEnd() -} - -// encodeFields encodes fields. -func (s *ExtraCurrencies) encodeFields(e *jx.Encoder) { - { - e.FieldStart("extra_currencies") - e.ArrStart() - for _, elem := range s.ExtraCurrencies { - elem.Encode(e) - } - e.ArrEnd() - } -} - -var jsonFieldsNameOfExtraCurrencies = [1]string{ - 0: "extra_currencies", -} - -// Decode decodes ExtraCurrencies from json. -func (s *ExtraCurrencies) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode ExtraCurrencies to nil") - } - var requiredBitSet [1]uint8 - - if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - switch string(k) { - case "extra_currencies": - requiredBitSet[0] |= 1 << 0 - if err := func() error { - s.ExtraCurrencies = make([]EcPreview, 0) - if err := d.Arr(func(d *jx.Decoder) error { - var elem EcPreview - if err := elem.Decode(d); err != nil { - return err - } - s.ExtraCurrencies = append(s.ExtraCurrencies, elem) - return nil - }); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "decode field \"extra_currencies\"") - } - default: - return d.Skip() - } - return nil - }); err != nil { - return errors.Wrap(err, "decode ExtraCurrencies") - } - // Validate required fields. - var failures []validate.FieldError - for i, mask := range [1]uint8{ - 0b00000001, - } { - if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { - // Mask only required fields and check equality to mask using XOR. - // - // If XOR result is not zero, result is not equal to expected, so some fields are missed. - // Bits of fields which would be set are actually bits of missed fields. - missed := bits.OnesCount8(result) - for bitN := 0; bitN < missed; bitN++ { - bitIdx := bits.TrailingZeros8(result) - fieldIdx := i*8 + bitIdx - var name string - if fieldIdx < len(jsonFieldsNameOfExtraCurrencies) { - name = jsonFieldsNameOfExtraCurrencies[fieldIdx] - } else { - name = strconv.Itoa(fieldIdx) - } - failures = append(failures, validate.FieldError{ - Name: name, - Error: validate.ErrFieldRequired, - }) - // Reset bit. - result &^= 1 << bitIdx - } - } - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s *ExtraCurrencies) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *ExtraCurrencies) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode implements json.Marshaler. func (s *ExtraCurrency) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/pkg/oas/oas_parameters_gen.go b/pkg/oas/oas_parameters_gen.go index eb3985f5..108bd843 100644 --- a/pkg/oas/oas_parameters_gen.go +++ b/pkg/oas/oas_parameters_gen.go @@ -7537,179 +7537,6 @@ func decodeGetEventParams(args [1]string, argsEscaped bool, r *http.Request) (pa return params, nil } -// GetExtraCurrenciesParams is parameters of getExtraCurrencies operation. -type GetExtraCurrenciesParams struct { - Limit OptInt - Offset OptInt -} - -func unpackGetExtraCurrenciesParams(packed middleware.Parameters) (params GetExtraCurrenciesParams) { - { - key := middleware.ParameterKey{ - Name: "limit", - In: "query", - } - if v, ok := packed[key]; ok { - params.Limit = v.(OptInt) - } - } - { - key := middleware.ParameterKey{ - Name: "offset", - In: "query", - } - if v, ok := packed[key]; ok { - params.Offset = v.(OptInt) - } - } - return params -} - -func decodeGetExtraCurrenciesParams(args [0]string, argsEscaped bool, r *http.Request) (params GetExtraCurrenciesParams, _ error) { - q := uri.NewQueryDecoder(r.URL.Query()) - // Set default value for query: limit. - { - val := int(1000) - params.Limit.SetTo(val) - } - // Decode query: limit. - if err := func() error { - cfg := uri.QueryParameterDecodingConfig{ - Name: "limit", - Style: uri.QueryStyleForm, - Explode: true, - } - - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var paramsDotLimitVal int - if err := func() error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToInt(val) - if err != nil { - return err - } - - paramsDotLimitVal = c - return nil - }(); err != nil { - return err - } - params.Limit.SetTo(paramsDotLimitVal) - return nil - }); err != nil { - return err - } - if err := func() error { - if value, ok := params.Limit.Get(); ok { - if err := func() error { - if err := (validate.Int{ - MinSet: true, - Min: 1, - MaxSet: true, - Max: 1000, - MinExclusive: false, - MaxExclusive: false, - MultipleOfSet: false, - MultipleOf: 0, - }).Validate(int64(value)); err != nil { - return errors.Wrap(err, "int") - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - return params, &ogenerrors.DecodeParamError{ - Name: "limit", - In: "query", - Err: err, - } - } - // Set default value for query: offset. - { - val := int(0) - params.Offset.SetTo(val) - } - // Decode query: offset. - if err := func() error { - cfg := uri.QueryParameterDecodingConfig{ - Name: "offset", - Style: uri.QueryStyleForm, - Explode: true, - } - - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var paramsDotOffsetVal int - if err := func() error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToInt(val) - if err != nil { - return err - } - - paramsDotOffsetVal = c - return nil - }(); err != nil { - return err - } - params.Offset.SetTo(paramsDotOffsetVal) - return nil - }); err != nil { - return err - } - if err := func() error { - if value, ok := params.Offset.Get(); ok { - if err := func() error { - if err := (validate.Int{ - MinSet: true, - Min: 0, - MaxSet: false, - Max: 0, - MinExclusive: false, - MaxExclusive: false, - MultipleOfSet: false, - MultipleOf: 0, - }).Validate(int64(value)); err != nil { - return errors.Wrap(err, "int") - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - return params, &ogenerrors.DecodeParamError{ - Name: "offset", - In: "query", - Err: err, - } - } - return params, nil -} - // GetExtraCurrencyInfoParams is parameters of getExtraCurrencyInfo operation. type GetExtraCurrencyInfoParams struct { // Extra currency id. diff --git a/pkg/oas/oas_response_encoders_gen.go b/pkg/oas/oas_response_encoders_gen.go index 46380a0b..e6811bb2 100644 --- a/pkg/oas/oas_response_encoders_gen.go +++ b/pkg/oas/oas_response_encoders_gen.go @@ -777,20 +777,6 @@ func encodeGetEventResponse(response *Event, w http.ResponseWriter, span trace.S return nil } -func encodeGetExtraCurrenciesResponse(response *ExtraCurrencies, w http.ResponseWriter, span trace.Span) error { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - w.WriteHeader(200) - span.SetStatus(codes.Ok, http.StatusText(200)) - - e := new(jx.Encoder) - response.Encode(e) - if _, err := e.WriteTo(w); err != nil { - return errors.Wrap(err, "write") - } - - return nil -} - func encodeGetExtraCurrencyInfoResponse(response *EcPreview, w http.ResponseWriter, span trace.Span) error { w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) diff --git a/pkg/oas/oas_router_gen.go b/pkg/oas/oas_router_gen.go index 5b2c87ce..27d219c4 100644 --- a/pkg/oas/oas_router_gen.go +++ b/pkg/oas/oas_router_gen.go @@ -1701,67 +1701,31 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } elem = origElem - case 't': // Prefix: "tra-currenc" + case 't': // Prefix: "tra-currency/" origElem := elem - if l := len("tra-currenc"); len(elem) >= l && elem[0:l] == "tra-currenc" { + if l := len("tra-currency/"); len(elem) >= l && elem[0:l] == "tra-currency/" { elem = elem[l:] } else { break } - if len(elem) == 0 { - break - } - switch elem[0] { - case 'i': // Prefix: "ies" - origElem := elem - if l := len("ies"); len(elem) >= l && elem[0:l] == "ies" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "GET": - s.handleGetExtraCurrenciesRequest([0]string{}, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET") - } - - return - } - - elem = origElem - case 'y': // Prefix: "y/" - origElem := elem - if l := len("y/"); len(elem) >= l && elem[0:l] == "y/" { - elem = elem[l:] - } else { - break - } - - // Param: "id" - // Leaf parameter - args[0] = elem - elem = "" - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "GET": - s.handleGetExtraCurrencyInfoRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET") - } + // Param: "id" + // Leaf parameter + args[0] = elem + elem = "" - return + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleGetExtraCurrencyInfoRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET") } - elem = origElem + return } elem = origElem @@ -5284,73 +5248,33 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } elem = origElem - case 't': // Prefix: "tra-currenc" + case 't': // Prefix: "tra-currency/" origElem := elem - if l := len("tra-currenc"); len(elem) >= l && elem[0:l] == "tra-currenc" { + if l := len("tra-currency/"); len(elem) >= l && elem[0:l] == "tra-currency/" { elem = elem[l:] } else { break } - if len(elem) == 0 { - break - } - switch elem[0] { - case 'i': // Prefix: "ies" - origElem := elem - if l := len("ies"); len(elem) >= l && elem[0:l] == "ies" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - switch method { - case "GET": - // Leaf: GetExtraCurrencies - r.name = "GetExtraCurrencies" - r.summary = "" - r.operationID = "getExtraCurrencies" - r.pathPattern = "/v2/extra-currencies" - r.args = args - r.count = 0 - return r, true - default: - return - } - } - - elem = origElem - case 'y': // Prefix: "y/" - origElem := elem - if l := len("y/"); len(elem) >= l && elem[0:l] == "y/" { - elem = elem[l:] - } else { - break - } - - // Param: "id" - // Leaf parameter - args[0] = elem - elem = "" + // Param: "id" + // Leaf parameter + args[0] = elem + elem = "" - if len(elem) == 0 { - switch method { - case "GET": - // Leaf: GetExtraCurrencyInfo - r.name = "GetExtraCurrencyInfo" - r.summary = "" - r.operationID = "getExtraCurrencyInfo" - r.pathPattern = "/v2/extra-currency/{id}" - r.args = args - r.count = 1 - return r, true - default: - return - } + if len(elem) == 0 { + switch method { + case "GET": + // Leaf: GetExtraCurrencyInfo + r.name = "GetExtraCurrencyInfo" + r.summary = "" + r.operationID = "getExtraCurrencyInfo" + r.pathPattern = "/v2/extra-currency/{id}" + r.args = args + r.count = 1 + return r, true + default: + return } - - elem = origElem } elem = origElem diff --git a/pkg/oas/oas_schemas_gen.go b/pkg/oas/oas_schemas_gen.go index da889f43..d90f6bfb 100644 --- a/pkg/oas/oas_schemas_gen.go +++ b/pkg/oas/oas_schemas_gen.go @@ -5476,21 +5476,6 @@ func (s *Event) SetInProgress(val bool) { s.InProgress = val } -// Ref: #/components/schemas/ExtraCurrencies -type ExtraCurrencies struct { - ExtraCurrencies []EcPreview `json:"extra_currencies"` -} - -// GetExtraCurrencies returns the value of ExtraCurrencies. -func (s *ExtraCurrencies) GetExtraCurrencies() []EcPreview { - return s.ExtraCurrencies -} - -// SetExtraCurrencies sets the value of ExtraCurrencies. -func (s *ExtraCurrencies) SetExtraCurrencies(val []EcPreview) { - s.ExtraCurrencies = val -} - // Ref: #/components/schemas/ExtraCurrency type ExtraCurrency struct { Amount string `json:"amount"` diff --git a/pkg/oas/oas_server_gen.go b/pkg/oas/oas_server_gen.go index 1d1809b7..6947616d 100644 --- a/pkg/oas/oas_server_gen.go +++ b/pkg/oas/oas_server_gen.go @@ -355,12 +355,6 @@ type Handler interface { // // GET /v2/events/{event_id} GetEvent(ctx context.Context, params GetEventParams) (*Event, error) - // GetExtraCurrencies implements getExtraCurrencies operation. - // - // Get a list of all extra currencies in the blockchain. - // - // GET /v2/extra-currencies - GetExtraCurrencies(ctx context.Context, params GetExtraCurrenciesParams) (*ExtraCurrencies, error) // GetExtraCurrencyInfo implements getExtraCurrencyInfo operation. // // Get extra currency info by id. diff --git a/pkg/oas/oas_unimplemented_gen.go b/pkg/oas/oas_unimplemented_gen.go index 84178645..4d81e570 100644 --- a/pkg/oas/oas_unimplemented_gen.go +++ b/pkg/oas/oas_unimplemented_gen.go @@ -525,15 +525,6 @@ func (UnimplementedHandler) GetEvent(ctx context.Context, params GetEventParams) return r, ht.ErrNotImplemented } -// GetExtraCurrencies implements getExtraCurrencies operation. -// -// Get a list of all extra currencies in the blockchain. -// -// GET /v2/extra-currencies -func (UnimplementedHandler) GetExtraCurrencies(ctx context.Context, params GetExtraCurrenciesParams) (r *ExtraCurrencies, _ error) { - return r, ht.ErrNotImplemented -} - // GetExtraCurrencyInfo implements getExtraCurrencyInfo operation. // // Get extra currency info by id. diff --git a/pkg/oas/oas_validators_gen.go b/pkg/oas/oas_validators_gen.go index 65101135..77a8c732 100644 --- a/pkg/oas/oas_validators_gen.go +++ b/pkg/oas/oas_validators_gen.go @@ -2378,29 +2378,6 @@ func (s *Event) Validate() error { return nil } -func (s *ExtraCurrencies) Validate() error { - if s == nil { - return validate.ErrNilPointer - } - - var failures []validate.FieldError - if err := func() error { - if s.ExtraCurrencies == nil { - return errors.New("nil is invalid value") - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "extra_currencies", - Error: err, - }) - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} - func (s *FoundAccounts) Validate() error { if s == nil { return validate.ErrNilPointer