Skip to content

Commit

Permalink
Rebranding from Zcoin to Firo (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
araarakelyan1985 committed Dec 28, 2020
1 parent 4697d75 commit 15b88ef
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 229 deletions.
4 changes: 2 additions & 2 deletions bchain/coins/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
"github.com/trezor/blockbook/bchain/coins/vertcoin"
"github.com/trezor/blockbook/bchain/coins/viacoin"
"github.com/trezor/blockbook/bchain/coins/vipstarcoin"
"github.com/trezor/blockbook/bchain/coins/xzc"
"github.com/trezor/blockbook/bchain/coins/firo"
"github.com/trezor/blockbook/bchain/coins/zec"
"github.com/trezor/blockbook/common"
)
Expand Down Expand Up @@ -94,7 +94,7 @@ func init() {
BlockChainFactories["PIVX"] = pivx.NewPivXRPC
BlockChainFactories["PIVX Testnet"] = pivx.NewPivXRPC
BlockChainFactories["Polis"] = polis.NewPolisRPC
BlockChainFactories["Zcoin"] = xzc.NewZcoinRPC
BlockChainFactories["Firo"] = firo.NewFiroRPC
BlockChainFactories["Fujicoin"] = fujicoin.NewFujicoinRPC
BlockChainFactories["Flo"] = flo.NewFloRPC
BlockChainFactories["Bellcoin"] = bellcoin.NewBellcoinRPC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xzc
package firo

import (
"bytes"
Expand All @@ -8,14 +8,14 @@ import (
"github.com/martinboehm/btcd/wire"
)

// ZcoinMsgTx encapsulate zcoin tx and extra
type ZcoinMsgTx struct {
// FiroMsgTx encapsulate firo tx and extra
type FiroMsgTx struct {
wire.MsgTx
Extra []byte
}

// TxHash calculate hash of transaction
func (msg *ZcoinMsgTx) TxHash() chainhash.Hash {
func (msg *FiroMsgTx) TxHash() chainhash.Hash {
extraSize := uint64(len(msg.Extra))
sizeOfExtraSize := 0
if extraSize != 0 {
Expand All @@ -36,8 +36,8 @@ func (msg *ZcoinMsgTx) TxHash() chainhash.Hash {
return chainhash.DoubleHashH(buf.Bytes())
}

// XzcDecode to decode bitcoin tx and extra
func (msg *ZcoinMsgTx) XzcDecode(r io.Reader, pver uint32, enc wire.MessageEncoding) error {
// FiroDecode to decode bitcoin tx and extra
func (msg *FiroMsgTx) FiroDecode(r io.Reader, pver uint32, enc wire.MessageEncoding) error {
if err := msg.MsgTx.BtcDecode(r, pver, enc); err != nil {
return err
}
Expand Down
61 changes: 35 additions & 26 deletions bchain/coins/xzc/zcoinparser.go → bchain/coins/firo/firoparser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xzc
package firo

import (
"bytes"
Expand All @@ -14,10 +14,13 @@ import (
)

const (
OpZeroCoinMint = 0xc1
OpZeroCoinSpend = 0xc2
OpSigmaMint = 0xc3
OpSigmaSpend = 0xc4
OpZeroCoinMint = 0xc1
OpZeroCoinSpend = 0xc2
OpSigmaMint = 0xc3
OpSigmaSpend = 0xc4
OpLelantusMint = 0xc5
OpLelantusJMint = 0xc6
OpLelantusJoinSplit = 0xc7

MainnetMagic wire.BitcoinNet = 0xe3d9fef1
TestnetMagic wire.BitcoinNet = 0xcffcbeea
Expand Down Expand Up @@ -60,21 +63,21 @@ func init() {
RegtestParams.Net = RegtestMagic
}

// ZcoinParser handle
type ZcoinParser struct {
// FiroParser handle
type FiroParser struct {
*btc.BitcoinParser
}

// NewZcoinParser returns new ZcoinParser instance
func NewZcoinParser(params *chaincfg.Params, c *btc.Configuration) *ZcoinParser {
return &ZcoinParser{
// NewFiroParser returns new FiroParser instance
func NewFiroParser(params *chaincfg.Params, c *btc.Configuration) *FiroParser {
return &FiroParser{
BitcoinParser: btc.NewBitcoinParser(params, c),
}
}

// GetChainParams contains network parameters for the main Zcoin network,
// the regression test Zcoin network, the test Zcoin network and
// the simulation test Zcoin network, in this order
// GetChainParams contains network parameters for the main Firo network,
// the regression test Firo network, the test Firo network and
// the simulation test Firo network, in this order
func GetChainParams(chain string) *chaincfg.Params {
if !chaincfg.IsRegistered(&MainNetParams) {
err := chaincfg.Register(&MainNetParams)
Expand All @@ -99,7 +102,7 @@ func GetChainParams(chain string) *chaincfg.Params {
}

// GetAddressesFromAddrDesc returns addresses for given address descriptor with flag if the addresses are searchable
func (p *ZcoinParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error) {
func (p *FiroParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error) {

if len(addrDesc) > 0 {
switch addrDesc[0] {
Expand All @@ -111,24 +114,30 @@ func (p *ZcoinParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor
return []string{"Sigmamint"}, false, nil
case OpSigmaSpend:
return []string{"Sigmaspend"}, false, nil
case OpLelantusMint:
return []string{"LelantusMint"}, false, nil
case OpLelantusJMint:
return []string{"LelantusJMint"}, false, nil
case OpLelantusJoinSplit:
return []string{"LelantusJoinSplit"}, false, nil
}
}

return p.OutputScriptToAddressesFunc(addrDesc)
}

// PackTx packs transaction to byte array using protobuf
func (p *ZcoinParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]byte, error) {
func (p *FiroParser) 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 *ZcoinParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
func (p *FiroParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
return p.BaseParser.UnpackTx(buf)
}

// TxFromZcoinMsgTx converts bitcoin wire Tx to bchain.Tx
func (p *ZcoinParser) TxFromZcoinMsgTx(t *ZcoinMsgTx, parseAddresses bool) bchain.Tx {
// TxFromFiroMsgTx converts bitcoin wire Tx to bchain.Tx
func (p *FiroParser) TxFromFiroMsgTx(t *FiroMsgTx, parseAddresses bool) bchain.Tx {
btx := p.TxFromMsgTx(&t.MsgTx, parseAddresses)

// NOTE: wire.MsgTx.TxHash() doesn't include extra
Expand All @@ -138,7 +147,7 @@ func (p *ZcoinParser) TxFromZcoinMsgTx(t *ZcoinMsgTx, parseAddresses bool) bchai
}

// ParseBlock parses raw block to our Block struct
func (p *ZcoinParser) ParseBlock(b []byte) (*bchain.Block, error) {
func (p *FiroParser) ParseBlock(b []byte) (*bchain.Block, error) {
reader := bytes.NewReader(b)

// parse standard block header first
Expand Down Expand Up @@ -193,7 +202,7 @@ func (p *ZcoinParser) ParseBlock(b []byte) (*bchain.Block, error) {
txs := make([]bchain.Tx, ntx)

for i := uint64(0); i < ntx; i++ {
tx := ZcoinMsgTx{}
tx := FiroMsgTx{}

// read version and seek back
var version uint32 = 0
Expand All @@ -215,13 +224,13 @@ func (p *ZcoinParser) ParseBlock(b []byte) (*bchain.Block, error) {
enc = wire.BaseEncoding
}

if err = tx.XzcDecode(reader, 0, enc); err != nil {
if err = tx.FiroDecode(reader, 0, enc); err != nil {
return nil, err
}

btx := p.TxFromZcoinMsgTx(&tx, false)
btx := p.TxFromFiroMsgTx(&tx, false)

if err = p.parseZcoinTx(&btx); err != nil {
if err = p.parseFiroTx(&btx); err != nil {
return nil, err
}

Expand All @@ -238,7 +247,7 @@ func (p *ZcoinParser) ParseBlock(b []byte) (*bchain.Block, error) {
}

// ParseTxFromJson parses JSON message containing transaction and returns Tx struct
func (p *ZcoinParser) ParseTxFromJson(msg json.RawMessage) (*bchain.Tx, error) {
func (p *FiroParser) ParseTxFromJson(msg json.RawMessage) (*bchain.Tx, error) {
var tx bchain.Tx
err := json.Unmarshal(msg, &tx)
if err != nil {
Expand All @@ -255,12 +264,12 @@ func (p *ZcoinParser) ParseTxFromJson(msg json.RawMessage) (*bchain.Tx, error) {
vout.JsonValue = ""
}

p.parseZcoinTx(&tx)
p.parseFiroTx(&tx)

return &tx, nil
}

func (p *ZcoinParser) parseZcoinTx(tx *bchain.Tx) error {
func (p *FiroParser) parseFiroTx(tx *bchain.Tx) error {
for i := range tx.Vin {
vin := &tx.Vin[i]

Expand Down
Loading

0 comments on commit 15b88ef

Please sign in to comment.