-
Notifications
You must be signed in to change notification settings - Fork 39
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
Adds Faucet + gateway to launcher #1734
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package faucet | ||
|
||
// Option is a function that applies configs to a Config Object | ||
type Option = func(c *Config) | ||
|
||
// Config holds the properties that configure the package | ||
type Config struct { | ||
tenNodeHost string | ||
tenNodePort int | ||
faucetPort int | ||
faucetPrivKey string | ||
dockerImage string | ||
} | ||
|
||
func NewFaucetConfig(opts ...Option) *Config { | ||
defaultConfig := &Config{} | ||
|
||
for _, opt := range opts { | ||
opt(defaultConfig) | ||
} | ||
|
||
return defaultConfig | ||
} | ||
|
||
func WithTenNodeHost(s string) Option { | ||
return func(c *Config) { | ||
c.tenNodeHost = s | ||
} | ||
} | ||
|
||
func WithFaucetPrivKey(s string) Option { | ||
return func(c *Config) { | ||
c.faucetPrivKey = s | ||
} | ||
} | ||
|
||
func WithDockerImage(s string) Option { | ||
return func(c *Config) { | ||
c.dockerImage = s | ||
} | ||
} | ||
|
||
func WithTenNodePort(i int) Option { | ||
return func(c *Config) { | ||
c.tenNodePort = i | ||
} | ||
} | ||
|
||
func WithFaucetPort(i int) Option { | ||
return func(c *Config) { | ||
c.faucetPort = i | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package faucet | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/sanity-io/litter" | ||
"github.com/ten-protocol/go-ten/go/common/docker" | ||
"github.com/ten-protocol/go-ten/go/common/retry" | ||
"github.com/valyala/fasthttp" | ||
) | ||
|
||
type DockerFaucet struct { | ||
cfg *Config | ||
} | ||
|
||
func NewDockerFaucet(cfg *Config) (*DockerFaucet, error) { | ||
return &DockerFaucet{ | ||
cfg: cfg, | ||
}, nil // todo (@pedro) - add validation | ||
otherview marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (n *DockerFaucet) Start() error { | ||
fmt.Printf("Starting faucet with config: \n%s\n\n", litter.Sdump(*n.cfg)) | ||
|
||
cmds := []string{ | ||
"/home/obscuro/go-obscuro/tools/faucet/cmd/faucet", | ||
"--nodeHost", n.cfg.tenNodeHost, | ||
"--nodePort", fmt.Sprintf("%d", n.cfg.tenNodePort), | ||
"--pk", n.cfg.faucetPrivKey, | ||
"--jwtSecret", "someKey", | ||
"--serverPort", fmt.Sprintf("%d", n.cfg.faucetPort), | ||
} | ||
|
||
_, err := docker.StartNewContainer("faucet", n.cfg.dockerImage, cmds, []int{n.cfg.faucetPort}, nil, nil, nil) | ||
return err | ||
otherview marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (n *DockerFaucet) IsReady() error { | ||
timeout := time.Minute | ||
interval := time.Second | ||
|
||
return retry.Do(func() error { | ||
statusCode, _, err := fasthttp.Get(nil, fmt.Sprintf("http://127.0.0.1:%d/health/", n.cfg.faucetPort)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we capture the body in case it has useful error information? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No useful info from the health point responses for the faucet and the gw atm, but I guess we can do that in the future. |
||
if err != nil { | ||
return err | ||
} | ||
|
||
if statusCode != fasthttp.StatusOK { | ||
return fmt.Errorf("status not ok - status received: %s", fasthttp.StatusMessage(statusCode)) | ||
} | ||
|
||
return nil | ||
}, retry.NewTimeoutStrategy(timeout, interval)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package gateway | ||
|
||
// Option is a function that applies configs to a Config Object | ||
type Option = func(c *Config) | ||
|
||
// Config holds the properties that configure the package | ||
type Config struct { | ||
tenNodeHost string | ||
tenNodeHTTPPort int | ||
tenNodeWSPort int | ||
gatewayHTTPPort int | ||
gatewayWSPort int | ||
dockerImage string | ||
} | ||
|
||
func NewGatewayConfig(opts ...Option) *Config { | ||
defaultConfig := &Config{} | ||
|
||
for _, opt := range opts { | ||
opt(defaultConfig) | ||
} | ||
|
||
return defaultConfig | ||
} | ||
|
||
func WithTenNodeHost(s string) Option { | ||
return func(c *Config) { | ||
c.tenNodeHost = s | ||
} | ||
} | ||
|
||
func WithDockerImage(s string) Option { | ||
return func(c *Config) { | ||
c.dockerImage = s | ||
} | ||
} | ||
|
||
func WithTenNodeHTTPPort(i int) Option { | ||
return func(c *Config) { | ||
c.tenNodeHTTPPort = i | ||
} | ||
} | ||
|
||
func WithTenNodeWSPort(i int) Option { | ||
return func(c *Config) { | ||
c.tenNodeWSPort = i | ||
} | ||
} | ||
|
||
func WithGatewayHTTPPort(i int) Option { | ||
return func(c *Config) { | ||
c.gatewayHTTPPort = i | ||
} | ||
} | ||
|
||
func WithGatewayWSPort(i int) Option { | ||
return func(c *Config) { | ||
c.gatewayWSPort = i | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package gateway | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/sanity-io/litter" | ||
"github.com/ten-protocol/go-ten/go/common/docker" | ||
"github.com/ten-protocol/go-ten/go/common/retry" | ||
"github.com/valyala/fasthttp" | ||
) | ||
|
||
type DockerGateway struct { | ||
cfg *Config | ||
} | ||
|
||
func NewDockerGateway(cfg *Config) (*DockerGateway, error) { | ||
return &DockerGateway{ | ||
cfg: cfg, | ||
}, nil // todo (@pedro) - add validation | ||
otherview marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (n *DockerGateway) Start() error { | ||
fmt.Printf("Starting gateway with config: \n%s\n\n", litter.Sdump(*n.cfg)) | ||
|
||
cmds := []string{ | ||
"/home/obscuro/go-obscuro/tools/walletextension/bin/wallet_extension_linux", | ||
"--host", "0.0.0.0", | ||
"--port", fmt.Sprintf("%d", n.cfg.gatewayHTTPPort), | ||
"--portWS", fmt.Sprintf("%d", n.cfg.gatewayWSPort), | ||
"--nodePortHTTP", fmt.Sprintf("%d", n.cfg.tenNodeHTTPPort), | ||
"--nodePortWS", fmt.Sprintf("%d", n.cfg.tenNodeWSPort), | ||
"--nodeHost", n.cfg.tenNodeHost, | ||
"--dbType", "sqlite", | ||
} | ||
|
||
_, err := docker.StartNewContainer("gateway", n.cfg.dockerImage, cmds, []int{n.cfg.gatewayHTTPPort, n.cfg.gatewayWSPort}, nil, nil, nil) | ||
otherview marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return err | ||
} | ||
|
||
func (n *DockerGateway) IsReady() error { | ||
timeout := time.Minute | ||
interval := time.Second | ||
|
||
return retry.Do(func() error { | ||
statusCode, _, err := fasthttp.Get(nil, fmt.Sprintf("http://127.0.0.1:%d/health/", n.cfg.gatewayHTTPPort)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again with the body potentially to speed up debugging. |
||
if err != nil { | ||
return err | ||
} | ||
|
||
if statusCode != fasthttp.StatusOK { | ||
return fmt.Errorf("status not ok - status received: %s", fasthttp.StatusMessage(statusCode)) | ||
} | ||
|
||
return nil | ||
}, retry.NewTimeoutStrategy(timeout, interval)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package faucet | |
import "math/big" | ||
|
||
type Config struct { | ||
Port int | ||
Host string | ||
HTTPPort int | ||
PK string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ func NewWebServer(faucetServer *faucet.Faucet, bindAddress string, jwtSecret []b | |
|
||
r.GET("/balance", balanceReqHandler(faucetServer)) | ||
|
||
r.GET("/health", healthReqHandler()) | ||
|
||
return &WebServer{ | ||
engine: r, | ||
faucet: faucetServer, | ||
|
@@ -170,3 +172,10 @@ func balanceReqHandler(faucetServer *faucet.Faucet) gin.HandlerFunc { | |
c.JSON(http.StatusOK, gin.H{"balance": balance.String()}) | ||
} | ||
} | ||
|
||
// returns the remaining native balance of the faucet | ||
func healthReqHandler() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
c.JSON(http.StatusOK, gin.H{"healthy": true}) | ||
} | ||
} | ||
Comment on lines
+175
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Faucet didn't have a health handler - particularly useful to determine when the container is up and running. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag was unused and threw me off when hooking up the ports