2015-12-17 03:42:52 +03:00
|
|
|
package main
|
|
|
|
|
2015-12-30 03:23:27 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
2016-02-23 05:24:56 +03:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/grpclog"
|
2015-12-30 03:23:27 +03:00
|
|
|
"net"
|
2016-01-17 06:09:41 +03:00
|
|
|
"net/http"
|
|
|
|
_ "net/http/pprof"
|
2015-12-30 05:59:16 +03:00
|
|
|
"os"
|
2016-02-23 05:24:56 +03:00
|
|
|
"strconv"
|
2015-12-30 03:23:27 +03:00
|
|
|
|
2016-01-16 21:38:48 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwallet"
|
2015-12-30 03:23:27 +03:00
|
|
|
)
|
|
|
|
|
2015-12-17 03:42:52 +03:00
|
|
|
func main() {
|
2015-12-30 03:23:27 +03:00
|
|
|
|
2016-02-23 05:24:56 +03:00
|
|
|
loadedConfig, err := loadConfig()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("unable to load config: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if loadedConfig.SPVMode == true {
|
|
|
|
shell(loadedConfig.SPVHostAdr, loadedConfig.NetParams)
|
2016-02-03 10:37:29 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-01-17 06:01:06 +03: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-30 03:23:27 +03: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-02-23 05:24:56 +03:00
|
|
|
config := &lnwallet.Config{
|
|
|
|
PrivatePass: []byte("hello"),
|
|
|
|
DataDir: loadedConfig.DataDir,
|
|
|
|
RpcHost: loadedConfig.BTCDHost,
|
|
|
|
RpcUser: loadedConfig.BTCDUser,
|
|
|
|
RpcPass: loadedConfig.BTCDPass,
|
|
|
|
RpcNoTLS: loadedConfig.BTCDNoTLS,
|
|
|
|
CACert: loadedConfig.BTCDCACert,
|
|
|
|
NetParams: loadedConfig.NetParams,
|
|
|
|
}
|
2016-01-07 02:12:06 +03:00
|
|
|
lnwallet, db, err := lnwallet.NewLightningWallet(config)
|
2015-12-30 03:23:27 +03:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("unable to create wallet: %v\n", err)
|
2015-12-30 05:59:16 +03:00
|
|
|
os.Exit(1)
|
2015-12-30 03:23:27 +03:00
|
|
|
}
|
2016-01-07 02:12:06 +03:00
|
|
|
|
2015-12-30 03:23:27 +03:00
|
|
|
if err := lnwallet.Startup(); err != nil {
|
|
|
|
fmt.Printf("unable to start wallet: %v\n", err)
|
2015-12-30 05:59:16 +03:00
|
|
|
os.Exit(1)
|
2015-12-30 03:23:27 +03:00
|
|
|
}
|
2016-01-07 02:12:06 +03:00
|
|
|
|
2015-12-30 05:59:16 +03:00
|
|
|
fmt.Println("wallet open")
|
2016-01-07 02:12:06 +03:00
|
|
|
defer db.Close()
|
2015-12-30 05:59:16 +03:00
|
|
|
|
2016-01-17 06:09:41 +03:00
|
|
|
// Set up the core server which will listen for incoming peer
|
|
|
|
// connections.
|
2016-02-23 05:24:56 +03:00
|
|
|
defaultListenAddr := []string{net.JoinHostPort("", strconv.Itoa(loadedConfig.PeerPort))}
|
|
|
|
server, err := newServer(defaultListenAddr, loadedConfig.NetParams,
|
2016-01-17 06:09:41 +03:00
|
|
|
lnwallet)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("unable to create server: %v\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
server.Start()
|
|
|
|
|
2015-12-30 03:23:27 +03:00
|
|
|
// Initialize, and register our implementation of the gRPC server.
|
|
|
|
var opts []grpc.ServerOption
|
|
|
|
grpcServer := grpc.NewServer(opts...)
|
2016-01-17 06:09:41 +03:00
|
|
|
lnrpc.RegisterLightningServer(grpcServer, server.rpcServer)
|
2015-12-30 03:23:27 +03:00
|
|
|
|
|
|
|
// Finally, start the grpc server listening for HTTP/2 connections.
|
2016-02-23 05:24:56 +03:00
|
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", loadedConfig.RPCPort))
|
2015-12-30 03:23:27 +03:00
|
|
|
if err != nil {
|
|
|
|
grpclog.Fatalf("failed to listen: %v", err)
|
|
|
|
fmt.Printf("failed to listen: %v", err)
|
2015-12-30 05:59:16 +03:00
|
|
|
os.Exit(1)
|
2015-12-30 03:23:27 +03:00
|
|
|
}
|
|
|
|
grpcServer.Serve(lis)
|
2015-12-17 03:42:52 +03:00
|
|
|
}
|