Compare commits

..

1 commit

Author SHA1 Message Date
peter
4d9a2f5cc1 lbcdblocknotify: support multiple stratum server 2022-10-18 16:56:43 +08:00
5 changed files with 64 additions and 46 deletions

View file

@ -977,8 +977,8 @@ func NewImportMultiCmd(requests []ImportMultiRequest, options *ImportMultiOption
// RescanBlockchainCmd defines the RescanBlockchain JSON-RPC command.
type RescanBlockchainCmd struct {
StartHeight *int32 `jsonrpcdefault:"0"`
StopHeight *int32
StartHeight *int64 `jsonrpcdefault:"0"`
StopHeight *int64 `jsonrpcdefault:"0"`
}
// NewRescanBlockchainCmd returns a new instance which can be used to issue
@ -986,7 +986,7 @@ type RescanBlockchainCmd struct {
//
// The parameters which are pointers indicate they are optional. Passing nil
// for optional parameters will use the default value.
func NewRescanBlockchainCmd(startHeight *int32, stopHeight *int32) *RescanBlockchainCmd {
func NewRescanBlockchainCmd(startHeight *int64, stopHeight *int64) *RescanBlockchainCmd {
return &RescanBlockchainCmd{
StartHeight: startHeight,
StopHeight: stopHeight,

View file

@ -319,8 +319,8 @@ type ListUnspentResult struct {
// RescanBlockchainResult models the data returned from the rescanblockchain command.
type RescanBlockchainResult struct {
StartHeight int32 `json:"start_height"`
StoptHeight int32 `json:"stop_height"`
StartHeight int64 `json:"start_height"`
StoptHeight int64 `json:"stop_height"`
}
// SignRawTransactionError models the data that contains script verification

View file

@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"log"
"os/exec"
"path/filepath"
@ -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")
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}
client := newLbcdClient(*rpcserver, *rpcuser, *rpcpass, *notls, adpt)
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)
}
// Start the eventt handler.
go b.start()
// Adaptater receives lbcd notifications, and emit events.
adpt := adapter{b}
client := newLbcdClient(*rpcserver, *rpcuser, *rpcpass, *notls, adpt)
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()
quit := make(chan bool)
<-quit
}
func (f *stratumFlag) String() string {
return fmt.Sprintf("%v", []string(*f))
}
func (f *stratumFlag) Set(value string) error {
*f = append(*f, value)
return nil
}

View file

@ -2062,14 +2062,14 @@ func (r FutureRescanBlockchainResult) Receive() (*btcjson.RescanBlockchainResult
// returned instance.
//
// See RescanBlockchain for the blocking version and more details.
func (c *Client) RescanBlockchainAsync(startHeight *int32, stopHeight *int32) FutureRescanBlockchainResult {
func (c *Client) RescanBlockchainAsync(startHeight *int64, stopHeight *int64) FutureRescanBlockchainResult {
cmd := btcjson.NewRescanBlockchainCmd(startHeight, stopHeight)
return c.SendCmd(cmd)
}
// RescanBlockchain rescans the local blockchain for wallet related
// transactions from the startHeight to the the inclusive stopHeight.
func (c *Client) RescanBlockchain(startHeight *int32, stopHeight *int32) (*btcjson.RescanBlockchainResult, error) {
func (c *Client) RescanBlockchain(startHeight *int64, stopHeight *int64) (*btcjson.RescanBlockchainResult, error) {
return c.RescanBlockchainAsync(startHeight, stopHeight).Receive()
}

View file

@ -206,7 +206,7 @@ func StripClaimScriptPrefix(script []byte) []byte {
return script[cs.Size:]
}
const illegalChars = "=&#:$%?/;\\\b\n\t\r\x00"
const illegalChars = "=&#:*$%?/;\\\b\n\t\r\x00"
func AllClaimsAreSane(script []byte, enforceSoftFork bool) error {
cs, err := ExtractClaimScript(script)