Skip to content

Commit

Permalink
use blocktime index for send transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
anjor committed Dec 17, 2024
1 parent 3ed45d2 commit e6065f1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions grpc-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,21 @@ func (multi *MultiEpoch) processSlotTransactions(
txResp.Transaction.Meta = tx.Meta
txResp.Transaction.Index = tx.Index

// To do: add blocketime after index work is done
epochNumber := slottools.CalcEpochForSlot(slot)
epochHandler, err := multi.GetEpoch(epochNumber)
if err != nil {
return status.Errorf(codes.NotFound, "Epoch %d is not available", epochNumber)
}
blocktimeIndex := epochHandler.GetBlocktimeIndex()
if blocktimeIndex != nil {
blocktime, err := blocktimeIndex.Get(uint64(slot))
if err != nil {
return status.Errorf(codes.Internal, "Failed to get blocktime: %v", err)
}
txResp.BlockTime = int64(blocktime)
} else {
return status.Errorf(codes.Internal, "Failed to get blocktime: blocktime index is nil")
}
}

if err := ser.Send(txResp); err != nil {
Expand Down Expand Up @@ -878,7 +892,16 @@ func (multi *MultiEpoch) processSlotTransactions(
}
txResp.Slot = uint64(txn.Slot)

// To do: add blocktime after index work is done
blocktimeIndex := epochHandler.GetBlocktimeIndex()
if blocktimeIndex != nil {
blocktime, err := blocktimeIndex.Get(uint64(txn.Slot))
if err != nil {
return status.Errorf(codes.Internal, "Failed to get blocktime: %v", err)
}
txResp.BlockTime = int64(blocktime)
} else {
return status.Errorf(codes.Internal, "Failed to get blocktime: blocktime index is nil")
}
}

if err := ser.Send(txResp); err != nil {
Expand Down

0 comments on commit e6065f1

Please sign in to comment.