blockbook/bchain/coins/zec/zcashparser.go

80 lines
2.3 KiB
Go
Raw Normal View History

2018-03-20 10:28:03 -06:00
package zec
import (
"blockbook/bchain"
"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"
"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
)
// ZCashParser handle
type ZCashParser struct {
*bchain.BaseParser
}
2018-03-20 10:28:03 -06:00
// NewZCashParser returns new ZCashParser instance
func NewZCashParser(c *btc.Configuration) *ZCashParser {
return &ZCashParser{
&bchain.BaseParser{
BlockAddressesToKeep: c.BlockAddressesToKeep,
AmountDecimalPoint: 8,
},
}
}
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
}
// GetAddrDescFromVout returns internal address representation of given transaction output
func (p *ZCashParser) GetAddrDescFromVout(output *bchain.Vout) (bchain.AddressDescriptor, error) {
2018-03-20 10:28:03 -06:00
if len(output.ScriptPubKey.Addresses) != 1 {
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
}
// GetAddrDescFromAddress returns internal address representation of given address
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
}
// GetAddressesFromAddrDesc returns addresses for given address descriptor with flag if the addresses are searchable
func (p *ZCashParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error) {
// TODO implement
return nil, false, errors.New("GetAddressesFromAddrDesc: not implemented")
}
// GetScriptFromAddrDesc returns output script for given address descriptor
func (p *ZCashParser) GetScriptFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]byte, error) {
// TODO implement
return nil, errors.New("GetScriptFromAddrDesc: not implemented")
}