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]]
branch = "master"
name = "github.com/btcsuite/btcd"
packages = ["btcec","chaincfg","chaincfg/chainhash","txscript","wire"]
packages = ["blockchain","btcec","chaincfg","chaincfg/chainhash","database","txscript","wire"]
revision = "a1d1ea70dd212a440beb9caa4b766a58d1ed0254"
[[projects]]
@ -25,6 +25,24 @@
packages = [".","base58","bech32"]
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]]
name = "github.com/pkg/profile"
packages = ["."]
@ -46,6 +64,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "119cb8683257687e541ae944d0f3a29aa916bb81dcedd6a69a0f765fd8f1be9d"
inputs-digest = "b02ba452e22aa8fee86c7c5ba26ab49ca8f59d5541124eece5b5719c12adde9f"
solver-name = "gps-cdcl"
solver-version = 1

View File

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

View File

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

View File

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

View File

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

View File

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