-
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
6cf9caf
commit 929a512
Showing
2 changed files
with
44 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/sourcegraph/jsonrpc2" | ||
) | ||
|
||
func (multi *MultiEpoch) handleGetGenesisHash(ctx context.Context, conn *requestContext, req *jsonrpc2.Request) (*jsonrpc2.Error, error) { | ||
// Epoch 0 contains the genesis config. | ||
epochNumber := uint64(0) | ||
epochHandler, err := multi.GetEpoch(epochNumber) | ||
if err != nil { | ||
// If epoch 0 is not available, then the genesis config is not available. | ||
return &jsonrpc2.Error{ | ||
Code: CodeNotFound, | ||
Message: fmt.Sprintf("Epoch %d is not available", epochNumber), | ||
}, fmt.Errorf("failed to get epoch %d: %w", epochNumber, err) | ||
} | ||
|
||
genesis := epochHandler.GetGenesis() | ||
if genesis == nil { | ||
return &jsonrpc2.Error{ | ||
Code: CodeNotFound, | ||
Message: "Genesis is not available", | ||
}, fmt.Errorf("genesis is nil") | ||
} | ||
|
||
genesisHash := genesis.Hash | ||
|
||
err = conn.ReplyRaw( | ||
ctx, | ||
req.ID, | ||
genesisHash.String(), | ||
) | ||
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