mirror of
https://github.com/wader/fq.git
synced 2024-11-29 04:10:01 +03:00
004406de65
Makes bitcoin_blkdat fails fast as it is part of probe group. Speeds up reading a big JSON file etc.
38 lines
794 B
Go
38 lines
794 B
Go
package bitcoin
|
|
|
|
import (
|
|
"github.com/wader/fq/format"
|
|
"github.com/wader/fq/pkg/decode"
|
|
"github.com/wader/fq/pkg/interp"
|
|
)
|
|
|
|
var bitcoinBlockFormat decode.Group
|
|
|
|
func init() {
|
|
interp.RegisterFormat(decode.Format{
|
|
Name: format.BITCOIN_BLKDAT,
|
|
Description: "Bitcoin blk.dat",
|
|
Groups: []string{format.PROBE},
|
|
Dependencies: []decode.Dependency{
|
|
{Names: []string{format.BITCOIN_BLOCK}, Group: &bitcoinBlockFormat},
|
|
},
|
|
DecodeFn: decodeBlkDat,
|
|
RootArray: true,
|
|
RootName: "blocks",
|
|
})
|
|
}
|
|
|
|
func decodeBlkDat(d *decode.D, in interface{}) interface{} {
|
|
validBlocks := 0
|
|
for !d.End() {
|
|
d.FieldFormat("block", bitcoinBlockFormat, format.BitCoinBlockIn{HasHeader: true})
|
|
validBlocks++
|
|
}
|
|
|
|
if validBlocks == 0 {
|
|
d.Fatalf("no valid blocks found")
|
|
}
|
|
|
|
return nil
|
|
}
|