Skip to content

Commit

Permalink
Pass mainnet uri as env variable to development config (#998)
Browse files Browse the repository at this point in the history
* Pass mainnet uri as env variable to development config

* Check rpc url before sending request
  • Loading branch information
aopoltorzhicky authored Oct 28, 2023
1 parent b76e9eb commit e9cfc9c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion configs/development.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rpc:
mainnet:
uri: https://rpc.tzkt.io/archive
uri: ${MAINNET_RPC_URI:-https://rpc.tzkt.io/mainnet}
timeout: 20
requests_per_second: 15
ghostnet:
Expand Down
7 changes: 3 additions & 4 deletions internal/helpers/string.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package helpers

import (
"fmt"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -29,13 +28,13 @@ func GenerateID() string {
}

// URLJoin -
func URLJoin(baseURL, queryPath string) string {
func URLJoin(baseURL, queryPath string) (string, error) {
u, err := url.Parse(baseURL)
if err != nil {
return fmt.Sprintf("%s/%s", baseURL, queryPath)
return "", err
}
u.Path = path.Join(u.Path, queryPath)
return u.String()
return u.String(), nil
}

// SpaceStringsBuilder -
Expand Down
11 changes: 8 additions & 3 deletions internal/noderpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ func (rpc *NodeRPC) makeRequest(ctx context.Context, req *http.Request) (*http.R
}

func (rpc *NodeRPC) makeGetRequest(ctx context.Context, uri string) (*http.Response, error) {
url := helpers.URLJoin(rpc.baseURL, uri)
url, err := helpers.URLJoin(rpc.baseURL, uri)
if err != nil {
return nil, errors.Wrap(ErrNodeRPCError, err.Error())
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, errors.Errorf("makeGetRequest.NewRequest: %v", err)
Expand All @@ -129,8 +132,10 @@ func (rpc *NodeRPC) makeGetRequest(ctx context.Context, uri string) (*http.Respo
}

func (rpc *NodeRPC) makePostRequest(ctx context.Context, uri string, data interface{}) (*http.Response, error) {
url := helpers.URLJoin(rpc.baseURL, uri)

url, err := helpers.URLJoin(rpc.baseURL, uri)
if err != nil {
return nil, errors.Wrap(ErrNodeRPCError, err.Error())
}
bData, err := json.Marshal(data)
if err != nil {
return nil, errors.Errorf("makePostRequest.json.Marshal: %v", err)
Expand Down

0 comments on commit e9cfc9c

Please sign in to comment.