From a9ca63608d62576bde95d0052996ed867e8c5952 Mon Sep 17 00:00:00 2001 From: Anjor Kanekar Date: Wed, 18 Dec 2024 11:25:45 +0000 Subject: [PATCH] use blocktime index for send transactions (#206) --- grpc-server.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/grpc-server.go b/grpc-server.go index 1baec44..e94ce3a 100644 --- a/grpc-server.go +++ b/grpc-server.go @@ -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 { @@ -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 {