|
| 1 | +//go:build dev |
| 2 | +// +build dev |
| 3 | + |
| 4 | +package perms |
| 5 | + |
| 6 | +import ( |
| 7 | + "net" |
| 8 | + |
| 9 | + "github.com/btcsuite/btcd/chaincfg" |
| 10 | + "github.com/lightningnetwork/lnd/autopilot" |
| 11 | + "github.com/lightningnetwork/lnd/chainreg" |
| 12 | + "github.com/lightningnetwork/lnd/channeldb" |
| 13 | + "github.com/lightningnetwork/lnd/lnrpc" |
| 14 | + "github.com/lightningnetwork/lnd/lnrpc/autopilotrpc" |
| 15 | + "github.com/lightningnetwork/lnd/lnrpc/chainrpc" |
| 16 | + "github.com/lightningnetwork/lnd/lnrpc/devrpc" |
| 17 | + "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" |
| 18 | + "github.com/lightningnetwork/lnd/lnrpc/neutrinorpc" |
| 19 | + "github.com/lightningnetwork/lnd/lnrpc/peersrpc" |
| 20 | + "github.com/lightningnetwork/lnd/lnrpc/routerrpc" |
| 21 | + "github.com/lightningnetwork/lnd/lnrpc/signrpc" |
| 22 | + "github.com/lightningnetwork/lnd/lnrpc/walletrpc" |
| 23 | + "github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc" |
| 24 | + "github.com/lightningnetwork/lnd/lnrpc/wtclientrpc" |
| 25 | + "github.com/lightningnetwork/lnd/lntest/mock" |
| 26 | + "github.com/lightningnetwork/lnd/routing" |
| 27 | + "github.com/lightningnetwork/lnd/sweep" |
| 28 | +) |
| 29 | + |
| 30 | +// mockConfig implements lnrpc.SubServerConfigDispatcher. It provides the |
| 31 | +// functionality required so that the lnrpc.GrpcHandler.CreateSubServer |
| 32 | +// function can be called without panicking. |
| 33 | +type mockConfig struct{} |
| 34 | + |
| 35 | +var _ lnrpc.SubServerConfigDispatcher = (*mockConfig)(nil) |
| 36 | + |
| 37 | +// FetchConfig is a mock implementation of lnrpc.SubServerConfigDispatcher. It |
| 38 | +// is used as a parameter to lnrpc.GrpcHandler.CreateSubServer and allows the |
| 39 | +// function to be called without panicking. This is useful because |
| 40 | +// CreateSubServer can be used to extract the permissions required by each |
| 41 | +// registered subserver. |
| 42 | +// |
| 43 | +// TODO(elle): remove this once the sub-server permission lists in LND have been |
| 44 | +// exported |
| 45 | +func (t *mockConfig) FetchConfig(subServerName string) (interface{}, bool) { |
| 46 | + switch subServerName { |
| 47 | + case "InvoicesRPC": |
| 48 | + return &invoicesrpc.Config{}, true |
| 49 | + case "WatchtowerClientRPC": |
| 50 | + return &wtclientrpc.Config{ |
| 51 | + Resolver: func(_, _ string) (*net.TCPAddr, error) { |
| 52 | + return nil, nil |
| 53 | + }, |
| 54 | + }, true |
| 55 | + case "AutopilotRPC": |
| 56 | + return &autopilotrpc.Config{ |
| 57 | + Manager: &autopilot.Manager{}, |
| 58 | + }, true |
| 59 | + case "ChainRPC": |
| 60 | + return &chainrpc.Config{ |
| 61 | + ChainNotifier: &chainreg.NoChainBackend{}, |
| 62 | + Chain: &mock.ChainIO{}, |
| 63 | + }, true |
| 64 | + case "DevRPC": |
| 65 | + return &devrpc.Config{ |
| 66 | + ActiveNetParams: &chaincfg.RegressionNetParams, |
| 67 | + GraphDB: &channeldb.ChannelGraph{}, |
| 68 | + }, true |
| 69 | + case "NeutrinoKitRPC": |
| 70 | + return &neutrinorpc.Config{}, true |
| 71 | + case "PeersRPC": |
| 72 | + return &peersrpc.Config{}, true |
| 73 | + case "RouterRPC": |
| 74 | + return &routerrpc.Config{ |
| 75 | + Router: &routing.ChannelRouter{}, |
| 76 | + }, true |
| 77 | + case "SignRPC": |
| 78 | + return &signrpc.Config{ |
| 79 | + Signer: &mock.DummySigner{}, |
| 80 | + }, true |
| 81 | + case "WalletKitRPC": |
| 82 | + return &walletrpc.Config{ |
| 83 | + FeeEstimator: &chainreg.NoChainBackend{}, |
| 84 | + Wallet: &mock.WalletController{}, |
| 85 | + KeyRing: &mock.SecretKeyRing{}, |
| 86 | + Sweeper: &sweep.UtxoSweeper{}, |
| 87 | + Chain: &mock.ChainIO{}, |
| 88 | + }, true |
| 89 | + case "WatchtowerRPC": |
| 90 | + return &watchtowerrpc.Config{}, true |
| 91 | + default: |
| 92 | + return nil, false |
| 93 | + } |
| 94 | +} |
0 commit comments