mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
improve dropafter as with showblock
This commit is contained in:
parent
2231e04e2b
commit
8a2299c1e1
1 changed files with 32 additions and 22 deletions
|
@ -6,11 +6,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/conformal/btcdb"
|
"github.com/conformal/btcdb"
|
||||||
_ "github.com/conformal/btcdb/ldb"
|
_ "github.com/conformal/btcdb/ldb"
|
||||||
"github.com/conformal/btcwire"
|
"github.com/conformal/btcwire"
|
||||||
|
"github.com/conformal/go-flags"
|
||||||
"github.com/conformal/seelog"
|
"github.com/conformal/seelog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -19,6 +19,13 @@ import (
|
||||||
|
|
||||||
type ShaHash btcwire.ShaHash
|
type ShaHash btcwire.ShaHash
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
DataDir string `short:"b" long:"datadir" description:"Directory to store data"`
|
||||||
|
DbType string `long:"dbtype" description:"Database backend"`
|
||||||
|
TestNet3 bool `long:"testnet" description:"Use the test network"`
|
||||||
|
ShaString string `short:"s" description:"Block SHA to process" required:"true"`
|
||||||
|
}
|
||||||
|
|
||||||
var log seelog.LoggerInterface
|
var log seelog.LoggerInterface
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -27,15 +34,18 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
cfg := config{
|
||||||
var dbType string
|
DbType: "leveldb",
|
||||||
var datadir string
|
DataDir: filepath.Join(btcdHomeDir(), "data"),
|
||||||
var shastring string
|
}
|
||||||
flag.StringVar(&dbType, "dbtype", "", "Database backend to use for the Block Chain")
|
parser := flags.NewParser(&cfg, flags.Default)
|
||||||
flag.StringVar(&datadir, "datadir", "", "Directory to store data")
|
_, err := parser.Parse()
|
||||||
flag.StringVar(&shastring, "s", "", "Block sha to process")
|
if err != nil {
|
||||||
|
if e, ok := err.(*flags.Error); !ok || e.Type != flags.ErrHelp {
|
||||||
flag.Parse()
|
parser.WriteHelp(os.Stderr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
log, err = seelog.LoggerFromWriterWithMinLevel(os.Stdout,
|
log, err = seelog.LoggerFromWriterWithMinLevel(os.Stdout,
|
||||||
seelog.TraceLvl)
|
seelog.TraceLvl)
|
||||||
|
@ -46,24 +56,24 @@ func main() {
|
||||||
defer log.Flush()
|
defer log.Flush()
|
||||||
btcdb.UseLogger(log)
|
btcdb.UseLogger(log)
|
||||||
|
|
||||||
if len(dbType) == 0 {
|
var testnet string
|
||||||
dbType = "sqlite"
|
if cfg.TestNet3 {
|
||||||
|
testnet = "testnet"
|
||||||
|
} else {
|
||||||
|
testnet = "mainnet"
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(datadir) == 0 {
|
cfg.DataDir = filepath.Join(cfg.DataDir, testnet)
|
||||||
datadir = filepath.Join(btcdHomeDir(), "data")
|
|
||||||
}
|
|
||||||
datadir = filepath.Join(datadir, "mainnet")
|
|
||||||
|
|
||||||
blockDbNamePrefix := "blocks"
|
blockDbNamePrefix := "blocks"
|
||||||
dbName := blockDbNamePrefix + "_" + dbType
|
dbName := blockDbNamePrefix + "_" + cfg.DbType
|
||||||
if dbType == "sqlite" {
|
if cfg.DbType == "sqlite" {
|
||||||
dbName = dbName + ".db"
|
dbName = dbName + ".db"
|
||||||
}
|
}
|
||||||
dbPath := filepath.Join(datadir, dbName)
|
dbPath := filepath.Join(cfg.DataDir, dbName)
|
||||||
|
|
||||||
log.Infof("loading db")
|
log.Infof("loading db")
|
||||||
db, err := btcdb.OpenDB(dbType, dbPath)
|
db, err := btcdb.OpenDB(cfg.DbType, dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("db open failed: %v", err)
|
log.Warnf("db open failed: %v", err)
|
||||||
return
|
return
|
||||||
|
@ -74,9 +84,9 @@ func main() {
|
||||||
_, height, err := db.NewestSha()
|
_, height, err := db.NewestSha()
|
||||||
log.Infof("loaded block height %v", height)
|
log.Infof("loaded block height %v", height)
|
||||||
|
|
||||||
sha, err := getSha(db, shastring)
|
sha, err := getSha(db, cfg.ShaString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("Invalid block %v", shastring)
|
log.Infof("Invalid block hash %v", cfg.ShaString)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue