2016-07-14 04:37:50 +03:00
|
|
|
package main
|
|
|
|
|
2017-05-03 05:42:10 +03:00
|
|
|
import (
|
2018-03-13 02:31:01 +03:00
|
|
|
"github.com/lightningnetwork/lnd/keychain"
|
2017-05-03 05:42:10 +03:00
|
|
|
litecoinCfg "github.com/ltcsuite/ltcd/chaincfg"
|
2018-03-24 12:26:48 +03:00
|
|
|
litecoinWire "github.com/ltcsuite/ltcd/wire"
|
2018-06-05 04:34:16 +03:00
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
|
|
bitcoinCfg "github.com/btcsuite/btcd/chaincfg"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
|
|
bitcoinWire "github.com/btcsuite/btcd/wire"
|
2017-05-03 05:42:10 +03:00
|
|
|
)
|
2016-07-14 04:37:50 +03:00
|
|
|
|
|
|
|
// activeNetParams is a pointer to the parameters specific to the currently
|
|
|
|
// active bitcoin network.
|
2017-05-03 05:42:10 +03:00
|
|
|
var activeNetParams = bitcoinTestNetParams
|
2016-07-14 04:37:50 +03:00
|
|
|
|
2017-05-03 05:42:10 +03:00
|
|
|
// 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
|
2018-03-13 02:31:01 +03:00
|
|
|
rpcPort string
|
|
|
|
CoinType uint32
|
2016-07-14 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2017-05-03 05:42:10 +03:00
|
|
|
// 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
|
2018-03-13 02:31:01 +03:00
|
|
|
rpcPort string
|
|
|
|
CoinType uint32
|
2017-05-03 05:42:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// bitcoinTestNetParams contains parameters specific to the 3rd version of the
|
|
|
|
// test network.
|
|
|
|
var bitcoinTestNetParams = bitcoinNetParams{
|
2018-03-13 02:31:01 +03:00
|
|
|
Params: &bitcoinCfg.TestNet3Params,
|
|
|
|
rpcPort: "18334",
|
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
2016-07-14 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2018-03-15 12:00:44 +03:00
|
|
|
// bitcoinMainNetParams contains parameters specific to the current Bitcoin
|
|
|
|
// mainnet.
|
|
|
|
var bitcoinMainNetParams = bitcoinNetParams{
|
|
|
|
Params: &bitcoinCfg.MainNetParams,
|
|
|
|
rpcPort: "8334",
|
|
|
|
CoinType: keychain.CoinTypeBitcoin,
|
|
|
|
}
|
|
|
|
|
2017-05-03 05:42:10 +03:00
|
|
|
// bitcoinSimNetParams contains parameters specific to the simulation test
|
|
|
|
// network.
|
|
|
|
var bitcoinSimNetParams = bitcoinNetParams{
|
2018-03-13 02:31:01 +03:00
|
|
|
Params: &bitcoinCfg.SimNetParams,
|
|
|
|
rpcPort: "18556",
|
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
2016-07-14 04:37:50 +03:00
|
|
|
}
|
2017-05-03 05:42:10 +03:00
|
|
|
|
2018-03-15 03:08:23 +03:00
|
|
|
// litecoinTestNetParams contains parameters specific to the 4th version of the
|
2017-05-03 05:42:10 +03:00
|
|
|
// test network.
|
2018-03-15 03:08:23 +03:00
|
|
|
var litecoinTestNetParams = litecoinNetParams{
|
2018-03-13 02:31:01 +03:00
|
|
|
Params: &litecoinCfg.TestNet4Params,
|
|
|
|
rpcPort: "19334",
|
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
2017-05-03 05:42:10 +03:00
|
|
|
}
|
|
|
|
|
2018-03-15 12:00:44 +03:00
|
|
|
// litecoinMainNetParams contains the parameters specific to the current
|
|
|
|
// Litecoin mainnet.
|
|
|
|
var litecoinMainNetParams = litecoinNetParams{
|
|
|
|
Params: &litecoinCfg.MainNetParams,
|
|
|
|
rpcPort: "9334",
|
|
|
|
CoinType: keychain.CoinTypeLitecoin,
|
|
|
|
}
|
|
|
|
|
2017-07-12 02:54:43 +03:00
|
|
|
// regTestNetParams contains parameters specific to a local regtest network.
|
|
|
|
var regTestNetParams = bitcoinNetParams{
|
2018-03-13 02:31:01 +03:00
|
|
|
Params: &bitcoinCfg.RegressionNetParams,
|
|
|
|
rpcPort: "18334",
|
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
2017-07-12 02:54:43 +03:00
|
|
|
}
|
|
|
|
|
2017-05-03 05:42:10 +03:00
|
|
|
// 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.
|
2018-03-15 12:01:17 +03:00
|
|
|
func applyLitecoinParams(params *bitcoinNetParams, litecoinParams *litecoinNetParams) {
|
|
|
|
params.Name = litecoinParams.Name
|
2018-03-24 12:26:48 +03:00
|
|
|
params.Net = bitcoinWire.BitcoinNet(litecoinParams.Net)
|
2018-03-15 12:01:17 +03:00
|
|
|
params.DefaultPort = litecoinParams.DefaultPort
|
|
|
|
params.CoinbaseMaturity = litecoinParams.CoinbaseMaturity
|
2017-05-03 05:42:10 +03:00
|
|
|
|
2018-03-15 12:01:17 +03:00
|
|
|
copy(params.GenesisHash[:], litecoinParams.GenesisHash[:])
|
2017-05-03 05:42:10 +03:00
|
|
|
|
|
|
|
// Address encoding magics
|
2018-03-15 12:01:17 +03:00
|
|
|
params.PubKeyHashAddrID = litecoinParams.PubKeyHashAddrID
|
|
|
|
params.ScriptHashAddrID = litecoinParams.ScriptHashAddrID
|
|
|
|
params.PrivateKeyID = litecoinParams.PrivateKeyID
|
|
|
|
params.WitnessPubKeyHashAddrID = litecoinParams.WitnessPubKeyHashAddrID
|
|
|
|
params.WitnessScriptHashAddrID = litecoinParams.WitnessScriptHashAddrID
|
|
|
|
params.Bech32HRPSegwit = litecoinParams.Bech32HRPSegwit
|
2017-05-03 05:42:10 +03:00
|
|
|
|
2018-03-15 12:01:17 +03:00
|
|
|
copy(params.HDPrivateKeyID[:], litecoinParams.HDPrivateKeyID[:])
|
|
|
|
copy(params.HDPublicKeyID[:], litecoinParams.HDPublicKeyID[:])
|
2017-05-03 05:42:10 +03:00
|
|
|
|
2018-03-15 12:01:17 +03:00
|
|
|
params.HDCoinType = litecoinParams.HDCoinType
|
2017-05-03 05:42:10 +03:00
|
|
|
|
2018-03-15 12:01:17 +03:00
|
|
|
checkPoints := make([]chaincfg.Checkpoint, len(litecoinParams.Checkpoints))
|
|
|
|
for i := 0; i < len(litecoinParams.Checkpoints); i++ {
|
2017-09-01 13:17:19 +03:00
|
|
|
var chainHash chainhash.Hash
|
2018-03-15 12:01:17 +03:00
|
|
|
copy(chainHash[:], litecoinParams.Checkpoints[i].Hash[:])
|
2017-09-01 13:17:19 +03:00
|
|
|
|
|
|
|
checkPoints[i] = chaincfg.Checkpoint{
|
2018-03-15 12:01:17 +03:00
|
|
|
Height: litecoinParams.Checkpoints[i].Height,
|
2017-09-01 13:17:19 +03:00
|
|
|
Hash: &chainHash,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
params.Checkpoints = checkPoints
|
|
|
|
|
2018-03-15 12:01:17 +03:00
|
|
|
params.rpcPort = litecoinParams.rpcPort
|
|
|
|
params.CoinType = litecoinParams.CoinType
|
2017-05-03 05:42:10 +03:00
|
|
|
}
|
2018-03-24 12:26:48 +03:00
|
|
|
|
|
|
|
// isTestnet tests if the given 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
|
|
|
|
}
|
|
|
|
}
|