Skip to content

Commit

Permalink
Russian Bitcoin hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
National Bitcoiner committed Jun 20, 2020
1 parent 8288495 commit e56bf6d
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
64 changes: 64 additions & 0 deletions bchain/coins/russianbitcoin/russianbitcoinparser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package russianbitcoin

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

// magic numbers
const (
MainnetMagic wire.BitcoinNet = 0xd8b4bef8
TestnetMagic wire.BitcoinNet = 0x0809110c
RegtestMagic wire.BitcoinNet = 0xdbd5bffb
)

// chain parameters
var (
MainNetParams chaincfg.Params
TestNetParams chaincfg.Params
)

func init() {
MainNetParams = chaincfg.MainNetParams
MainNetParams.Net = MainnetMagic
MainNetParams.PubKeyHashAddrID = []byte{102}
MainNetParams.ScriptHashAddrID = []byte{11}
MainNetParams.Bech32HRPSegwit = "rubtcm"

TestNetParams = chaincfg.TestNet3Params
TestNetParams.Net = TestnetMagic
TestNetParams.PubKeyHashAddrID = []byte{105}
TestNetParams.ScriptHashAddrID = []byte{13}
TestNetParams.Bech32HRPSegwit = "rubtct"
}

// RussianBitcoinParser handle
type RussianBitcoinParser struct {
*btc.BitcoinParser
}

// NewRussianBitcoinParser returns new RussianBitcoinParser instance
func NewRussianBitcoinParser(params *chaincfg.Params, c *btc.Configuration) *RussianBitcoinParser {
return &RussianBitcoinParser{BitcoinParser: btc.NewBitcoinParser(params, c)}
}

// GetChainParams contains network parameters for the main RussianBitcoin network,
// and the test RussianBitcoin network
func GetChainParams(chain string) *chaincfg.Params {
if !chaincfg.IsRegistered(&MainNetParams) {
err := chaincfg.Register(&MainNetParams)
if err == nil {
err = chaincfg.Register(&TestNetParams)
}
if err != nil {
panic(err)
}
}
switch chain {
case "test":
return &TestNetParams
default:
return &MainNetParams
}
}
58 changes: 58 additions & 0 deletions bchain/coins/russianbitcoin/russianbitcoinrpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package russianbitcoin

import (
"encoding/json"

"github.com/golang/glog"
"github.com/nbcorg/blockbook/bchain"
"github.com/nbcorg/blockbook/bchain/coins/btc"
)

// RussianBitcoinRPC is an interface to JSON-RPC bitcoind service.
type RussianBitcoinRPC struct {
*btc.BitcoinRPC
}

// NewRussianBitcoinRPC returns new RussianBitcoinRPC instance.
func NewRussianBitcoinRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
b, err := btc.NewBitcoinRPC(config, pushHandler)
if err != nil {
return nil, err
}

s := &RussianBitcoinRPC{
b.(*btc.BitcoinRPC),
}
s.RPCMarshaler = btc.JSONMarshalerV2{}
s.ChainConfig.SupportsEstimateFee = false

return s, nil
}

// Initialize initializes RussianBitcoinRPC instance.
func (b *RussianBitcoinRPC) Initialize() error {
ci, err := b.GetChainInfo()
if err != nil {
return err
}
chainName := ci.Chain

glog.Info("Chain name ", chainName)
params := GetChainParams(chainName)

// always create parser
b.Parser = NewRussianBitcoinParser(params, b.ChainConfig)

// parameters for getInfo request
if params.Net == MainnetMagic {
b.Testnet = false
b.Network = "livenet"
} else {
b.Testnet = true
b.Network = "testnet"
}

glog.Info("rpc: block chain ", params.Name)

return nil
}

0 comments on commit e56bf6d

Please sign in to comment.