2018-06-08 07:23:28 -06:00
|
|
|
package dash
|
|
|
|
|
|
|
|
import (
|
|
|
|
"blockbook/bchain/coins/btc"
|
|
|
|
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
2018-09-06 00:56:29 -06:00
|
|
|
"github.com/jakm/btcutil/chaincfg"
|
2018-06-08 07:23:28 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
MainnetMagic wire.BitcoinNet = 0xbd6b0cbf
|
|
|
|
TestnetMagic wire.BitcoinNet = 0xffcae2ce
|
|
|
|
RegtestMagic wire.BitcoinNet = 0xdcb7c1fc
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
MainNetParams chaincfg.Params
|
|
|
|
TestNetParams chaincfg.Params
|
|
|
|
RegtestParams chaincfg.Params
|
|
|
|
)
|
|
|
|
|
2018-09-28 14:54:08 -06:00
|
|
|
func initParams() {
|
2018-06-08 07:23:28 -06:00
|
|
|
MainNetParams = chaincfg.MainNetParams
|
|
|
|
MainNetParams.Net = MainnetMagic
|
|
|
|
|
|
|
|
// Address encoding magics
|
2018-09-06 00:56:29 -06:00
|
|
|
MainNetParams.PubKeyHashAddrID = []byte{76} // base58 prefix: X
|
|
|
|
MainNetParams.ScriptHashAddrID = []byte{16} // base58 prefix: 7
|
2018-06-08 07:23:28 -06:00
|
|
|
|
|
|
|
TestNetParams = chaincfg.TestNet3Params
|
|
|
|
TestNetParams.Net = TestnetMagic
|
|
|
|
|
|
|
|
// Address encoding magics
|
2018-09-06 00:56:29 -06:00
|
|
|
TestNetParams.PubKeyHashAddrID = []byte{140} // base58 prefix: y
|
|
|
|
TestNetParams.ScriptHashAddrID = []byte{19} // base58 prefix: 8 or 9
|
2018-06-08 07:23:28 -06:00
|
|
|
|
|
|
|
RegtestParams = chaincfg.RegressionNetParams
|
|
|
|
RegtestParams.Net = RegtestMagic
|
|
|
|
|
|
|
|
// Address encoding magics
|
2018-09-06 00:56:29 -06:00
|
|
|
RegtestParams.PubKeyHashAddrID = []byte{140} // base58 prefix: y
|
|
|
|
RegtestParams.ScriptHashAddrID = []byte{19} // base58 prefix: 8 or 9
|
2018-06-08 07:23:28 -06:00
|
|
|
|
|
|
|
err := chaincfg.Register(&MainNetParams)
|
|
|
|
if err == nil {
|
|
|
|
err = chaincfg.Register(&TestNetParams)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
err = chaincfg.Register(&RegtestParams)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DashParser handle
|
|
|
|
type DashParser struct {
|
|
|
|
*btc.BitcoinParser
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewDashParser returns new DashParser instance
|
|
|
|
func NewDashParser(params *chaincfg.Params, c *btc.Configuration) *DashParser {
|
|
|
|
return &DashParser{BitcoinParser: btc.NewBitcoinParser(params, c)}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetChainParams contains network parameters for the main Dash network,
|
|
|
|
// the regression test Dash network, the test Dash network and
|
|
|
|
// the simulation test Dash network, in this order
|
|
|
|
func GetChainParams(chain string) *chaincfg.Params {
|
2018-09-28 14:54:08 -06:00
|
|
|
if MainNetParams.Name == "" {
|
|
|
|
initParams()
|
|
|
|
}
|
2018-06-08 07:23:28 -06:00
|
|
|
switch chain {
|
|
|
|
case "test":
|
|
|
|
return &TestNetParams
|
|
|
|
case "regtest":
|
|
|
|
return &RegtestParams
|
|
|
|
default:
|
|
|
|
return &MainNetParams
|
|
|
|
}
|
|
|
|
}
|