Beispiel #1
0
// 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())
	}
}
Beispiel #2
0
func main() {
	flag.Parse()

	logger := log.New(os.Stdout, "", log.Ltime|log.Llongfile)
	logger.Println(valout, valout)

	params := btcbuilder.BuilderParams{
		Fee:      int64(*fee),
		DustAmnt: 546,
		InTarget: int64(*valout),
	}

	btcparams, err := btcbuilder.NetParamsFromStr(*network)
	if err != nil {
		logger.Fatal(err)
	}
	params = btcbuilder.SetParams(btcparams.Net, params)

	single := btcbuilder.NewPayToPubKeyHash(params, 1)
	fmt.Println(single.Summarize())
	list := []btcbuilder.TxBuilder{
		single,
	}
	fanout := btcbuilder.NewFanOutBuilder(params, list, *numouts)

	fmt.Println(btcbuilder.Send(fanout, params))
}