Skip to content

Commit 7b66cf1

Browse files
committed
initial commit
0 parents  commit 7b66cf1

12 files changed

Lines changed: 1226 additions & 0 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
[Dd]ebug/
11+
[Dd]ebugPublic/
12+
[Rr]elease/
13+
x64/
14+
build/
15+
bld/
16+
[Bb]in/
17+
[Oo]bj/
18+
19+
# MSTest test Results
20+
[Tt]est[Rr]esult*/
21+
[Bb]uild[Ll]og.*
22+
23+
#NUNIT
24+
*.VisualState.xml
25+
TestResult.xml
26+
27+
*_i.c
28+
*_p.c
29+
*_i.h
30+
*.ilk
31+
*.meta
32+
*.obj
33+
*.pch
34+
*.pdb
35+
*.pgc
36+
*.pgd
37+
*.rsp
38+
*.sbr
39+
*.tlb
40+
*.tli
41+
*.tlh
42+
*.tmp
43+
*.tmp_proj
44+
*.log
45+
*.vspscc
46+
*.vssscc
47+
.builds
48+
*.pidb
49+
*.svclog
50+
*.scc
51+
52+
# Chutzpah Test files
53+
_Chutzpah*
54+
55+
# Visual C++ cache files
56+
ipch/
57+
*.aps
58+
*.ncb
59+
*.opensdf
60+
*.sdf
61+
*.cachefile
62+
63+
# Visual Studio profiler
64+
*.psess
65+
*.vsp
66+
*.vspx
67+
68+
# TFS 2012 Local Workspace
69+
$tf/
70+
71+
# Guidance Automation Toolkit
72+
*.gpState
73+
74+
# ReSharper is a .NET coding add-in
75+
_ReSharper*/
76+
*.[Rr]e[Ss]harper
77+
*.DotSettings.user
78+
79+
# JustCode is a .NET coding addin-in
80+
.JustCode
81+
82+
# TeamCity is a build add-in
83+
_TeamCity*
84+
85+
# DotCover is a Code Coverage Tool
86+
*.dotCover
87+
88+
# NCrunch
89+
*.ncrunch*
90+
_NCrunch_*
91+
.*crunch*.local.xml
92+
93+
# MightyMoose
94+
*.mm.*
95+
AutoTest.Net/
96+
97+
# Web workbench (sass)
98+
.sass-cache/
99+
100+
# Installshield output folder
101+
[Ee]xpress/
102+
103+
# DocProject is a documentation generator add-in
104+
DocProject/buildhelp/
105+
DocProject/Help/*.HxT
106+
DocProject/Help/*.HxC
107+
DocProject/Help/*.hhc
108+
DocProject/Help/*.hhk
109+
DocProject/Help/*.hhp
110+
DocProject/Help/Html2
111+
DocProject/Help/html
112+
113+
# Click-Once directory
114+
publish/
115+
116+
# Publish Web Output
117+
*.[Pp]ublish.xml
118+
*.azurePubxml
119+
120+
# NuGet Packages Directory
121+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
122+
#packages/*
123+
## TODO: If the tool you use requires repositories.config, also uncomment the next line
124+
#!packages/repositories.config
125+
126+
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
127+
# This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented)
128+
!packages/build/
129+
130+
# Windows Azure Build Output
131+
csx/
132+
*.build.csdef
133+
134+
# Windows Store app package directory
135+
AppPackages/
136+
137+
# Others
138+
sql/
139+
*.Cache
140+
ClientBin/
141+
[Ss]tyle[Cc]op.*
142+
~$*
143+
*~
144+
*.dbmdl
145+
*.dbproj.schemaview
146+
*.pfx
147+
*.publishsettings
148+
node_modules/
149+
150+
# RIA/Silverlight projects
151+
Generated_Code/
152+
153+
# Backup & report files from converting an old project file to a newer
154+
# Visual Studio version. Backup files are not needed, because we have git ;-)
155+
_UpgradeReport_Files/
156+
Backup*/
157+
UpgradeLog*.XML
158+
UpgradeLog*.htm
159+
160+
# SQL Server files
161+
App_Data/*.mdf
162+
App_Data/*.ldf
163+
164+
# Business Intelligence projects
165+
*.rdl.data
166+
*.bim.layout
167+
*.bim_*.settings
168+
169+
# Microsoft Fakes
170+
FakesAssemblies/
171+
172+
# =========================
173+
# Windows detritus
174+
# =========================
175+
176+
# Windows image file caches
177+
Thumbs.db
178+
ehthumbs.db
179+
180+
# Folder config file
181+
Desktop.ini
182+
183+
# Recycle Bin used on file shares
184+
$RECYCLE.BIN/

BlockChainParser.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.21005.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlockChainParser", "BlockChainParser\BlockChainParser.csproj", "{E2BE82C9-B72D-4DA4-987D-1A6EFFD769C6}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E2BE82C9-B72D-4DA4-987D-1A6EFFD769C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E2BE82C9-B72D-4DA4-987D-1A6EFFD769C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E2BE82C9-B72D-4DA4-987D-1A6EFFD769C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E2BE82C9-B72D-4DA4-987D-1A6EFFD769C6}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

BlockChainParser/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
5+
</startup>
6+
</configuration>

BlockChainParser/BlockChain.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* BlockChainParser - http://github.com/kria/BlockChainParser
3+
*
4+
* Copyright (C) 2014 Kristian Adrup
5+
*
6+
* This file is part of BlockChainParser.
7+
*
8+
* BlockChainParser is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by the
10+
* Free Software Foundation, either version 3 of the License, or (at your
11+
* option) any later version. See included file COPYING for details.
12+
*/
13+
14+
using System;
15+
using System.Collections.Generic;
16+
using System.IO;
17+
using System.Linq;
18+
using System.Numerics;
19+
using System.Text;
20+
using System.Threading.Tasks;
21+
22+
namespace BlockChainParser
23+
{
24+
public class BlockChain
25+
{
26+
private const uint magicId = 0xD9B4BEF9;
27+
// trueDiffOne == 0x00000000FFFF0000000000000000000000000000000000000000000000000000
28+
private static readonly double trueDiffOne = Double.Parse("26959535291011309493156476344723991336010898738574164086137773096960");
29+
30+
/// <summary>
31+
/// Parse a Bitcoin-Qt blk*.dat file and generate a callback event on each block.
32+
/// </summary>
33+
/// <param name="path">Path of file to parse</param>
34+
/// <param name="callback">Callback method</param>
35+
/// <returns>number of blocks parsed</returns>
36+
public static int ParseBlockFile(string path, Action<string, double> callback) {
37+
int blockCount = 0;
38+
39+
using (FileStream fs = File.OpenRead(path))
40+
{
41+
var rdr = new BinaryReader(fs);
42+
while (fs.Position < fs.Length)
43+
{
44+
uint magic = rdr.ReadUInt32();
45+
if (magic != magicId) throw new Exception("Expected magic, bailing file!");
46+
47+
uint headerLength = rdr.ReadUInt32();
48+
uint versionNumber = rdr.ReadUInt32();
49+
50+
byte[] hashBuf = rdr.ReadBytes(32);
51+
BigInteger prevHash = new BigInteger(hashBuf);
52+
53+
Array.Reverse(hashBuf); // to big endian from little
54+
string hashstr = Utils.ToHexString(hashBuf);
55+
double blockDiff = Math.Round(trueDiffOne / (double)prevHash);
56+
57+
callback(hashstr, blockDiff);
58+
59+
blockCount++;
60+
fs.Seek(headerLength - 36, SeekOrigin.Current);
61+
}
62+
}
63+
return blockCount;
64+
}
65+
}
66+
67+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E2BE82C9-B72D-4DA4-987D-1A6EFFD769C6}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>BlockChainParser</RootNamespace>
11+
<AssemblyName>BlockChainParser</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="CommandLine">
36+
<HintPath>..\lib\CommandLine.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Numerics" />
41+
<Reference Include="System.Xml.Linq" />
42+
<Reference Include="System.Data.DataSetExtensions" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Xml" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="BlockChain.cs" />
49+
<Compile Include="Program.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
<Compile Include="Utils.cs" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<None Include="App.config" />
55+
</ItemGroup>
56+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
57+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
58+
Other similar extension points exist, see Microsoft.Common.targets.
59+
<Target Name="BeforeBuild">
60+
</Target>
61+
<Target Name="AfterBuild">
62+
</Target>
63+
-->
64+
</Project>

0 commit comments

Comments
 (0)