Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GoByte(GBX) support #695

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bchain/coins/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/trezor/blockbook/bchain/coins/flo"
"github.com/trezor/blockbook/bchain/coins/fujicoin"
"github.com/trezor/blockbook/bchain/coins/gamecredits"
"github.com/trezor/blockbook/bchain/coins/gobyte"
"github.com/trezor/blockbook/bchain/coins/grs"
"github.com/trezor/blockbook/bchain/coins/koto"
"github.com/trezor/blockbook/bchain/coins/liquid"
Expand Down Expand Up @@ -79,6 +80,8 @@ func init() {
BlockChainFactories["Decred"] = dcr.NewDecredRPC
BlockChainFactories["Decred Testnet"] = dcr.NewDecredRPC
BlockChainFactories["GameCredits"] = gamecredits.NewGameCreditsRPC
BlockChainFactories["GoByte"] = gobyte.NewGoByteRPC
BlockChainFactories["GoByte Testnet"] = gobyte.NewGoByteRPC
BlockChainFactories["Koto"] = koto.NewKotoRPC
BlockChainFactories["Koto Testnet"] = koto.NewKotoRPC
BlockChainFactories["Litecoin"] = litecoin.NewLitecoinRPC
Expand Down
99 changes: 99 additions & 0 deletions bchain/coins/gobyte/gobyteparser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package gobyte

import (
"github.com/martinboehm/btcd/wire"
"github.com/martinboehm/btcutil/chaincfg"
"github.com/trezor/blockbook/bchain"
"github.com/trezor/blockbook/bchain/coins/btc"
)

const (
// MainnetMagic is mainnet network constant
MainnetMagic wire.BitcoinNet = 0x1ab2c3d4
// TestnetMagic is testnet network constant
TestnetMagic wire.BitcoinNet = 0xd12bb37a
// RegtestMagic is regtest network constant
RegtestMagic wire.BitcoinNet = 0xa1b3d57b
)

var (
// MainNetParams are parser parameters for mainnet
MainNetParams chaincfg.Params
// TestNetParams are parser parameters for testnet
TestNetParams chaincfg.Params
// RegtestParams are parser parameters for regtest
RegtestParams chaincfg.Params
)

func init() {
MainNetParams = chaincfg.MainNetParams
MainNetParams.Net = MainnetMagic

// Address encoding magics
MainNetParams.PubKeyHashAddrID = []byte{38} // base58 prefix: G
MainNetParams.ScriptHashAddrID = []byte{10} // base58 prefix: 5

TestNetParams = chaincfg.TestNet3Params
TestNetParams.Net = TestnetMagic

// Address encoding magics
TestNetParams.PubKeyHashAddrID = []byte{112} // base58 prefix: n
TestNetParams.ScriptHashAddrID = []byte{20} // base58 prefix: 9

RegtestParams = chaincfg.RegressionNetParams
RegtestParams.Net = RegtestMagic

// Address encoding magics
RegtestParams.PubKeyHashAddrID = []byte{112} // base58 prefix: n
RegtestParams.ScriptHashAddrID = []byte{20} // base58 prefix: 9
}

// GoByteParser handle
type GoByteParser struct {
*btc.BitcoinLikeParser
baseparser *bchain.BaseParser
}

// NewGoByteParser returns new GoByteParser instance
func NewGoByteParser(params *chaincfg.Params, c *btc.Configuration) *GoByteParser {
return &GoByteParser{
BitcoinLikeParser: btc.NewBitcoinLikeParser(params, c),
baseparser: &bchain.BaseParser{},
}
}

// GetChainParams contains network parameters for the main GoByte network,
// the regression test GoByte network, the test GoByte network and
// the simulation test GoByte network, in this order
func GetChainParams(chain string) *chaincfg.Params {
if !chaincfg.IsRegistered(&MainNetParams) {
err := chaincfg.Register(&MainNetParams)
if err == nil {
err = chaincfg.Register(&TestNetParams)
}
if err == nil {
err = chaincfg.Register(&RegtestParams)
}
if err != nil {
panic(err)
}
}
switch chain {
case "test":
return &TestNetParams
case "regtest":
return &RegtestParams
default:
return &MainNetParams
}
}

// PackTx packs transaction to byte array using protobuf
func (p *GoByteParser) 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 *GoByteParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
return p.baseparser.UnpackTx(buf)
}
Loading