Split application and library.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,4 @@
|
||||
/.vs/*
|
||||
/BasicBlockChain/bin/*
|
||||
/BasicBlockChain/obj/*
|
||||
*/bin/*
|
||||
*/obj/*
|
||||
/packages/
|
||||
|
||||
56
BasicBlockChain.Core/BasicBlockChain.Core.csproj
Normal file
56
BasicBlockChain.Core/BasicBlockChain.Core.csproj
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{919BC116-C8FC-4B65-B742-226B38437C48}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BasicBlockChain.Core</RootNamespace>
|
||||
<AssemblyName>BasicBlockChain.Core</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="VAR.Json, Version=1.1.1.36534, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\VAR.Json.1.1.1.36534\lib\net461\VAR.Json.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Block.cs" />
|
||||
<Compile Include="BlockChain.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Transaction.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -2,8 +2,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using VAR.Json;
|
||||
|
||||
namespace BasicBlockChain
|
||||
namespace BasicBlockChain.Core
|
||||
{
|
||||
public class Block
|
||||
{
|
||||
@@ -26,8 +27,7 @@ namespace BasicBlockChain
|
||||
|
||||
private string GetData()
|
||||
{
|
||||
VAR.Json.JsonWriter jsonWriter = new VAR.Json.JsonWriter(1);
|
||||
return jsonWriter.Write(Transactions);
|
||||
return JsonWriter.WriteObject(Transactions);
|
||||
}
|
||||
|
||||
public string CalculateHash(string data = null, SHA256 sha256 = null)
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BasicBlockChain
|
||||
namespace BasicBlockChain.Core
|
||||
{
|
||||
public class BlockChain
|
||||
{
|
||||
36
BasicBlockChain.Core/Properties/AssemblyInfo.cs
Normal file
36
BasicBlockChain.Core/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("BasicBlockChain.Core")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("BasicBlockChain.Core")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("919bc116-c8fc-4b65-b742-226b38437c48")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace BasicBlockChain
|
||||
namespace BasicBlockChain.Core
|
||||
{
|
||||
public class Transaction
|
||||
{
|
||||
4
BasicBlockChain.Core/packages.config
Normal file
4
BasicBlockChain.Core/packages.config
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="VAR.Json" version="1.1.1.36534" targetFramework="net48" />
|
||||
</packages>
|
||||
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.28803.452
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicBlockChain", "BasicBlockChain\BasicBlockChain.csproj", "{34581A96-29BE-4AB6-9298-BC1AD3E78369}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicBlockChain.Core", "BasicBlockChain.Core\BasicBlockChain.Core.csproj", "{919BC116-C8FC-4B65-B742-226B38437C48}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{34581A96-29BE-4AB6-9298-BC1AD3E78369}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{34581A96-29BE-4AB6-9298-BC1AD3E78369}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{34581A96-29BE-4AB6-9298-BC1AD3E78369}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{919BC116-C8FC-4B65-B742-226B38437C48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{919BC116-C8FC-4B65-B742-226B38437C48}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{919BC116-C8FC-4B65-B742-226B38437C48}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{919BC116-C8FC-4B65-B742-226B38437C48}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -42,20 +42,22 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="VAR.Json, Version=1.0.6252.27492, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\VAR.Json.1.0.6252.27492\lib\net461\VAR.Json.dll</HintPath>
|
||||
<Reference Include="VAR.Json, Version=1.1.1.36534, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\VAR.Json.1.1.1.36534\lib\net461\VAR.Json.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Block.cs" />
|
||||
<Compile Include="BlockChain.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Transaction.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BasicBlockChain.Core\BasicBlockChain.Core.csproj">
|
||||
<Project>{919bc116-c8fc-4b65-b742-226b38437c48}</Project>
|
||||
<Name>BasicBlockChain.Core</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using BasicBlockChain.Core;
|
||||
using VAR.Json;
|
||||
|
||||
namespace BasicBlockChain
|
||||
{
|
||||
@@ -6,20 +8,18 @@ namespace BasicBlockChain
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
VAR.Json.JsonWriter jsonWriter = new VAR.Json.JsonWriter(1);
|
||||
|
||||
// Example BlockChain with some example data
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("#### Mining BlockChain with sample data");
|
||||
var startTime = DateTime.UtcNow;
|
||||
BlockChain nullCoin = new BlockChain(genesisDate: new DateTime(2000, 1, 1), difficulty: 2);
|
||||
BlockChain nullCoin = new BlockChain(genesisDate: new DateTime(2000, 1, 1), difficulty: 3);
|
||||
nullCoin.AddTransaction(new Transaction("VAR", "NAM", 10_000_000, new DateTime(2000, 1, 2)));
|
||||
nullCoin.ProcessPendingTransactions(new DateTime(2000, 1, 2), "Kable");
|
||||
nullCoin.AddTransaction(new Transaction("NAM", "VAR", 5_000_000, new DateTime(2000, 1, 3)));
|
||||
nullCoin.ProcessPendingTransactions(new DateTime(2000, 1, 3), "Kable");
|
||||
nullCoin.AddTransaction(new Transaction("NAM", "VAR", 5_000_000, new DateTime(2000, 1, 4)));
|
||||
nullCoin.ProcessPendingTransactions(new DateTime(2000, 1, 4), "Kable");
|
||||
Console.WriteLine(jsonWriter.Write(nullCoin));
|
||||
Console.WriteLine(JsonWriter.WriteObject(nullCoin, indent: true));
|
||||
var endTime = DateTime.UtcNow;
|
||||
Console.WriteLine($"Duration: {endTime - startTime}");
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace BasicBlockChain
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("#### Tampering with the data");
|
||||
nullCoin.Chain[1].Transactions[0].MicroCoinAmount = 1000_000_000;
|
||||
Console.WriteLine(jsonWriter.Write(nullCoin));
|
||||
Console.WriteLine(JsonWriter.WriteObject(nullCoin, indent: true));
|
||||
|
||||
// Verify
|
||||
Console.WriteLine("BlockChain is Valid? {0}", nullCoin.Verify() ? "True" : "False");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="VAR.Json" version="1.0.6252.27492" targetFramework="net472" />
|
||||
<package id="VAR.Json" version="1.1.1.36534" targetFramework="net48" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user