kopia lustrzana https://github.com/bugout-dev/moonstream
Status server works with polygon node also
rodzic
326b1615b5
commit
20a8878735
|
@ -6,7 +6,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
settings "github.com/bugout-dev/moonstream/crawlers/server/configs"
|
||||
settings "github.com/bugout-dev/moonstream/nodes/server/configs"
|
||||
)
|
||||
|
||||
// Handle panic errors to prevent server shutdown
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
settings "github.com/bugout-dev/moonstream/crawlers/server/configs"
|
||||
settings "github.com/bugout-dev/moonstream/nodes/server/configs"
|
||||
)
|
||||
|
||||
func pingRoute(w http.ResponseWriter, req *http.Request) {
|
||||
|
@ -19,7 +19,7 @@ func pingRoute(w http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
// Fetch latest block from Geth
|
||||
func pingGethRoute(w http.ResponseWriter, req *http.Request) {
|
||||
func (es *extendedServer) pingGethRoute(w http.ResponseWriter, req *http.Request) {
|
||||
postBody, err := json.Marshal(map[string]interface{}{
|
||||
"jsonrpc": "2.0",
|
||||
"method": "eth_blockNumber",
|
||||
|
@ -31,7 +31,17 @@ func pingGethRoute(w http.ResponseWriter, req *http.Request) {
|
|||
http.Error(w, http.StatusText(500), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
gethResponse, err := http.Post(settings.MOONSTREAM_IPC_PATH, "application/json",
|
||||
var IPC_PATH string
|
||||
if es.blockchain == "ethereum" {
|
||||
IPC_PATH = settings.MOONSTREAM_NODE_ETHEREUM_IPC_PATH
|
||||
} else if es.blockchain == "polygon" {
|
||||
IPC_PATH = settings.MOONSTREAM_NODE_POLYGON_IPC_PATH
|
||||
} else {
|
||||
log.Printf("Unaccepted blockchain type: %s", es.blockchain)
|
||||
http.Error(w, http.StatusText(400), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
gethResponse, err := http.Post(IPC_PATH, "application/json",
|
||||
bytes.NewBuffer(postBody))
|
||||
if err != nil {
|
||||
log.Printf("Unable to request geth, error: %s", err)
|
||||
|
|
|
@ -7,16 +7,24 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type extendedServer struct {
|
||||
blockchain string
|
||||
}
|
||||
|
||||
func InitServer() {
|
||||
var listeningAddr string
|
||||
var listeningPort string
|
||||
var blockchain string
|
||||
flag.StringVar(&listeningAddr, "host", "127.0.0.1", "Server listening address")
|
||||
flag.StringVar(&listeningPort, "port", "8080", "Server listening port")
|
||||
flag.StringVar(&blockchain, "blockchain", "", "Blockchain to work with (Ethereum/Polygon)")
|
||||
flag.Parse()
|
||||
|
||||
es := extendedServer{blockchain: blockchain}
|
||||
|
||||
serverMux := http.NewServeMux()
|
||||
serverMux.HandleFunc("/ping", pingRoute)
|
||||
serverMux.HandleFunc("/status", pingGethRoute)
|
||||
serverMux.HandleFunc("/status", es.pingGethRoute)
|
||||
|
||||
// Set middlewares from bottom to top
|
||||
serverHandler := corsMiddleware(serverMux)
|
||||
|
@ -30,6 +38,6 @@ func InitServer() {
|
|||
WriteTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
log.Printf("Starting server at %s:%s\n", listeningAddr, listeningPort)
|
||||
log.Printf("Starting server at %s:%s for blockchain %s\n", listeningAddr, listeningPort, blockchain)
|
||||
server.ListenAndServe()
|
||||
}
|
||||
|
|
|
@ -8,7 +8,12 @@ import (
|
|||
// Geth configs
|
||||
var MOONSTREAM_NODE_ETHEREUM_IPC_ADDR = os.Getenv("MOONSTREAM_NODE_ETHEREUM_IPC_ADDR")
|
||||
var MOONSTREAM_NODE_ETHEREUM_IPC_PORT = os.Getenv("MOONSTREAM_NODE_ETHEREUM_IPC_PORT")
|
||||
var MOONSTREAM_IPC_PATH = fmt.Sprintf("http://%s:%s", MOONSTREAM_NODE_ETHEREUM_IPC_ADDR, MOONSTREAM_NODE_ETHEREUM_IPC_PORT)
|
||||
var MOONSTREAM_NODE_ETHEREUM_IPC_PATH = fmt.Sprintf("http://%s:%s", MOONSTREAM_NODE_ETHEREUM_IPC_ADDR, MOONSTREAM_NODE_ETHEREUM_IPC_PORT)
|
||||
|
||||
// Bor configs
|
||||
var MOONSTREAM_NODE_POLYGON_IPC_ADDR = os.Getenv("MOONSTREAM_NODE_POLYGON_IPC_ADDR")
|
||||
var MOONSTREAM_NODE_POLYGON_IPC_PORT = os.Getenv("MOONSTREAM_NODE_POLYGON_IPC_PORT")
|
||||
var MOONSTREAM_NODE_POLYGON_IPC_PATH = fmt.Sprintf("http://%s:%s", MOONSTREAM_NODE_POLYGON_IPC_ADDR, MOONSTREAM_NODE_POLYGON_IPC_PORT)
|
||||
|
||||
// CORS
|
||||
var MOONSTREAM_CORS_ALLOWED_ORIGINS = os.Getenv("MOONSTREAM_CORS_ALLOWED_ORIGINS")
|
||||
|
|
|
@ -5,5 +5,6 @@ set -e
|
|||
|
||||
MOONSTREAM_CLUSTER_SERVER_HOST="${MOONSTREAM_CLUSTER_SERVER_HOST:-0.0.0.0}"
|
||||
MOONSTREAM_CLUSTER_SERVER_PORT="${MOONSTREAM_CLUSTER_SERVER_PORT:-8080}"
|
||||
MOONSTREAM_CLUSTER_BLOCKCHAIN="${MOONSTREAM_CLUSTER_BLOCKCHAIN:-ethereum}"
|
||||
|
||||
go run main.go -host "${MOONSTREAM_CLUSTER_SERVER_HOST}" -port "${MOONSTREAM_CLUSTER_SERVER_PORT}"
|
||||
go run main.go -host "${MOONSTREAM_CLUSTER_SERVER_HOST}" -port "${MOONSTREAM_CLUSTER_SERVER_PORT}" -blockchain "${MOONSTREAM_CLUSTER_BLOCKCHAIN}"
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
module github.com/bugout-dev/moonstream/crawlers/server
|
||||
module github.com/bugout-dev/moonstream/nodes/server
|
||||
|
||||
go 1.17
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/bugout-dev/moonstream/crawlers/server/cmd"
|
||||
"github.com/bugout-dev/moonstream/nodes/server/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
export MOONSTREAM_NODE_ETHEREUM_IPC_ADDR="127.0.0.1"
|
||||
export MOONSTREAM_NODE_ETHEREUM_IPC_PORT="8545"
|
||||
export MOONSTREAM_NODE_POLYGON_IPC_ADDR="127.0.0.1"
|
||||
export MOONSTREAM_NODE_POLYGON_IPC_PORT="8545"
|
||||
export MOONSTREAM_CORS_ALLOWED_ORIGINS="http://localhost:3000,https://moonstream.to,https://www.moonstream.to,https://alpha.moonstream.to"
|
||||
|
|
Ładowanie…
Reference in New Issue