mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-18 19:41:21 +02:00
chainreg: add Config, move chainparams.go
Creates a Config that initializes the chainregistry struct in the lnd package. Also moves all of chainparams.go to the chainreg package.
This commit is contained in:
145
chainreg/chainparams.go
Normal file
145
chainreg/chainparams.go
Normal file
@@ -0,0 +1,145 @@
|
||||
package chainreg
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
bitcoinCfg "github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
bitcoinWire "github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
litecoinCfg "github.com/ltcsuite/ltcd/chaincfg"
|
||||
litecoinWire "github.com/ltcsuite/ltcd/wire"
|
||||
)
|
||||
|
||||
// BitcoinNetParams couples the p2p parameters of a network with the
|
||||
// corresponding RPC port of a daemon running on the particular network.
|
||||
type BitcoinNetParams struct {
|
||||
*bitcoinCfg.Params
|
||||
RPCPort string
|
||||
CoinType uint32
|
||||
}
|
||||
|
||||
// LitecoinNetParams couples the p2p parameters of a network with the
|
||||
// corresponding RPC port of a daemon running on the particular network.
|
||||
type LitecoinNetParams struct {
|
||||
*litecoinCfg.Params
|
||||
RPCPort string
|
||||
CoinType uint32
|
||||
}
|
||||
|
||||
// BitcoinTestNetParams contains parameters specific to the 3rd version of the
|
||||
// test network.
|
||||
var BitcoinTestNetParams = BitcoinNetParams{
|
||||
Params: &bitcoinCfg.TestNet3Params,
|
||||
RPCPort: "18334",
|
||||
CoinType: keychain.CoinTypeTestnet,
|
||||
}
|
||||
|
||||
// BitcoinMainNetParams contains parameters specific to the current Bitcoin
|
||||
// mainnet.
|
||||
var BitcoinMainNetParams = BitcoinNetParams{
|
||||
Params: &bitcoinCfg.MainNetParams,
|
||||
RPCPort: "8334",
|
||||
CoinType: keychain.CoinTypeBitcoin,
|
||||
}
|
||||
|
||||
// BitcoinSimNetParams contains parameters specific to the simulation test
|
||||
// network.
|
||||
var BitcoinSimNetParams = BitcoinNetParams{
|
||||
Params: &bitcoinCfg.SimNetParams,
|
||||
RPCPort: "18556",
|
||||
CoinType: keychain.CoinTypeTestnet,
|
||||
}
|
||||
|
||||
// LitecoinSimNetParams contains parameters specific to the simulation test
|
||||
// network.
|
||||
var LitecoinSimNetParams = LitecoinNetParams{
|
||||
Params: &litecoinCfg.TestNet4Params,
|
||||
RPCPort: "18556",
|
||||
CoinType: keychain.CoinTypeTestnet,
|
||||
}
|
||||
|
||||
// LitecoinTestNetParams contains parameters specific to the 4th version of the
|
||||
// test network.
|
||||
var LitecoinTestNetParams = LitecoinNetParams{
|
||||
Params: &litecoinCfg.TestNet4Params,
|
||||
RPCPort: "19334",
|
||||
CoinType: keychain.CoinTypeTestnet,
|
||||
}
|
||||
|
||||
// LitecoinMainNetParams contains the parameters specific to the current
|
||||
// Litecoin mainnet.
|
||||
var LitecoinMainNetParams = LitecoinNetParams{
|
||||
Params: &litecoinCfg.MainNetParams,
|
||||
RPCPort: "9334",
|
||||
CoinType: keychain.CoinTypeLitecoin,
|
||||
}
|
||||
|
||||
// LitecoinRegTestNetParams contains parameters specific to a local litecoin
|
||||
// regtest network.
|
||||
var LitecoinRegTestNetParams = LitecoinNetParams{
|
||||
Params: &litecoinCfg.RegressionNetParams,
|
||||
RPCPort: "18334",
|
||||
CoinType: keychain.CoinTypeTestnet,
|
||||
}
|
||||
|
||||
// BitcoinRegTestNetParams contains parameters specific to a local bitcoin
|
||||
// regtest network.
|
||||
var BitcoinRegTestNetParams = BitcoinNetParams{
|
||||
Params: &bitcoinCfg.RegressionNetParams,
|
||||
RPCPort: "18334",
|
||||
CoinType: keychain.CoinTypeTestnet,
|
||||
}
|
||||
|
||||
// ApplyLitecoinParams applies the relevant chain configuration parameters that
|
||||
// differ for litecoin to the chain parameters typed for btcsuite derivation.
|
||||
// This function is used in place of using something like interface{} to
|
||||
// abstract over _which_ chain (or fork) the parameters are for.
|
||||
func ApplyLitecoinParams(params *BitcoinNetParams,
|
||||
litecoinParams *LitecoinNetParams) {
|
||||
|
||||
params.Name = litecoinParams.Name
|
||||
params.Net = bitcoinWire.BitcoinNet(litecoinParams.Net)
|
||||
params.DefaultPort = litecoinParams.DefaultPort
|
||||
params.CoinbaseMaturity = litecoinParams.CoinbaseMaturity
|
||||
|
||||
copy(params.GenesisHash[:], litecoinParams.GenesisHash[:])
|
||||
|
||||
// Address encoding magics
|
||||
params.PubKeyHashAddrID = litecoinParams.PubKeyHashAddrID
|
||||
params.ScriptHashAddrID = litecoinParams.ScriptHashAddrID
|
||||
params.PrivateKeyID = litecoinParams.PrivateKeyID
|
||||
params.WitnessPubKeyHashAddrID = litecoinParams.WitnessPubKeyHashAddrID
|
||||
params.WitnessScriptHashAddrID = litecoinParams.WitnessScriptHashAddrID
|
||||
params.Bech32HRPSegwit = litecoinParams.Bech32HRPSegwit
|
||||
|
||||
copy(params.HDPrivateKeyID[:], litecoinParams.HDPrivateKeyID[:])
|
||||
copy(params.HDPublicKeyID[:], litecoinParams.HDPublicKeyID[:])
|
||||
|
||||
params.HDCoinType = litecoinParams.HDCoinType
|
||||
|
||||
checkPoints := make([]chaincfg.Checkpoint, len(litecoinParams.Checkpoints))
|
||||
for i := 0; i < len(litecoinParams.Checkpoints); i++ {
|
||||
var chainHash chainhash.Hash
|
||||
copy(chainHash[:], litecoinParams.Checkpoints[i].Hash[:])
|
||||
|
||||
checkPoints[i] = chaincfg.Checkpoint{
|
||||
Height: litecoinParams.Checkpoints[i].Height,
|
||||
Hash: &chainHash,
|
||||
}
|
||||
}
|
||||
params.Checkpoints = checkPoints
|
||||
|
||||
params.RPCPort = litecoinParams.RPCPort
|
||||
params.CoinType = litecoinParams.CoinType
|
||||
}
|
||||
|
||||
// IsTestnet tests if the givern params correspond to a testnet
|
||||
// parameter configuration.
|
||||
func IsTestnet(params *BitcoinNetParams) bool {
|
||||
switch params.Params.Net {
|
||||
case bitcoinWire.TestNet3, bitcoinWire.BitcoinNet(litecoinWire.TestNet4):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
78
chainreg/chainregistry.go
Normal file
78
chainreg/chainregistry.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package chainreg
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcwallet/wallet"
|
||||
"github.com/lightninglabs/neutrino"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lncfg"
|
||||
)
|
||||
|
||||
// Config houses necessary fields that a chainControl instance needs to
|
||||
// function.
|
||||
type Config struct {
|
||||
// Bitcoin defines settings for the Bitcoin chain.
|
||||
Bitcoin *lncfg.Chain
|
||||
|
||||
// Litecoin defines settings for the Litecoin chain.
|
||||
Litecoin *lncfg.Chain
|
||||
|
||||
// PrimaryChain is a function that returns our primary chain via its
|
||||
// ChainCode.
|
||||
PrimaryChain func() ChainCode
|
||||
|
||||
// HeightHintCacheQueryDisable is a boolean that disables height hint
|
||||
// queries if true.
|
||||
HeightHintCacheQueryDisable bool
|
||||
|
||||
// NeutrinoMode defines settings for connecting to a neutrino light-client.
|
||||
NeutrinoMode *lncfg.Neutrino
|
||||
|
||||
// BitcoindMode defines settings for connecting to a bitcoind node.
|
||||
BitcoindMode *lncfg.Bitcoind
|
||||
|
||||
// LitecoindMode defines settings for connecting to a litecoind node.
|
||||
LitecoindMode *lncfg.Bitcoind
|
||||
|
||||
// BtcdMode defines settings for connecting to a btcd node.
|
||||
BtcdMode *lncfg.Btcd
|
||||
|
||||
// LtcdMode defines settings for connecting to an ltcd node.
|
||||
LtcdMode *lncfg.Btcd
|
||||
|
||||
// LocalChanDB is a pointer to the local backing channel database.
|
||||
LocalChanDB *channeldb.DB
|
||||
|
||||
// RemoteChanDB is a pointer to the remote backing channel database.
|
||||
RemoteChanDB *channeldb.DB
|
||||
|
||||
// PrivateWalletPw is the private wallet password to the underlying
|
||||
// btcwallet instance.
|
||||
PrivateWalletPw []byte
|
||||
|
||||
// PublicWalletPw is the public wallet password to the underlying btcwallet
|
||||
// instance.
|
||||
PublicWalletPw []byte
|
||||
|
||||
// Birthday specifies the time the wallet was initially created.
|
||||
Birthday time.Time
|
||||
|
||||
// RecoveryWindow specifies the address look-ahead for which to scan when
|
||||
// restoring a wallet.
|
||||
RecoveryWindow uint32
|
||||
|
||||
// Wallet is a pointer to the backing wallet instance.
|
||||
Wallet *wallet.Wallet
|
||||
|
||||
// NeutrinoCS is a pointer to a neutrino ChainService. Must be non-nil if
|
||||
// using neutrino.
|
||||
NeutrinoCS *neutrino.ChainService
|
||||
|
||||
// ActiveNetParams details the current chain we are on.
|
||||
ActiveNetParams BitcoinNetParams
|
||||
|
||||
// FeeURL defines the URL for fee estimation we will use. This field is
|
||||
// optional.
|
||||
FeeURL string
|
||||
}
|
Reference in New Issue
Block a user