Merge pull request #1926 from halseth/lnd-package

Move daemon from main to lnd package
This commit is contained in:
Olaoluwa Osuntokun 2019-04-25 17:52:19 -07:00 committed by GitHub
commit b44556fa8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 59 additions and 49 deletions

@ -92,17 +92,17 @@ btcd:
build: build:
@$(call print, "Building debug lnd and lncli.") @$(call print, "Building debug lnd and lncli.")
$(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG) $(GOBUILD) -tags="$(DEV_TAGS)" -o lnd-debug $(LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli $(GOBUILD) -tags="$(DEV_TAGS)" -o lncli-debug $(LDFLAGS) $(PKG)/cmd/lncli
build-itest: build-itest:
@$(call print, "Building itest lnd and lncli.") @$(call print, "Building itest lnd and lncli.")
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG) $(GOBUILD) -tags="$(ITEST_TAGS)" -o lnd-itest $(LDFLAGS) $(PKG)/cmd/lnd
$(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(LDFLAGS) $(PKG)/cmd/lncli $(GOBUILD) -tags="$(ITEST_TAGS)" -o lncli-itest $(LDFLAGS) $(PKG)/cmd/lncli
install: install:
@$(call print, "Installing lnd and lncli.") @$(call print, "Installing lnd and lncli.")
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG) $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lnd
$(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lncli $(GOINSTALL) -tags="${tags}" $(LDFLAGS) $(PKG)/cmd/lncli
scratch: build scratch: build

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,6 +1,6 @@
// +build !rpctest // +build !rpctest
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"github.com/btcsuite/btcd/chaincfg" "github.com/btcsuite/btcd/chaincfg"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"encoding/hex" "encoding/hex"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"fmt" "fmt"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"fmt" "fmt"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"fmt" "fmt"

21
cmd/lnd/main.go Normal file

@ -0,0 +1,21 @@
package main
import (
"fmt"
"os"
flags "github.com/jessevdk/go-flags"
"github.com/lightningnetwork/lnd"
)
func main() {
// Call the "real" main in a nested manner so the defers will properly
// be executed in the case of a graceful shutdown.
if err := lnd.Main(); err != nil {
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
} else {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
}
}

@ -2,7 +2,7 @@
// Copyright (c) 2015-2016 The Decred developers // Copyright (c) 2015-2016 The Decred developers
// Copyright (C) 2015-2017 The Lightning Network Developers // Copyright (C) 2015-2017 The Lightning Network Developers
package main package lnd
import ( import (
"errors" "errors"

2
doc.go

@ -1 +1 @@
package main package lnd

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,6 +1,6 @@
// +build !rpctest // +build !rpctest
package main package lnd
import ( import (
"errors" "errors"

27
lnd.go

@ -2,7 +2,7 @@
// Copyright (c) 2015-2016 The Decred developers // Copyright (c) 2015-2016 The Decred developers
// Copyright (C) 2015-2017 The Lightning Network Developers // Copyright (C) 2015-2017 The Lightning Network Developers
package main package lnd
import ( import (
"bytes" "bytes"
@ -18,7 +18,6 @@ import (
"math/big" "math/big"
"net" "net"
"net/http" "net/http"
_ "net/http/pprof"
"os" "os"
"path/filepath" "path/filepath"
"runtime/pprof" "runtime/pprof"
@ -26,6 +25,9 @@ import (
"sync" "sync"
"time" "time"
// Blank import to set up profiling HTTP handlers.
_ "net/http/pprof"
"gopkg.in/macaroon-bakery.v2/bakery" "gopkg.in/macaroon-bakery.v2/bakery"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -36,7 +38,6 @@ import (
"github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcwallet/wallet" "github.com/btcsuite/btcwallet/wallet"
proxy "github.com/grpc-ecosystem/grpc-gateway/runtime" proxy "github.com/grpc-ecosystem/grpc-gateway/runtime"
flags "github.com/jessevdk/go-flags"
"github.com/lightninglabs/neutrino" "github.com/lightninglabs/neutrino"
"github.com/lightningnetwork/lnd/autopilot" "github.com/lightningnetwork/lnd/autopilot"
@ -89,10 +90,10 @@ var (
} }
) )
// lndMain is the true entry point for lnd. This function is required since // Main is the true entry point for lnd. This function is required since defers
// defers created in the top-level scope of a main method aren't executed if // created in the top-level scope of a main method aren't executed if os.Exit()
// os.Exit() is called. // is called.
func lndMain() error { func Main() error {
// Load the configuration, and parse any command line options. This // Load the configuration, and parse any command line options. This
// function will also set up logging properly. // function will also set up logging properly.
loadedConfig, err := loadConfig() loadedConfig, err := loadConfig()
@ -468,18 +469,6 @@ func getTLSConfig(cfg *config) (*tls.Config, *credentials.TransportCredentials,
return tlsCfg, &restCreds, restProxyDest, nil return tlsCfg, &restCreds, restProxyDest, nil
} }
func main() {
// Call the "real" main in a nested manner so the defers will properly
// be executed in the case of a graceful shutdown.
if err := lndMain(); err != nil {
if e, ok := err.(*flags.Error); ok && e.Type == flags.ErrHelp {
} else {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
}
}
// fileExists reports whether the named file or directory exists. // fileExists reports whether the named file or directory exists.
// This function is taken from https://github.com/btcsuite/btcd // This function is taken from https://github.com/btcsuite/btcd
func fileExists(name string) bool { func fileExists(name string) bool {

@ -1,6 +1,6 @@
// +build rpctest // +build rpctest
package main package lnd
import ( import (
"bytes" "bytes"

2
log.go

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"fmt" "fmt"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"fmt" "fmt"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,6 +1,6 @@
// +build !rpctest // +build !rpctest
package main package lnd
import ( import (
"io/ioutil" "io/ioutil"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,6 +1,6 @@
// +build !rpctest // +build !rpctest
package main package lnd
import ( import (
"testing" "testing"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"errors" "errors"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,6 +1,6 @@
// +build !rpctest // +build !rpctest
package main package lnd
import "testing" import "testing"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"fmt" "fmt"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,6 +1,6 @@
// +build !rpctest // +build !rpctest
package main package lnd
import ( import (
"bytes" "bytes"

@ -1,4 +1,4 @@
package main package lnd
import ( import (
"sync" "sync"