github.com/decred/dcrlnd@v0.7.6/lnwallet/dcrwallet/config.go (about)

     1  package dcrwallet
     2  
     3  import (
     4  	"path/filepath"
     5  	"time"
     6  
     7  	"github.com/decred/dcrd/chaincfg/v3"
     8  	"github.com/decred/dcrd/wire"
     9  	"github.com/decred/dcrlnd/blockcache"
    10  	"github.com/decred/dcrlnd/channeldb"
    11  	"github.com/decred/dcrlnd/lnwallet"
    12  	"github.com/decred/dcrlnd/lnwallet/chainfee"
    13  
    14  	"decred.org/dcrwallet/v4/wallet"
    15  	walletloader "github.com/decred/dcrlnd/lnwallet/dcrwallet/loader"
    16  
    17  	// This is required to register bdb as a valid walletdb driver. In the
    18  	// init function of the package, it registers itself. The import is used
    19  	// to activate the side effects w/o actually binding the package name to
    20  	// a file-level variable.
    21  	_ "decred.org/dcrwallet/v4/wallet/drivers/bdb"
    22  )
    23  
    24  // WalletSyncer is an exported interface for the available wallet sync backends
    25  // (RPC, SPV, etc). While this interface is exported to ease construction of a
    26  // Config structure, only implementations provided by this package are
    27  // supported, since currently the implementation is tightly coupled to the
    28  // DcrWallet struct.
    29  //
    30  // The current backend implementations also implement the BlockChainIO
    31  // interface.
    32  type WalletSyncer interface {
    33  	start(w *DcrWallet) error
    34  	stop()
    35  	waitForShutdown()
    36  }
    37  
    38  // Config is a struct which houses configuration parameters which modify the
    39  // instance of DcrWallet generated by the New() function.
    40  type Config struct {
    41  	// DataDir is the name of the directory where the wallet's persistent
    42  	// state should be stored.
    43  	DataDir string
    44  
    45  	// LogDir is the name of the directory which should be used to store
    46  	// generated log files.
    47  	LogDir string
    48  
    49  	// PrivatePass is the private password to the underlying dcrwallet
    50  	// instance. Without this, the wallet cannot be decrypted and operated.
    51  	PrivatePass []byte
    52  
    53  	// PublicPass is the optional public password to dcrwallet. This is
    54  	// optionally used to encrypt public material such as public keys and
    55  	// scripts.
    56  	PublicPass []byte
    57  
    58  	// HdSeed is an optional seed to feed into the wallet. If this is
    59  	// unspecified, a new seed will be generated.
    60  	HdSeed []byte
    61  
    62  	// Birthday specifies the time at which this wallet was initially
    63  	// created. It is used to bound rescans for used addresses.
    64  	Birthday time.Time
    65  
    66  	// FeeEstimator is an instance of the fee estimator interface which
    67  	// will be used by the wallet to dynamically set transaction fees when
    68  	// crafting transactions.
    69  	FeeEstimator chainfee.Estimator
    70  
    71  	// RecoveryWindow specifies the address look-ahead for which to scan
    72  	// when restoring a wallet. The recovery window will apply to all
    73  	// default BIP44 derivation paths.
    74  	RecoveryWindow uint32
    75  
    76  	// Syncer stores a specific implementation of a WalletSyncer (either an
    77  	// RPC syncer or a SPV syncer) capabale of maintaining the wallet
    78  	// backend synced to the chain.
    79  	Syncer WalletSyncer
    80  
    81  	// ChainIO is a direct connection to the blockchain IO driver needed by
    82  	// the wallet.
    83  	//
    84  	// TODO(decred) Ideally this should be performed by wallet operations
    85  	// but not all operations needed by the drivers are currently
    86  	// implemented in the wallet.
    87  	ChainIO lnwallet.BlockChainIO
    88  
    89  	// NetParams is the net parameters for the target chain.
    90  	NetParams *chaincfg.Params
    91  
    92  	// Wallet is an unlocked wallet instance that is set if the
    93  	// UnlockerService has already opened and unlocked the wallet. If this
    94  	// is nil, then a wallet might have just been created or is simply not
    95  	// encrypted at all, in which case it should be attempted to be loaded
    96  	// normally when creating the DcrWallet.
    97  	Wallet *wallet.Wallet
    98  
    99  	// Loader is the loader used to initialize the Wallet field. If Wallet
   100  	// is specified, then Loader MUST be specified as well.
   101  	Loader *walletloader.Loader
   102  
   103  	// BlockCache is an optional in-memory block cache.
   104  	BlockCache *blockcache.BlockCache
   105  
   106  	DB *channeldb.DB
   107  }
   108  
   109  // NetworkDir returns the directory name of a network directory to hold wallet
   110  // files.
   111  func NetworkDir(dataDir string, chainParams *chaincfg.Params) string {
   112  	netname := chainParams.Name
   113  	switch chainParams.Net {
   114  	case 0x48e7a065: // testnet2
   115  		netname = "testnet2"
   116  	case wire.TestNet3:
   117  		netname = "testnet3"
   118  	}
   119  	return filepath.Join(dataDir, netname)
   120  }