From f10a75c82caa2eaec4152c4f3188036bc7b2cdaa Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Mon, 18 Sep 2017 11:31:38 +0200 Subject: [PATCH] Initial Commit --- .gitignore | 40 ++++++++++++++++++++++ BlockTemplate.cs | 28 ++++++++++++++++ Properties/AssemblyInfo.cs | 26 +++++++++++++++ cryptonote.csproj | 65 ++++++++++++++++++++++++++++++++++++ packages.config | 4 +++ rpc/Daemon.cs | 68 ++++++++++++++++++++++++++++++++++++++ tools/HexString.cs | 20 +++++++++++ 7 files changed, 251 insertions(+) create mode 100644 .gitignore create mode 100644 BlockTemplate.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 cryptonote.csproj create mode 100644 packages.config create mode 100644 rpc/Daemon.cs create mode 100644 tools/HexString.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e82d27 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# Autosave files +*~ + +# build +[Oo]bj/ +[Bb]in/ +packages/ +TestResults/ + +# globs +Makefile.in +*.DS_Store +*.sln.cache +*.suo +*.cache +*.pidb +*.userprefs +*.usertasks +config.log +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.user +*.tar.gz +tarballs/ +test-results/ +Thumbs.db + +# Mac bundle stuff +*.dmg +*.app + +# resharper +*_Resharper.* +*.Resharper + +# dotCover +*.dotCover diff --git a/BlockTemplate.cs b/BlockTemplate.cs new file mode 100644 index 0000000..af7b301 --- /dev/null +++ b/BlockTemplate.cs @@ -0,0 +1,28 @@ +using System; +namespace cryptonote +{ + public class BlockTemplate + { + public BlockTemplate(byte[] blob, Int64 difficulty, Int64 height, string prev_hash, Int64 reserved_offset, Int64 reserve_size) + { + this.Blob = blob; + this.Height = height; + this.Difficulty = difficulty; + this.PreviousHash = prev_hash; + this.ReservedOffset = reserved_offset; + this.ReserveSize = reserve_size; + + } + + public byte[] Blob { get; private set; } + public Int64 Difficulty { get; private set; } + public Int64 Height { get; private set; } + public Int64 ReservedOffset { get; private set; } + public Int64 ReserveSize { get; private set; } + public string PreviousHash { get; private set; } + + + + + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..277be1c --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("cryptonote")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/cryptonote.csproj b/cryptonote.csproj new file mode 100644 index 0000000..31b5c12 --- /dev/null +++ b/cryptonote.csproj @@ -0,0 +1,65 @@ + + + + Debug + AnyCPU + {52C68C13-2DC2-438A-9EC1-E8C4953B07DF} + Library + cryptonote + cryptonote + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + true + bin\Release + prompt + 4 + false + + + + + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + {DCE6066E-9709-4D12-8994-F7879C3557D6} + JSONRPC + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..ee51c23 --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/rpc/Daemon.cs b/rpc/Daemon.cs new file mode 100644 index 0000000..ccf136f --- /dev/null +++ b/rpc/Daemon.cs @@ -0,0 +1,68 @@ +using System; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Collections.Generic; +using System.Threading.Tasks; + +using JSONRPC; +using cryptonote.tools; + +namespace cryptonote.rpc +{ + public class Daemon + { + RPCConnector rpc; + + public Daemon(string host,int port) + { + this.rpc = new RPCConnector(host, port); + } + + + public int GetBlockCount(){ + Response response = rpc.Call("getblockcount"); + if (response.Success()){ + return Convert.ToInt32(response.result["count"].ToObject()); + } + return -1; + } + + public BlockTemplate getBlockTemplate(string wallet,uint reserve_size){ + BlockTemplate bt = null; + Response response = this.rpc.Call() + .method("getblocktemplate") + .parameter("wallet_address", wallet) + .parameter("reserve_size", 60) + .execute(); + + if (response.Success()){ + byte[] blob = HexString.toBytes(response.result["blocktemplate_blob"].ToString()); + bt = new BlockTemplate( + blob, + response.result["difficulty"].ToObject(), + response.result["height"].ToObject(), + response.result["prev_hash"].ToObject(), + response.result["reserved_offset"].ToObject(), + reserve_size + ); + } + return bt; + } + + public bool check(){ + return this.rpc.Call("get_info").Success(); + + } + + public Int64 getTargetHeight(){ + Response response = rpc.Call("get_info"); + if (response.Success()){ + return response.result["target_height"].ToObject(); + } + return -1; + } + + + } +} diff --git a/tools/HexString.cs b/tools/HexString.cs new file mode 100644 index 0000000..bb330e4 --- /dev/null +++ b/tools/HexString.cs @@ -0,0 +1,20 @@ +using System; +namespace cryptonote.tools +{ + public class HexString + { + public static byte[] toBytes(string hexstring) + { + byte[] bytes = new byte[hexstring.Length >> 1]; + for (int n = 0; n < hexstring.Length >> 1;n++){ + bytes[n] = Convert.ToByte(hexstring.Substring(n << 1, 2), 16); + } + return bytes; + } + + public static String toString(byte[] bytes){ + return BitConverter.ToString(bytes).Replace("-", String.Empty); + } + + } +}