implemented jeffs nits

This commit is contained in:
Matt Johnstone 2024-10-06 16:58:15 +02:00
parent db8373b81d
commit bf217cfc22
No known key found for this signature in database
GPG Key ID: BE985FBB9BE7D3BB
3 changed files with 8 additions and 21 deletions

View File

@ -208,7 +208,7 @@ func (c *SlotWatcher) fetchAndEmitBlockProduction(ctx context.Context, endSlot i
// make sure the bounds are contained within the epoch we are currently watching:
if err := c.checkValidSlotRange(startSlot, endSlot); err != nil {
panic(err)
klog.Fatalf("invalid slot range: %v", err)
}
// fetch block production:

View File

@ -1,25 +1,11 @@
package main
import (
"encoding/json"
"fmt"
"k8s.io/klog/v2"
)
func assertf(condition bool, format string, args ...any) {
if !condition {
panic(fmt.Errorf(format, args...))
klog.Fatalf(format, args...)
}
}
// prettyPrint is just a useful debugging function
func prettyPrint(obj any) {
// For pretty-printed JSON, use json.MarshalIndent
prettyJSON, err := json.MarshalIndent(obj, "", " ")
if err != nil {
fmt.Println("Error marshalling to pretty JSON:", err, ". obj: ", obj)
return
}
// Print the pretty JSON string
fmt.Println(string(prettyJSON))
}

View File

@ -92,14 +92,14 @@ func (c *Client) getResponse(ctx context.Context, method string, params []any, r
request := &rpcRequest{Version: "2.0", ID: 1, Method: method, Params: params}
buffer, err := json.Marshal(request)
if err != nil {
panic(err)
klog.Fatalf("failed to marshal request: %v", err)
}
klog.V(2).Infof("jsonrpc request: %s", string(buffer))
// make request:
req, err := http.NewRequestWithContext(ctx, "POST", c.rpcAddr, bytes.NewBuffer(buffer))
if err != nil {
panic(err)
klog.Fatalf("failed to create request: %v", err)
}
req.Header.Set("content-type", "application/json")
@ -177,7 +177,7 @@ func (c *Client) GetBlockProduction(
) (*BlockProduction, error) {
// can't provide a last slot without a first:
if firstSlot == nil && lastSlot != nil {
panic("can't provide a last slot without a first!")
klog.Fatalf("can't provide a last slot without a first!")
}
// format params:
@ -190,7 +190,8 @@ func (c *Client) GetBlockProduction(
if lastSlot != nil {
// make sure first and last slot are in order:
if *firstSlot > *lastSlot {
panic(fmt.Errorf("last slot %v is greater than first slot %v", *lastSlot, *firstSlot))
err := fmt.Errorf("last slot %v is greater than first slot %v", *lastSlot, *firstSlot)
klog.Fatalf("%v", err)
}
blockRange["lastSlot"] = *lastSlot
}