mirror of
https://github.com/wader/fq.git
synced 2024-12-23 13:22:58 +03:00
Merge pull request #402 from wader/bitcoin-blkdata-has-header
bitcoin_blkdat,bitcoin_block: Make sure there is a header if blkdat
This commit is contained in:
commit
32c16dd839
@ -188,11 +188,17 @@ out # Decode value as bitcoin_blkdat
|
||||
out ... | bitcoin_blkdat
|
||||
"help(bitcoin_block)"
|
||||
out bitcoin_block: Bitcoin block decoder
|
||||
out Options:
|
||||
out has_header=false Has blkdat header
|
||||
out Examples:
|
||||
out # Decode file as bitcoin_block
|
||||
out $ fq -d bitcoin_block . file
|
||||
out # Decode value as bitcoin_block
|
||||
out ... | bitcoin_block
|
||||
out # Decode file using bitcoin_block options
|
||||
out $ fq -d bitcoin_block -o has_header=false . file
|
||||
out # Decode value as bitcoin_block
|
||||
out ... | bitcoin_block({has_header:false})
|
||||
"help(bitcoin_script)"
|
||||
out bitcoin_script: Bitcoin script decoder
|
||||
out Examples:
|
||||
|
@ -25,7 +25,7 @@ func init() {
|
||||
func decodeBlkDat(d *decode.D, in interface{}) interface{} {
|
||||
validBlocks := 0
|
||||
for !d.End() {
|
||||
d.FieldFormat("block", bitcoinBlockFormat, nil)
|
||||
d.FieldFormat("block", bitcoinBlockFormat, format.BitCoinBlockIn{HasHeader: true})
|
||||
validBlocks++
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,9 @@ func init() {
|
||||
{Names: []string{format.BITCOIN_TRANSACTION}, Group: &bitcoinTranscationFormat},
|
||||
},
|
||||
DecodeFn: decodeBitcoinBlock,
|
||||
DecodeInArg: format.BitCoinBlockIn{
|
||||
HasHeader: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@ -32,19 +35,24 @@ var rawHexReverse = scalar.Fn(func(s scalar.S) (scalar.S, error) {
|
||||
})
|
||||
|
||||
func decodeBitcoinBlock(d *decode.D, in interface{}) interface{} {
|
||||
bbi, _ := in.(format.BitCoinBlockIn)
|
||||
size := d.BitsLeft()
|
||||
|
||||
// TODO: move to blkdat but how to model it?
|
||||
switch d.PeekBits(32) {
|
||||
case 0xf9beb4d9,
|
||||
0x0b110907,
|
||||
0xfabfb5da:
|
||||
d.FieldU32("magic", scalar.UToSymStr{
|
||||
0xf9beb4d9: "mainnet",
|
||||
0x0b110907: "testnet3",
|
||||
0xfabfb5da: "regtest",
|
||||
}, scalar.ActualHex)
|
||||
size = int64(d.FieldU32LE("size")) * 8
|
||||
if bbi.HasHeader {
|
||||
magic := d.PeekBits(32)
|
||||
switch magic {
|
||||
case 0xf9beb4d9,
|
||||
0x0b110907,
|
||||
0xfabfb5da:
|
||||
d.FieldU32("magic", scalar.UToSymStr{
|
||||
0xf9beb4d9: "mainnet",
|
||||
0x0b110907: "testnet3",
|
||||
0xfabfb5da: "regtest",
|
||||
}, scalar.ActualHex)
|
||||
size = int64(d.FieldU32LE("size")) * 8
|
||||
default:
|
||||
d.Fatalf("unknown magic %x", magic)
|
||||
}
|
||||
}
|
||||
|
||||
d.Endian = decode.LittleEndian
|
||||
|
@ -310,3 +310,7 @@ type CSVLIn struct {
|
||||
Comma string `doc:"Separator character"`
|
||||
Comment string `doc:"Comment line character"`
|
||||
}
|
||||
|
||||
type BitCoinBlockIn struct {
|
||||
HasHeader bool `doc:"Has blkdat header"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user