Skip to content

Commit

Permalink
Merge pull request #610 from iotaledger/feat/add-latest-parent-issuin…
Browse files Browse the repository at this point in the history
…g-time

Add LatestParentBlockIssuingTime to BlockIssuance endpoint
  • Loading branch information
muXxer authored Dec 6, 2023
2 parents bcd79e5 + c624905 commit a377997
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions components/restapi/core/blocks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package core

import (
"time"

"github.com/labstack/echo/v4"

"github.com/iotaledger/hive.go/ierrors"
Expand Down Expand Up @@ -84,12 +86,28 @@ func blockIssuance() (*api.IssuanceBlockHeaderResponse, error) {
return nil, ierrors.Wrap(echo.ErrServiceUnavailable, "no strong parents available")
}

// get the latest parent block issuing time
var latestParentBlockIssuingTime time.Time
for _, parentType := range []iotago.ParentsType{iotago.StrongParentType, iotago.WeakParentType, iotago.ShallowLikeParentType} {
for _, blockID := range references[parentType] {
block, exists := deps.Protocol.Engines.Main.Get().Block(blockID)
if !exists {
return nil, ierrors.Wrapf(echo.ErrNotFound, "no block found for parent, block ID: %s", blockID.ToHex())
}

if latestParentBlockIssuingTime.Before(block.ProtocolBlock().Header.IssuingTime) {
latestParentBlockIssuingTime = block.ProtocolBlock().Header.IssuingTime
}
}
}

resp := &api.IssuanceBlockHeaderResponse{
StrongParents: references[iotago.StrongParentType],
WeakParents: references[iotago.WeakParentType],
ShallowLikeParents: references[iotago.ShallowLikeParentType],
LatestFinalizedSlot: deps.Protocol.Engines.Main.Get().SyncManager.LatestFinalizedSlot(),
LatestCommitment: deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Commitment(),
StrongParents: references[iotago.StrongParentType],
WeakParents: references[iotago.WeakParentType],
ShallowLikeParents: references[iotago.ShallowLikeParentType],
LatestParentBlockIssuingTime: latestParentBlockIssuingTime,
LatestFinalizedSlot: deps.Protocol.Engines.Main.Get().SyncManager.LatestFinalizedSlot(),
LatestCommitment: deps.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Commitment(),
}

return resp, nil
Expand Down

0 comments on commit a377997

Please sign in to comment.