1
1
mirror of https://github.com/wader/fq.git synced 2024-11-29 04:10:01 +03:00
fq/format/bitcoin/bitcoin_blkdat.go
Mattias Wadman 004406de65 bitcoin_blkdat,bitcoin_block: Make sure there is a header if blkdat
Makes bitcoin_blkdat fails fast as it is part of probe group.
Speeds up reading a big JSON file etc.
2022-08-26 12:07:53 +02:00

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
}