Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
22 changes: 22 additions & 0 deletions Blockchain/Client_ViggiCoin v2.0/Client_ViggiCoin v2.0.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client_ViggiCoin v2.0", "Client_ViggiCoin v2.0\Client_ViggiCoin v2.0.csproj", "{1D43135D-88C1-421F-90D3-8E4E75811B60}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1D43135D-88C1-421F-90D3-8E4E75811B60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D43135D-88C1-421F-90D3-8E4E75811B60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D43135D-88C1-421F-90D3-8E4E75811B60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D43135D-88C1-421F-90D3-8E4E75811B60}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blockchain
{
//Wrapper usato per ritornare valori dalla funzione CPeers.DoRequest()
class ArgumentWrapper<T>
{
public T Value;

public ArgumentWrapper()
{ }

public ArgumentWrapper(T Value)
{
this.Value = Value;
}
}
}
49 changes: 49 additions & 0 deletions Blockchain/Client_ViggiCoin v2.0/Client_ViggiCoin v2.0/CBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;

namespace Blockchain
{
public class CBlock
{
public string Hash;
public ulong BlockNumber;
public string Transiction;
public ulong Nonce;
public ulong Timestamp;
public ushort Difficutly;
public static int TargetMiningTime = 60;

public CBlock()
{ }

public CBlock(string Hash, ulong NumBlock, string Transiction, ulong Nonce, ulong Timestamp, ushort Difficutly)
{
this.Hash = Hash;
this.BlockNumber = NumBlock;
this.Transiction = Transiction;
this.Nonce = Nonce;
this.Timestamp = Timestamp;
this.Difficutly = Difficutly;
}

/// <summary>
/// Crea un nuovo oggetto CBlock usando una stringa che lo rappresenta.
/// </summary>
/// <param name="BlockString">Stringa che rappresenta l'oggetto CBlock.</param>
public static CBlock Deserialize(string SerializedBlock)
{
string[] blockField;
SerializedBlock = SerializedBlock.Trim('{', '}');
blockField = SerializedBlock.Split(';');
if (Program.DEBUG)
CIO.DebugOut("Deserializing block number: "+ blockField[1]+".");
return new CBlock(blockField[0], Convert.ToUInt64(blockField[1]), blockField[2], Convert.ToUInt64(blockField[3]), Convert.ToUInt64(blockField[4]), Convert.ToUInt16(blockField[5]));
}

/*
public ulong BlockNumber
{
get { return mBlockNumber; }
}
*/
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.IO;

namespace Blockchain
{
class CBlockChain
{
private CBlock mLastBlock=null; //ultimo blocco ricevuto
private CBlock mLastValidBlock = null; //ultimo blocco sicuramente valido
#region Singleton
private static CBlockChain instance;

private CBlockChain()
{
Load();
}

public static CBlockChain Instance
{
get
{
if (instance == null)
{
instance = new CBlockChain();
}
return instance;
}
}
#endregion Singleton

public CBlock LastBlock
{
get { return mLastBlock; }
}

public CBlock LastValidBlock
{
get { return mLastBlock; }
}

/// <summary>
/// Carica l'ultimo blocco della blockchain.
/// </summary>
private void Load()
{
StreamReader file = new StreamReader("blockchain.txt");
mLastValidBlock = CBlock.Deserialize(file.ReadLine());

}


internal static bool Validate(CBlock b)
{
throw new System.NotImplementedException();
}

internal static void Add(CBlock b)
{
throw new System.NotImplementedException();
}

internal static void Add(CBlock[] b)
{
throw new System.NotImplementedException();
}
}
}
37 changes: 37 additions & 0 deletions Blockchain/Client_ViggiCoin v2.0/Client_ViggiCoin v2.0/CIO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blockchain
{
class CIO
{
//v 2.0 "Vgg"
//input/output da modificare se non è più su console
public static void WriteLine(string s)
{
Console.WriteLine(s);
}

public static void Write(string s)
{
Console.WriteLine(s);
}

public static void DebugOut(string s)
{
WriteLine(s);
WriteLine("");
}

public static string ReadLine()
{
return Console.ReadLine();
}


}
}

Loading