92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package zec
|
|
|
|
import (
|
|
"blockbook/bchain"
|
|
"blockbook/bchain/coins/btc"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
|
"github.com/jakm/btcutil/chaincfg"
|
|
)
|
|
|
|
const (
|
|
MainnetMagic wire.BitcoinNet = 0x6427e924
|
|
TestnetMagic wire.BitcoinNet = 0xbff91afa
|
|
RegtestMagic wire.BitcoinNet = 0x5f3fe8aa
|
|
)
|
|
|
|
var (
|
|
MainNetParams chaincfg.Params
|
|
TestNetParams chaincfg.Params
|
|
)
|
|
|
|
func initParams() {
|
|
MainNetParams = chaincfg.MainNetParams
|
|
MainNetParams.Net = MainnetMagic
|
|
|
|
// Address encoding magics
|
|
MainNetParams.AddressMagicLen = 2
|
|
MainNetParams.PubKeyHashAddrID = []byte{0x1C, 0xB8} // base58 prefix: t1
|
|
MainNetParams.ScriptHashAddrID = []byte{0x1C, 0xBD} // base58 prefix: t3
|
|
|
|
TestNetParams = chaincfg.TestNet3Params
|
|
TestNetParams.Net = TestnetMagic
|
|
|
|
// Address encoding magics
|
|
TestNetParams.AddressMagicLen = 2
|
|
TestNetParams.PubKeyHashAddrID = []byte{0x1D, 0x25} // base58 prefix: tm
|
|
TestNetParams.ScriptHashAddrID = []byte{0x1C, 0xBA} // base58 prefix: t2
|
|
|
|
err := chaincfg.Register(&MainNetParams)
|
|
if err == nil {
|
|
err = chaincfg.Register(&TestNetParams)
|
|
}
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// ZCashParser handle
|
|
type ZCashParser struct {
|
|
*btc.BitcoinParser
|
|
baseparser *bchain.BaseParser
|
|
}
|
|
|
|
// NewZCashParser returns new ZCashParser instance
|
|
func NewZCashParser(params *chaincfg.Params, c *btc.Configuration) *ZCashParser {
|
|
return &ZCashParser{
|
|
BitcoinParser: btc.NewBitcoinParser(params, c),
|
|
baseparser: &bchain.BaseParser{},
|
|
}
|
|
}
|
|
|
|
// GetChainParams contains network parameters for the main ZCash network,
|
|
// the regression test ZCash network, the test ZCash network and
|
|
// the simulation test ZCash network, in this order
|
|
func GetChainParams(chain string) *chaincfg.Params {
|
|
if MainNetParams.Name == "" {
|
|
initParams()
|
|
}
|
|
var params *chaincfg.Params
|
|
switch chain {
|
|
case "test":
|
|
return &TestNetParams
|
|
case "regtest":
|
|
params = &chaincfg.RegressionNetParams
|
|
params.Net = RegtestMagic
|
|
default:
|
|
return &MainNetParams
|
|
}
|
|
|
|
return params
|
|
}
|
|
|
|
// PackTx packs transaction to byte array using protobuf
|
|
func (p *ZCashParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) {
|
|
return p.baseparser.PackTx(tx, height, blockTime)
|
|
}
|
|
|
|
// UnpackTx unpacks transaction from protobuf byte array
|
|
func (p *ZCashParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
|
|
return p.baseparser.UnpackTx(buf)
|
|
}
|