1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module blkdump
is aliced
;
25 //version = dump_scripts;
28 // ////////////////////////////////////////////////////////////////////////// //
29 // rev???.dat: magic[4], version[4], hash[32]
32 // ////////////////////////////////////////////////////////////////////////// //
33 bool isAsciiScript (const(ubyte)[] script
) {
34 if (script
.length
< 1) return false;
35 foreach (immutable ubyte b
; script
) {
37 if (b
!= 13 && b
!= 10 && b
!= 9) return false;
38 } else if (b
>= 127) {
46 string
s2a (const(ubyte)[] script
) {
48 res
.reserve(script
.length
);
49 foreach (char ch
; cast(const(char)[])script
) {
50 if (ch
< ' ' || ch
>= 127) ch
= '.';
57 // ////////////////////////////////////////////////////////////////////////// //
58 bool parseBlock (ref MemBuffer mbuf
) {
59 import std
.range
: enumerate
;
60 auto blk
= BtcBlock(mbuf
);
62 auto hdr
= blk
.header
;
63 //hdr.bits = 0x1d001234;
64 writeln("version: ", hdr
.ver
);
65 writeln("time: ", hdr
.time
);
66 writeln("prev: ", hdr
.prev
.bin2hex
);
67 writeln("root: ", hdr
.root
.bin2hex
);
68 //writeln("bits: ", hdr.bits2str);
69 writeln("bits: ", hdr
.decodeBits
.bin2hex
);
70 //writeln("bits: ", hdr.bits);
71 //writefln("bits: 0x%08x", hdr.bits);
72 //assert(hdr.zero == 0);
73 foreach (immutable tidx
, const ref tx
; blk
[].enumerate
) {
74 writeln("transaction #", tidx
, "; version is ", tx
.ver
, "; inputs: ", tx
.incount
, "; outputs: ", tx
.outcount
, "; lock=", tx
.locktime
, "; datalen=", tx
.data
.length
, "; txid=", tx
.txid
.bin2hex
);
76 writeln(" -- inputs --");
77 foreach (immutable vidx
, const ref txin
; tx
.inputs
.enumerate
) {
78 writeln(" #", vidx
, ": vout=", txin
.vout
, "; seq=", txin
.seq
, "; script_length=", txin
.script
.length
, "; id=", txin
.id
.bin2hex
);
79 version(dump_scripts
) {
80 const(ubyte)[] sc
= txin
.script
;
84 writefln(" %04X: %s", ofs
, btsDecodeOne(sc
));
85 sc
= sc
[btsOpSize(sc
)..$];
91 if (tx
.outcount
> 0) {
92 writeln(" -- outputs --");
93 foreach (immutable vidx
, const ref txout
; tx
.outputs
.enumerate
) {
94 writeln(" #", vidx
, ": value=", txout
.value
, "; script_length=", txout
.script
.length
);
95 version(dump_scripts
) {
96 const(ubyte)[] sc
= txout
.script
;
100 writefln(" %04X: %s", ofs
, btsDecodeOne(sc
));
101 sc
= sc
[btsOpSize(sc
)..$];
108 //writeln(fl.position-8);
113 // ////////////////////////////////////////////////////////////////////////// //
116 void main (string
[] args
) {
117 assert(args
.length
> 1);
118 auto fl
= MMapFile(args
[1]);
119 auto mbuf
= MemBuffer(fl
[]);
120 auto stt
= MonoTime
.currTime
;
121 int count
= 0, total
= 0;
122 while (!mbuf
.empty
) {
123 if (!parseBlock(mbuf
)) break;
125 if (++count
>= 1024) {
127 auto ctt
= MonoTime
.currTime
;
128 if ((ctt
-stt
).total
!"msecs" >= 1000) {
129 stderr
.write("\r", total
, " blocks processed...");
134 stderr
.writeln("\r", total
, " blocks processed...");