github.com/lbryio/lbcd@v0.22.119/rpcclient/examples/lbcdblocknotify/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "log" 6 "os/exec" 7 "path/filepath" 8 "strings" 9 10 "github.com/lbryio/lbcutil" 11 ) 12 13 var ( 14 lbcdHomeDir = lbcutil.AppDataDir("lbcd", false) 15 defaultCert = filepath.Join(lbcdHomeDir, "rpc.cert") 16 ) 17 var ( 18 coinid = flag.String("coinid", "1425", "Coin ID") 19 stratumServer = flag.String("stratum", "", "Stratum server") 20 stratumPass = flag.String("stratumpass", "", "Stratum server password") 21 rpcserver = flag.String("rpcserver", "localhost:9245", "LBCD RPC server") 22 rpcuser = flag.String("rpcuser", "rpcuser", "LBCD RPC username") 23 rpcpass = flag.String("rpcpass", "rpcpass", "LBCD RPC password") 24 rpccert = flag.String("rpccert", defaultCert, "LBCD RPC certificate") 25 notls = flag.Bool("notls", false, "Connect to LBCD with TLS disabled") 26 run = flag.String("run", "", "Run custom shell command") 27 quiet = flag.Bool("quiet", false, "Do not print logs") 28 ) 29 30 func main() { 31 32 flag.Parse() 33 34 // Setup notification handler 35 b := newBridge(*stratumServer, *stratumPass, *coinid) 36 37 if len(*run) > 0 { 38 // Check if ccommand exists. 39 strs := strings.Split(*run, " ") 40 cmd := strs[0] 41 _, err := exec.LookPath(cmd) 42 if err != nil { 43 log.Fatalf("ERROR: %s not found: %s", cmd, err) 44 } 45 b.customCmd = *run 46 } 47 48 // Start the eventt handler. 49 go b.start() 50 51 // Adaptater receives lbcd notifications, and emit events. 52 adpt := adapter{b} 53 54 client := newLbcdClient(*rpcserver, *rpcuser, *rpcpass, *notls, adpt) 55 56 go func() { 57 err := <-b.errorc 58 log.Fatalf("ERROR: %s", err) 59 client.Shutdown() 60 }() 61 62 // Wait until the client either shuts down gracefully (or the user 63 // terminates the process with Ctrl+C). 64 client.WaitForShutdown() 65 }