2022-01-04 18:52:39 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
2022-08-08 08:03:33 +02:00
|
|
|
"os/exec"
|
2022-01-04 18:52:39 +01:00
|
|
|
"path/filepath"
|
2022-08-08 08:03:33 +02:00
|
|
|
"strings"
|
2022-01-04 18:52:39 +01:00
|
|
|
|
|
|
|
"github.com/lbryio/lbcutil"
|
|
|
|
)
|
|
|
|
|
2022-08-08 08:03:33 +02:00
|
|
|
var (
|
2022-10-14 04:50:12 +02:00
|
|
|
lbcdHomeDir = lbcutil.AppDataDir("lbcd", false)
|
|
|
|
defaultCert = filepath.Join(lbcdHomeDir, "rpc.cert")
|
|
|
|
)
|
|
|
|
var (
|
|
|
|
coinid = flag.String("coinid", "1425", "Coin ID")
|
|
|
|
stratumServer = flag.String("stratum", "", "Stratum server")
|
|
|
|
stratumPass = flag.String("stratumpass", "", "Stratum server password")
|
|
|
|
rpcserver = flag.String("rpcserver", "localhost:9245", "LBCD RPC server")
|
|
|
|
rpcuser = flag.String("rpcuser", "rpcuser", "LBCD RPC username")
|
|
|
|
rpcpass = flag.String("rpcpass", "rpcpass", "LBCD RPC password")
|
|
|
|
rpccert = flag.String("rpccert", defaultCert, "LBCD RPC certificate")
|
|
|
|
notls = flag.Bool("notls", false, "Connect to LBCD with TLS disabled")
|
|
|
|
run = flag.String("run", "", "Run custom shell command")
|
|
|
|
quiet = flag.Bool("quiet", false, "Do not print logs")
|
2022-08-08 08:03:33 +02:00
|
|
|
)
|
|
|
|
|
2022-10-14 04:50:12 +02:00
|
|
|
func main() {
|
2022-08-08 08:03:33 +02:00
|
|
|
|
2022-10-14 04:50:12 +02:00
|
|
|
flag.Parse()
|
2022-08-08 08:03:33 +02:00
|
|
|
|
2022-10-14 04:50:12 +02:00
|
|
|
// Setup notification handler
|
|
|
|
b := newBridge(*stratumServer, *stratumPass, *coinid)
|
2022-08-08 08:03:33 +02:00
|
|
|
|
2022-10-14 04:50:12 +02:00
|
|
|
if len(*run) > 0 {
|
|
|
|
// Check if ccommand exists.
|
|
|
|
strs := strings.Split(*run, " ")
|
|
|
|
cmd := strs[0]
|
|
|
|
_, err := exec.LookPath(cmd)
|
2022-08-08 08:03:33 +02:00
|
|
|
if err != nil {
|
2022-10-14 04:50:12 +02:00
|
|
|
log.Fatalf("ERROR: %s not found: %s", cmd, err)
|
2022-08-08 08:03:33 +02:00
|
|
|
}
|
2022-10-14 04:50:12 +02:00
|
|
|
b.customCmd = *run
|
2022-01-04 18:52:39 +01:00
|
|
|
}
|
|
|
|
|
2022-10-14 04:50:12 +02:00
|
|
|
// Start the eventt handler.
|
|
|
|
go b.start()
|
2022-01-04 18:52:39 +01:00
|
|
|
|
2022-10-14 04:50:12 +02:00
|
|
|
// Adaptater receives lbcd notifications, and emit events.
|
|
|
|
adpt := adapter{b}
|
2022-01-04 18:52:39 +01:00
|
|
|
|
2022-10-14 04:50:12 +02:00
|
|
|
client := newLbcdClient(*rpcserver, *rpcuser, *rpcpass, *notls, adpt)
|
2022-01-04 18:52:39 +01:00
|
|
|
|
2022-10-14 04:50:12 +02:00
|
|
|
go func() {
|
|
|
|
err := <-b.errorc
|
|
|
|
log.Fatalf("ERROR: %s", err)
|
|
|
|
client.Shutdown()
|
|
|
|
}()
|
2022-01-04 18:52:39 +01:00
|
|
|
|
|
|
|
// Wait until the client either shuts down gracefully (or the user
|
|
|
|
// terminates the process with Ctrl+C).
|
|
|
|
client.WaitForShutdown()
|
|
|
|
}
|