2020-09-29 20:00:19 +03:00
|
|
|
package chainreg
|
2016-07-14 04:37:50 +03:00
|
|
|
|
2017-05-03 05:42:10 +03:00
|
|
|
import (
|
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"
|
2018-07-18 05:23:47 +03:00
|
|
|
"github.com/lightningnetwork/lnd/keychain"
|
|
|
|
litecoinCfg "github.com/ltcsuite/ltcd/chaincfg"
|
|
|
|
litecoinWire "github.com/ltcsuite/ltcd/wire"
|
2017-05-03 05:42:10 +03:00
|
|
|
)
|
2016-07-14 04:37:50 +03:00
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// BitcoinNetParams couples the p2p parameters of a network with the
|
2017-05-03 05:42:10 +03:00
|
|
|
// corresponding RPC port of a daemon running on the particular network.
|
2020-09-29 20:00:19 +03:00
|
|
|
type BitcoinNetParams struct {
|
2017-05-03 05:42:10 +03:00
|
|
|
*bitcoinCfg.Params
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort string
|
2018-03-13 02:31:01 +03:00
|
|
|
CoinType uint32
|
2016-07-14 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// LitecoinNetParams couples the p2p parameters of a network with the
|
2017-05-03 05:42:10 +03:00
|
|
|
// corresponding RPC port of a daemon running on the particular network.
|
2020-09-29 20:00:19 +03:00
|
|
|
type LitecoinNetParams struct {
|
2017-05-03 05:42:10 +03:00
|
|
|
*litecoinCfg.Params
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort string
|
2018-03-13 02:31:01 +03:00
|
|
|
CoinType uint32
|
2017-05-03 05:42:10 +03:00
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// BitcoinTestNetParams contains parameters specific to the 3rd version of the
|
2017-05-03 05:42:10 +03:00
|
|
|
// test network.
|
2020-09-29 20:00:19 +03:00
|
|
|
var BitcoinTestNetParams = BitcoinNetParams{
|
2018-03-13 02:31:01 +03:00
|
|
|
Params: &bitcoinCfg.TestNet3Params,
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort: "18334",
|
2018-03-13 02:31:01 +03:00
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
2016-07-14 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// BitcoinMainNetParams contains parameters specific to the current Bitcoin
|
2018-03-15 12:00:44 +03:00
|
|
|
// mainnet.
|
2020-09-29 20:00:19 +03:00
|
|
|
var BitcoinMainNetParams = BitcoinNetParams{
|
2018-03-15 12:00:44 +03:00
|
|
|
Params: &bitcoinCfg.MainNetParams,
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort: "8334",
|
2018-03-15 12:00:44 +03:00
|
|
|
CoinType: keychain.CoinTypeBitcoin,
|
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// BitcoinSimNetParams contains parameters specific to the simulation test
|
2017-05-03 05:42:10 +03:00
|
|
|
// network.
|
2020-09-29 20:00:19 +03:00
|
|
|
var BitcoinSimNetParams = BitcoinNetParams{
|
2018-03-13 02:31:01 +03:00
|
|
|
Params: &bitcoinCfg.SimNetParams,
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort: "18556",
|
2018-03-13 02:31:01 +03:00
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
2016-07-14 04:37:50 +03:00
|
|
|
}
|
2017-05-03 05:42:10 +03:00
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// LitecoinSimNetParams contains parameters specific to the simulation test
|
2018-09-14 09:03:09 +03:00
|
|
|
// network.
|
2020-09-29 20:00:19 +03:00
|
|
|
var LitecoinSimNetParams = LitecoinNetParams{
|
|
|
|
Params: &litecoinCfg.TestNet4Params,
|
|
|
|
RPCPort: "18556",
|
2018-09-14 09:03:09 +03:00
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// LitecoinTestNetParams contains parameters specific to the 4th version of the
|
2017-05-03 05:42:10 +03:00
|
|
|
// test network.
|
2020-09-29 20:00:19 +03:00
|
|
|
var LitecoinTestNetParams = LitecoinNetParams{
|
2018-03-13 02:31:01 +03:00
|
|
|
Params: &litecoinCfg.TestNet4Params,
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort: "19334",
|
2018-03-13 02:31:01 +03:00
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
2017-05-03 05:42:10 +03:00
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// LitecoinMainNetParams contains the parameters specific to the current
|
2018-03-15 12:00:44 +03:00
|
|
|
// Litecoin mainnet.
|
2020-09-29 20:00:19 +03:00
|
|
|
var LitecoinMainNetParams = LitecoinNetParams{
|
2018-03-15 12:00:44 +03:00
|
|
|
Params: &litecoinCfg.MainNetParams,
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort: "9334",
|
2018-03-15 12:00:44 +03:00
|
|
|
CoinType: keychain.CoinTypeLitecoin,
|
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// LitecoinRegTestNetParams contains parameters specific to a local litecoin
|
2018-11-30 00:53:01 +03:00
|
|
|
// regtest network.
|
2020-09-29 20:00:19 +03:00
|
|
|
var LitecoinRegTestNetParams = LitecoinNetParams{
|
2018-11-30 00:53:01 +03:00
|
|
|
Params: &litecoinCfg.RegressionNetParams,
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort: "18334",
|
2018-11-30 00:53:01 +03:00
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// BitcoinRegTestNetParams contains parameters specific to a local bitcoin
|
2018-11-30 00:53:01 +03:00
|
|
|
// regtest network.
|
2020-09-29 20:00:19 +03:00
|
|
|
var BitcoinRegTestNetParams = BitcoinNetParams{
|
2018-03-13 02:31:01 +03:00
|
|
|
Params: &bitcoinCfg.RegressionNetParams,
|
2020-09-29 20:00:19 +03:00
|
|
|
RPCPort: "18334",
|
2018-03-13 02:31:01 +03:00
|
|
|
CoinType: keychain.CoinTypeTestnet,
|
2017-07-12 02:54:43 +03:00
|
|
|
}
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// ApplyLitecoinParams applies the relevant chain configuration parameters that
|
2017-05-03 05:42:10 +03:00
|
|
|
// 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.
|
2020-09-29 20:00:19 +03:00
|
|
|
func ApplyLitecoinParams(params *BitcoinNetParams,
|
|
|
|
litecoinParams *LitecoinNetParams) {
|
|
|
|
|
2018-03-15 12:01:17 +03:00
|
|
|
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
|
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
params.RPCPort = litecoinParams.RPCPort
|
2018-03-15 12:01:17 +03:00
|
|
|
params.CoinType = litecoinParams.CoinType
|
2017-05-03 05:42:10 +03:00
|
|
|
}
|
2018-03-24 12:26:48 +03:00
|
|
|
|
2020-09-29 20:00:19 +03:00
|
|
|
// IsTestnet tests if the givern params correspond to a testnet
|
2018-03-24 12:26:48 +03:00
|
|
|
// parameter configuration.
|
2020-09-29 20:00:19 +03:00
|
|
|
func IsTestnet(params *BitcoinNetParams) bool {
|
2018-03-24 12:26:48 +03:00
|
|
|
switch params.Params.Net {
|
|
|
|
case bitcoinWire.TestNet3, bitcoinWire.BitcoinNet(litecoinWire.TestNet4):
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|