2018-12-05 12:52:34 -07:00
|
|
|
package liquid
|
|
|
|
|
|
|
|
import (
|
2018-12-05 14:34:44 -07:00
|
|
|
"blockbook/bchain"
|
2018-12-05 12:52:34 -07:00
|
|
|
"blockbook/bchain/coins/btc"
|
|
|
|
|
2019-01-04 06:05:51 -07:00
|
|
|
"github.com/martinboehm/btcd/wire"
|
|
|
|
"github.com/martinboehm/btcutil/chaincfg"
|
2018-12-05 12:52:34 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
MainnetMagic wire.BitcoinNet = 0xdab5bffa
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
MainNetParams chaincfg.Params
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
MainNetParams = chaincfg.MainNetParams
|
|
|
|
MainNetParams.Net = MainnetMagic
|
|
|
|
MainNetParams.PubKeyHashAddrID = []byte{57}
|
|
|
|
MainNetParams.ScriptHashAddrID = []byte{39}
|
|
|
|
// BLINDED_ADDRESS 12
|
|
|
|
}
|
|
|
|
|
|
|
|
// LiquidParser handle
|
|
|
|
type LiquidParser struct {
|
|
|
|
*btc.BitcoinParser
|
2018-12-05 14:34:44 -07:00
|
|
|
baseparser *bchain.BaseParser
|
2018-12-05 12:52:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewLiquidParser returns new LiquidParser instance
|
|
|
|
func NewLiquidParser(params *chaincfg.Params, c *btc.Configuration) *LiquidParser {
|
2018-12-05 14:34:44 -07:00
|
|
|
return &LiquidParser{
|
|
|
|
BitcoinParser: btc.NewBitcoinParser(params, c),
|
|
|
|
baseparser: &bchain.BaseParser{},
|
|
|
|
}
|
2018-12-05 12:52:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetChainParams contains network parameters for the main GameCredits network,
|
|
|
|
// and the test GameCredits network
|
|
|
|
func GetChainParams(chain string) *chaincfg.Params {
|
|
|
|
if !chaincfg.IsRegistered(&MainNetParams) {
|
|
|
|
err := chaincfg.Register(&MainNetParams)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch chain {
|
|
|
|
default:
|
|
|
|
return &MainNetParams
|
|
|
|
}
|
|
|
|
}
|
2018-12-05 14:34:44 -07:00
|
|
|
|
|
|
|
// PackTx packs transaction to byte array using protobuf
|
|
|
|
func (p *LiquidParser) 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 *LiquidParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
|
|
|
|
return p.baseparser.UnpackTx(buf)
|
|
|
|
}
|