Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(OraklNode) Separate utils inner paths #1271

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions node/pkg/admin/adapter/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"bisonai.com/orakl/node/pkg/admin/utils"
"bisonai.com/orakl/node/pkg/bus"
"bisonai.com/orakl/node/pkg/db"
oraklUtil "bisonai.com/orakl/node/pkg/utils"
"bisonai.com/orakl/node/pkg/utils/request"
"github.com/go-playground/validator"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -51,7 +51,7 @@ func syncFromOraklConfig(c *fiber.Ctx) error {
configUrl := getConfigUrl()

var adapters BulkAdapters
adapters, err := oraklUtil.GetRequest[BulkAdapters](configUrl, nil, map[string]string{"Content-Type": "application/json"})
adapters, err := request.GetRequest[BulkAdapters](configUrl, nil, map[string]string{"Content-Type": "application/json"})
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("failed to get orakl config: " + err.Error())
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func addFromOraklConfig(c *fiber.Ctx) error {
}

var adapters BulkAdapters
adapters, err := oraklUtil.GetRequest[BulkAdapters](configUrl, nil, map[string]string{"Content-Type": "application/json"})
adapters, err := request.GetRequest[BulkAdapters](configUrl, nil, map[string]string{"Content-Type": "application/json"})
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("failed to get orakl config: " + err.Error())
}
Expand Down
8 changes: 5 additions & 3 deletions node/pkg/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"bisonai.com/orakl/node/pkg/bus"
"bisonai.com/orakl/node/pkg/db"
"bisonai.com/orakl/node/pkg/utils"
"bisonai.com/orakl/node/pkg/utils/reducer"
"bisonai.com/orakl/node/pkg/utils/request"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -294,7 +296,7 @@ func (a *App) fetch(fetcher Fetcher) ([]float64, error) {
return
}

