Skip to content

Commit

Permalink
Fixes trying to signAndBroadcast emptry report list + logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Satchitananda committed Nov 12, 2024
1 parent cd177f2 commit 7556356
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions kvasir/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ func SubmitReport(c *Context, l *Logger, keyIndex int64, reports []ReportMsgWith
ids[i] = report.request.RequestID
versionMap[report.execVersion] = true
}

if len(reports) == 0 {
l.Info(":warning: No reports to submit")
return
}

l = l.With("rids", ids)

versions := make([]string, 0, len(versionMap))
Expand Down Expand Up @@ -243,6 +249,7 @@ func abciQuery(c *Context, l *Logger, path string, data []byte) (*ctypes.ResultA
func uploadToIPFS(c *Context, l *Logger, file []byte, report ReportMsgWithKey) (string, error) {
pngFile, err := os.Open(string(file))
if err != nil {
l.Error(":exploding_head: Failed to open file with error: %s", c, err.Error())
return "", err
}
defer func() {
Expand All @@ -252,12 +259,14 @@ func uploadToIPFS(c *Context, l *Logger, file []byte, report ReportMsgWithKey) (

img, err := png.Decode(pngFile)
if err != nil {
l.Error(":exploding_head: Failed to decode png with error: %s", c, err.Error())
return "", err
}

// Create a new JPG file
jpgFile, err := os.Create(string(file) + ".jpg")
if err != nil {
l.Error(":exploding_head: Failed to create JPG with error: %s", c, err.Error())
return "", err
}
defer func() {
Expand All @@ -272,6 +281,7 @@ func uploadToIPFS(c *Context, l *Logger, file []byte, report ReportMsgWithKey) (
// Encode the image to JPEG and save it
err = jpeg.Encode(jpgFile, img, &options)
if err != nil {
l.Error(":exploding_head: Failed to encode JPG file with error: %s", c, err.Error())
return "", err
}

Expand All @@ -293,6 +303,7 @@ func uploadToIPFS(c *Context, l *Logger, file []byte, report ReportMsgWithKey) (
jpgFile.Seek(0, 0)
jpgCID, err := sh.Add(jpgFile, shell.Pin(true))
if err != nil {
l.Error(":exploding_head: Failed to Add JPG file with error: %s", c, err.Error())
return "", err
}

Expand All @@ -307,11 +318,13 @@ func uploadToIPFS(c *Context, l *Logger, file []byte, report ReportMsgWithKey) (

jsonData, err := json.Marshal(data)
if err != nil {
l.Error(":exploding_head: Failed to dump JSON file with error: %s", c, err.Error())
return "", err
}

cid, err := sh.Add(bytes.NewReader(jsonData), shell.Pin(true))
if err != nil {
l.Error(":exploding_head: Failed to upload JSON file with error: %s", c, err.Error())
return "", err
}

Expand Down

0 comments on commit 7556356

Please sign in to comment.