Skip to content

Commit

Permalink
Add new BlockIssuance function to NodeBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsporn committed Apr 19, 2024
1 parent 14ed394 commit a24f54b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
30 changes: 30 additions & 0 deletions pkg/nodebridge/block_issuance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package nodebridge

import (
"context"

inx "github.com/iotaledger/inx/go"
"github.com/iotaledger/iota.go/v4/api"
)

// BlockIssuance requests the necessary data to issue a block.
func (n *nodeBridge) BlockIssuance(ctx context.Context, count uint32) (*api.IssuanceBlockHeaderResponse, error) {
resp, err := n.client.ReadBlockIssuance(ctx, &inx.BlockIssuanceRequest{MaxStrongParentsCount: count, MaxShallowLikeParentsCount: count, MaxWeakParentsCount: count})
if err != nil {
return nil, err
}

latestCommitment, err := resp.UnwrapLatestCommitment(n.APIProvider().CommittedAPI())
if err != nil {
return nil, err
}

return &api.IssuanceBlockHeaderResponse{
StrongParents: resp.UnwrapStrongParents(),
WeakParents: resp.UnwrapWeakParents(),
ShallowLikeParents: resp.UnwrapShallowLikeParents(),
LatestParentBlockIssuingTime: resp.UnwrapLatestParentBlockIssuingTime(),
LatestFinalizedSlot: resp.UnwrapLatestFinalizedSlot(),
LatestCommitment: latestCommitment,
}, nil
}
4 changes: 2 additions & 2 deletions pkg/nodebridge/node_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ type NodeBridge interface {
// PruningEpoch returns the pruning epoch.
PruningEpoch() iotago.EpochIndex

// RequestTips requests tips.
RequestTips(ctx context.Context, count uint32) (strong iotago.BlockIDs, weak iotago.BlockIDs, shallowLike iotago.BlockIDs, err error)
// BlockIssuance requests the necessary data to issue a block.
BlockIssuance(ctx context.Context, count uint32) (*api.IssuanceBlockHeaderResponse, error)
}

var _ NodeBridge = &nodeBridge{}
Expand Down
18 changes: 0 additions & 18 deletions pkg/nodebridge/tips.go

This file was deleted.

0 comments on commit a24f54b

Please sign in to comment.