result, err := utils.Reduce(res, definition.Reducers)
result, err := reducer.Reduce(res, definition.Reducers)
if err != nil {
errChan <- err
return
Expand Down Expand Up @@ -338,11 +340,11 @@ func (a *App) requestFeed(definition Definition) (interface{}, error) {
}

func (a *App) requestWithoutProxy(definition Definition) (interface{}, error) {
return utils.GetRequest[interface{}](definition.Url, nil, definition.Headers)
return request.GetRequest[interface{}](definition.Url, nil, definition.Headers)
}

func (a *App) requestWithProxy(definition Definition, proxyUrl string) (interface{}, error) {
return utils.GetRequestProxy[interface{}](definition.Url, nil, definition.Headers, proxyUrl)
return request.GetRequestProxy[interface{}](definition.Url, nil, definition.Headers, proxyUrl)
}

func (a *App) filterProxyByLocation(location string) []Proxy {
Expand Down
4 changes: 2 additions & 2 deletions node/pkg/fetcher/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"bisonai.com/orakl/node/pkg/bus"
"bisonai.com/orakl/node/pkg/utils"
"bisonai.com/orakl/node/pkg/utils/reducer"
)

const (
Expand Down Expand Up @@ -56,7 +56,7 @@ type Definition struct {
Url string `json:"url"`
Headers map[string]string `json:"headers"`
Method string `json:"method"`
Reducers []utils.Reducer `json:"reducers"`
Reducers []reducer.Reducer `json:"reducers"`
Location *string `json:"location"`
}

Expand Down
4 changes: 2 additions & 2 deletions node/pkg/reporter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"bisonai.com/orakl/node/pkg/bus"
"bisonai.com/orakl/node/pkg/raft"
"bisonai.com/orakl/node/pkg/utils"
"bisonai.com/orakl/node/pkg/utils/klaytn_helper"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/host"
)
Expand Down Expand Up @@ -39,7 +39,7 @@ type App struct {

type ReporterNode struct {
Raft *raft.Raft
TxHelper *utils.TxHelper
TxHelper *klaytn_helper.TxHelper

lastSubmissions map[string]int64
contractAddress string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package klaytn_helper

import (
"context"
Expand All @@ -12,6 +12,7 @@ import (
"time"

"bisonai.com/orakl/node/pkg/db"
"bisonai.com/orakl/node/pkg/utils/request"

"github.com/klaytn/klaytn"
"github.com/klaytn/klaytn/accounts/abi"
Expand Down Expand Up @@ -142,7 +143,7 @@ func (t *TxHelper) GetSignedFromDelegator(tx *types.Transaction) (*types.Transac
return nil, err
}

result, err := UrlRequest[SignModel](t.delegatorUrl+"/api/v1/sign/volatile", "POST", payload, nil, "")
result, err := request.UrlRequest[SignModel](t.delegatorUrl+"/api/v1/sign/volatile", "POST", payload, nil, "")
if err != nil {
log.Error().Err(err).Msg("failed to request sign from delegator")
return nil, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package reducer

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package request

import (
"bytes"
Expand Down
24 changes: 12 additions & 12 deletions node/pkg/utils/tests/klaytn_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"
"testing"

"bisonai.com/orakl/node/pkg/utils"
"bisonai.com/orakl/node/pkg/utils/klaytn_helper"
"github.com/stretchr/testify/assert"
)

func TestNewTxHelper(t *testing.T) {
ctx := context.Background()
txHelper, err := utils.NewTxHelper(ctx)
txHelper, err := klaytn_helper.NewTxHelper(ctx)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -19,7 +19,7 @@ func TestNewTxHelper(t *testing.T) {

func TestNextReporter(t *testing.T) {
ctx := context.Background()
txHelper, err := utils.NewTxHelper(ctx)
txHelper, err := klaytn_helper.NewTxHelper(ctx)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -33,7 +33,7 @@ func TestNextReporter(t *testing.T) {

func TestMakeDirectTx(t *testing.T) {
ctx := context.Background()
txHelper, err := utils.NewTxHelper(ctx)
txHelper, err := klaytn_helper.NewTxHelper(ctx)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -47,7 +47,7 @@ func TestMakeDirectTx(t *testing.T) {

func TestMakeFeeDelegatedTx(t *testing.T) {
ctx := context.Background()
txHelper, err := utils.NewTxHelper(ctx)
txHelper, err := klaytn_helper.NewTxHelper(ctx)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -61,7 +61,7 @@ func TestMakeFeeDelegatedTx(t *testing.T) {

func TestTxToHashToTx(t *testing.T) {
ctx := context.Background()
txHelper, err := utils.NewTxHelper(ctx)
txHelper, err := klaytn_helper.NewTxHelper(ctx)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -72,10 +72,10 @@ func TestTxToHashToTx(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
}

hash := utils.TxToHash(rawTx)
hash := klaytn_helper.TxToHash(rawTx)
assert.NotEqual(t, hash, "")

tx, err := utils.HashToTx(hash)
tx, err := klaytn_helper.HashToTx(hash)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -85,13 +85,13 @@ func TestTxToHashToTx(t *testing.T) {

func TestGenerateABI(t *testing.T) {
ctx := context.Background()
txHelper, err := utils.NewTxHelper(ctx)
txHelper, err := klaytn_helper.NewTxHelper(ctx)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
defer txHelper.Close()

abi, err := utils.GenerateABI("increment()")
abi, err := klaytn_helper.GenerateABI("increment()")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -101,7 +101,7 @@ func TestGenerateABI(t *testing.T) {

func TestSubmitRawTxString(t *testing.T) {
ctx := context.Background()
txHelper, err := utils.NewTxHelper(ctx)
txHelper, err := klaytn_helper.NewTxHelper(ctx)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
Expand All @@ -117,7 +117,7 @@ func TestSubmitRawTxString(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
}

rawTxString := utils.TxToHash(signedTx)
rawTxString := klaytn_helper.TxToHash(signedTx)
err = txHelper.SubmitRawTxString(ctx, rawTxString)
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions node/pkg/utils/tests/reducer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"bisonai.com/orakl/node/pkg/utils"
"bisonai.com/orakl/node/pkg/utils/reducer"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -72,7 +72,7 @@ var sampleResult = `[
]`

func TestReduceAll(t *testing.T) {
var red []utils.Reducer
var red []reducer.Reducer
err := json.Unmarshal([]byte(reducers), &red)
if err != nil {
t.Fatalf("error unmarshalling sample def: %v", err)
Expand All @@ -84,7 +84,7 @@ func TestReduceAll(t *testing.T) {
t.Fatalf("error unmarshalling sample result: %v", err)
}

result, err := utils.Reduce(res, red)
result, err := reducer.Reduce(res, red)
if err != nil {
t.Fatalf("error reducing: %v", err)
}
Expand Down
16 changes: 8 additions & 8 deletions node/pkg/utils/tests/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net/http/httptest"
"testing"

"bisonai.com/orakl/node/pkg/utils"
"bisonai.com/orakl/node/pkg/utils/request"
)

type TestResponse struct {
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestGetRequest(t *testing.T) {
Test: "value",
}

testResponse, err := utils.GetRequest[TestResponse](server.URL, requestBody, headers)
testResponse, err := request.GetRequest[TestResponse](server.URL, requestBody, headers)
if err != nil {
t.Errorf("Error making request: %v", err)
}
Expand All @@ -120,7 +120,7 @@ func TestGetRequestRaw(t *testing.T) {
Test: "value",
}

res, err := utils.GetRequestRaw(server.URL, requestBody, headers)
res, err := request.GetRequestRaw(server.URL, requestBody, headers)
if err != nil {
t.Errorf("Error making request: %v", err)
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestUrlRequest(t *testing.T) {
Test: "value",
}

testResponse, err := utils.UrlRequest[TestResponse](server.URL, "GET", requestBody, headers, "")
testResponse, err := request.UrlRequest[TestResponse](server.URL, "GET", requestBody, headers, "")
if err != nil {
t.Errorf("Error making request: %v", err)
}
Expand All @@ -180,7 +180,7 @@ func TestUrlRequestRaw(t *testing.T) {
Test: "value",
}

res, err := utils.UrlRequestRaw(server.URL, "GET", requestBody, headers, "")
res, err := request.UrlRequestRaw(server.URL, "GET", requestBody, headers, "")
if err != nil {
t.Errorf("Error making request: %v", err)
}
Expand Down Expand Up @@ -223,7 +223,7 @@ func TestGetRequestProxy(t *testing.T) {
Test: "value",
}

testResponse, err := utils.GetRequestProxy[TestResponse](server.URL, requestBody, headers, proxy.URL)
testResponse, err := request.GetRequestProxy[TestResponse](server.URL, requestBody, headers, proxy.URL)
if err != nil {
t.Errorf("Error making request: %v", err)
}
Expand All @@ -249,7 +249,7 @@ func TestUrlRequestProxy(t *testing.T) {
"Test-Header": "test-value",
}

testResponse, err := utils.UrlRequest[TestResponse](server.URL, "GET", requestBody, headers, proxy.URL)
testResponse, err := request.UrlRequest[TestResponse](server.URL, "GET", requestBody, headers, proxy.URL)
if err != nil {
t.Errorf("Error making request: %v", err)
}
Expand All @@ -276,7 +276,7 @@ func TestUrlRequestRawProxy(t *testing.T) {
"Test-Header": "test-value",
}

res, err := utils.UrlRequestRaw(server.URL, "GET", requestBody, headers, proxy.URL)
res, err := request.UrlRequestRaw(server.URL, "GET", requestBody, headers, proxy.URL)
if err != nil {
t.Errorf("Error making request: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions node/script/test_submission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"fmt"
"math/big"

"bisonai.com/orakl/node/pkg/utils"
"bisonai.com/orakl/node/pkg/utils/klaytn_helper"
"github.com/rs/zerolog/log"
)

// send single submission through this script

func testContractDelegatedCall(ctx context.Context, contractAddress string, contractFunction string, args ...interface{}) error {
txHelper, err := utils.NewTxHelper(ctx)
txHelper, err := klaytn_helper.NewTxHelper(ctx)
if err != nil {
log.Error().Err(err).Msg("NewTxHelper")
return err
Expand Down
Loading