Rename package bitcoin to bchain

This commit is contained in:
Martin Boehm 2018-01-31 15:23:17 +01:00
parent 41c6ed8b6f
commit a403b8d0fe
7 changed files with 29 additions and 29 deletions

View File

@ -1,4 +1,4 @@
package bitcoin package bchain
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package bitcoin package bchain
import ( import (
"bytes" "bytes"

View File

@ -1,4 +1,4 @@
package bitcoin package bchain
import ( import (
"encoding/binary" "encoding/binary"
@ -24,7 +24,7 @@ type MQMessage struct {
// New creates new Bitcoind ZeroMQ listener // New creates new Bitcoind ZeroMQ listener
// callback function receives messages // callback function receives messages
func New(binding string, callback func(*MQMessage)) (*MQ, error) { func NewMQ(binding string, callback func(*MQMessage)) (*MQ, error) {
context, err := zmq.NewContext() context, err := zmq.NewContext()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -1,4 +1,4 @@
package bitcoin package bchain
import ( import (
"github.com/btcsuite/btcd/txscript" "github.com/btcsuite/btcd/txscript"

View File

@ -10,7 +10,7 @@ import (
"syscall" "syscall"
"time" "time"
"blockbook/bitcoin" "blockbook/bchain"
"blockbook/db" "blockbook/db"
"blockbook/server" "blockbook/server"
@ -48,7 +48,7 @@ var (
var ( var (
syncChannel = make(chan struct{}) syncChannel = make(chan struct{})
chain *bitcoin.BitcoinRPC chain *bchain.BitcoinRPC
index *db.RocksDB index *db.RocksDB
) )
@ -71,15 +71,15 @@ func main() {
return return
} }
chain = bitcoin.NewBitcoinRPC( chain = bchain.NewBitcoinRPC(
*rpcURL, *rpcURL,
*rpcUser, *rpcUser,
*rpcPass, *rpcPass,
time.Duration(*rpcTimeout)*time.Second) time.Duration(*rpcTimeout)*time.Second)
if *parse { if *parse {
chain.Parser = &bitcoin.BitcoinBlockParser{ chain.Parser = &bchain.BitcoinBlockParser{
Params: bitcoin.GetChainParams()[0], Params: bchain.GetChainParams()[0],
} }
} }
@ -126,13 +126,13 @@ func main() {
}() }()
} }
var mq *bitcoin.MQ var mq *bchain.MQ
if *zeroMQBinding != "" { if *zeroMQBinding != "" {
if !*synchronize { if !*synchronize {
glog.Error("zeromq connection without synchronization does not make sense, ignoring zeromq parameter") glog.Error("zeromq connection without synchronization does not make sense, ignoring zeromq parameter")
} else { } else {
go syncLoop() go syncLoop()
mq, err = bitcoin.New(*zeroMQBinding, mqHandler) mq, err = bchain.NewMQ(*zeroMQBinding, mqHandler)
if err != nil { if err != nil {
glog.Fatal("mq: ", err) glog.Fatal("mq: ", err)
} }
@ -149,7 +149,7 @@ func main() {
address := *queryAddress address := *queryAddress
if address != "" { if address != "" {
script, err := bitcoin.AddressToOutputScript(address) script, err := bchain.AddressToOutputScript(address)
if err != nil { if err != nil {
glog.Fatalf("GetTransactions %v", err) glog.Fatalf("GetTransactions %v", err)
} }
@ -180,7 +180,7 @@ func syncLoop() {
} }
} }
func mqHandler(m *bitcoin.MQMessage) { func mqHandler(m *bchain.MQMessage) {
body := hex.EncodeToString(m.Body) body := hex.EncodeToString(m.Body)
glog.Infof("MQ: %s-%d %s", m.Topic, m.Sequence, body) glog.Infof("MQ: %s-%d %s", m.Topic, m.Sequence, body)
if m.Topic == "hashblock" { if m.Topic == "hashblock" {
@ -192,7 +192,7 @@ func mqHandler(m *bitcoin.MQMessage) {
} }
} }
func waitForSignalAndShutdown(s *server.HttpServer, mq *bitcoin.MQ, timeout time.Duration) { func waitForSignalAndShutdown(s *server.HttpServer, mq *bchain.MQ, timeout time.Duration) {
stop := make(chan os.Signal, 1) stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM) signal.Notify(stop, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
@ -241,13 +241,13 @@ func resyncIndex() error {
return nil return nil
} }
var header *bitcoin.BlockHeader var header *bchain.BlockHeader
if local != "" { if local != "" {
// Is local tip on the best chain? // Is local tip on the best chain?
header, err = chain.GetBlockHeader(local) header, err = chain.GetBlockHeader(local)
forked := false forked := false
if err != nil { if err != nil {
if e, ok := err.(*bitcoin.RPCError); ok && e.Message == "Block not found" { if e, ok := err.(*bchain.RPCError); ok && e.Message == "Block not found" {
forked = true forked = true
} else { } else {
return err return err
@ -378,7 +378,7 @@ func connectBlocksParallel(
} }
err := connectBlockChunk(low, high) err := connectBlockChunk(low, high)
if err != nil { if err != nil {
if e, ok := err.(*bitcoin.RPCError); ok && (e.Message == "Block height out of range" || e.Message == "Block not found") { if e, ok := err.(*bchain.RPCError); ok && (e.Message == "Block height out of range" || e.Message == "Block not found") {
break break
} }
glog.Fatalf("connectBlocksParallel %d-%d %v", low, high, err) glog.Fatalf("connectBlocksParallel %d-%d %v", low, high, err)
@ -401,7 +401,7 @@ func connectBlockChunk(
connected, err := isBlockConnected(higher) connected, err := isBlockConnected(higher)
if err != nil || connected { if err != nil || connected {
// if higher is over the best block, continue with lower block, otherwise return error // if higher is over the best block, continue with lower block, otherwise return error
if e, ok := err.(*bitcoin.RPCError); !ok || e.Message != "Block height out of range" { if e, ok := err.(*bchain.RPCError); !ok || e.Message != "Block height out of range" {
return err return err
} }
} }
@ -452,7 +452,7 @@ func isBlockConnected(
} }
type blockResult struct { type blockResult struct {
block *bitcoin.Block block *bchain.Block
err error err error
} }

View File

@ -1,7 +1,7 @@
package db package db
import ( import (
"blockbook/bitcoin" "blockbook/bchain"
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
@ -151,15 +151,15 @@ const (
opDelete = 1 opDelete = 1
) )
func (d *RocksDB) ConnectBlock(block *bitcoin.Block) error { func (d *RocksDB) ConnectBlock(block *bchain.Block) error {
return d.writeBlock(block, opInsert) return d.writeBlock(block, opInsert)
} }
func (d *RocksDB) DisconnectBlock(block *bitcoin.Block) error { func (d *RocksDB) DisconnectBlock(block *bchain.Block) error {
return d.writeBlock(block, opDelete) return d.writeBlock(block, opDelete)
} }
func (d *RocksDB) writeBlock(block *bitcoin.Block, op int) error { func (d *RocksDB) writeBlock(block *bchain.Block, op int) error {
wb := gorocksdb.NewWriteBatch() wb := gorocksdb.NewWriteBatch()
defer wb.Destroy() defer wb.Destroy()
@ -194,7 +194,7 @@ type outpoint struct {
func (d *RocksDB) writeOutputs( func (d *RocksDB) writeOutputs(
wb *gorocksdb.WriteBatch, wb *gorocksdb.WriteBatch,
block *bitcoin.Block, block *bchain.Block,
op int, op int,
) error { ) error {
records := make(map[string][]outpoint) records := make(map[string][]outpoint)
@ -283,7 +283,7 @@ func unpackOutputValue(buf []byte) ([]outpoint, error) {
func (d *RocksDB) writeInputs( func (d *RocksDB) writeInputs(
wb *gorocksdb.WriteBatch, wb *gorocksdb.WriteBatch,
block *bitcoin.Block, block *bchain.Block,
op int, op int,
) error { ) error {
for _, tx := range block.Txs { for _, tx := range block.Txs {
@ -361,7 +361,7 @@ func (d *RocksDB) getInput(key []byte) ([]byte, error) {
func (d *RocksDB) writeHeight( func (d *RocksDB) writeHeight(
wb *gorocksdb.WriteBatch, wb *gorocksdb.WriteBatch,
block *bitcoin.Block, block *bchain.Block,
op int, op int,
) error { ) error {
key := packUint(block.Height) key := packUint(block.Height)

View File

@ -1,7 +1,7 @@
package server package server
import ( import (
"blockbook/bitcoin" "blockbook/bchain"
"blockbook/db" "blockbook/db"
"context" "context"
"encoding/json" "encoding/json"
@ -131,7 +131,7 @@ func (s *HttpServer) transactions(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
respondError(w, err, fmt.Sprintf("address %s", address)) respondError(w, err, fmt.Sprintf("address %s", address))
} }
script, err := bitcoin.AddressToOutputScript(address) script, err := bchain.AddressToOutputScript(address)
if err != nil { if err != nil {
respondError(w, err, fmt.Sprintf("address %s", address)) respondError(w, err, fmt.Sprintf("address %s", address))
} }