Skip to content

Commit

Permalink
who's a good boy?
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberphysic4l committed Oct 4, 2023
1 parent 9de81b0 commit 951a1c4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
67 changes: 0 additions & 67 deletions components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package core

import (
"io"

"github.com/labstack/echo/v4"

"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/inx-app/pkg/httpserver"
"github.com/iotaledger/iota-core/pkg/blockhandler"
"github.com/iotaledger/iota-core/pkg/model"
"github.com/iotaledger/iota-core/pkg/restapi"
iotago "github.com/iotaledger/iota.go/v4"
Expand Down Expand Up @@ -64,67 +61,3 @@ func blockIssuance(_ echo.Context) (*apimodels.IssuanceBlockHeaderResponse, erro

return resp, nil
}

func sendBlock(c echo.Context) (*apimodels.BlockCreatedResponse, error) {
mimeType, err := httpserver.GetRequestContentType(c, httpserver.MIMEApplicationVendorIOTASerializerV2, echo.MIMEApplicationJSON)
if err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

var iotaBlock = &iotago.ProtocolBlock{}

if c.Request().Body == nil {
// bad request
return nil, ierrors.Wrap(httpserver.ErrInvalidParameter, "invalid block, error: request body missing")
}

bytes, err := io.ReadAll(c.Request().Body)
if err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

switch mimeType {
case echo.MIMEApplicationJSON:
// Do not validate here, the parents might need to be set
if err := deps.Protocol.CurrentAPI().JSONDecode(bytes, iotaBlock); err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

case httpserver.MIMEApplicationVendorIOTASerializerV2:
version, _, err := iotago.VersionFromBytes(bytes)
if err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

apiForVersion, err := deps.Protocol.APIForVersion(version)
if err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

// Do not validate here, the parents might need to be set
if _, err := apiForVersion.Decode(bytes, iotaBlock); err != nil {
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "invalid block, error: %w", err)
}

default:
return nil, echo.ErrUnsupportedMediaType
}

blockID, err := deps.BlockHandler.AttachBlock(c.Request().Context(), iotaBlock)
if err != nil {
switch {
case ierrors.Is(err, blockhandler.ErrBlockAttacherInvalidBlock):
return nil, ierrors.Wrapf(httpserver.ErrInvalidParameter, "failed to attach block: %w", err)

case ierrors.Is(err, blockhandler.ErrBlockAttacherAttachingNotPossible):
return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to attach block: %w", err)

default:
return nil, ierrors.Wrapf(echo.ErrInternalServerError, "failed to attach block: %w", err)
}
}

return &apimodels.BlockCreatedResponse{
BlockID: blockID,
}, nil
}
13 changes: 0 additions & 13 deletions components/restapi/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,6 @@ func checkNodeSynced() echo.MiddlewareFunc {
}
}

func checkUpcomingUnsupportedProtocolVersion() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// todo update with protocol upgrades support
// if !deps.ProtocolManager.NextPendingSupported() {
// return ierrors.Wrap(echo.ErrServiceUnavailable, "node does not support the upcoming protocol upgrade")
// }

return next(c)
}
}
}

func responseByHeader(c echo.Context, obj any) error {
mimeType, err := httpserver.GetAcceptHeaderContentType(c, httpserver.MIMEApplicationVendorIOTASerializerV2, echo.MIMEApplicationJSON)
if err != nil && err != httpserver.ErrNotAcceptable {
Expand Down

0 comments on commit 951a1c4

Please sign in to comment.