-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Faucet + gateway to launcher (#1734)
* Adds Faucet + gateway to launcher * port * ports
- Loading branch information
Showing
9 changed files
with
287 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
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 | ||
} | ||
|
||
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)) | ||
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
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) | ||
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)) | ||
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters