2019-03-15 16:02:16 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/edouardparis/lntop/config"
|
|
|
|
"github.com/edouardparis/lntop/logging"
|
|
|
|
"github.com/edouardparis/lntop/network/backend"
|
|
|
|
"github.com/edouardparis/lntop/network/backend/lnd"
|
|
|
|
"github.com/edouardparis/lntop/network/backend/mock"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Network struct {
|
|
|
|
backend.Backend
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(c *config.Network, logger logging.Logger) (*Network, error) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
b backend.Backend
|
|
|
|
)
|
|
|
|
if c.Type == "mock" {
|
|
|
|
b = mock.New(c)
|
|
|
|
} else {
|
|
|
|
b, err = lnd.New(c, logger.With(logging.String("network", "lnd")))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 15:00:25 +00:00
|
|
|
err = b.Ping()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-03-15 16:02:16 +00:00
|
|
|
return &Network{b}, nil
|
|
|
|
}
|