Skip to content
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

lbcdblocknotify: support multiple stratum server #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 53 additions & 35 deletions rpcclient/examples/lbcdblocknotify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"log"
"os/exec"
"path/filepath"
Expand All @@ -10,56 +11,73 @@ import (
"github.com/lbryio/lbcutil"
)

type stratumFlag []string

var (
lbcdHomeDir = lbcutil.AppDataDir("lbcd", false)
defaultCert = filepath.Join(lbcdHomeDir, "rpc.cert")
stratumList stratumFlag
)
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")
coinid = flag.String("coinid", "1425", "Coin ID")
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")
)

func main() {

flag.Var(&stratumList, "stratum", "--stratum=stratum1 --stratum=stratum2")
peterpan0708 marked this conversation as resolved.
Show resolved Hide resolved
flag.Parse()
for _, stratum := range stratumList {
go func(stratum string) {
// Setup notification handler
b := newBridge(stratum, *stratumPass, *coinid)

// Setup notification handler
b := newBridge(*stratumServer, *stratumPass, *coinid)
if len(*run) > 0 {
// Check if ccommand exists.
strs := strings.Split(*run, " ")
cmd := strs[0]
_, err := exec.LookPath(cmd)
if err != nil {
log.Fatalf("ERROR: %s not found: %s", cmd, err)
}
b.customCmd = *run
}

if len(*run) > 0 {
// Check if ccommand exists.
strs := strings.Split(*run, " ")
cmd := strs[0]
_, err := exec.LookPath(cmd)
if err != nil {
log.Fatalf("ERROR: %s not found: %s", cmd, err)
}
b.customCmd = *run
}
// Start the eventt handler.
go b.start()

// Adaptater receives lbcd notifications, and emit events.
adpt := adapter{b}

// Start the eventt handler.
go b.start()
client := newLbcdClient(*rpcserver, *rpcuser, *rpcpass, *notls, adpt)

// Adaptater receives lbcd notifications, and emit events.
adpt := adapter{b}
go func() {
err := <-b.errorc
log.Fatalf("ERROR: %s", err)
client.Shutdown()
}()
// Wait until the client either shuts down gracefully (or the user
// terminates the process with Ctrl+C).
client.WaitForShutdown()
}(stratum)
}

client := newLbcdClient(*rpcserver, *rpcuser, *rpcpass, *notls, adpt)
quit := make(chan bool)
<-quit
}

go func() {
err := <-b.errorc
log.Fatalf("ERROR: %s", err)
client.Shutdown()
}()
func (f *stratumFlag) String() string {
return fmt.Sprintf("%v", []string(*f))
}

// Wait until the client either shuts down gracefully (or the user
// terminates the process with Ctrl+C).
client.WaitForShutdown()
func (f *stratumFlag) Set(value string) error {
*f = append(*f, value)
peterpan0708 marked this conversation as resolved.
Show resolved Hide resolved
return nil
}