コード例 #1
0
ファイル: main.go プロジェクト: mehulsbhatt/watchtower
// Main does 3 things.
// It starts a hub that has txJson channels in and out for sending txs from
// the bitcoin network into connected websockets. It starts the bitcoin listening
// side by creating a watchtower and passing a reference to that hub. Finally it
// starts listening for websockect connections to pass to the hub.
func main() {
	flag.Parse()

	net, err := btcbuilder.NetParamsFromStr(*btcnet)
	if err != nil {
		log.Fatal(err)
	}

	cfg := watchtower.TowerCfg{
		Addr:        *nodeaddr,
		Net:         net.Net,
		StartHeight: 0,
	}

	hub := &hub{
		btcpipe:     make(chan []byte, 256),
		register:    make(chan *conn),
		unregister:  make(chan *conn),
		connections: make(map[*conn]struct{}),
	}

	go hub.run()
	go watchtower.Create(cfg, txClosure(hub), blockClosure(hub))

	http.Handle("/ws", websocket.Handler(wsHandlerClosure(hub)))
	log.Printf("Listening for conns at: %s%s\n", *addr, "/ws")
	if err := http.ListenAndServe(*addr, nil); err != nil {
		log.Fatal("Http service died: ", err.Error())
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: mehulsbhatt/watchtower
func main() {
	addr := "127.0.0.1:18333"
	testnet := btcwire.TestNet3
	var err error
	conn, err = sql.Open("sqlite3", "sample.db")
	if err != nil {
		log.Fatal(err)
	}

	watchtower.Create(addr, testnet, txParser, blockParser)
}