2023-02-27 07:15:48 -08:00
|
|
|
package subservers
|
|
|
|
|
|
|
|
|
|
import (
|
2023-05-02 11:35:13 +02:00
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
restProxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
2023-02-27 07:15:48 -08:00
|
|
|
"github.com/lightninglabs/lndclient"
|
|
|
|
|
"github.com/lightninglabs/pool"
|
|
|
|
|
"github.com/lightninglabs/pool/poolrpc"
|
2024-05-23 13:52:28 +02:00
|
|
|
"github.com/lightninglabs/taproot-assets/fn"
|
2023-02-27 07:15:48 -08:00
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
|
|
|
|
"google.golang.org/grpc"
|
2023-05-02 08:52:28 +02:00
|
|
|
"gopkg.in/macaroon-bakery.v2/bakery"
|
2023-02-27 07:15:48 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// poolSubServer implements the SubServer interface.
|
|
|
|
|
type poolSubServer struct {
|
|
|
|
|
*pool.Server
|
|
|
|
|
remote bool
|
|
|
|
|
cfg *pool.Config
|
|
|
|
|
remoteCfg *RemoteDaemonConfig
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A compile-time check to ensure that poolSubServer implements SubServer.
|
|
|
|
|
var _ SubServer = (*poolSubServer)(nil)
|
|
|
|
|
|
|
|
|
|
// NewPoolSubServer returns a new pool implementation of the SubServer
|
|
|
|
|
// interface.
|
|
|
|
|
func NewPoolSubServer(cfg *pool.Config, remoteCfg *RemoteDaemonConfig,
|
|
|
|
|
remote bool) SubServer {
|
|
|
|
|
|
2023-05-02 11:43:52 +02:00
|
|
|
// Overwrite the pool daemon's user agent name, so it sends "litd"
|
|
|
|
|
// instead of and "poold".
|
|
|
|
|
pool.SetAgentName("litd")
|
|
|
|
|
|
2023-02-27 07:15:48 -08:00
|
|
|
return &poolSubServer{
|
|
|
|
|
Server: pool.NewServer(cfg),
|
|
|
|
|
cfg: cfg,
|
|
|
|
|
remoteCfg: remoteCfg,
|
|
|
|
|
remote: remote,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Name returns the name of the sub-server.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) Name() string {
|
|
|
|
|
return POOL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remote returns true if the sub-server is running remotely and so should be
|
|
|
|
|
// connected to instead of spinning up an integrated server.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) Remote() bool {
|
|
|
|
|
return p.remote
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RemoteConfig returns the config required to connect to the sub-server if it
|
|
|
|
|
// is running in remote mode.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) RemoteConfig() *RemoteDaemonConfig {
|
|
|
|
|
return p.remoteCfg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start starts the sub-server in integrated mode.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) Start(lnClient lnrpc.LightningClient,
|
|
|
|
|
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error {
|
|
|
|
|
|
|
|
|
|
return p.StartAsSubserver(lnClient, lndGrpc, withMacaroonService)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RegisterGrpcService must register the sub-server's GRPC server with the given
|
|
|
|
|
// registrar.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) RegisterGrpcService(registrar grpc.ServiceRegistrar) {
|
|
|
|
|
poolrpc.RegisterTraderServer(registrar, p)
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-02 11:35:13 +02:00
|
|
|
// RegisterRestService registers the sub-server's REST handlers with the given
|
|
|
|
|
// endpoint.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) RegisterRestService(ctx context.Context,
|
|
|
|
|
mux *restProxy.ServeMux, endpoint string,
|
|
|
|
|
dialOpts []grpc.DialOption) error {
|
|
|
|
|
|
|
|
|
|
return poolrpc.RegisterTraderHandlerFromEndpoint(
|
|
|
|
|
ctx, mux, endpoint, dialOpts,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 07:15:48 -08:00
|
|
|
// ServerErrChan returns an error channel that should be listened on after
|
|
|
|
|
// starting the sub-server to listen for any runtime errors. It is optional and
|
|
|
|
|
// may be set to nil. This only applies in integrated mode.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) ServerErrChan() chan error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MacPath returns the path to the sub-server's macaroon if it is not running in
|
|
|
|
|
// remote mode.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) MacPath() string {
|
|
|
|
|
return p.cfg.MacaroonPath
|
|
|
|
|
}
|
2023-05-02 08:52:28 +02:00
|
|
|
|
|
|
|
|
// Permissions returns a map of all RPC methods and their required macaroon
|
|
|
|
|
// permissions to access the sub-server.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) Permissions() map[string][]bakery.Op {
|
2025-05-26 14:06:02 +02:00
|
|
|
return poolrpc.RequiredPermissions
|
2023-05-02 08:52:28 +02:00
|
|
|
}
|
2023-08-08 21:32:18 +02:00
|
|
|
|
|
|
|
|
// WhiteListedURLs returns a map of all the sub-server's URLs that can be
|
|
|
|
|
// accessed without a macaroon.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is part of the SubServer interface.
|
|
|
|
|
func (p *poolSubServer) WhiteListedURLs() map[string]struct{} {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2024-05-23 13:52:28 +02:00
|
|
|
|
|
|
|
|
// Impl returns the actual implementation of the sub-server. This might not be
|
|
|
|
|
// set if the sub-server is running in remote mode.
|
|
|
|
|
func (p *poolSubServer) Impl() fn.Option[any] {
|
|
|
|
|
if p.Server == nil {
|
|
|
|
|
return fn.None[any]()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fn.Some[any](p.Server)
|
|
|
|
|
}
|