Skip to content

Commit 5005a80

Browse files
committed
WIP
1 parent 0dcf30b commit 5005a80

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

rocketpool/node/http.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package node
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"net/http"
8+
9+
"github.com/rocket-pool/smartnode/shared/services/config"
10+
cfgtypes "github.com/rocket-pool/smartnode/shared/types/config"
11+
"google.golang.org/genproto/googleapis/maps/routes/v1"
12+
)
13+
14+
type httpServer struct {
15+
server *http.Server
16+
}
17+
18+
func startHTTP(ctx context.Context, cfg *config.RocketPoolConfig) {
19+
host := "127.0.0.1"
20+
if cfg.Smartnode.OpenAPIPort.Value == cfgtypes.RPC_OpenLocalhost {
21+
host = "0.0.0.0"
22+
}
23+
24+
port, ok := cfg.Smartnode.APIPort.Value.(uint16)
25+
if !ok {
26+
log.Fatalf("Error getting API port: %v", err)
27+
}
28+
29+
httpServer := &httpServer{}
30+
31+
server := &http.Server{
32+
Addr: fmt.Sprintf("%s:%d", host, port),
33+
Handler: httpServer,
34+
}
35+
36+
httpServer.server = server
37+
}
38+
39+
func (s *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
40+
41+
w.WriteHeader(http.StatusOK)
42+
w.Write([]byte("Hello, World!"))
43+
}
44+
45+
func (s *httpServer) addRoute(r *routes.Route) {
46+
}

rocketpool/node/node.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package node
22

33
import (
4+
"context"
45
"fmt"
56
"math/big"
67
"net/http"
@@ -119,6 +120,12 @@ func run(c *cli.Context) error {
119120
m := state.NewNetworkStateManager(rp, cfg.Smartnode.GetStateManagerContracts(), bc, &updateLog)
120121
stateLocker := collectors.NewStateLocker()
121122

123+
// Create a context for the daemon
124+
ctx := context.Background()
125+
126+
// Start the HTTP server
127+
startHTTP(ctx, cfg)
128+
122129
// Initialize tasks
123130
manageFeeRecipient, err := newManageFeeRecipient(c, log.NewColorLogger(ManageFeeRecipientColor))
124131
if err != nil {

rocketpool/node/routes/state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package routes

0 commit comments

Comments
 (0)