Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions chainregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ type chainControl struct {

signer lnwallet.Signer

keyRing keychain.KeyRing

wc lnwallet.WalletController

msgSigner lnwallet.MessageSigner

chainNotifier chainntnfs.ChainNotifier
Expand Down Expand Up @@ -502,6 +506,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
cc.msgSigner = wc
cc.signer = wc
cc.chainIO = wc
cc.wc = wc

// Select the default channel constraints for the primary chain.
channelConstraints := defaultBtcChannelConstraints
Expand All @@ -512,6 +517,7 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
keyRing := keychain.NewBtcWalletKeyRing(
wc.InternalWallet(), activeNetParams.CoinType,
)
cc.keyRing = keyRing

// Create, and start the lnwallet, which handles the core payment
// channel logic, and exposes control via proxy state machines.
Expand Down
181 changes: 47 additions & 134 deletions lnrpc/signrpc/signer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions lnrpc/signrpc/signer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ message KeyLocator {
}

message KeyDescriptor {
oneof key {
/**
The raw bytes of the key being identified. Either this or the KeyLocator
must be specified.
*/
bytes raw_key_bytes = 1;

/**
The key locator that identifies which key to use for signing. Either this
or the raw bytes of the target key must be specified.
*/
KeyLocator key_loc = 2;
}
/**
The raw bytes of the key being identified. Either this or the KeyLocator
must be specified.
*/
bytes raw_key_bytes = 1;

/**
The key locator that identifies which key to use for signing. Either this
or the raw bytes of the target key must be specified.
*/
KeyLocator key_loc = 2;
}

message TxOut {
Expand Down
41 changes: 41 additions & 0 deletions lnrpc/walletrpc/config_active.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// +build walletrpc

package walletrpc

import (
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/macaroons"
)

// Config is the primary configuration struct for the WalletKit RPC server. It
// contains all the items required for the signer rpc server to carry out its
// duties. The fields with struct tags are meant to be parsed as normal
// configuration options, while if able to be populated, the latter fields MUST
// also be specified.
type Config struct {
// WalletKitMacPath is the path for the signer macaroon. If unspecified
// then we assume that the macaroon will be found under the network
// directory, named DefaultWalletKitMacFilename.
WalletKitMacPath string `long:"walletkitmacaroonpath" description:"Path to the wallet kit macaroon"`

// NetworkDir is the main network directory wherein the signer rpc
// server will find the macaroon named DefaultWalletKitMacFilename.
NetworkDir string

// MacService is the main macaroon service that we'll use to handle
// authentication for the signer rpc server.
MacService *macaroons.Service

// FeeEstimator is an instance of the primary fee estimator instance
// the WalletKit will use to respond to fee estimation requests.
FeeEstimator lnwallet.FeeEstimator

// Wallet is the primary wallet that the WalletKit will use to proxy
// any relevant requests to.
Wallet lnwallet.WalletController

// KeyRing is an interface that the WalletKit will use to derive any
// keys due to incoming client requests.
KeyRing keychain.KeyRing
}
8 changes: 8 additions & 0 deletions lnrpc/walletrpc/config_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// +build !walletrpc

package walletrpc

// Config is the primary configuration struct for the WalletKit RPC server.
// When the server isn't active (via the build flag), callers outside this
// package will see this shell of a config file.
type Config struct{}
73 changes: 73 additions & 0 deletions lnrpc/walletrpc/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// +build walletrpc

package walletrpc

import (
"fmt"

"github.com/lightningnetwork/lnd/lnrpc"
)

// createNewSubServer is a helper method that will create the new WalletKit RPC
// sub server given the main config dispatcher method. If we're unable to find
// the config that is meant for us in the config dispatcher, then we'll exit
// with an error.
func createNewSubServer(configRegistry lnrpc.SubServerConfigDispatcher) (lnrpc.SubServer, lnrpc.MacaroonPerms, error) {
// We'll attempt to look up the config that we expect, according to our
// subServerName name. If we can't find this, then we'll exit with an
// error, as we're unable to properly initialize ourselves without this
// config.
walletKitServerConf, ok := configRegistry.FetchConfig(subServerName)
if !ok {
return nil, nil, fmt.Errorf("unable to find config for "+
"subserver type %s", subServerName)
}

// Now that we've found an object mapping to our service name, we'll
// ensure that it's the type we need.
config, ok := walletKitServerConf.(*Config)
if !ok {
return nil, nil, fmt.Errorf("wrong type of config for "+
"subserver %s, expected %T got %T", subServerName,
&Config{}, walletKitServerConf)
}

// Before we try to make the new WalletKit service instance, we'll
// perform some sanity checks on the arguments to ensure that they're
// useable.
switch {
case config.MacService != nil && config.NetworkDir == "":
return nil, nil, fmt.Errorf("NetworkDir must be set to " +
"create WalletKit RPC server")

case config.FeeEstimator == nil:
return nil, nil, fmt.Errorf("FeeEstimator must be set to " +
"create WalletKit RPC server")

case config.Wallet == nil:
return nil, nil, fmt.Errorf("Wallet must be set to create " +
"WalletKit RPC server")

case config.KeyRing == nil:
return nil, nil, fmt.Errorf("KeyRing must be set to create " +
"WalletKit RPC server")
}

return New(config)
}

func init() {
subServer := &lnrpc.SubServerDriver{
SubServerName: subServerName,
New: func(c lnrpc.SubServerConfigDispatcher) (lnrpc.SubServer, lnrpc.MacaroonPerms, error) {
return createNewSubServer(c)
},
}

// If the build tag is active, then we'll register ourselves as a
// sub-RPC server within the global lnrpc package namespace.
if err := lnrpc.RegisterSubServer(subServer); err != nil {
panic(fmt.Sprintf("failed to register sub server driver '%s': %v",
subServerName, err))
}
}
Loading