2015-12-16 16:42:52 -08:00
|
|
|
package main
|
|
|
|
|
2015-12-29 16:23:27 -08:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2016-01-16 19:09:41 -08:00
|
|
|
"net/http"
|
|
|
|
_ "net/http/pprof"
|
2015-12-29 18:59:16 -08:00
|
|
|
"os"
|
2015-12-30 21:40:41 -08:00
|
|
|
"time"
|
2015-12-29 16:23:27 -08:00
|
|
|
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/grpclog"
|
|
|
|
|
2016-01-16 19:09:41 -08:00
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
2016-01-16 10:38:48 -08:00
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
2015-12-29 16:23:27 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-01-16 19:09:41 -08:00
|
|
|
rpcPort = flag.Int("rpcport", 10009, "The port for the rpc server")
|
|
|
|
peerPort = flag.String("peerport", "10011", "The port to listen on for incoming p2p connections")
|
|
|
|
dataDir = flag.String("datadir", "test_wal", "The directory to store lnd's data within")
|
2015-12-29 16:23:27 -08:00
|
|
|
)
|
|
|
|
|
2015-12-16 16:42:52 -08:00
|
|
|
func main() {
|
2015-12-29 16:23:27 -08:00
|
|
|
flag.Parse()
|
|
|
|
|
2016-01-16 19:01:06 -08:00
|
|
|
go func() {
|
|
|
|
listenAddr := net.JoinHostPort("", "5009")
|
|
|
|
profileRedirect := http.RedirectHandler("/debug/pprof",
|
|
|
|
http.StatusSeeOther)
|
|
|
|
http.Handle("/", profileRedirect)
|
|
|
|
fmt.Println(http.ListenAndServe(listenAddr, nil))
|
|
|
|
}()
|
|
|
|
|
2015-12-29 16:23:27 -08:00
|
|
|
// Create, and start the lnwallet, which handles the core payment channel
|
|
|
|
// logic, and exposes control via proxy state machines.
|
|
|
|
// TODO(roasbeef): accept config via cli flags, move to real config file
|
|
|
|
// afterwards
|
2016-01-16 19:09:41 -08:00
|
|
|
config := &lnwallet.Config{PrivatePass: []byte("hello"), DataDir: *dataDir}
|
|
|
|
|
2016-01-06 15:12:06 -08:00
|
|
|
lnwallet, db, err := lnwallet.NewLightningWallet(config)
|
2015-12-29 16:23:27 -08:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("unable to create wallet: %v\n", err)
|
2015-12-29 18:59:16 -08:00
|
|
|
os.Exit(1)
|
2015-12-29 16:23:27 -08:00
|
|
|
}
|
2016-01-06 15:12:06 -08:00
|
|
|
|
2015-12-29 16:23:27 -08:00
|
|
|
if err := lnwallet.Startup(); err != nil {
|
|
|
|
fmt.Printf("unable to start wallet: %v\n", err)
|
2015-12-29 18:59:16 -08:00
|
|
|
os.Exit(1)
|
2015-12-29 16:23:27 -08:00
|
|
|
}
|
2016-01-06 15:12:06 -08:00
|
|
|
|
|
|
|
lnwallet.Unlock(config.PrivatePass, time.Duration(0))
|
2015-12-29 18:59:16 -08:00
|
|
|
fmt.Println("wallet open")
|
2016-01-06 15:12:06 -08:00
|
|
|
defer db.Close()
|
2015-12-29 18:59:16 -08:00
|
|
|
|
2016-01-16 19:09:41 -08:00
|
|
|
// Set up the core server which will listen for incoming peer
|
|
|
|
// connections.
|
|
|
|
defaultListenAddr := []string{net.JoinHostPort("", *peerPort)}
|
|
|
|
server, err := newServer(defaultListenAddr, &chaincfg.TestNet3Params,
|
|
|
|
lnwallet)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("unable to create server: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
server.Start()
|
|
|
|
|
2015-12-29 16:23:27 -08:00
|
|
|
// Initialize, and register our implementation of the gRPC server.
|
|
|
|
var opts []grpc.ServerOption
|
|
|
|
grpcServer := grpc.NewServer(opts...)
|
2016-01-16 19:09:41 -08:00
|
|
|
lnrpc.RegisterLightningServer(grpcServer, server.rpcServer)
|
2015-12-29 16:23:27 -08:00
|
|
|
|
|
|
|
// Finally, start the grpc server listening for HTTP/2 connections.
|
2016-01-16 19:09:41 -08:00
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *rpcPort))
|
2015-12-29 16:23:27 -08:00
|
|
|
if err != nil {
|
|
|
|
grpclog.Fatalf("failed to listen: %v", err)
|
|
|
|
fmt.Printf("failed to listen: %v", err)
|
2015-12-29 18:59:16 -08:00
|
|
|
os.Exit(1)
|
2015-12-29 16:23:27 -08:00
|
|
|
}
|
|
|
|
grpcServer.Serve(lis)
|
2015-12-16 16:42:52 -08:00
|
|
|
}
|