From 692486c944c0ca701b67b9d1a7bdb722daa2991f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 2 May 2017 19:42:10 -0700 Subject: [PATCH] config: add litecoin testnet4 parameters to the set of RPC parameters This commit adds the new litecoin testnet4 parameters to the set of currently supported RPC parameters. Due to the way golfing handles namespacing we had to implement a bit of a hack in order to allow both litecoin and bitcoin parameters to be used within the codebase. In the future, we may create a structure similar to chaincfg.Params _directly_ within lnd so the implementation can be a bit cleaner. --- params.go | 71 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/params.go b/params.go index 7d119f9c..9eda0038 100644 --- a/params.go +++ b/params.go @@ -1,26 +1,73 @@ package main -import "github.com/roasbeef/btcd/chaincfg" +import ( + litecoinCfg "github.com/ltcsuite/ltcd/chaincfg" + bitcoinCfg "github.com/roasbeef/btcd/chaincfg" + "github.com/roasbeef/btcd/wire" +) // activeNetParams is a pointer to the parameters specific to the currently // active bitcoin network. -var activeNetParams = testNetParams +var activeNetParams = bitcoinTestNetParams -// netParams couples the p2p parameters of a network with the corresponding RPC -// port of a daemon running on the particular network. -type netParams struct { - *chaincfg.Params +// 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 } -// testNetParams contains parameters specific to the 3rd version of the test network. -var testNetParams = netParams{ - Params: &chaincfg.TestNet3Params, +// 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 +} + +// bitcoinTestNetParams contains parameters specific to the 3rd version of the +// test network. +var bitcoinTestNetParams = bitcoinNetParams{ + Params: &bitcoinCfg.TestNet3Params, rpcPort: "18334", } -// simNetParams contains parameters specific to the simulation test network. -var simNetParams = netParams{ - Params: &chaincfg.SimNetParams, +// bitcoinSimNetParams contains parameters specific to the simulation test +// network. +var bitcoinSimNetParams = bitcoinNetParams{ + Params: &bitcoinCfg.SimNetParams, rpcPort: "18556", } + +// liteTestNetParams contains parameters specific to the 4th version of the +// test network. +var liteTestNetParams = litecoinNetParams{ + Params: &litecoinCfg.TestNet4Params, + rpcPort: "19334", +} + +// 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) { + params.Name = liteTestNetParams.Name + params.Net = wire.BitcoinNet(liteTestNetParams.Net) + params.DefaultPort = liteTestNetParams.DefaultPort + params.CoinbaseMaturity = liteTestNetParams.CoinbaseMaturity + + copy(params.GenesisHash[:], liteTestNetParams.GenesisHash[:]) + + // Address encoding magics + params.PubKeyHashAddrID = liteTestNetParams.PubKeyHashAddrID + params.ScriptHashAddrID = liteTestNetParams.ScriptHashAddrID + params.PrivateKeyID = liteTestNetParams.PrivateKeyID + params.WitnessPubKeyHashAddrID = liteTestNetParams.WitnessPubKeyHashAddrID + params.WitnessScriptHashAddrID = liteTestNetParams.WitnessScriptHashAddrID + + copy(params.HDPrivateKeyID[:], liteTestNetParams.HDPrivateKeyID[:]) + copy(params.HDPublicKeyID[:], liteTestNetParams.HDPublicKeyID[:]) + + params.HDCoinType = liteTestNetParams.HDCoinType + + params.rpcPort = liteTestNetParams.rpcPort +}