@@ -382,7 +382,20 @@ type StakerShares struct {
382382//
383383// If not blockHeight is provided, the most recently indexed block will be used.
384384// If showHistorical is true, returns all historical share records; otherwise returns aggregated current state.
385- func (pds * ProtocolDataService ) ListStakerShares (ctx context.Context , staker string , strategy string , blockHeight uint64 , showHistorical bool ) ([]* StakerShares , error ) {
385+ // For historical results, startBlock and endBlock can be used to filter the block range.
386+ func (pds * ProtocolDataService ) ListStakerShares (ctx context.Context , staker string , strategy string , blockHeight uint64 , showHistorical bool , startBlock uint64 , endBlock uint64 ) ([]* StakerShares , error ) {
387+ // Validate that start and end blocks are required when historical is true
388+ if showHistorical {
389+ if startBlock == 0 {
390+ return nil , errors .New ("startBlock is required when showHistorical is true" )
391+ }
392+ if endBlock == 0 {
393+ return nil , errors .New ("endBlock is required when showHistorical is true" )
394+ }
395+ if startBlock > endBlock {
396+ return nil , errors .New ("startBlock cannot be greater than endBlock" )
397+ }
398+ }
386399
387400 bh , err := pds .BaseDataService .GetCurrentBlockHeightIfNotPresent (ctx , blockHeight )
388401 if err != nil {
@@ -403,7 +416,8 @@ func (pds *ProtocolDataService) ListStakerShares(ctx context.Context, staker str
403416 ssd.transaction_hash,
404417 ssd.log_index
405418 from staker_share_deltas as ssd
406- where ssd.block_number <= @blockHeight
419+ where ssd.block_number >= @startBlock
420+ and ssd.block_number <= @endBlock
407421 `
408422 if strategy != "" {
409423 query += `
@@ -471,6 +485,11 @@ func (pds *ProtocolDataService) ListStakerShares(ctx context.Context, staker str
471485 queryParams = append (queryParams , sql .Named ("strategy" , strategy ))
472486 }
473487
488+ if showHistorical {
489+ queryParams = append (queryParams , sql .Named ("startBlock" , startBlock ))
490+ queryParams = append (queryParams , sql .Named ("endBlock" , endBlock ))
491+ }
492+
474493 res := pds .db .Raw (query , queryParams ... ).Scan (& shares )
475494 if res .Error != nil {
476495 return nil , res .Error
0 commit comments