2024-03-19 00:31:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/api"
|
|
|
|
"github.com/status-im/status-go/logutils"
|
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
|
|
|
"github.com/status-im/status-go/services/wakuv2ext"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setupLogger(file string) *zap.Logger {
|
|
|
|
logFile := fmt.Sprintf("%s.log", strings.ToLower(file))
|
|
|
|
logSettings := logutils.LogSettings{
|
|
|
|
Enabled: true,
|
|
|
|
MobileSystem: false,
|
|
|
|
Level: "DEBUG",
|
|
|
|
File: logFile,
|
|
|
|
MaxSize: 100,
|
|
|
|
MaxBackups: 3,
|
|
|
|
CompressRotated: true,
|
|
|
|
}
|
|
|
|
if err := logutils.OverrideRootLogWithConfig(logSettings, false); err != nil {
|
|
|
|
logger.Fatalf("Error initializing logger: %v", err)
|
|
|
|
}
|
|
|
|
|
2024-04-09 15:44:43 +00:00
|
|
|
return logutils.ZapLogger()
|
2024-03-19 00:31:35 +00:00
|
|
|
}
|
|
|
|
|
2024-04-09 15:44:43 +00:00
|
|
|
func start(cCtx *cli.Context, name string, port int, apiModules string) (*StatusCLI, error) {
|
2024-03-19 00:31:35 +00:00
|
|
|
namedLogger := logger.Named(name)
|
|
|
|
namedLogger.Info("starting messager")
|
|
|
|
|
|
|
|
_ = setupLogger(name)
|
|
|
|
|
|
|
|
path := fmt.Sprintf("./test-%s", strings.ToLower(name))
|
|
|
|
err := os.MkdirAll(path, os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
backend := api.NewGethStatusBackend()
|
|
|
|
|
|
|
|
createAccountRequest := &requests.CreateAccount{
|
2024-04-09 15:44:43 +00:00
|
|
|
DisplayName: name,
|
2024-03-19 00:31:35 +00:00
|
|
|
CustomizationColor: "#ffffff",
|
|
|
|
Emoji: "some",
|
|
|
|
Password: "some-password",
|
|
|
|
BackupDisabledDataDir: fmt.Sprintf("./test-%s", strings.ToLower(name)),
|
|
|
|
LogFilePath: "log",
|
2024-04-09 15:44:43 +00:00
|
|
|
APIConfig: &requests.APIConfig{
|
|
|
|
APIModules: apiModules,
|
|
|
|
HTTPHost: "127.0.0.1",
|
|
|
|
HTTPPort: port,
|
|
|
|
},
|
2024-03-19 00:31:35 +00:00
|
|
|
}
|
2024-04-09 15:44:43 +00:00
|
|
|
_, err = backend.CreateAccountAndLogin(createAccountRequest)
|
2024-03-19 00:31:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
wakuService := backend.StatusNode().WakuV2ExtService()
|
|
|
|
if wakuService == nil {
|
|
|
|
return nil, errors.New("waku service is not available")
|
|
|
|
}
|
|
|
|
wakuAPI := wakuv2ext.NewPublicAPI(wakuService)
|
|
|
|
|
|
|
|
messenger := wakuAPI.Messenger()
|
|
|
|
_, err = wakuAPI.StartMessenger()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
namedLogger.Info("messenger started, public key: ", messenger.IdentityPublicKeyString())
|
|
|
|
|
|
|
|
time.Sleep(WaitingInterval)
|
|
|
|
|
|
|
|
data := StatusCLI{
|
|
|
|
name: name,
|
|
|
|
messenger: messenger,
|
|
|
|
backend: backend,
|
|
|
|
logger: namedLogger,
|
|
|
|
}
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
}
|
|
|
|
|
2024-04-09 15:44:43 +00:00
|
|
|
func (cli *StatusCLI) stop() {
|
2024-03-19 00:31:35 +00:00
|
|
|
err := cli.backend.StopNode()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error(err)
|
|
|
|
}
|
|
|
|
}
|