moonstream/nodes/node_balancer
kompotkot 26472d2ab9 Fixed env var naming 2022-03-16 21:35:28 +00:00
..
cmd Working nodebalancer with authorization via resources 2022-03-16 21:33:48 +00:00
configs Working nodebalancer with authorization via resources 2022-03-16 21:33:48 +00:00
README.md Working nodebalancer with authorization via resources 2022-03-16 21:33:48 +00:00
go.mod Get block and uth workflow 2022-03-16 14:49:39 +00:00
go.sum Get block and uth workflow 2022-03-16 14:49:39 +00:00
main.go Get block and uth workflow 2022-03-16 14:49:39 +00:00
sample.env Fixed env var naming 2022-03-16 21:35:28 +00:00

README.md

Node Balancer application

Installation

  • Prepare environment variables
  • Build application
go build -o nodebalancer

Work with nodebalancer

clients

nodebalancer clients | jq .

This command will return a list of bugout resources of registered users to access node balancer with their crawlers/app/project (in our project we will call it crawlers).

[
	{
		"user_id": "<user_id_from_any_bugout_application>",
		"access_id": "<access_uuid_which_provided_with_query>",
		"name": "<short_description_of_purpose_of_this_crawler>",
		"description": "<long_description>",
		"blockchain_access": true,
		"extended_methods": false
	}
]

access_id - token which allow access to nodebalancer, could be specified in both ways:

  • as a header x-moonstream-access-id with value access_id
  • as query parameter access_id=access_id

blockchain_access - boolean which allow you or not to have access to blockchain node, otherwise you will be redirected to database

extended_methods - boolean which allow you to call not whitelisted method to blockchain node, by default for new user this is equal to false

server

nodebalancer server -host 0.0.0.0 -port 8544 -healthcheck

Flag --healthcheck will execute background process to ping-pong available nodes to keep their status and current block number. Flag --debug will extend output of each request to server and healthchecks summary.

Work with node

Common request to fetch block number

curl --request GET 'http://127.0.0.1:8544/nb/ethereum/jsonrpc?access_id=<access_id>&data_source=<blockchain/database>' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "jsonrpc":"2.0",
        "method":"eth_getBlockByNumber",
        "params":["0xb71b64", false],
        "id":1
    }'