-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c24f03f
commit a03ae27
Showing
4 changed files
with
92 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/rpcpool/yellowstone-faithful/compactindex36" | ||
"github.com/sourcegraph/jsonrpc2" | ||
) | ||
|
||
func (multi *MultiEpoch) handleGetBlockTime(ctx context.Context, conn *requestContext, req *jsonrpc2.Request) (*jsonrpc2.Error, error) { | ||
blockNum, err := parseGetBlockTimeRequest(req.Params) | ||
if err != nil { | ||
return &jsonrpc2.Error{ | ||
Code: jsonrpc2.CodeInvalidParams, | ||
Message: "Invalid params", | ||
}, fmt.Errorf("failed to parse params: %w", err) | ||
} | ||
|
||
// find the epoch that contains the requested slot | ||
epochNumber := CalcEpochForSlot(blockNum) | ||
epochHandler, err := multi.GetEpoch(epochNumber) | ||
if err != nil { | ||
return &jsonrpc2.Error{ | ||
Code: CodeNotFound, | ||
Message: fmt.Sprintf("Epoch %d is not available", epochNumber), | ||
}, fmt.Errorf("failed to get epoch %d: %w", epochNumber, err) | ||
} | ||
|
||
block, err := epochHandler.GetBlock(WithSubrapghPrefetch(ctx, false), blockNum) | ||
if err != nil { | ||
if errors.Is(err, compactindex36.ErrNotFound) { | ||
return &jsonrpc2.Error{ | ||
Code: CodeNotFound, | ||
Message: fmt.Sprintf("Slot %d was skipped, or missing in long-term storage", blockNum), | ||
}, err | ||
} else { | ||
return &jsonrpc2.Error{ | ||
Code: jsonrpc2.CodeInternalError, | ||
Message: "Failed to get block", | ||
}, fmt.Errorf("failed to get block: %w", err) | ||
} | ||
} | ||
blockTime := uint64(block.Meta.Blocktime) | ||
err = conn.ReplyRaw( | ||
ctx, | ||
req.ID, | ||
blockTime, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to reply: %w", err) | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters