-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
1,053 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package snowgem | ||
|
||
import ( | ||
"github.com/trezor/blockbook/bchain" | ||
"github.com/trezor/blockbook/bchain/coins/btc" | ||
|
||
"github.com/martinboehm/btcd/wire" | ||
"github.com/martinboehm/btcutil/chaincfg" | ||
) | ||
|
||
const ( | ||
// MainnetMagic is mainnet network constant | ||
MainnetMagic wire.BitcoinNet = 0x6427c824 | ||
// TestnetMagic is testnet network constant | ||
TestnetMagic wire.BitcoinNet = 0xbff91afa | ||
// RegtestMagic is regtest network constant | ||
RegtestMagic wire.BitcoinNet = 0x5f3fe8aa | ||
) | ||
|
||
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.AddressMagicLen = 2 | ||
MainNetParams.PubKeyHashAddrID = []byte{0x1C, 0x28} // base58 prefix: s1 | ||
MainNetParams.ScriptHashAddrID = []byte{0x1C, 0x2D} // base58 prefix: s3 | ||
|
||
TestNetParams = chaincfg.TestNet3Params | ||
TestNetParams.Net = TestnetMagic | ||
|
||
// Address encoding magics | ||
TestNetParams.AddressMagicLen = 2 | ||
TestNetParams.PubKeyHashAddrID = []byte{0x1D, 0x25} // base58 prefix: tm | ||
TestNetParams.ScriptHashAddrID = []byte{0x1C, 0xBA} // base58 prefix: t2 | ||
|
||
RegtestParams = chaincfg.RegressionNetParams | ||
RegtestParams.Net = RegtestMagic | ||
} | ||
|
||
// SnowGemParser handle | ||
type SnowGemParser struct { | ||
*btc.BitcoinParser | ||
baseparser *bchain.BaseParser | ||
} | ||
|
||
// NewSnowGemParser returns new SnowGemParser instance | ||
func NewSnowGemParser(params *chaincfg.Params, c *btc.Configuration) *SnowGemParser { | ||
return &SnowGemParser{ | ||
BitcoinParser: btc.NewBitcoinParser(params, c), | ||
baseparser: &bchain.BaseParser{}, | ||
} | ||
} | ||
|
||
// GetChainParams contains network parameters for the main SnowGem network, | ||
// the regression test SnowGem network, the test SnowGem network and | ||
// the simulation test SnowGem 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 *SnowGemParser) 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 *SnowGemParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) { | ||
return p.baseparser.UnpackTx(buf) | ||
} |
Oops, something went wrong.