folder reorganization

pull/1/head
Martin Boehm 2018-01-18 16:44:31 +01:00
parent 0728ea7628
commit 441c0f9024
6 changed files with 52 additions and 17 deletions

22
Gopkg.lock generated
View File

@ -10,7 +10,7 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
name = "github.com/btcsuite/btcd" name = "github.com/btcsuite/btcd"
packages = ["btcec","chaincfg","chaincfg/chainhash","txscript","wire"] packages = ["blockchain","btcec","chaincfg","chaincfg/chainhash","database","txscript","wire"]
revision = "a1d1ea70dd212a440beb9caa4b766a58d1ed0254" revision = "a1d1ea70dd212a440beb9caa4b766a58d1ed0254"
[[projects]] [[projects]]
@ -25,6 +25,24 @@
packages = [".","base58","bech32"] packages = [".","base58","bech32"]
revision = "501929d3d046174c3d39f0ea54ece471aa17238c" revision = "501929d3d046174c3d39f0ea54ece471aa17238c"
[[projects]]
name = "github.com/gorilla/context"
packages = ["."]
revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a"
version = "v1.1"
[[projects]]
name = "github.com/gorilla/handlers"
packages = ["."]
revision = "90663712d74cb411cbef281bc1e08c19d1a76145"
version = "v1.3.0"
[[projects]]
name = "github.com/gorilla/mux"
packages = ["."]
revision = "53c1911da2b537f792e7cafcb446b05ffe33b996"
version = "v1.6.1"
[[projects]] [[projects]]
name = "github.com/pkg/profile" name = "github.com/pkg/profile"
packages = ["."] packages = ["."]
@ -46,6 +64,6 @@
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "119cb8683257687e541ae944d0f3a29aa916bb81dcedd6a69a0f765fd8f1be9d" inputs-digest = "b02ba452e22aa8fee86c7c5ba26ab49ca8f59d5541124eece5b5719c12adde9f"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@ -1,4 +1,4 @@
package main package bitcoin
import ( import (
"bytes" "bytes"
@ -109,6 +109,10 @@ type resGetRawTransactionVerbose struct {
Result Tx `json:"result"` Result Tx `json:"result"`
} }
type BlockParser interface {
ParseBlock(b []byte) (*Block, error)
}
// BitcoinRPC is an interface to JSON-RPC bitcoind service. // BitcoinRPC is an interface to JSON-RPC bitcoind service.
type BitcoinRPC struct { type BitcoinRPC struct {
client http.Client client http.Client

View File

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

View File

@ -1,4 +1,4 @@
package main package bitcoin
type ScriptSig struct { type ScriptSig struct {
Asm string `json:"asm"` Asm string `json:"asm"`

View File

@ -6,13 +6,12 @@ import (
"sync" "sync"
"time" "time"
"blockbook/db"
"blockbook/server"
"github.com/pkg/profile" "github.com/pkg/profile"
) )
type BlockParser interface {
ParseBlock(b []byte) (*Block, error)
}
type Blockchain interface { type Blockchain interface {
GetBestBlockHash() (string, error) GetBestBlockHash() (string, error)
GetBlockHash(height uint32) (string, error) GetBlockHash(height uint32) (string, error)
@ -49,6 +48,8 @@ var (
syncWorkers = flag.Int("workers", 8, "number of workers to process blocks") syncWorkers = flag.Int("workers", 8, "number of workers to process blocks")
dryRun = flag.Bool("dryrun", false, "do not index blocks, only download") dryRun = flag.Bool("dryrun", false, "do not index blocks, only download")
parse = flag.Bool("parse", false, "use in-process block parsing") parse = flag.Bool("parse", false, "use in-process block parsing")
httpServer = flag.Bool("http", true, "run http server (default true)")
) )
func main() { func main() {
@ -77,12 +78,23 @@ func main() {
} }
} }
db, err := NewRocksDB(*dbPath) db, err := db.NewRocksDB(*dbPath)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer db.Close() defer db.Close()
if *httpServer {
s, err := server.New(db)
if err != nil {
log.Fatalf("https: %s", err)
}
err = s.Run()
if err != nil {
log.Fatalf("https: %s", err)
}
}
if *resync { if *resync {
if err := resyncIndex(rpc, db); err != nil { if err := resyncIndex(rpc, db); err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -1,6 +1,7 @@
package main package db
import ( import (
"blockbook/bitcoin"
"bytes" "bytes"
"encoding/binary" "encoding/binary"
"encoding/hex" "encoding/hex"
@ -105,15 +106,15 @@ const (
opDelete = 1 opDelete = 1
) )
func (d *RocksDB) ConnectBlock(block *Block) error { func (d *RocksDB) ConnectBlock(block *bitcoin.Block) error {
return d.writeBlock(block, opInsert) return d.writeBlock(block, opInsert)
} }
func (d *RocksDB) DisconnectBlock(block *Block) error { func (d *RocksDB) DisconnectBlock(block *bitcoin.Block) error {
return d.writeBlock(block, opDelete) return d.writeBlock(block, opDelete)
} }
func (d *RocksDB) writeBlock(block *Block, op int) error { func (d *RocksDB) writeBlock(block *bitcoin.Block, op int) error {
wb := gorocksdb.NewWriteBatch() wb := gorocksdb.NewWriteBatch()
defer wb.Destroy() defer wb.Destroy()
@ -146,7 +147,7 @@ type outpoint struct {
func (d *RocksDB) writeOutputs( func (d *RocksDB) writeOutputs(
wb *gorocksdb.WriteBatch, wb *gorocksdb.WriteBatch,
block *Block, block *bitcoin.Block,
op int, op int,
) error { ) error {
records := make(map[string][]outpoint) records := make(map[string][]outpoint)
@ -234,7 +235,7 @@ func unpackOutputValue(buf []byte) ([]outpoint, error) {
func (d *RocksDB) writeInputs( func (d *RocksDB) writeInputs(
wb *gorocksdb.WriteBatch, wb *gorocksdb.WriteBatch,
block *Block, block *bitcoin.Block,
op int, op int,
) error { ) error {
for _, tx := range block.Txs { for _, tx := range block.Txs {
@ -291,7 +292,7 @@ func (d *RocksDB) GetBlockHash(height uint32) (string, error) {
func (d *RocksDB) writeHeight( func (d *RocksDB) writeHeight(
wb *gorocksdb.WriteBatch, wb *gorocksdb.WriteBatch,
block *Block, block *bitcoin.Block,
op int, op int,
) error { ) error {
key := packUint(block.Height) key := packUint(block.Height)