main.go raw

   1  // Command nostrino-testnode serves a deterministic regtest chain with BIP157
   2  // compact filters. It is a development fixture for the bridge and light
   3  // client, not a Bitcoin node.
   4  package main
   5  
   6  import (
   7  	"flag"
   8  	"fmt"
   9  	"os"
  10  	"os/signal"
  11  	"syscall"
  12  
  13  	"git.smesh.lol/nostrino/internal/testnode"
  14  	"git.smesh.lol/nostrino/pkg/chain"
  15  )
  16  
  17  func main() {
  18  	listen := flag.String("listen", "127.0.0.1:18444", "listen address")
  19  	blocks := flag.Int("blocks", 50, "blocks after genesis")
  20  	flag.Parse()
  21  
  22  	profile := chain.Regtest
  23  	node, err := testnode.New(&profile, testnode.Config{Blocks: *blocks})
  24  	if err != nil {
  25  		fmt.Fprintln(os.Stderr, "nostrino-testnode:", err)
  26  		os.Exit(1)
  27  	}
  28  	addr, err := node.Listen(*listen)
  29  	if err != nil {
  30  		fmt.Fprintln(os.Stderr, "nostrino-testnode:", err)
  31  		os.Exit(1)
  32  	}
  33  	fmt.Printf("testnode listening on %s height=%d\n", addr, node.Height())
  34  	if h, ok := node.Header(node.Height()); ok {
  35  		fmt.Printf("tip: %d %s\n", node.Height(), h.BlockHash())
  36  	}
  37  	sig := make(chan os.Signal, 1)
  38  	signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
  39  	<-sig
  40  	node.Close()
  41  }
  42