2018-03-20 10:28:03 -06:00
|
|
|
package zec
|
|
|
|
|
|
|
|
import (
|
|
|
|
"blockbook/bchain"
|
2018-05-28 06:57:44 -06:00
|
|
|
"blockbook/bchain/coins/btc"
|
2018-06-20 09:57:51 -06:00
|
|
|
"blockbook/bchain/coins/utils"
|
2018-05-22 04:33:38 -06:00
|
|
|
|
|
|
|
"github.com/btcsuite/btcd/chaincfg"
|
|
|
|
"github.com/btcsuite/btcd/wire"
|
2018-08-28 16:25:26 -06:00
|
|
|
"github.com/juju/errors"
|
2018-05-22 04:33:38 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
MainnetMagic wire.BitcoinNet = 0x6427e924
|
|
|
|
TestnetMagic wire.BitcoinNet = 0xbff91afa
|
|
|
|
RegtestMagic wire.BitcoinNet = 0x5f3fe8aa
|
2018-03-20 10:28:03 -06:00
|
|
|
)
|
|
|
|
|
2018-04-08 03:24:29 -06:00
|
|
|
// ZCashParser handle
|
2018-04-08 07:50:19 -06:00
|
|
|
type ZCashParser struct {
|
|
|
|
*bchain.BaseParser
|
|
|
|
}
|
2018-03-20 10:28:03 -06:00
|
|
|
|
2018-07-25 07:56:08 -06:00
|
|
|
// NewZCashParser returns new ZCashParser instance
|
2018-05-28 06:57:44 -06:00
|
|
|
func NewZCashParser(c *btc.Configuration) *ZCashParser {
|
|
|
|
return &ZCashParser{
|
|
|
|
&bchain.BaseParser{
|
|
|
|
BlockAddressesToKeep: c.BlockAddressesToKeep,
|
2018-07-25 07:56:08 -06:00
|
|
|
AmountDecimalPoint: 8,
|
2018-05-28 06:57:44 -06:00
|
|
|
},
|
|
|
|
}
|
2018-05-18 07:04:40 -06:00
|
|
|
}
|
|
|
|
|
2018-05-22 04:33:38 -06:00
|
|
|
// 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 {
|
|
|
|
var params *chaincfg.Params
|
|
|
|
switch chain {
|
|
|
|
case "test":
|
|
|
|
params = &chaincfg.TestNet3Params
|
|
|
|
params.Net = TestnetMagic
|
|
|
|
case "regtest":
|
|
|
|
params = &chaincfg.RegressionNetParams
|
|
|
|
params.Net = RegtestMagic
|
|
|
|
default:
|
|
|
|
params = &chaincfg.MainNetParams
|
|
|
|
params.Net = MainnetMagic
|
|
|
|
}
|
|
|
|
|
|
|
|
return params
|
|
|
|
}
|
|
|
|
|
2018-08-28 16:25:26 -06:00
|
|
|
// GetAddrDescFromVout returns internal address representation of given transaction output
|
2018-08-30 14:39:03 -06:00
|
|
|
func (p *ZCashParser) GetAddrDescFromVout(output *bchain.Vout) (bchain.AddressDescriptor, error) {
|
2018-03-20 10:28:03 -06:00
|
|
|
if len(output.ScriptPubKey.Addresses) != 1 {
|
2018-03-23 06:15:19 -06:00
|
|
|
return nil, nil
|
2018-03-20 10:28:03 -06:00
|
|
|
}
|
2018-06-20 09:57:51 -06:00
|
|
|
hash, _, err := utils.CheckDecode(output.ScriptPubKey.Addresses[0])
|
2018-03-26 03:41:32 -06:00
|
|
|
return hash, err
|
2018-03-20 10:28:03 -06:00
|
|
|
}
|
|
|
|
|
2018-08-28 16:25:26 -06:00
|
|
|
// GetAddrDescFromAddress returns internal address representation of given address
|
2018-08-30 14:39:03 -06:00
|
|
|
func (p *ZCashParser) GetAddrDescFromAddress(address string) (bchain.AddressDescriptor, error) {
|
2018-06-20 09:57:51 -06:00
|
|
|
hash, _, err := utils.CheckDecode(address)
|
2018-03-26 03:41:32 -06:00
|
|
|
return hash, err
|
2018-03-20 10:28:03 -06:00
|
|
|
}
|
2018-08-28 16:25:26 -06:00
|
|
|
|
|
|
|
// GetAddressesFromAddrDesc returns addresses for given address descriptor with flag if the addresses are searchable
|
2018-08-30 14:39:03 -06:00
|
|
|
func (p *ZCashParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error) {
|
2018-08-28 16:25:26 -06:00
|
|
|
// TODO implement
|
|
|
|
return nil, false, errors.New("GetAddressesFromAddrDesc: not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetScriptFromAddrDesc returns output script for given address descriptor
|
2018-08-30 14:39:03 -06:00
|
|
|
func (p *ZCashParser) GetScriptFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]byte, error) {
|
2018-08-28 16:25:26 -06:00
|
|
|
// TODO implement
|
|
|
|
return nil, errors.New("GetScriptFromAddrDesc: not implemented")
|
|
|
|
}
|