multi: Add Taproot Assets subserver

This commit is contained in:
positiveblue 2023-05-03 16:59:42 -07:00 committed by Oliver Gugger
parent 91316901e2
commit 4be6ffb31f
No known key found for this signature in database
GPG key ID: 8E4256593F177720
9 changed files with 1406 additions and 88 deletions

View file

@ -24,6 +24,7 @@ import (
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop/loopd"
"github.com/lightninglabs/pool"
"github.com/lightninglabs/taproot-assets/tapcfg"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/cert"
@ -46,6 +47,7 @@ const (
defaultFaradayMode = ModeIntegrated
defaultLoopMode = ModeIntegrated
defaultPoolMode = ModeIntegrated
defaultTapMode = ModeIntegrated
defaultConfigFilename = "lit.conf"
@ -68,9 +70,11 @@ const (
defaultRemoteFaradayRpcServer = "localhost:8465"
defaultRemoteLoopRpcServer = "localhost:11010"
defaultRemotePoolRpcServer = "localhost:12010"
defaultLndChainSubDir = "chain"
defaultLndChain = "bitcoin"
defaultLndMacaroon = "admin.macaroon"
defaultRemoteTapRpcServer = "localhost:10029"
defaultLndChainSubDir = "chain"
defaultLndChain = "bitcoin"
defaultLndMacaroon = "admin.macaroon"
// DefaultAutogenValidity is the default validity of a self-signed
// certificate. The value corresponds to 14 months
@ -89,6 +93,7 @@ var (
faradayDefaultConfig = faraday.DefaultConfig()
loopDefaultConfig = loopd.DefaultConfig()
poolDefaultConfig = pool.DefaultConfig()
tapDefaultConfig = tapcfg.DefaultConfig()
// DefaultLitDir is the default directory where LiT tries to find its
// configuration file and store its data (in remote lnd node). This is a
@ -190,6 +195,9 @@ type Config struct {
PoolMode string `long:"pool-mode" description:"The mode to run pool in, either 'integrated' (default) or 'remote'. 'integrated' means poold is started alongside the UI and everything is stored in pool's main data directory, configure everything by using the --pool.* flags. 'remote' means the UI connects to an existing poold node and acts as a proxy for gRPC calls to it." choice:"integrated" choice:"remote"`
Pool *pool.Config `group:"Integrated pool options (use when pool-mode=integrated)" namespace:"pool"`
TaprootAssetsMode string `long:"taproot-assets-mode" description:"The mode to run taproot assets in, either 'integrated' (default) or 'remote'. 'integrated' means tapd is started alongside the UI and everything is stored in tap's main data directory, configure everything by using the --taproot-assets.* flags. 'remote' means the UI connects to an existing tapd node and acts as a proxy for gRPC calls to it." choice:"integrated" choice:"remote"`
TaprootAssets *tapcfg.Config `group:"Integrated taproot assets options (use when taproot-assets=integrated)" namespace:"taproot-assets"`
RPCMiddleware *mid.Config `group:"RPC middleware options" namespace:"rpcmiddleware"`
Autopilot *autopilotserver.Config `group:"Autopilot server options" namespace:"autopilot"`
@ -206,6 +214,7 @@ type Config struct {
faradayRemote bool
loopRemote bool
poolRemote bool
tapRemote bool
// lndAdminMacaroon is the admin macaroon that is given to us by lnd
// over an in-memory connection on startup. This is only set in
@ -281,6 +290,11 @@ func defaultConfig() *Config {
MacaroonPath: poolDefaultConfig.MacaroonPath,
TLSCertPath: poolDefaultConfig.TLSCertPath,
},
TaprootAssets: &subservers.RemoteDaemonConfig{
RPCServer: defaultRemoteTapRpcServer,
MacaroonPath: tapDefaultConfig.RpcConf.MacaroonPath,
TLSCertPath: tapDefaultConfig.RpcConf.TLSCertPath,
},
},
Network: DefaultNetwork,
LndMode: DefaultLndMode,
@ -297,6 +311,8 @@ func defaultConfig() *Config {
Loop: &loopDefaultConfig,
PoolMode: defaultPoolMode,
Pool: &poolDefaultConfig,
TaprootAssetsMode: defaultTapMode,
TaprootAssets: &tapDefaultConfig,
RPCMiddleware: mid.DefaultConfig(),
FirstLNCConnDeadline: defaultFirstLNCConnTimeout,
Autopilot: &autopilotserver.Config{
@ -347,6 +363,7 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
cfg.faradayRemote = cfg.FaradayMode == ModeRemote
cfg.loopRemote = cfg.LoopMode == ModeRemote
cfg.poolRemote = cfg.PoolMode == ModeRemote
cfg.tapRemote = cfg.TaprootAssetsMode == ModeRemote
// Now that we've registered all loggers, let's parse, validate, and set
// the debug log level(s). In remote lnd mode we have a global log level
@ -445,6 +462,11 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
return nil, err
}
cfg.TaprootAssets, err = tapcfg.ValidateConfig(*cfg.TaprootAssets, log)
if err != nil {
return nil, err
}
// We've set the network before and have now validated the loop config
// which updated its default paths for that network. So if we're in
// remote mode and not mainnet, we want to update our default paths for
@ -493,6 +515,19 @@ func loadAndValidateConfig(interceptor signal.Interceptor) (*Config, error) {
}
}
defaultTapCfg := tapcfg.DefaultConfig()
if cfg.tapRemote && cfg.Network != DefaultNetwork {
if cfg.Remote.TaprootAssets.MacaroonPath == defaultTapCfg.RpcConf.MacaroonPath {
macaroonPath := cfg.TaprootAssets.RpcConf.MacaroonPath
cfg.Remote.TaprootAssets.MacaroonPath = macaroonPath
}
if cfg.Remote.TaprootAssets.TLSCertPath == defaultTapCfg.RpcConf.TLSCertPath {
tlsCertPath := cfg.TaprootAssets.RpcConf.TLSCertPath
cfg.Remote.TaprootAssets.TLSCertPath = tlsCertPath
}
}
return cfg, nil
}
@ -692,6 +727,7 @@ func setNetwork(cfg *Config) error {
cfg.Faraday.Network = cfg.Network
cfg.Loop.Network = cfg.Network
cfg.Pool.Network = cfg.Network
cfg.TaprootAssets.ChainConf.Network = cfg.Network
return nil
}

93
go.mod
View file

@ -22,6 +22,7 @@ require (
github.com/lightninglabs/pool v0.6.2-beta.0.20230329135228-c3bffb52df3a
github.com/lightninglabs/pool/auctioneerrpc v1.1.0
github.com/lightninglabs/protobuf-hex-display v1.4.3-hex-display
github.com/lightninglabs/taproot-assets v0.2.0
github.com/lightningnetwork/lnd v0.16.2-beta
github.com/lightningnetwork/lnd/cert v1.2.1
github.com/lightningnetwork/lnd/kvdb v1.4.1
@ -35,15 +36,18 @@ require (
golang.org/x/crypto v0.7.0
golang.org/x/net v0.8.0
golang.org/x/sync v0.1.0
google.golang.org/grpc v1.41.0
google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.28.1
gopkg.in/macaroon-bakery.v2 v2.1.0
gopkg.in/macaroon.v2 v2.1.0
)
require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e // indirect
github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/Yawning/aez v0.0.0-20211027044916-e49e68abd344 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/aead/siphash v1.0.1 // indirect
@ -58,8 +62,10 @@ require (
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
github.com/btcsuite/winsvc v1.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/caddyserver/certmagic v0.17.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
@ -70,40 +76,54 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/decred/dcrd/lru v1.0.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/docker/cli v20.10.14+incompatible // indirect
github.com/docker/docker v20.10.13+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fergusstrange/embedded-postgres v1.10.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/golang-migrate/migrate/v4 v4.15.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.10.0 // indirect
github.com/jackc/pgconn v1.12.0 // indirect
github.com/jackc/pgerrcode v0.0.0-20201024163028-a0d42d470451 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.1.1 // indirect
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.8.1 // indirect
github.com/jackc/pgx/v4 v4.13.0 // indirect
github.com/jackc/puddle v1.1.3 // indirect
github.com/jackc/pgtype v1.11.0 // indirect
github.com/jackc/pgx/v4 v4.16.0 // indirect
github.com/jackc/puddle v1.2.1 // indirect
github.com/jackpal/gateway v1.0.5 // indirect
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad // indirect
github.com/jedib0t/go-pretty/v6 v6.2.7 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/jrick/logrotate v1.0.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/loggo v0.0.0-20210728185423-eebad3a902c4 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kkdai/bstream v1.0.0 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/klauspost/pgzip v1.2.5 // indirect
github.com/lib/pq v1.10.3 // indirect
github.com/libdns/libdns v0.2.1 // indirect
github.com/lightninglabs/gozmq v0.0.0-20191113021534-d20a764486bf // indirect
github.com/lightninglabs/lightning-node-connect/hashmailrpc v1.0.2 // indirect
github.com/lightninglabs/neutrino v0.15.0 // indirect
@ -116,26 +136,35 @@ require (
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mholt/acmez v1.0.4 // indirect
github.com/mholt/archiver/v3 v3.5.0 // indirect
github.com/miekg/dns v1.1.43 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nwaples/rardecode v1.1.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runc v1.1.2 // indirect
github.com/ory/dockertest/v3 v3.9.1 // indirect
github.com/pierrec/lz4/v4 v4.1.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/prometheus/common v0.30.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/fastuuid v1.2.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/soheilhy/cmux v0.1.5 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
@ -143,6 +172,9 @@ require (
github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802 // indirect
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect
@ -153,24 +185,25 @@ require (
go.etcd.io/etcd/pkg/v3 v3.5.7 // indirect
go.etcd.io/etcd/raft/v3 v3.5.7 // indirect
go.etcd.io/etcd/server/v3 v3.5.7 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.25.0 // indirect
go.opentelemetry.io/otel v1.0.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.0.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.0.1 // indirect
go.opentelemetry.io/otel/sdk v1.0.1 // indirect
go.opentelemetry.io/otel/trace v1.0.1 // indirect
go.opentelemetry.io/proto/otlp v0.9.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0 // indirect
go.opentelemetry.io/otel v1.3.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.3.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.3.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.3.0 // indirect
go.opentelemetry.io/otel/sdk v1.3.0 // indirect
go.opentelemetry.io/otel/trace v1.3.0 // indirect
go.opentelemetry.io/proto/otlp v0.11.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/exp v0.0.0-20221111094246-ab4555d3164f // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced // indirect
google.golang.org/genproto v0.0.0-20220314164441-57ef72a4c106 // indirect
gopkg.in/errgo.v1 v1.0.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
@ -178,11 +211,11 @@ require (
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.22.2 // indirect
modernc.org/libc v1.22.3 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.20.3 // indirect
modernc.org/sqlite v1.21.0 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
nhooyr.io/websocket v1.8.7 // indirect

1171
go.sum

File diff suppressed because it is too large Load diff

View file

@ -29,6 +29,7 @@ import (
"github.com/lightninglabs/loop/looprpc"
pool "github.com/lightninglabs/pool/perms"
"github.com/lightninglabs/pool/poolrpc"
tap "github.com/lightninglabs/taproot-assets/perms"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@ -647,7 +648,7 @@ func runGRPCAuthTest(t *testing.T, hostPort, tlsCertPath, macPath string,
// Then finally we try with the correct macaroon which should now
// succeed.
macBytes, err := ioutil.ReadFile(macPath)
macBytes, err := os.ReadFile(macPath)
require.NoError(t, err)
ctxm = macaroonContext(ctxt, macBytes)
resp, err := makeRequest(ctxm, rawConn)
@ -1099,6 +1100,7 @@ func bakeSuperMacaroon(cfg *LitNodeConfig, readOnly bool) (string, error) {
permsMgr.RegisterSubServer(
subservers.FARADAY, faraday.RequiredPermissions,
)
permsMgr.RegisterSubServer(subservers.TAP, tap.RequiredPermissions)
superMacPermissions := permsMgr.ActivePermissions(readOnly)
nullID := [4]byte{}

2
log.go
View file

@ -13,6 +13,7 @@ import (
"github.com/lightninglabs/lightning-terminal/subservers"
"github.com/lightninglabs/loop/loopd"
"github.com/lightninglabs/pool"
tap "github.com/lightninglabs/taproot-assets"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/signal"
@ -86,6 +87,7 @@ func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
faraday.SetupLoggers(root, intercept)
loopd.SetupLoggers(root, intercept)
pool.SetupLoggers(root, intercept)
tap.SetupLoggers(root, intercept)
// Setup the gRPC loggers too.
grpclog.SetLoggerV2(NewGrpcLogLogger(root, intercept, GrpcLogSubsystem))

View file

@ -9,10 +9,11 @@ type RemoteConfig struct {
LitDebugLevel string `long:"lit-debuglevel" description:"For lnd remote mode only: Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems."`
Lnd *RemoteDaemonConfig `group:"Remote lnd (use when lnd-mode=remote)" namespace:"lnd"`
Faraday *RemoteDaemonConfig `group:"Remote faraday (use when faraday-mode=remote)" namespace:"faraday"`
Loop *RemoteDaemonConfig `group:"Remote loop (use when loop-mode=remote)" namespace:"loop"`
Pool *RemoteDaemonConfig `group:"Remote pool (use when pool-mode=remote)" namespace:"pool"`
Lnd *RemoteDaemonConfig `group:"Remote lnd (use when lnd-mode=remote)" namespace:"lnd"`
Faraday *RemoteDaemonConfig `group:"Remote faraday (use when faraday-mode=remote)" namespace:"faraday"`
Loop *RemoteDaemonConfig `group:"Remote loop (use when loop-mode=remote)" namespace:"loop"`
Pool *RemoteDaemonConfig `group:"Remote pool (use when pool-mode=remote)" namespace:"pool"`
TaprootAssets *RemoteDaemonConfig `group:"Remote taproot-assets (use when taproot-assets-mode=remote)" namespace:"taproot-assets"`
}
// RemoteDaemonConfig holds the configuration parameters that are needed to

View file

@ -15,6 +15,7 @@ const (
LIT string = "lit"
LOOP string = "loop"
POOL string = "pool"
TAP string = "taproot-assets"
FARADAY string = "faraday"
)

View file

@ -0,0 +1,167 @@
package subservers
import (
"context"
restProxy "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/lightninglabs/lndclient"
tap "github.com/lightninglabs/taproot-assets"
"github.com/lightninglabs/taproot-assets/perms"
"github.com/lightninglabs/taproot-assets/tapcfg"
"github.com/lightninglabs/taproot-assets/taprpc"
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
"github.com/lightningnetwork/lnd/lnrpc"
"google.golang.org/grpc"
"gopkg.in/macaroon-bakery.v2/bakery"
)
// taprootAssetsSubServer implements the SubServer interface.
type taprootAssetsSubServer struct {
*tap.Server
remote bool
cfg *tapcfg.Config
remoteCfg *RemoteDaemonConfig
errChan chan error
}
// A compile-time check to ensure that taprootAssetsSubServer implements
// SubServer.
var _ SubServer = (*taprootAssetsSubServer)(nil)
// NewTaprootAssetsSubServer returns a new tap implementation of the SubServer
// interface.
func NewTaprootAssetsSubServer(cfg *tapcfg.Config,
remoteCfg *RemoteDaemonConfig, remote bool) SubServer {
// Overwrite the tap daemon's user agent name, so it sends "litd"
// instead of "tapd".
tap.SetAgentName("litd")
return &taprootAssetsSubServer{
cfg: cfg,
remoteCfg: remoteCfg,
remote: remote,
errChan: make(chan error, 1),
}
}
// Name returns the name of the sub-server.
//
// NOTE: this is part of the SubServer interface.
func (t *taprootAssetsSubServer) Name() string {
return TAP
}
// 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 (t *taprootAssetsSubServer) Remote() bool {
return t.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 (t *taprootAssetsSubServer) RemoteConfig() *RemoteDaemonConfig {
return t.remoteCfg
}
// Start starts the sub-server in integrated mode.
//
// NOTE: this is part of the SubServer interface.
func (t *taprootAssetsSubServer) Start(_ lnrpc.LightningClient,
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error {
t.cfg.RpcConf.NoMacaroons = !withMacaroonService
var err error
t.cfg, err = tapcfg.ValidateConfig(*t.cfg, log)
if err != nil {
return err
}
server, err := tapcfg.CreateSubServerFromConfig(
t.cfg, log, &lndGrpc.LndServices, t.errChan,
)
if err != nil {
return err
}
t.Server = server
return t.StartAsSubserver(lndGrpc)
}
// RegisterGrpcService must register the sub-server's GRPC server with the given
// registrar.
//
// NOTE: this is part of the SubServer interface.
func (t *taprootAssetsSubServer) RegisterGrpcService(
registrar grpc.ServiceRegistrar) {
taprpc.RegisterTaprootAssetsServer(registrar, t)
mintrpc.RegisterMintServer(registrar, t)
assetwalletrpc.RegisterAssetWalletServer(registrar, t)
}
// RegisterRestService registers the sub-server's REST handlers with the given
// endpoint.
//
// NOTE: this is part of the SubServer interface.
func (t *taprootAssetsSubServer) RegisterRestService(ctx context.Context,
mux *restProxy.ServeMux, endpoint string,
dialOpts []grpc.DialOption) error {
err := taprpc.RegisterTaprootAssetsHandlerFromEndpoint(
ctx, mux, endpoint, dialOpts,
)
if err != nil {
return err
}
err = mintrpc.RegisterMintHandlerFromEndpoint(
ctx, mux, endpoint, dialOpts,
)
if err != nil {
return err
}
err = assetwalletrpc.RegisterAssetWalletHandlerFromEndpoint(
ctx, mux, endpoint, dialOpts,
)
if err != nil {
return err
}
return nil
}
// 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 (t *taprootAssetsSubServer) ServerErrChan() chan error {
return t.errChan
}
// 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 (t *taprootAssetsSubServer) MacPath() string {
return t.cfg.RpcConf.MacaroonPath
}
// 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 (t *taprootAssetsSubServer) Permissions() map[string][]bakery.Op {
return perms.RequiredPermissions
}

View file

@ -1421,6 +1421,11 @@ func (g *LightningTerminal) initSubServers() {
g.subServerMgr.AddServer(subservers.NewPoolSubServer(
g.cfg.Pool, g.cfg.Remote.Pool, g.cfg.poolRemote,
))
g.subServerMgr.AddServer(subservers.NewTaprootAssetsSubServer(
g.cfg.TaprootAssets, g.cfg.Remote.TaprootAssets,
g.cfg.tapRemote,
))
}
// BakeSuperMacaroon uses the lnd client to bake a macaroon that can include