Skip to content

Commit

Permalink
fix: update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Mar 15, 2024
1 parent 113744d commit e43ed29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 6 additions & 5 deletions api/adapter/controller.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package adapter

import (
"bisonai.com/orakl/api/feed"
"bisonai.com/orakl/api/utils"
"encoding/json"
"fmt"
"strconv"

"bisonai.com/orakl/api/feed"
"bisonai.com/orakl/api/utils"

"github.com/ethereum/go-ethereum/crypto"
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -58,7 +59,7 @@ func insert(c *fiber.Ctx) error {

err := computeAdapterHash(payload, true)
if err != nil {
panic(err)
return c.Status(fiber.StatusInternalServerError).SendString("failed to compute adapter hash: " + err.Error())
}

row, err := utils.QueryRow[AdapterIdModel](c, InsertAdapter, map[string]any{
Expand Down Expand Up @@ -105,7 +106,7 @@ func hash(c *fiber.Ctx) error {

err = computeAdapterHash(&payload, verify)
if err != nil {
panic(err)
return c.Status(fiber.StatusInternalServerError).SendString("failed to compute adapter hash: " + err.Error())
}
return c.JSON(payload)
}
Expand Down Expand Up @@ -152,7 +153,7 @@ func computeAdapterHash(data *AdapterInsertModel, verify bool) error {

out, err := json.Marshal(input)
if err != nil {
panic(err)
return err
}

hash := crypto.Keccak256Hash([]byte(out))
Expand Down
15 changes: 8 additions & 7 deletions api/aggregator/controller.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package aggregator

import (
"encoding/json"
"fmt"
"strconv"

"bisonai.com/orakl/api/adapter"
"bisonai.com/orakl/api/chain"
"bisonai.com/orakl/api/feed"
"bisonai.com/orakl/api/utils"
"encoding/json"
"fmt"
"strconv"

"github.com/ethereum/go-ethereum/crypto"
"github.com/go-playground/validator/v10"
Expand Down Expand Up @@ -118,7 +119,7 @@ func insert(c *fiber.Ctx) error {
}
err = computeAggregatorHash(&hashComputeParam, true)
if err != nil {
panic(err)
return c.Status(fiber.StatusInternalServerError).SendString("failed to compute aggregator hash: " + err.Error())
}

insertParam := _AggregatorInsertModel{
Expand Down Expand Up @@ -207,7 +208,7 @@ func hash(c *fiber.Ctx) error {

err = computeAggregatorHash(&hashComputeParam, verify)
if err != nil {
panic(err)
return c.Status(fiber.StatusInternalServerError).SendString("failed to compute aggregator hash: " + err.Error())
}

return c.JSON(hashComputeParam)
Expand Down Expand Up @@ -313,13 +314,13 @@ func computeAggregatorHash(data *AggregatorHashComputeInputModel, verify bool) e
processData := input.AggregatorHashComputeProcessModel
out, err := json.Marshal(processData)
if err != nil {
panic(err)
return err
}

hash := crypto.Keccak256Hash([]byte(out))
hashString := fmt.Sprintf("0x%x", hash)
if verify && data.AggregatorHash != hashString {
panic(err)
return fmt.Errorf("hashes do not match!\nexpected %s, received %s", hashString, data.AdapterHash)
}

data.AggregatorHash = hashString
Expand Down

0 comments on commit e43ed29

Please sign in to comment.