Skip to content

Commit

Permalink
Remove optional slot index in RouteBlockIssuance
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Nov 21, 2023
1 parent dab4fad commit b9f35d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
20 changes: 3 additions & 17 deletions components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"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"
"github.com/iotaledger/iota.go/v4/nodeclient/apimodels"
Expand Down Expand Up @@ -66,31 +65,18 @@ func blockWithMetadataByID(c echo.Context) (*apimodels.BlockWithMetadataResponse
}, nil
}

func blockIssuanceBySlot(slotIndex iotago.SlotIndex) (*apimodels.IssuanceBlockHeaderResponse, error) {
func blockIssuance() (*apimodels.IssuanceBlockHeaderResponse, error) {
references := deps.Protocol.MainEngineInstance().TipSelection.SelectTips(iotago.BasicBlockMaxParents)

var slotCommitment *model.Commitment
var err error
// by default we use latest commitment
if slotIndex == 0 {
slotCommitment = deps.Protocol.MainEngineInstance().SyncManager.LatestCommitment()
} else {
slotCommitment, err = deps.Protocol.MainEngineInstance().Storage.Commitments().Load(slotIndex)
if err != nil {
return nil, ierrors.Wrapf(echo.ErrNotFound, "failed to load commitment for requested slot %d: %s", slotIndex, err)
}
}

if len(references[iotago.StrongParentType]) == 0 {
return nil, ierrors.Wrap(echo.ErrServiceUnavailable, "get references failed")
return nil, ierrors.Wrap(echo.ErrServiceUnavailable, "no strong parents available")
}

resp := &apimodels.IssuanceBlockHeaderResponse{
StrongParents: references[iotago.StrongParentType],
WeakParents: references[iotago.WeakParentType],
ShallowLikeParents: references[iotago.ShallowLikeParentType],
LatestFinalizedSlot: deps.Protocol.MainEngineInstance().SyncManager.LatestFinalizedSlot(),
Commitment: slotCommitment.Commitment(),
Commitment: deps.Protocol.MainEngineInstance().SyncManager.LatestCommitment().Commitment(),
}

return resp, nil
Expand Down
4 changes: 1 addition & 3 deletions components/restapi/core/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ func configure() error {
}, checkNodeSynced())

routeGroup.GET(RouteBlockIssuance, func(c echo.Context) error {
index, _ := httpserver.ParseSlotQueryParam(c, restapipkg.ParameterSlotIndex)

resp, err := blockIssuanceBySlot(index)
resp, err := blockIssuance()
if err != nil {
return err
}
Expand Down

0 comments on commit b9f35d7

Please sign in to comment.