diff --git a/.gitignore b/.gitignore
index 8d1a377..ad2d3a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,165 +1,25 @@
-## Ignore Visual Studio temporary files, build results, and
-## files generated by popular Visual Studio add-ons.
-
-# User-specific files
-*.suo
-*.user
-*.sln.docstates
-
-# Build results
-
-[Dd]ebug/
-[Rr]elease/
-x64/
-build/
[Bb]in/
[Oo]bj/
+[Ww]orking*/
+Build/Temp/
+Doc/doc.shfbproj_*
-# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
-!packages/*/build/
-
-# MSTest test Results
-[Tt]est[Rr]esult*/
-[Bb]uild[Ll]og.*
-
-*_i.c
-*_p.c
-*.ilk
-*.meta
-*.obj
-*.pch
-*.pdb
-*.pgc
-*.pgd
-*.rsp
-*.sbr
-*.tlb
-*.tli
-*.tlh
-*.tmp
-*.tmp_proj
-*.log
-*.vspscc
-*.vssscc
-.builds
-*.pidb
-*.log
-*.scc
-
-# Visual C++ cache files
-ipch/
-*.aps
-*.ncb
-*.opensdf
-*.sdf
-*.cachefile
-
-# Visual Studio profiler
-*.psess
-*.vsp
-*.vspx
-
-# Guidance Automation Toolkit
-*.gpState
-
-# ReSharper is a .NET coding add-in
-_ReSharper*/
-*.[Rr]e[Ss]harper
-
-# TeamCity is a build add-in
-_TeamCity*
-
-# DotCover is a Code Coverage Tool
-*.dotCover
-
-# NCrunch
-*.ncrunch*
-.*crunch*.local.xml
-
-# Installshield output folder
-[Ee]xpress/
-
-# DocProject is a documentation generator add-in
-DocProject/buildhelp/
-DocProject/Help/*.HxT
-DocProject/Help/*.HxC
-DocProject/Help/*.hhc
-DocProject/Help/*.hhk
-DocProject/Help/*.hhp
-DocProject/Help/Html2
-DocProject/Help/html
-
-# Click-Once directory
-publish/
+TestResults/
-# Publish Web Output
-*.Publish.xml
+**/packages/*
+!**/packages/build/
-# NuGet Packages Directory
-## TODO: If you have NuGet Package Restore enabled, uncomment the next line
-#packages/
-
-# Windows Azure Build Output
-csx
-*.build.csdef
-
-# Windows Store app package directory
-AppPackages/
-
-# Others
-sql/
-*.Cache
-ClientBin/
-[Ss]tyle[Cc]op.*
-~$*
-*~
-*.dbmdl
-*.[Pp]ublish.xml
-*.pfx
-*.publishsettings
-
-# RIA/Silverlight projects
-Generated_Code/
-
-# Backup & report files from converting an old project file to a newer
-# Visual Studio version. Backup files are not needed, because we have git ;-)
-_UpgradeReport_Files/
-Backup*/
-UpgradeLog*.XML
-UpgradeLog*.htm
-
-# SQL Server files
-App_Data/*.mdf
-App_Data/*.ldf
-
-#RiderC#
-.idea/
-*.*.iml
-
-#LightSwitch generated files
-GeneratedArtifacts/
-_Pvt_Extensions/
-ModelManifest.xml
-
-# =========================
-# Windows detritus
-# =========================
-
-# Windows image file caches
-Thumbs.db
-ehthumbs.db
-
-# Folder config file
-Desktop.ini
-
-# Recycle Bin used on file shares
-$RECYCLE.BIN/
-
-# Mac desktop service store files
-.DS_Store
-
-
-# Sandcasle Output Folder
-Help/*
-/.vs/IotaApi
-/packages
+BenchmarkDotNet.Artifacts/
+*.suo
+*.user
+*.userprefs
+_ReSharper.*
+*.ReSharper.user
+*.resharper.user
+.vs/
+.vscode/
+*.lock.json
+*.nuget.props
+*.nuget.targets
+*.orig
+.DS_Store
\ No newline at end of file
diff --git a/IotaApi.Standard.Tests/IotaApi.Standard.Tests.csproj b/IotaApi.Standard.Tests/IotaApi.Standard.Tests.csproj
deleted file mode 100644
index 895f697..0000000
--- a/IotaApi.Standard.Tests/IotaApi.Standard.Tests.csproj
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
- netcoreapp2.0
-
- false
-
- Iota.Api.Standard.Tests
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/IotaApi.Standard.Tests/IotaApiTests.cs b/IotaApi.Standard.Tests/IotaApiTests.cs
deleted file mode 100644
index 3870ded..0000000
--- a/IotaApi.Standard.Tests/IotaApiTests.cs
+++ /dev/null
@@ -1,301 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Iota.Api.Standard.Exception;
-using Iota.Api.Standard.Model;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests
-{
- [TestClass]
- public class IotaApiTests
- {
- private static readonly string TEST_SEED1 =
- "IHDEENZYITYVYSPKAURUZAQKGVJEREFDJMYTANNXXGPZ9GJWTEOJJ9IPMXOGZNQLSNMFDSQOTZAEETUEA";
-
- private static readonly string TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_1 =
- "MALAZGDVZIAQQRTNYJDSZMY9VE9LAHQKTVCUOAGZUCX9IBUMODFFTMGUIUAXGLWZQ9CYRSLYBM9QBIBYAEIAOPKXEA";
-
- private static readonly string TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2 =
- "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC";
-
- private static readonly string TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_3 =
- "ASCZZOBQDMNHLELQKWJBMRETMHBTF9V9TNKYDIFW9PDXPUHPVVGHMSWPVMNJHSJF99QFCMNTPCPGS9DT9XAFKJVO9X";
-
- private static readonly string TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_1 =
- "MALAZGDVZIAQQRTNYJDSZMY9VE9LAHQKTVCUOAGZUCX9IBUMODFFTMGUIUAXGLWZQ9CYRSLYBM9QBIBYA";
-
- private static readonly string TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2 =
- "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZC";
-
- private static readonly string TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_3 =
- "ASCZZOBQDMNHLELQKWJBMRETMHBTF9V9TNKYDIFW9PDXPUHPVVGHMSWPVMNJHSJF99QFCMNTPCPGS9DT9";
-
- private static readonly string TEST_SEED2 =
- "IHDEENZYITYVYSPKAURUZAQKGVJEREFDJMYTANNXXGPZ9GJWTEOJJ9IPMXOGZNQLSNMFDSQOTZAEETUEA";
-
- private static readonly string TEST_HASH =
- "9XWWWXVQYPKLVMAMFPXFSE9UCAGVY9RZO9NHGAZEXIRIJRZULGMFOJNDKUNFUCSURWRDDPVMYG9X99999"; //06/02/2018,04:36
-
- private static readonly string TEST_TRYTES =
- "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCQ9CA9TA99999999999999999999XC9999999999999999999999999TPLCUYD99999999999B99999999WFVTNIRLVFIVKAQEEDFRWWLXIPHRQNG9EAY9QEWRFDLECXDGJLIKBAKBYPTAZPISWVXJLBJISGGLWTBVDNBEBXBG9PZHPK9SVNH99LZVXYZSVODZZIIXNJJQAYXCNKISVFVXGVQMURVEMSDGLRLZADQCOHRHW99999K9SYJTSNRZVYWGSV9AXVTPKMTLHPCTIJGNNAMALVPQUCGCZXZFFUQSXCHPSJLXBADVOIZO9PSZYTA9999XC9999999999999999999999999WWF9MWCJE999999999MMMMMMMMMPRQAGSHN9ZHEWVAANNPXSDRRROY";
-
- private static readonly string TEST_MESSAGE = "COTA";
- private static readonly string TEST_TAG = "COTASPAM9999999999999999999";
-
- // ReSharper disable once InconsistentNaming
- private static readonly string[] TEST_ADDRESSES =
- {
- "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC",
- "P9UDUZMN9DEXCRQEKLJYSBSBZFCHOBPJSDKMLCCVJDOVOFDWMNBZRIRRZJGINOUMPJBMYYZEGRTIDUABD",
- "MIMVJEYREIIZLXOXQROMPJFCIX9NFVXD9ZQMNZERPI9OJIJFUWQ9WCTMKXEEPHYPWEZPHLJBJOFH9YTRB",
- "FOJHXRVJRFMJTFDUWJYYZXCZIJXKQALLXMLKHZFDMHWTIBBXUKSNSUYJLKYRQBNXKRSUXZHDTPWXYD9YF",
- "B9YNPQO9EXID9RDEEGLCBJBYKBLWHTOQOZKTLJDFPJZOPKJJTNUYUVVTDJPBCBYIWGPSCMNRZFGFHFSXH",
- "NQEFOAFIYKZOUXDFQ9X9PHCNSDETRTJZINZ9EYGKU99QJLDSTSC9VTBAA9FHLNLNYQXWLTNPRJDWCGIPP",
- "CEGLBSXDJVXGKGOUHRGMAQDRVYXCQLXBKUDWKFFSIABCUYRATFPTEEDIFYGAASKFZYREHLBIXBTKP9KLC",
- "QLOXU9GIQXPPE9UUT9DSIDSIESRIXMTGZJMKLSJTNBCRELAVLWVJLUOLKGFCWAEPEQWZWPBV9YZJJEHUS",
- "XIRMYJSGQXMM9YPHJVVLAVGBBLEEMOOKHHBFWKEAXJFONZLNSLBCGPQEVDMMOGHFVRDSYTETIFOIVNCR9",
- "PDVVBYBXMHZKADPAYOKQNDPHRSWTHAWQ9GRVIBOIMZQTYCWEPCDWDVRSOUNASVBDLBOAMVLYEVVCMAM9N",
- "U9GAIAPUUQWJGISAZWPLHUELTZ9WSHWXS9JLPKOWHRRIVUKGWCTJMBULVMKTETTUNHZ9HWHBALUCJIROU",
- "VFPMKZLLMDUOEKNBEKQZPTNZJZF9UHRWSTHXLWQQ9OAXTZQHTZPAWNJNXKAZFSDFWKFQEKZIGJTLWQFLO",
- "IGHK9XIWOAYBZUEZHQLEXBPTXSWVANIOUZZCPNKUIJIJOJNAQCJWUJHYKCZOIKVAAHDGAWJZKLTPVQL9G",
- "LXQPWMNXSUZTEYNC9ZBBFHY9YWCCOVKBNIIOUSVXZJZMJKJFDUWGUVXYCHGKUHEEIDHSGEWFAHVJPRIJT",
- "AKFDX9PGGQLZUWRMZ9YBDF9CG9TWXCNALCSXSAWHFIMGXCSYCJLSWIQDGGVDRMNEKKECQEYAITGNLNJFQ",
- "YX9QSPYMSFVOW9UVZRDVOCPYYMUTDHCCPKHMXQSJQJYIXVCHILKW9GBYJTYGLIKBTRQMDCYBMLLNGSSIK",
- "DSYCJKNG9TAGJHSKZQ9XLKAKNSKJFZIPVEDGJFXRTFGENHZFQGXHWDBNXLLDABDMOYELPG9DIXSNJFWAR",
- "9ANNACZYLDDPZILLQBQG9YMG9XJUMTAENDFQ9HMSSEFWYOAXPJTUXBFTSAXDJPAO9FKTWBBSCSFMOUR9I",
- "WDTFFXHBHMFQQVXQLBFJFVVHVIIAVYM9PFAZCHMKET9ESMHIRHSMVDJBZTXPTAFVIASMSXRDCIYVWVQNO",
- "XCCPS9GMTSUB9DXPVKLTBDHOFX9PJMBYZQYQEXMRQDPGQPLWRGZGXODYJKGVFOHHYUJRCSXAIDGYSAWRB",
- "KVEBCGMEOPDPRCQBPIEMZTTXYBURGZVNH9PLHKPMM9D9FUKWIGLKZROGNSYIFHULLWQWXCNAW9HKKVIDC"
- };
-
- private static readonly string TestTrytesValid =
- "JUSTANOTHERTEST999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999PNGMCSNRCTRHCHPXYTPKEJYPCOWKOMRXZFHH9N9VDIKMNVAZCMIYRHVJIAZARZTUETJVFDMBEBIQE9QTH999999999999999999999999999COTASPAM9999999999999999999VISYF9DGE999999999999999999FB9CRHGOHK9EIDHDUWSGDDONYQAABTRXXMFUKRZHMVJAPCAADTRDCWZJRHAPL9LRIVZFVKQV9GAWSSJZDPWGPQTPWCPNYONYGGSJLJAQYXLZ9FMOTUJT9RIXAOXFDQZSTZYBCHSNLSM9JAXTMNQBUHAAZIIR999999PWGPQTPWCPNYONYGGSJLJAQYXLZ9FMOTUJT9RIXAOXFDQZSTZYBCHSNLSM9JAXTMNQBUHAAZIIR999999KXOQZNGXOCACOVYKPWWJFQQMEWDQVUZRI99WFQEJANSOPVLZGQHLUEYKPYPMSTLDRDVEBMCQMKQLL9JFS";
-
- private static int MIN_WEIGHT_MAGNITUDE = 14;
- private static int DEPTH = 9;
-
- private IotaApi _iotaClient;
-
- [TestInitialize]
- public void CreateApiClientInstance()
- {
- _iotaClient = new IotaApi("node.iotawallet.info", 14265);
- }
-
- [TestMethod]
- public void ShouldGetInputs()
- {
- var res = _iotaClient.GetInputs(TEST_SEED1, 2, 0, 0, 0);
- Console.WriteLine(res);
- Assert.IsNotNull(res);
- Assert.IsNotNull(res.TotalBalance);
- Assert.IsNotNull(res.InputsList);
- }
-
- [TestMethod]
- public void ShouldCreateANewAddressWithChecksum()
- {
- // ReSharper disable RedundantArgumentDefaultValue
- var res1 = _iotaClient.GetNewAddress(TEST_SEED1, 1, 0, true, 5, false);
- Assert.AreEqual(res1[0], TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_1);
-
- var res2 = _iotaClient.GetNewAddress(TEST_SEED1, 2, 0, true, 5, false);
- Assert.AreEqual(res2[0], TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2);
-
- var res3 = _iotaClient.GetNewAddress(TEST_SEED1, 3, 0, true, 5, false);
- Assert.AreEqual(res3[0], TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_3);
- // ReSharper restore RedundantArgumentDefaultValue
- }
-
- [TestMethod]
- public void ShouldCreateANewAddressWithoutChecksum()
- {
- // ReSharper disable RedundantArgumentDefaultValue
- var res1 = _iotaClient.GetNewAddress(TEST_SEED1, 1, 0, false, 5, false);
- Assert.AreEqual(res1[0], TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_1);
-
- var res2 = _iotaClient.GetNewAddress(TEST_SEED1, 2, 0, false, 5, false);
- Assert.AreEqual(res2[0], TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2);
-
- var res3 = _iotaClient.GetNewAddress(TEST_SEED1, 3, 0, false, 5, false);
- Assert.AreEqual(res3[0], TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_3);
- // ReSharper restore RedundantArgumentDefaultValue
- }
-
- [TestMethod]
- public void ShouldCreate100Addresses()
- {
- // ReSharper disable RedundantArgumentDefaultValue
- var res = _iotaClient.GetNewAddress(TEST_SEED1, 2, 0, false, 100, false);
- Assert.AreEqual(res.Length, 100);
- // ReSharper restore RedundantArgumentDefaultValue
- }
-
- [TestMethod]
- [ExpectedException(typeof(NotEnoughBalanceException))]
- public void ShouldPrepareTransfer()
- {
- var transfers = new List
- {
- new Transfer(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2, 100, TEST_MESSAGE, TEST_TAG),
- };
-
- var trytes = _iotaClient.PrepareTransfers(TEST_SEED1, 2, transfers.ToArray(), null, null, false);
-
- Assert.IsNotNull(trytes);
- Assert.IsFalse(trytes.Count == 0);
-
- }
-
- //seed contains 0 balance
- [TestMethod]
- [ExpectedException(typeof(NotEnoughBalanceException))]
- public void ShouldPrepareTransferWithInputs()
- {
- List inputlist = new List();
- List transfers = new List();
-
- var inputs = _iotaClient.GetInputs(TEST_SEED1, 2, 0, 0, 0);
-
- inputlist.AddRange(inputs.InputsList);
-
- transfers.Add(new Transfer(TEST_ADDRESS_WITH_CHECKSUM_SECURITY_LEVEL_2, 100, TEST_MESSAGE, TEST_TAG));
- List trytes =
- _iotaClient.PrepareTransfers(TEST_SEED1, 2, transfers.ToArray(), null, inputlist, true);
-
- Assert.IsNotNull(trytes);
- Assert.IsFalse(trytes.Count == 0);
- }
-
-
- [TestMethod]
- public void ShouldGetLastInclusionState()
- {
- var res = _iotaClient.GetLatestInclusion(new[] {TEST_HASH});
- Assert.IsNotNull(res.States);
- }
-
- [TestMethod]
- public void ShouldFindTransactionObjects()
- {
- var ftr = _iotaClient.FindTransactionObjects(TEST_ADDRESSES);
- Assert.IsNotNull(ftr);
- }
-
- [TestMethod]
- public void ShouldGetAccountData()
- {
- var accountData = _iotaClient.GetAccountData(TEST_SEED1, 2, 0, true, 0, true, 0, 0, true, 0);
- Assert.IsNotNull(accountData);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void ShouldNotGetBundle()
- {
- var bundle = _iotaClient.GetBundle("SADASD");
- Assert.IsNotNull(bundle);
- }
-
- [TestMethod]
- public void ShouldGetBundle()
- {
- var bundle = _iotaClient.GetBundle(TEST_HASH);
- Assert.IsNotNull(bundle);
- }
-
- [TestMethod]
- public void ShouldGetTransfers()
- {
- // ReSharper disable RedundantArgumentDefaultValue
- var gtr = _iotaClient.GetTransfers(TEST_SEED1, 2, 0, 0, false);
- // ReSharper restore RedundantArgumentDefaultValue
-
- foreach (var b in gtr) Assert.IsTrue(b.Transactions.TrueForAll(t => t != null));
- }
-
- [Ignore]
- [TestMethod]
- public void ShouldReplayBundle()
- {
- var replayedList = _iotaClient.ReplayBundle(TEST_HASH, DEPTH, MIN_WEIGHT_MAGNITUDE);
- Assert.IsNotNull(replayedList);
- }
-
- [Ignore]
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void ShouldNotSendTrytes()
- {
- _iotaClient.SendTrytes(new[] {TEST_TRYTES}, 9);
- }
-
- [TestMethod]
- public void ShouldGetTrytes()
- {
- _iotaClient.GetTrytes(TEST_HASH);
- }
-
- [TestMethod]
- public void ShouldBroadcastAndStore()
- {
- _iotaClient.BroadcastAndStore(new List {TEST_TRYTES});
- }
-
- [Ignore]
- [TestMethod]
- public void ShouldSendTrytes()
- {
- _iotaClient.SendTrytes(new[] {TestTrytesValid}, 9);
- }
-
- [Ignore]
- [TestMethod]
- [ExpectedException(typeof(IllegalStateException))]
- public void ShouldNotSendTransfer()
- {
- Transfer[] transfers =
- {
- new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 2, TEST_MESSAGE, TEST_TAG)
- };
-
- var result = _iotaClient.SendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers, null, null,
- false, true);
- Assert.IsNotNull(result);
- }
-
- [Ignore]
- [TestMethod]
- public void ShouldSendTransferWithoutInputs()
- {
- var transfers = new List
- {
- new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 1, "JUSTANOTHERTEST", TEST_TAG)
- };
-
- var str = _iotaClient.SendTransfer(TEST_SEED2, 2, 9, 14, transfers.ToArray(), null, null, false, true);
-
- Assert.IsNotNull(str);
- }
-
- [Ignore]
- [TestMethod]
- public void ShouldSendTransferWithInputs()
- {
- List inputlist = new List();
- List transfers = new List();
-
- var inputs = _iotaClient.GetInputs(TEST_SEED1, 2, 0, 0, 1);
-
- inputlist.AddRange(inputs.InputsList);
-
- transfers.Add(new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 1, TEST_MESSAGE, TEST_TAG));
-
- var str = _iotaClient.SendTransfer(TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers.ToArray(),
- inputlist.ToArray(), null,
- true, true);
-
- Assert.IsNotNull(str);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard.Tests/IotaCoreApiTest.cs b/IotaApi.Standard.Tests/IotaCoreApiTest.cs
deleted file mode 100644
index 5e75e72..0000000
--- a/IotaApi.Standard.Tests/IotaCoreApiTest.cs
+++ /dev/null
@@ -1,172 +0,0 @@
-using System.Linq;
-using Iota.Api.Standard.Exception;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests
-{
- [TestClass]
- public class IotaCoreApiTest
- {
- private static readonly string TEST_BUNDLE =
- "XZKJUUMQOYUQFKMWQZNTFMSS9FKJLOEV9DXXXWPMQRTNCOUSUQNTBIJTVORLOQPLYZOTMLFRHYKMTGZZU";
-
- private static readonly string TEST_ADDRESS_WITH_CHECKSUM =
- "PNGMCSNRCTRHCHPXYTPKEJYPCOWKOMRXZFHH9N9VDIKMNVAZCMIYRHVJIAZARZTUETJVFDMBEBIQE9QTHBFWDAOEFA";
-
- private static readonly string TEST_HASH =
- "OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999";
-
- private static IotaApi _iotaApi;
-
- [TestInitialize]
- public void CreateProxyInstance()
- {
- _iotaApi = new IotaApi("node.iotawallet.info", 14265);
- }
-
- [TestMethod]
- public void ShouldGetNodeInfo()
- {
- var nodeInfo = _iotaApi.GetNodeInfo();
- Assert.IsNotNull(nodeInfo.AppVersion);
- Assert.IsNotNull(nodeInfo.AppName);
- Assert.IsNotNull(nodeInfo.JreVersion);
- Assert.IsNotNull(nodeInfo.JreAvailableProcessors);
- Assert.IsNotNull(nodeInfo.JreFreeMemory);
- Assert.IsNotNull(nodeInfo.JreMaxMemory);
- Assert.IsNotNull(nodeInfo.JreTotalMemory);
- Assert.IsNotNull(nodeInfo.LatestMilestone);
- Assert.IsNotNull(nodeInfo.LatestMilestoneIndex);
- Assert.IsNotNull(nodeInfo.LatestSolidSubtangleMilestone);
- Assert.IsNotNull(nodeInfo.LatestSolidSubtangleMilestoneIndex);
- Assert.IsNotNull(nodeInfo.Neighbors);
- Assert.IsNotNull(nodeInfo.PacketsQueueSize);
- Assert.IsNotNull(nodeInfo.Time);
- Assert.IsNotNull(nodeInfo.Tips);
- Assert.IsNotNull(nodeInfo.TransactionsToRequest);
- }
-
- [TestMethod]
- public void ShouldGetNeighbors()
- {
- var neighbors = _iotaApi.GetNeighbors();
- Assert.IsNotNull(neighbors.Neighbors);
- }
-
- [TestMethod]
- public void ShouldAddNeighbors()
- {
- try
- {
- var res = _iotaApi.AddNeighbors("udp://8.8.8.8:14265");
- Assert.IsNotNull(res);
- }
- catch (IotaApiException e)
- {
- Assert.IsTrue(e.Message.Contains("not available on this node"));
- }
- }
-
- [TestMethod]
- public void ShouldRemoveNeighbors()
- {
- try
- {
- var res = _iotaApi.RemoveNeighbors("udp://8.8.8.8:14265");
- Assert.IsNotNull(res);
- }
- catch (IotaApiException e)
- {
- Assert.IsTrue(e.Message.Contains("not available on this node"));
- }
- }
-
- [TestMethod]
- public void ShouldGetTips()
- {
- var tips = _iotaApi.GetTips();
- Assert.IsNotNull(tips);
- }
-
- [TestMethod]
- public void ShouldFindTransactionsByAddresses()
- {
- var trans = _iotaApi.FindTransactionsByAddresses(TEST_ADDRESS_WITH_CHECKSUM);
- Assert.IsNotNull(trans.Hashes);
- Assert.IsTrue(trans.Hashes.Count > 0);
- }
-
- [TestMethod]
- public void ShouldFindTransactionsByApprovees()
- {
- var trans = _iotaApi.FindTransactionsByApprovees(TEST_HASH);
- Assert.IsNotNull(trans.Hashes);
- }
-
- [TestMethod]
- public void ShouldFindTransactionsByBundles()
- {
- var trans = _iotaApi.FindTransactionsByBundles(TEST_HASH);
- Assert.IsNotNull(trans.Hashes);
- }
-
- [TestMethod]
- public void ShouldFindTransactionsByDigests()
- {
- var trans = _iotaApi.FindTransactionsByDigests(TEST_HASH);
- Assert.IsNotNull(trans.Hashes);
- }
-
- [TestMethod]
- public void ShouldGetTrytes()
- {
- var res = _iotaApi.GetTrytes(TEST_HASH);
- Assert.IsNotNull(res.Trytes);
- }
-
- [TestMethod]
- [ExpectedException(typeof(IotaApiException), "One of the tips absents")]
- public void ShouldNotGetInclusionStates()
- {
- var res = _iotaApi.GetInclusionStates(new[] {TEST_HASH},
- new[] {"DNSBRJWNOVUCQPILOQIFDKBFJMVOTGHLIMLLRXOHFTJZGRHJUEDAOWXQRYGDI9KHYFGYDWQJZKX999999"});
- Assert.IsNotNull(res.States);
- }
-
- [TestMethod]
- public void ShouldGetInclusionStates()
- {
- var res =
- _iotaApi.GetInclusionStates(
- new[] {TEST_HASH},
- new[] {_iotaApi.GetNodeInfo().LatestSolidSubtangleMilestone});
- Assert.IsNotNull(res.States);
- }
-
- [TestMethod] // very long execution
- public void ShouldGetTransactionsToApprove()
- {
- var res = _iotaApi.GetTransactionsToApprove(27);
- Assert.IsNotNull(res.TrunkTransaction);
- Assert.IsNotNull(res.BranchTransaction);
- }
-
- [TestMethod]
- public void ShouldFindTransactions()
- {
- var test = TEST_BUNDLE;
- // ReSharper disable once UnusedVariable
- var resp = _iotaApi.FindTransactions(new[] {test}.ToList(),
- new[] {test}.ToList(), new[] {test}.ToList(), new[] {test}.ToList());
- }
-
- [TestMethod]
- public void ShouldGetBalances()
- {
- var res = _iotaApi.GetBalances(new[] {TEST_ADDRESS_WITH_CHECKSUM}.ToList(), 100);
- Assert.IsNotNull(res.Balances);
- Assert.IsNotNull(res.References);
- Assert.IsNotNull(res.MilestoneIndex);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard.Tests/Pow/KerlTest.cs b/IotaApi.Standard.Tests/Pow/KerlTest.cs
deleted file mode 100644
index f79d434..0000000
--- a/IotaApi.Standard.Tests/Pow/KerlTest.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using Iota.Api.Standard.Pow;
-using Iota.Api.Standard.Utils;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests.Pow
-{
- [TestClass]
- public class KerlTest
- {
- [TestMethod]
- public void ShouldCreateValidHash1()
- {
- var trits = Converter.ToTrits(
- "GYOMKVTSNHVJNCNFBBAH9AAMXLPLLLROQY99QN9DLSJUHDPBLCFFAIQXZA9BKMBJCYSFHFPXAHDWZFEIZ");
- var kerl = new Kerl();
- kerl.Reset();
- kerl.Absorb(trits, 0, trits.Length);
- var hashTrits = new int[trits.Length];
- kerl.Squeeze(hashTrits, 0, 243);
- var hash = Converter.ToTrytes(hashTrits);
- Assert.AreEqual(hash, "OXJCNFHUNAHWDLKKPELTBFUCVW9KLXKOGWERKTJXQMXTKFKNWNNXYD9DMJJABSEIONOSJTTEVKVDQEWTW");
- }
-
- [TestMethod]
- public void ShouldCreateValidHash2()
- {
- var trits = Converter.ToTrits(
- "9MIDYNHBWMBCXVDEFOFWINXTERALUKYYPPHKP9JJFGJEIUY9MUDVNFZHMMWZUYUSWAIOWEVTHNWMHANBH");
- var kerl = new Kerl();
- kerl.Reset();
- kerl.Absorb(trits, 0, trits.Length);
- var hashTrits = new int[trits.Length * 2];
- kerl.Squeeze(hashTrits, 0, 243 * 2);
- var hash = Converter.ToTrytes(hashTrits);
- Assert.AreEqual(hash,
- "G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJBVBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA");
- }
-
- [TestMethod]
- public void ShouldCreateValidHash3()
- {
- var trits = Converter.ToTrits(
- "G9JYBOMPUXHYHKSNRNMMSSZCSHOFYOYNZRSZMAAYWDYEIMVVOGKPJBVBM9TDPULSFUNMTVXRKFIDOHUXXVYDLFSZYZTWQYTE9SPYYWYTXJYQ9IFGYOLZXWZBKWZN9QOOTBQMWMUBLEWUEEASRHRTNIQWJQNDWRYLCA");
- var kerl = new Kerl();
- kerl.Reset();
- kerl.Absorb(trits, 0, trits.Length);
- var hashTrits = new int[trits.Length];
- kerl.Squeeze(hashTrits, 0, 243 * 2);
- var hash = Converter.ToTrytes(hashTrits);
- Assert.AreEqual(hash,
- "LUCKQVACOGBFYSPPVSSOXJEKNSQQRQKPZC9NXFSMQNRQCGGUL9OHVVKBDSKEQEBKXRNUJSRXYVHJTXBPDWQGNSCDCBAIRHAQCOWZEBSNHIJIGPZQITIBJQ9LNTDIBTCQ9EUWKHFLGFUVGGUWJONK9GBCDUIMAYMMQX");
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard.Tests/Pow/LocalPoWTest.cs b/IotaApi.Standard.Tests/Pow/LocalPoWTest.cs
deleted file mode 100644
index af85382..0000000
--- a/IotaApi.Standard.Tests/Pow/LocalPoWTest.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using System.Collections.Generic;
-using Iota.Api.Standard.Model;
-using Iota.Api.Standard.Pow;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests.Pow
-{
- [TestClass]
- public class LocalPoWTest
- {
- private static readonly string TEST_SEED1 =
- "IHDEENZYITYVYSPKAURUZAQKGVJEREFDJMYTANNXXGPZ9GJWTEOJJ9IPMXOGZNQLSNMFDSQOTZAEETUEA";
-
- private static readonly string TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2 =
- "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZC";
-
- private static readonly string TEST_MESSAGE = "JUSTANOTHERJOTATEST";
- private static readonly string TEST_TAG = "JOTASPAM9999999999999999999";
- private static readonly int MIN_WEIGHT_MAGNITUDE = 14;
- private static readonly int DEPTH = 9;
-
- private IotaApi _iotaClient;
-
- [TestInitialize]
- public void Setup()
- {
- _iotaClient = new IotaApi("node.iotawallet.info", 14265)
- {
- LocalPow = new PearlDiverLocalPoW()
- };
- }
-
- [TestMethod]
- public void ShouldSendTransfer()
- {
- var transfers = new List
- {
- new Transfer(TEST_ADDRESS_WITHOUT_CHECKSUM_SECURITY_LEVEL_2, 0, TEST_MESSAGE, TEST_TAG)
- };
- var result = _iotaClient.SendTransfer(
- TEST_SEED1, 2, DEPTH, MIN_WEIGHT_MAGNITUDE, transfers.ToArray(),
- null, null, false, false);
- Assert.IsNotNull(result);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard.Tests/Pow/PearlDiverTest.cs b/IotaApi.Standard.Tests/Pow/PearlDiverTest.cs
deleted file mode 100644
index 6ed6e67..0000000
--- a/IotaApi.Standard.Tests/Pow/PearlDiverTest.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-using System;
-using System.Text;
-using Iota.Api.Standard.Pow;
-using Iota.Api.Standard.Utils;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests.Pow
-{
- [TestClass]
- public class PearlDiverTest
- {
-
- private const int TryteLength = 2673;
- private const int MinWeightMagnitude = 9;
- private const int NumCores = -1; // use n-1 cores
-
- private static readonly Random Random = new Random();
- private PearlDiver _pearlDiver;
- private int[] _hashTrits;
-
- [TestInitialize]
- public void Setup()
- {
- _pearlDiver = new PearlDiver();
- _hashTrits = new int[Sponge.HashLength];
- }
-
-
- [TestMethod]
- public void TestRandomTryteHash()
- {
- string testTrytes = GetRandomTrytes();
-
- string hash = GetHashFor(testTrytes);
-
- string subHash = hash.Substring(Sponge.HashLength / 3 - MinWeightMagnitude / 3);
-
- bool success = InputValidator.IsNinesTrytes(subHash,subHash.Length);
- if (!success)
- {
- Console.WriteLine(testTrytes);
- }
-
- Assert.IsTrue(success, "The hash should have n nines");
- }
-
- [TestMethod]
- [Ignore]
- public void TestRandomTryteHash100()
- {
- for (int i = 0; i < 100; i++)
- {
- string testTrytes = GetRandomTrytes();
-
- string hash = GetHashFor(testTrytes);
-
- string subHash = hash.Substring(Sponge.HashLength / 3 - MinWeightMagnitude / 3);
-
- bool success = InputValidator.IsNinesTrytes(subHash, subHash.Length);
- if (!success)
- {
- Console.WriteLine(testTrytes);
- }
-
- Assert.IsTrue(success, "The hash should have n nines");
- }
- }
-
- private string GetRandomTrytes()
- {
- var trytes = new StringBuilder();
-
- for (int i = 0; i < TryteLength; i++)
- {
- trytes.Append(Constants.TryteAlphabet[Random.Next(27)]);
- }
-
- return trytes.ToString();
- }
-
- private string GetHashFor(string trytes)
- {
- Sponge curl = new Curl(CurlMode.CurlP81);
- int[] myTrits = Converter.ToTrits(trytes);
-
- bool result = _pearlDiver.Search(myTrits, MinWeightMagnitude, NumCores);
-
- Assert.IsTrue(result,"Search Failed");
-
- curl.Absorb(myTrits, 0, myTrits.Length);
- curl.Squeeze(_hashTrits, 0, Sponge.HashLength);
- curl.Reset();
-
- return Converter.ToTrytes(_hashTrits);
- }
- }
-}
diff --git a/IotaApi.Standard.Tests/Utils/BigIntConverterTest.cs b/IotaApi.Standard.Tests/Utils/BigIntConverterTest.cs
deleted file mode 100644
index 6337882..0000000
--- a/IotaApi.Standard.Tests/Utils/BigIntConverterTest.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using System;
-using Iota.Api.Standard.Utils;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Org.BouncyCastle.Math;
-
-namespace Iota.Api.Standard.Tests.Utils
-{
- [TestClass]
- public class BigIntConverterTest
- {
- private static readonly Random Random = new Random();
- // trits<->BigInteger<->byte
-
- [TestMethod]
- public void TestTritsAndBigInt()
- {
- var inputTrits = new int[243];
- for (var i = 0; i < inputTrits.Length; i++) inputTrits[i] = Random.Next(3) - 1;
-
- var bigInt = BigIntConverter.BigIntFromTrits(inputTrits, 0, inputTrits.Length);
-
- var outputTrits = new int[inputTrits.Length];
- BigIntConverter.TritsFromBigInt(bigInt, outputTrits, 0, outputTrits.Length);
-
- for (var i = 0; i < inputTrits.Length; i++) Assert.AreEqual(inputTrits[i], outputTrits[i]);
- }
-
- [TestMethod]
- public void TestBigIntAndByte()
- {
- var bytes = new byte[48];
- var bigInt0 = new BigInteger("-123456");
-
- BigIntConverter.BytesFromBigInt(bigInt0, bytes, 0, bytes.Length);
- var bigInt1 = BigIntConverter.BigIntFromBytes(bytes, 0, bytes.Length);
-
- Assert.AreEqual(bigInt0, bigInt1);
- }
-
- [TestMethod]
- public void TestFixedBigInt()
- {
- var inputTrits = new int[243];
- var outputTrits = new int[243];
- var bytes = new byte[384 / 8];
-
- for (var i = 0; i < inputTrits.Length; i++) inputTrits[i] = Random.Next(3) - 1;
-
- inputTrits[inputTrits.Length - 1] = 0;
- FixedBigIntConverter.FromTritsToBytes(inputTrits, bytes);
- FixedBigIntConverter.FromBytesToTrits(bytes, outputTrits);
- outputTrits[outputTrits.Length - 1] = 0;
-
- for (var i = 0; i < inputTrits.Length; i++) Assert.AreEqual(inputTrits[i], outputTrits[i]);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard.Tests/Utils/ChecksumTest.cs b/IotaApi.Standard.Tests/Utils/ChecksumTest.cs
deleted file mode 100644
index 77a5334..0000000
--- a/IotaApi.Standard.Tests/Utils/ChecksumTest.cs
+++ /dev/null
@@ -1,33 +0,0 @@
-using Iota.Api.Standard.Utils;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests.Utils
-{
- [TestClass]
- public class ChecksumTest
- {
- private static readonly string TEST_ADDRESS_WITHOUT_CHECKSUM =
- "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZC";
-
- private static readonly string TEST_ADDRESS_WITH_CHECKSUM =
- "LXQHWNY9CQOHPNMKFJFIJHGEPAENAOVFRDIBF99PPHDTWJDCGHLYETXT9NPUVSNKT9XDTDYNJKJCPQMZCCOZVXMTXC";
-
- [TestMethod]
- public void ShouldAddChecksum()
- {
- Assert.AreEqual(Checksum.AddChecksum(TEST_ADDRESS_WITHOUT_CHECKSUM), TEST_ADDRESS_WITH_CHECKSUM);
- }
-
- [TestMethod]
- public void ShouldRemoveChecksum()
- {
- Assert.AreEqual(TEST_ADDRESS_WITH_CHECKSUM.RemoveChecksum(), TEST_ADDRESS_WITHOUT_CHECKSUM);
- }
-
- [TestMethod]
- public void ShouldIsValidChecksum()
- {
- Assert.AreEqual(TEST_ADDRESS_WITH_CHECKSUM.IsValidChecksum(), true);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard.Tests/Utils/InputValidatorTests.cs b/IotaApi.Standard.Tests/Utils/InputValidatorTests.cs
deleted file mode 100644
index 45ffbe4..0000000
--- a/IotaApi.Standard.Tests/Utils/InputValidatorTests.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-using System.Collections.Generic;
-using Iota.Api.Standard.Model;
-using Iota.Api.Standard.Utils;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests.Utils
-{
- [TestClass]
- public class InputValidatorTests
- {
- private static readonly string TEST_ADDRESS_WITHOUT_CHECKSUM =
- "PNGMCSNRCTRHCHPXYTPKEJYPCOWKOMRXZFHH9N9VDIKMNVAZCMIYRHVJIAZARZTUETJVFDMBEBIQE9QTHBFWDAOEFA";
-
- private static readonly string TEST_ADDRESS_WITH_CHECKSUM =
- "PNGMCSNRCTRHCHPXYTPKEJYPCOWKOMRXZFHH9N9VDIKMNVAZCMIYRHVJIAZARZTUETJVFDMBEBIQE9QTHBFWDAOEFA";
-
- private static readonly string TEST_TRYTES =
- "BYSWEAUTWXHXZ9YBZISEK9LUHWGMHXCGEVNZHRLUWQFCUSDXZHOFHWHL9MQPVJXXZLIXPXPXF9KYEREFSKCPKYIIKPZVLHUTDFQKKVVBBN9ATTLPCNPJDWDEVIYYLGPZGCWXOBDXMLJC9VO9QXTTBLAXTTBFUAROYEGQIVB9MJWJKXJMCUPTWAUGFZBTZCSJVRBGMYXTVBDDS9MYUJCPZ9YDWWQNIPUAIJXXSNLKUBSCOIJPCLEFPOXFJREXQCUVUMKSDOVQGGHRNILCO9GNCLWFM9APMNMWYASHXQAYBEXF9QRIHIBHYEJOYHRQJAOKAQ9AJJFQ9WEIWIJOTZATIBOXQLBMIJU9PCGBLVDDVFP9CFFSXTDUXMEGOOFXWRTLFGV9XXMYWEMGQEEEDBTIJ9OJOXFAPFQXCDAXOUDMLVYRMRLUDBETOLRJQAEDDLNVIRQJUBZBO9CCFDHIX9MSQCWYAXJVWHCUPTRSXJDESISQPRKZAFKFRULCGVRSBLVFOPEYLEE99JD9SEBALQINPDAZHFAB9RNBH9AZWIJOTLBZVIEJIAYGMC9AZGNFWGRSWAXTYSXVROVNKCOQQIWGPNQZKHUNODGYADPYLZZZUQRTJRTODOUKAOITNOMWNGHJBBA99QUMBHRENGBHTH9KHUAOXBVIVDVYYZMSEYSJWIOGGXZVRGN999EEGQMCOYVJQRIRROMPCQBLDYIGQO9AMORPYFSSUGACOJXGAQSPDY9YWRRPESNXXBDQ9OZOXVIOMLGTSWAMKMTDRSPGJKGBXQIVNRJRFRYEZ9VJDLHIKPSKMYC9YEGHFDS9SGVDHRIXBEMLFIINOHVPXIFAZCJKBHVMQZEVWCOSNWQRDYWVAIBLSCBGESJUIBWZECPUCAYAWMTQKRMCHONIPKJYYTEGZCJYCT9ABRWTJLRQXKMWY9GWZMHYZNWPXULNZAPVQLPMYQZCYNEPOCGOHBJUZLZDPIXVHLDMQYJUUBEDXXPXFLNRGIPWBRNQQZJSGSJTTYHIGGFAWJVXWL9THTPWOOHTNQWCNYOYZXALHAZXVMIZE9WMQUDCHDJMIBWKTYH9AC9AFOT9DPCADCV9ZWUTE9QNOMSZPTZDJLJZCJGHXUNBJFUBJWQUEZDMHXGBPTNSPZBR9TGSKVOHMOQSWPGFLSWNESFKSAZY9HHERAXALZCABFYPOVLAHMIHVDBGKUMDXC9WHHTIRYHZVWNXSVQUWCR9M9RAGMFEZZKZ9XEOQGOSLFQCHHOKLDSA9QCMDGCGMRYJZLBVIFOLBIJPROKMHOYTBTJIWUZWJMCTKCJKKTR9LCVYPVJI9AHGI9JOWMIWZAGMLDFJA9WU9QAMEFGABIBEZNNAL9OXSBFLOEHKDGHWFQSHMPLYFCNXAAZYJLMQDEYRGL9QKCEUEJ9LLVUOINVSZZQHCIKPAGMT9CAYIIMTTBCPKWTYHOJIIY9GYNPAJNUJ9BKYYXSV9JSPEXYMCFAIKTGNRSQGUNIYZCRT9FOWENSZQPD9ALUPYYAVICHVYELYFPUYDTWUSWNIYFXPX9MICCCOOZIWRNJIDALWGWRATGLJXNAYTNIZWQ9YTVDBOFZRKO9CFWRPAQQRXTPACOWCPRLYRYSJARRKSQPR9TCFXDVIXLP9XVL99ERRDSOHBFJDJQQGGGCZNDQ9NYCTQJWVZIAELCRBJJFDMCNZU9FIZRPGNURTXOCDSQGXTQHKHUECGWFUUYS9J9NYQ9U9P9UUP9YMZHWWWCIASCFLCMSKTELZWUGCDE9YOKVOVKTAYPHDF9ZCCQAYPJIJNGSHUIHHCOSSOOBUDOKE9CJZGYSSGNCQJVBEFTZFJ9SQUHOASKRRGBSHWKBCBWBTJHOGQ9WOMQFHWJVEG9NYX9KWBTCAIXNXHEBDIOFO9ALYMFGRICLCKKLG9FOBOX9PDWNQRGHBKHGKKRLWTBEQMCWQRLHAVYYZDIIPKVQTHYTWQMTOACXZOQCDTJTBAAUWXSGJF9PNQIJ9AJRUMUVCPWYVYVARKR9RKGOUHHNKNVGGPDDLGKPQNOYHNKAVVKCXWXOQPZNSLATUJT9AUWRMPPSWHSTTYDFAQDXOCYTZHOYYGAIM9CELMZ9AZPWB9MJXGHOKDNNSZVUDAGXTJJSSZCPZVPZBYNNTUQABSXQWZCHDQSLGK9UOHCFKBIBNETK999999999999999999999999999999999999999999999999999999999999999999999999999999999NOXDXXKUDWLOFJLIPQIBRBMGDYCPGDNLQOLQS99EQYKBIU9VHCJVIPFUYCQDNY9APGEVYLCENJIOBLWNB999999999XKBRHUD99C99999999NKZKEKWLDKMJCI9N9XQOLWEPAYWSH9999999999999999999999999KDDTGZLIPBNZKMLTOLOXQVNGLASESDQVPTXALEKRMIOHQLUHD9ELQDBQETS9QFGTYOYWLNTSKKMVJAUXSIROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999IROUICDOXKSYZTDPEDKOQENTJOWJONDEWROCEJIEWFWLUAACVSJFTMCHHXJBJRKAAPUDXXVXFWP9X9999";
-
- private static readonly string TEST_HASH =
- "OAATQS9VQLSXCLDJVJJVYUGONXAXOFMJOZNSYWRZSWECMXAQQURHQBJNLD9IOFEPGZEPEMPXCIVRX9999";
-
- private static readonly string TEST_MESSAGE = "JOTA";
- private static readonly string TEST_TAG = "JOTASPAM9999999999999999999";
-
- [TestMethod]
- public void ShouldIsAddress()
- {
- Assert.AreEqual(InputValidator.IsAddress(TEST_ADDRESS_WITHOUT_CHECKSUM), true);
- }
-
- [TestMethod]
- public void ShouldCheckAddress()
- {
- Assert.AreEqual(InputValidator.IsAddress(TEST_ADDRESS_WITHOUT_CHECKSUM), true);
- }
-
- [TestMethod]
- public void ShouldIsTrytes()
- {
- Assert.AreEqual(InputValidator.IsTrytes(TEST_TRYTES, TEST_TRYTES.Length), true);
- }
-
- [TestMethod]
- public void ShouldIsValue()
- {
- Assert.AreEqual(InputValidator.IsValue("1234"), true);
- }
-
- [TestMethod]
- public void IsValueNeg()
- {
- Assert.AreEqual(InputValidator.IsValue("-1234"), true);
- }
-
- [TestMethod]
- public void IsValueNeg2()
- {
- Assert.AreEqual(InputValidator.IsValue("-"), false);
- }
-
- [TestMethod]
- public void ShouldIsArrayOfHashes()
- {
- Assert.AreEqual(InputValidator.IsArrayOfHashes(new[] {TEST_HASH, TEST_HASH}), true);
- }
-
- [TestMethod]
- public void ShouldIsArrayOfTrytes()
- {
- Assert.AreEqual(InputValidator.IsArrayOfTrytes(new[] {TEST_TRYTES, TEST_TRYTES}, 2673), true);
- }
-
- [TestMethod]
- public void ShouldIsNinesTrytes()
- {
- Assert.AreEqual(InputValidator.IsNinesTrytes("999999999", 9), true);
- }
-
-
- [TestMethod]
- public void ShouldIsTransfersCollectionCorrect()
- {
- var transfers = new List
- {
- new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG),
- new Transfer(TEST_ADDRESS_WITH_CHECKSUM, 0, TEST_MESSAGE, TEST_TAG)
- };
- Assert.AreEqual(InputValidator.IsTransfersCollectionValid(transfers), true);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard.Tests/Utils/MultisigTest.cs b/IotaApi.Standard.Tests/Utils/MultisigTest.cs
deleted file mode 100644
index 51ec308..0000000
--- a/IotaApi.Standard.Tests/Utils/MultisigTest.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Iota.Api.Standard.Model;
-using Iota.Api.Standard.Pow;
-using Iota.Api.Standard.Utils;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests.Utils
-{
- [TestClass]
- public class MultisigTest
- {
- private const string TestSeed1 = "ABCDFG";
- private const string TestSeed2 = "FDSAG";
-
- private const string RemainderAddress =
- "NZRALDYNVGJWUVLKDWFKJVNYLWQGCWYCURJIIZRLJIKSAIVZSGEYKTZRDBGJLOA9AWYJQB9IPWRAKUC9FBDRZJZXZG";
-
- private const string ReceiveAddress =
- "ZGHXPZYDKXPEOSQTAQOIXEEI9K9YKFKCWKYYTYAUWXK9QZAVMJXWAIZABOXHHNNBJIEBEUQRTBWGLYMTX";
-
- private const string TestTag = "JOTASPAM9999999999999999999";
-
-
- private IotaApi _iotaClient;
-
- [TestInitialize]
- public void CreateApiClientInstance()
- {
- _iotaClient = new IotaApi("node.iotawallet.info", 14265);
- }
-
- [TestMethod]
- public void BasicMultiSigTest()
- {
- Multisig ms = new Multisig();
-
- // First co-signer uses security level 3 and index 0 for the private key
- string digestOne = ms.GetDigest(TestSeed1, 3, 0);
-
- // We initiate the multisig address generation by absorbing the key digest
- ms.AddAddressDigest(new[] {digestOne});
-
- // Second cosigner also uses security level 3 and index 0 for the private key
- string digestTwo = ms.GetDigest(TestSeed2, 3, 0);
-
- // Add the multisig by absorbing the second cosigners key digest
- ms.AddAddressDigest(new[] {digestTwo});
-
- // finally we generate the multisig address itself
- string multiSigAddress = ms.FinalizeAddress();
-
- Console.WriteLine("MultisigAddress = " + multiSigAddress);
-
-
- bool isValidMultisigAddress = ms.ValidateAddress(multiSigAddress,
- new[] {Converter.ToTrits(digestOne), Converter.ToTrits(digestTwo)});
-
- Console.WriteLine("Is a valid multisig address " + isValidMultisigAddress);
-
- Assert.IsTrue(isValidMultisigAddress, "Address is not a valid multisigAddress");
-
- List transfers = new List
- {
- new Transfer(ReceiveAddress, 999, "", TestTag)
- };
-
- List trxs =
- _iotaClient.InitiateTransfer(6, multiSigAddress, RemainderAddress, transfers, true);
-
- Bundle bundle = new Bundle(trxs, trxs.Count);
-
- bundle = ms.AddSignature(bundle, multiSigAddress, ms.GetKey(TestSeed1, 0, 3));
-
- bundle = ms.AddSignature(bundle, multiSigAddress, ms.GetKey(TestSeed2, 0, 3));
-
-
- Signing sgn = new Signing(new Kerl());
-
- bool isValidSignature = sgn.ValidateSignatures(bundle, multiSigAddress);
- Console.WriteLine("Result of multi-signature validation is " + isValidSignature);
- Assert.IsTrue(isValidSignature, "MultiSignature not valid");
-
- }
- }
-}
diff --git a/IotaApi.Standard.Tests/Utils/TrytesConverterTest.cs b/IotaApi.Standard.Tests/Utils/TrytesConverterTest.cs
deleted file mode 100644
index 7f40866..0000000
--- a/IotaApi.Standard.Tests/Utils/TrytesConverterTest.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using System;
-using System.Linq;
-using Iota.Api.Standard.Utils;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Iota.Api.Standard.Tests.Utils
-{
- [TestClass]
- public class TrytesConverterTest
- {
- private static readonly Random Random = new Random();
-
- [TestMethod]
- public void ShouldConvertStringToTrytes()
- {
- Assert.AreEqual("IC", TrytesConverter.ToTrytes("Z"));
- Assert.AreEqual(TrytesConverter.ToTrytes("JOTA JOTA"), "TBYBCCKBEATBYBCCKB");
- }
-
- [TestMethod]
- public void ShouldConvertTrytesToString()
- {
- Assert.AreEqual("Z", TrytesConverter.ToString("IC"));
- Assert.AreEqual(TrytesConverter.ToString("TBYBCCKBEATBYBCCKB"), "JOTA JOTA");
- }
-
- [TestMethod]
- public void ShouldConvertBackAndForth()
- {
- var str = RandomString(1000);
- var back = TrytesConverter.ToString(TrytesConverter.ToTrytes(str));
- Assert.AreEqual(str, back);
- }
-
- public static string RandomString(int length)
- {
- const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- return new string(Enumerable.Repeat(chars, length)
- .Select(s => s[Random.Next(s.Length)]).ToArray());
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/AddNeighborsRequest.cs b/IotaApi.Standard/Core/AddNeighborsRequest.cs
deleted file mode 100644
index c9b108c..0000000
--- a/IotaApi.Standard/Core/AddNeighborsRequest.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
-
- ///
- /// This class represents the core API request 'AddNeighbors'.
- /// It is used to add a neighbor to the node
- ///
- ///
- public class AddNeighborsRequest : IotaRequest
- {
- ///
- /// Gets or sets the uris.
- ///
- ///
- /// The uris.
- ///
- public List Uris { get; set; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The uris of the neighbors to add.
- public AddNeighborsRequest(List uris) : base(Core.Command.AddNeighbors.GetCommandString())
- {
- Uris = uris;
- }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Uris)}: {string.Join(",", Uris)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/AttachToTangleRequest.cs b/IotaApi.Standard/Core/AttachToTangleRequest.cs
deleted file mode 100644
index 4ad947b..0000000
--- a/IotaApi.Standard/Core/AttachToTangleRequest.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
-
- ///
- /// This class represents the core API request 'AttachToTangle'.
- /// It is used to attach trytes to the tangle.
- ///
- public class AttachToTangleRequest : IotaRequest
- {
- private const int MinWeightMagnitudeMin = 18;
- private int _minWeightMagnitude = MinWeightMagnitudeMin;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The trunk transaction.
- /// The branch transaction.
- /// The trytes.
- /// The minimum weight magnitude.
- public AttachToTangleRequest(string trunkTransaction, string branchTransaction, string[] trytes,
- int minWeightMagnitude = 18) : base(Core.Command.AttachToTangle.GetCommandString())
- {
- TrunkTransaction = trunkTransaction;
- BranchTransaction = branchTransaction;
- Trytes = trytes;
- MinWeightMagnitude = minWeightMagnitude;
-
- if (Trytes == null)
- Trytes = new string[0];
- }
-
- ///
- /// Proof of Work intensity. Minimum value is 18
- ///
- public int MinWeightMagnitude
- {
- get { return _minWeightMagnitude; }
- set
- {
- if (value > MinWeightMagnitudeMin)
- _minWeightMagnitude = value;
- }
- }
-
- ///
- /// Trunk transaction to approve.
- ///
- public string TrunkTransaction { get; set; }
-
- ///
- /// Branch transaction to approve.
- ///
- public string BranchTransaction { get; set; }
-
- ///
- /// List of trytes (raw transaction data) to attach to the tangle.
- ///
- public string[] Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(MinWeightMagnitude)}: {MinWeightMagnitude}, {nameof(TrunkTransaction)}: {TrunkTransaction}, {nameof(BranchTransaction)}: {BranchTransaction}, {nameof(Trytes)}: {Trytes}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/AttachToTangleResponse.cs b/IotaApi.Standard/Core/AttachToTangleResponse.cs
deleted file mode 100644
index 75e2736..0000000
--- a/IotaApi.Standard/Core/AttachToTangleResponse.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// Response of
- ///
- public class AttachToTangleResponse
- {
- ///
- /// Gets or sets the trytes.
- ///
- ///
- /// The trytes.
- ///
- public List Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Trytes)}: {string.Join(",", Trytes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/BroadcastTransactionsRequest.cs b/IotaApi.Standard/Core/BroadcastTransactionsRequest.cs
deleted file mode 100644
index 329d05f..0000000
--- a/IotaApi.Standard/Core/BroadcastTransactionsRequest.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// Broadcast a list of transactions to all neighbors. The input trytes for this call are provided by attachToTangle
- ///
- public class BroadcastTransactionsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The trytes.
- public BroadcastTransactionsRequest(List trytes)
- : base(Core.Command.BroadcastTransactions.GetCommandString())
- {
- Trytes = trytes;
- }
-
- ///
- /// Gets or sets the trytes representing the transactions
- ///
- ///
- /// The trytes.
- ///
- public List Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Trytes)}: {string.Join(",", Trytes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/BroadcastTransactionsResponse.cs b/IotaApi.Standard/Core/BroadcastTransactionsResponse.cs
deleted file mode 100644
index f8feb07..0000000
--- a/IotaApi.Standard/Core/BroadcastTransactionsResponse.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// Response of
- ///
- public class BroadcastTransactionsResponse
- {
- // empty
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/Command.cs b/IotaApi.Standard/Core/Command.cs
deleted file mode 100644
index b20be21..0000000
--- a/IotaApi.Standard/Core/Command.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-using System.ComponentModel;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This enumeration defines the core API call commands
- ///
- public enum Command
- {
- ///
- /// Adds neighbours to the node
- ///
- [Description("addNeighbors")] AddNeighbors,
-
- ///
- /// Attaches to the tangle
- ///
- [Description("attachToTangle")] AttachToTangle,
-
- ///
- /// Broadcasts transactions
- ///
- [Description("broadcastTransactions")] BroadcastTransactions,
-
- ///
- /// Finds the transactions using different search criteria
- ///
- [Description("findTransactions")] FindTransactions,
-
- ///
- /// Gets the balances
- ///
- [Description("getBalances")] GetBalances,
-
- ///
- /// Gets the inclusion state
- ///
- [Description("getInclusionStates")] GetInclusionStates,
-
- ///
- /// Gets the neighbours of the node
- ///
- [Description("getNeighbors")] GetNeighbors,
-
- ///
- /// Get information about the node.
- ///
- [Description("getNodeInfo")] GetNodeInfo,
-
- ///
- /// Gets the tips of the node
- ///
- [Description("getTips")] GetTips,
-
- ///
- /// Gets the transactions to approve
- ///
- [Description("getTransactionsToApprove")] GetTransactionsToApprove,
-
- ///
- /// Gets the trytes
- ///
- [Description("getTrytes")] GetTrytes,
-
- ///
- /// Interrupt attaching to the tangle
- ///
- [Description("interruptAttachingToTangle")] InterruptAttachingToTangle,
-
- ///
- /// Removes neighbours from the node
- ///
- [Description("removeNeighbors")] RemoveNeighbors,
-
- ///
- /// Stores transactions
- ///
- [Description("storeTransactions")] StoreTransactions,
-
- ///
- /// Get Missing Transactions
- ///
- [Description("getMissingTransactions")] GetMissingTransactions,
-
- ///
- /// Check Consistency
- ///
- [Description("checkConsistency")] CheckConsistency,
-
- ///
- /// Were Addresses SpentFrom
- ///
- [Description("wereAddressesSpentFrom")] WereAddressesSpentFrom,
-
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/EnumHelper.cs b/IotaApi.Standard/Core/EnumHelper.cs
deleted file mode 100644
index 0a29e1c..0000000
--- a/IotaApi.Standard/Core/EnumHelper.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Reflection;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// Helper class that extracts the command string corresponding to the different s
- ///
- public static class EnumHelper
- {
- ///
- /// Retrieve the description on the enum
- ///
- /// The Enumeration
- /// A string representing the friendly name
- public static string GetCommandString(this Enum en)
- {
- Type type = en.GetType();
-
- MemberInfo[] memInfo = type.GetMember(en.ToString());
-
- if (memInfo != null && memInfo.Length > 0)
- {
- object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
-
- if (attrs != null && attrs.Length > 0)
- {
- return ((DescriptionAttribute) attrs[0]).Description;
- }
- }
-
- return en.ToString();
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/ErrorResponse.cs b/IotaApi.Standard/Core/ErrorResponse.cs
deleted file mode 100644
index 47eb381..0000000
--- a/IotaApi.Standard/Core/ErrorResponse.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- internal class ErrorResponse
- {
- public string Error { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/FindTransactionsRequest.cs b/IotaApi.Standard/Core/FindTransactionsRequest.cs
deleted file mode 100644
index 72eefc9..0000000
--- a/IotaApi.Standard/Core/FindTransactionsRequest.cs
+++ /dev/null
@@ -1,103 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core api request 'FindTransactions'
- ///
- public class FindTransactionsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The bundles.
- /// The addresses.
- /// The tags.
- /// The approvees.
- public FindTransactionsRequest(List bundles, List addresses, List tags,
- List approvees) : base(Core.Command.FindTransactions.GetCommandString())
- {
- Bundles = bundles;
- Addresses = addresses;
- Tags = tags;
- Approvees = approvees;
-
- if (Bundles == null)
- Bundles = new List();
- if (Addresses == null)
- Addresses = new List();
- if (Tags == null)
- Tags = new List();
- if (Approvees == null)
- Approvees = new List();
- }
-
- ///
- /// Gets or sets the bundles.
- ///
- ///
- /// The bundles.
- ///
- public List Bundles { get; set; }
-
- ///
- /// Gets or sets the addresses.
- ///
- ///
- /// The addresses.
- ///
- public List Addresses { get; set; }
-
- ///
- /// Gets or sets the tags.
- ///
- ///
- /// The tags.
- ///
- public List Tags { get; set; }
-
- ///
- /// Gets or sets the approvees.
- ///
- ///
- /// The approvees.
- ///
- public List Approvees { get; set; }
-
- ///
- ///
- ///
- ///
- public bool ShouldSerializeBundles()
- {
- return Bundles.Count > 0;
- }
-
- ///
- ///
- ///
- ///
- public bool ShouldSerializeAddresses()
- {
- return Addresses.Count > 0;
- }
-
- ///
- ///
- ///
- ///
- public bool ShouldSerializeTags()
- {
- return Tags.Count > 0;
- }
-
- ///
- ///
- ///
- ///
- public bool ShouldSerializeApprovees()
- {
- return Approvees.Count > 0;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/FindTransactionsResponse.cs b/IotaApi.Standard/Core/FindTransactionsResponse.cs
deleted file mode 100644
index 7eca193..0000000
--- a/IotaApi.Standard/Core/FindTransactionsResponse.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// Response of
- ///
- public class FindTransactionsResponse
- {
- ///
- /// Gets or sets the hashes.
- ///
- ///
- /// The hashes.
- ///
- public List Hashes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Hashes)}: {string.Join(",",Hashes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GenericIotaCoreApi.cs b/IotaApi.Standard/Core/GenericIotaCoreApi.cs
deleted file mode 100644
index 3e94785..0000000
--- a/IotaApi.Standard/Core/GenericIotaCoreApi.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-using System;
-using Iota.Api.Standard.Utils.Rest;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents a generic version of the core API that is used internally
- ///
- ///
- public class GenericIotaCoreApi : IGenericIotaCoreApi
- {
- private readonly string _host;
- private readonly int _port;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The host.
- /// The port.
- public GenericIotaCoreApi(string host, int port)
- {
- _host = host;
- _port = port;
- }
-
- ///
- /// Gets the hostname.
- ///
- ///
- /// The hostname.
- ///
- public string Hostname => _host;
-
- ///
- /// Gets the port.
- ///
- ///
- /// The port.
- ///
- public int Port => _port;
-
- ///
- /// Requests the specified request.
- ///
- /// The type of the request.
- /// The type of the response.
- /// The request.
- ///
- public TResponse Request(TRequest request) where TResponse : new()
- {
- JsonWebClient jsonWebClient = new JsonWebClient();
- return jsonWebClient.GetPOSTResponseSync(new Uri(CreateBaseUrl()),
- new JsonSerializer().Serialize(request));
- }
-
- ///
- /// Requests the specified request asynchronously
- ///
- /// The type of the request.
- /// The type of the response.
- /// The request.
- /// The response action.
- public void RequestAsync(TRequest request, Action responseAction)
- where TResponse : new()
- {
- JsonWebClient jsonWebClient = new JsonWebClient();
- jsonWebClient.GetPOSTResponseAsync(new Uri(CreateBaseUrl()),
- new JsonSerializer().Serialize(request), responseAction);
- }
-
- private string CreateBaseUrl()
- {
- return "http://" + _host + ":" + _port;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetBalancesRequest.cs b/IotaApi.Standard/Core/GetBalancesRequest.cs
deleted file mode 100644
index b08eca2..0000000
--- a/IotaApi.Standard/Core/GetBalancesRequest.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core api request 'GetBalances'
- ///
- public class GetBalancesRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The addresses.
- /// The threshold.
- public GetBalancesRequest(List addresses, long threshold = 100)
- : base(Core.Command.GetBalances.GetCommandString())
- {
- Addresses = addresses;
- Threshold = threshold;
- }
-
- ///
- /// Gets the threshold.
- ///
- ///
- /// The threshold.
- ///
- public long Threshold { get; }
-
- ///
- /// Gets the addresses.
- ///
- ///
- /// The addresses.
- ///
- public List Addresses { get; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Threshold)}: {Threshold}, {nameof(Addresses)}: {string.Join(",",Addresses)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetBalancesResponse.cs b/IotaApi.Standard/Core/GetBalancesResponse.cs
deleted file mode 100644
index 8342755..0000000
--- a/IotaApi.Standard/Core/GetBalancesResponse.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// Response of
- ///
- public class GetBalancesResponse : IotaResponse
- {
- ///
- /// Gets or sets the balances.
- ///
- ///
- /// The balances.
- ///
- public List Balances { get; set; }
-
- ///
- /// Gets or sets the references.
- ///
- ///
- /// The references.
- ///
- public List References { get; set; }
-
- ///
- /// Gets or sets the index of the milestone.
- ///
- ///
- /// The index of the milestone.
- ///
- public int MilestoneIndex { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return
- $"{nameof(Balances)}: {string.Join(",", Balances)}, {nameof(References)}: {string.Join(",", References)}, {nameof(MilestoneIndex)}: {MilestoneIndex}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetInclusionStatesRequest.cs b/IotaApi.Standard/Core/GetInclusionStatesRequest.cs
deleted file mode 100644
index fbb71a2..0000000
--- a/IotaApi.Standard/Core/GetInclusionStatesRequest.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core API request 'GetInclusionStates'
- ///
- ///
- public class GetInclusionStatesRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The transactions.
- /// The tips.
- public GetInclusionStatesRequest(string[] transactions, string[] tips)
- : base(Core.Command.GetInclusionStates.GetCommandString())
- {
- Transactions = transactions;
- Tips = tips;
- }
-
- ///
- /// Gets the transactions.
- ///
- ///
- /// The transactions.
- ///
- public string[] Transactions { get; }
-
- ///
- /// Gets the tips.
- ///
- ///
- /// The tips.
- ///
- public string[] Tips { get; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Transactions)}: {Transactions}, {nameof(Tips)}: {Tips}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetInclusionStatesResponse.cs b/IotaApi.Standard/Core/GetInclusionStatesResponse.cs
deleted file mode 100644
index 2944d90..0000000
--- a/IotaApi.Standard/Core/GetInclusionStatesResponse.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the response of
- ///
- ///
- public class GetInclusionStatesResponse : IotaResponse
- {
- ///
- /// Gets or sets the states.
- ///
- ///
- /// The states.
- ///
- public List States { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetNeighborsRequest.cs b/IotaApi.Standard/Core/GetNeighborsRequest.cs
deleted file mode 100644
index 21b64e6..0000000
--- a/IotaApi.Standard/Core/GetNeighborsRequest.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core API request 'GetNeighbors'
- ///
- ///
- public class GetNeighborsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public GetNeighborsRequest() : base(Core.Command.GetNeighbors.GetCommandString())
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetNeighborsResponse.cs b/IotaApi.Standard/Core/GetNeighborsResponse.cs
deleted file mode 100644
index d667b23..0000000
--- a/IotaApi.Standard/Core/GetNeighborsResponse.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System.Collections.Generic;
-using Iota.Api.Standard.Model;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// Response of
- ///
- public class GetNeighborsResponse
- {
- ///
- /// Gets or sets the neighbors.
- ///
- ///
- /// The neighbors.
- ///
- public List Neighbors { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetNodeInfoRequest.cs b/IotaApi.Standard/Core/GetNodeInfoRequest.cs
deleted file mode 100644
index 658ab6b..0000000
--- a/IotaApi.Standard/Core/GetNodeInfoRequest.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// Returns information about your node
- ///
- public class GetNodeInfoRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public GetNodeInfoRequest() : base(Core.Command.GetNodeInfo.GetCommandString())
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetTipsResponse.cs b/IotaApi.Standard/Core/GetTipsResponse.cs
deleted file mode 100644
index b9ca3b6..0000000
--- a/IotaApi.Standard/Core/GetTipsResponse.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the response of
- ///
- public class GetTipsResponse : IotaResponse
- {
- ///
- /// Gets or sets the hashes.
- ///
- ///
- /// The hashes.
- ///
- public List Hashes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Hashes)}: {string.Join(",", Hashes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetTransactionsToApproveRequest.cs b/IotaApi.Standard/Core/GetTransactionsToApproveRequest.cs
deleted file mode 100644
index 200987d..0000000
--- a/IotaApi.Standard/Core/GetTransactionsToApproveRequest.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core API call 'GetTransactionsToApprove'
- ///
- public class GetTransactionsToApproveRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The depth.
- public GetTransactionsToApproveRequest(int depth)
- : base(Core.Command.GetTransactionsToApprove.GetCommandString())
- {
- Depth = depth;
- }
-
- ///
- /// Gets the depth.
- ///
- ///
- /// The depth.
- ///
- public int Depth { get; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Depth)}: {Depth}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetTransactionsToApproveResponse.cs b/IotaApi.Standard/Core/GetTransactionsToApproveResponse.cs
deleted file mode 100644
index d093d78..0000000
--- a/IotaApi.Standard/Core/GetTransactionsToApproveResponse.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the response of
- ///
- public class GetTransactionsToApproveResponse : IotaResponse
- {
- ///
- /// Gets or sets the trunk transaction.
- ///
- ///
- /// The trunk transaction.
- ///
- public string TrunkTransaction { get; set; }
-
- ///
- /// Gets or sets the branch transaction.
- ///
- ///
- /// The branch transaction.
- ///
- public string BranchTransaction { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(TrunkTransaction)}: {TrunkTransaction}, {nameof(BranchTransaction)}: {BranchTransaction}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetTrytesRequest.cs b/IotaApi.Standard/Core/GetTrytesRequest.cs
deleted file mode 100644
index 3d2c1b9..0000000
--- a/IotaApi.Standard/Core/GetTrytesRequest.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core API request 'GetTrytes'
- ///
- public class GetTrytesRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public GetTrytesRequest() : base(Core.Command.GetTrytes.GetCommandString())
- {
-
- }
-
- ///
- /// Gets or sets the hashes.
- ///
- ///
- /// The hashes.
- ///
- public string[] Hashes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Hashes)}: {string.Join(",", Hashes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/GetTrytesResponse.cs b/IotaApi.Standard/Core/GetTrytesResponse.cs
deleted file mode 100644
index 41ac755..0000000
--- a/IotaApi.Standard/Core/GetTrytesResponse.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the response of
- ///
- public class GetTrytesResponse
- {
-
- ///
- /// Gets or sets the trytes.
- ///
- ///
- /// The trytes.
- ///
- public List Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Trytes)}: {string.Join(",", Trytes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/IGenericIotaCoreApi.cs b/IotaApi.Standard/Core/IGenericIotaCoreApi.cs
deleted file mode 100644
index f2018e9..0000000
--- a/IotaApi.Standard/Core/IGenericIotaCoreApi.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This interface abstracts a generic version of the core api that is used internally.
- ///
- public interface IGenericIotaCoreApi
- {
- ///
- /// Gets the hostname.
- ///
- ///
- /// The hostname.
- ///
- string Hostname { get; }
-
- ///
- /// Gets the port.
- ///
- ///
- /// The port.
- ///
- int Port { get; }
-
- ///
- /// Requests the specified request.
- ///
- /// The type of the request.
- /// The type of the response.
- /// The request.
- ///
- TResponse Request(TRequest request) where TResponse : new();
-
- ///
- /// Requests the specified request asynchronously
- ///
- /// The type of the request.
- /// The type of the response.
- /// The request.
- /// The response action.
- void RequestAsync(TRequest request, Action responseAction)
- where TResponse : new();
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/ILocalPoW.cs b/IotaApi.Standard/Core/ILocalPoW.cs
deleted file mode 100644
index 1588610..0000000
--- a/IotaApi.Standard/Core/ILocalPoW.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- ///
- ///
- public interface ILocalPoW
- {
- ///
- ///
- ///
- ///
- ///
- ///
- string PerformPoW(string trytes, int minWeightMagnitude);
- }
-}
diff --git a/IotaApi.Standard/Core/InterruptAttachingToTangleRequest.cs b/IotaApi.Standard/Core/InterruptAttachingToTangleRequest.cs
deleted file mode 100644
index be764fe..0000000
--- a/IotaApi.Standard/Core/InterruptAttachingToTangleRequest.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core api request 'InterruptAttachingToTangle'
- ///
- public class InterruptAttachingToTangleRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public InterruptAttachingToTangleRequest() : base(Core.Command.InterruptAttachingToTangle.GetCommandString())
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/InterruptAttachingToTangleResponse.cs b/IotaApi.Standard/Core/InterruptAttachingToTangleResponse.cs
deleted file mode 100644
index 0909d06..0000000
--- a/IotaApi.Standard/Core/InterruptAttachingToTangleResponse.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the response of
- ///
- ///
- public class InterruptAttachingToTangleResponse : IotaResponse
- {
-
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/IotaCoreApi.cs b/IotaApi.Standard/Core/IotaCoreApi.cs
deleted file mode 100644
index ec30250..0000000
--- a/IotaApi.Standard/Core/IotaCoreApi.cs
+++ /dev/null
@@ -1,258 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Iota.Api.Standard.Model;
-using Iota.Api.Standard.Utils;
-using RestSharp.Extensions;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class provides access to the Iota core API
- ///
- public class IotaCoreApi
- {
- private readonly IGenericIotaCoreApi _genericIotaCoreApi;
-
- ///
- ///
- ///
- public ILocalPoW LocalPow { get; set; }
-
- ///
- /// Creates a core api object that uses the specified connection settings to connect to a node
- ///
- /// hostname or API address of a node to interact with
- /// tcp/udp port
- public IotaCoreApi(string host, int port)
- {
- _genericIotaCoreApi = new GenericIotaCoreApi(host, port);
- }
-
- ///
- /// Attaches the specified transactions (trytes) to the Tangle by doing Proof of Work.
- /// You need to supply branchTransaction as well as trunkTransaction
- /// (basically the tips which you're going to validate and reference with this transaction)
- /// - both of which you'll get through the getTransactionsToApprove API call.
- ///
- /// Trunk transaction to approve.
- /// Branch transaction to approve.
- /// List of trytes (raw transaction data) to attach to the tangle.
- /// Proof of Work intensity. Minimum value is 18
- /// The returned value contains a different set of tryte values which you can input into broadcastTransactions and storeTransactions.
- /// The returned tryte value, the last 243 trytes basically consist of the: trunkTransaction + branchTransaction + nonce.
- /// These are valid trytes which are then accepted by the network.
- public AttachToTangleResponse AttachToTangle(string trunkTransaction, string branchTransaction,
- string[] trytes, int minWeightMagnitude = 18)
- {
- if (!InputValidator.IsHash(trunkTransaction))
- throw new ArgumentException("Invalid hashes provided.");
-
- if (!InputValidator.IsHash(branchTransaction))
- throw new ArgumentException("Invalid hashes provided.");
-
- if (!InputValidator.IsArrayOfTrytes(trytes, 2673))
- throw new ArgumentException("Invalid trytes provided.");
-
- if (LocalPow != null)
- {
- var response = new AttachToTangleResponse
- {
- Trytes = new List()
- };
-
- string previousTransaction = null;
- foreach (var t in trytes)
- {
- var txn = new Transaction(t)
- {
- TrunkTransaction = previousTransaction ?? trunkTransaction,
- BranchTransaction = previousTransaction == null ? branchTransaction : trunkTransaction
- };
-
- if (string.IsNullOrEmpty(txn.Tag) || txn.Tag.Matches("9*"))
- txn.Tag = txn.ObsoleteTag;
- txn.AttachmentTimestamp = IotaApiUtils.CreateTimeStampNow();
- txn.AttachmentTimestampLowerBound = 0;
- txn.AttachmentTimestampUpperBound = 3_812_798_742_493L;
-
- var resultTrytes = LocalPow.PerformPoW(txn.ToTransactionTrytes(), minWeightMagnitude);
-
- previousTransaction = new Transaction(resultTrytes).Hash;
-
- response.Trytes.Add(resultTrytes);
- }
-
- return response;
- }
-
- AttachToTangleRequest attachToTangleRequest = new AttachToTangleRequest(trunkTransaction, branchTransaction,
- trytes, minWeightMagnitude);
- return _genericIotaCoreApi.Request(attachToTangleRequest);
- }
-
- ///
- /// Broadcasts the transactions.
- ///
- /// The transactions in trytes representation
- /// the BroadcastTransactionsResponse
- public BroadcastTransactionsResponse BroadcastTransactions(List trytes)
- {
- return
- _genericIotaCoreApi.Request(
- new BroadcastTransactionsRequest(trytes));
- }
-
- ///
- /// Finds the transactions using the specified arguments as search criteria
- ///
- /// The addresses.
- /// The tags.
- /// The approves.
- /// The bundles.
- /// a FindTransactionsResponse, see
- public FindTransactionsResponse FindTransactions(List addresses, List tags,
- List approves, List bundles)
- {
- var findTransactionsRequest = new FindTransactionsRequest(bundles, addresses, tags, approves);
- return
- _genericIotaCoreApi.Request(findTransactionsRequest);
- }
-
- ///
- /// Gets the balances.
- ///
- /// The addresses.
- /// The threshold.
- /// It returns the confirmed balance which a list of addresses have at the latest confirmed milestone.
- /// In addition to the balances, it also returns the milestone as well as the index with which the confirmed balance was determined.
- /// The balances is returned as a list in the same order as the addresses were provided as input.
- public GetBalancesResponse GetBalances(List addresses, long threshold)
- {
- List addressesWithoutChecksum = new List();
- foreach (var address in addresses)
- {
- string address0 = address.RemoveChecksum();
- addressesWithoutChecksum.Add(address0);
- }
-
- GetBalancesRequest getBalancesRequest = new GetBalancesRequest(addressesWithoutChecksum, threshold);
- return _genericIotaCoreApi.Request(getBalancesRequest);
- }
-
- ///
- /// Gets the inclusion states of the specified transactions
- ///
- /// The transactions.
- /// The milestones.
- /// a GetInclusionStatesResponse, see
- public GetInclusionStatesResponse GetInclusionStates(string[] transactions, string[] milestones)
- {
- return
- _genericIotaCoreApi.Request(
- new GetInclusionStatesRequest(transactions, milestones));
- }
-
- ///
- /// Stores the specified transactions in trytes into the local storage. The trytes to be used for this call are returned by attachToTangle.
- ///
- /// The trytes representing the transactions
- /// a
- public StoreTransactionsResponse StoreTransactions(List trytes)
- {
- return
- _genericIotaCoreApi.Request(
- new StoreTransactionsRequest(trytes));
- }
-
- ///
- /// Gets the node information.
- ///
- /// a containing information about the node.
- public GetNodeInfoResponse GetNodeInfo()
- {
- return _genericIotaCoreApi.Request(new GetNodeInfoRequest());
- }
-
- ///
- /// Gets the tips.
- ///
- /// a containing a list of tips
- public GetTipsResponse GetTips()
- {
- GetTipsRequest getTipsRequest = new GetTipsRequest();
- return _genericIotaCoreApi.Request(getTipsRequest);
- }
-
- ///
- /// Gets the transactions to approve.
- ///
- /// The depth is the number of bundles to go back to determine the transactions for approval.
- /// The higher your depth value, the more "babysitting" you do for the network (as you have to confirm more transactions).
- /// trunkTransaction and branchTransaction (result of the Tip selection)
- public GetTransactionsToApproveResponse GetTransactionsToApprove(int depth)
- {
- GetTransactionsToApproveRequest getTransactionsToApproveRequest = new GetTransactionsToApproveRequest(depth);
- return
- _genericIotaCoreApi.Request(
- getTransactionsToApproveRequest);
- }
-
- ///
- /// Gets the raw transaction data (trytes) of a specific transaction.
- /// These trytes can then be easily converted into the actual transaction object using the constructor of Transaction
- ///
- /// The hashes of the transactions
- /// a containing a list of trytes
- public GetTrytesResponse GetTrytes(params string[] hashes)
- {
- GetTrytesRequest getTrytesRequest = new GetTrytesRequest() {Hashes = hashes};
- return _genericIotaCoreApi.Request(getTrytesRequest);
- }
-
- ///
- /// Interrupts and completely aborts the attachToTangle process.
- ///
- /// an
- public InterruptAttachingToTangleResponse InterruptAttachingToTangle()
- {
- InterruptAttachingToTangleRequest request = new InterruptAttachingToTangleRequest();
- return
- _genericIotaCoreApi.Request(
- request);
- }
-
- ///
- /// Gets the neighbors the node is connected to
- ///
- /// A containing the set of neighbors the node is connected to as well as their activity count. The activity counter is reset after restarting IRI.
- public GetNeighborsResponse GetNeighbors()
- {
- GetNeighborsRequest getNeighborsRequest = new GetNeighborsRequest();
- return _genericIotaCoreApi.Request(getNeighborsRequest);
- }
-
- ///
- /// Adds the neighbor(s) to the node. It should be noted that this is only temporary, and the added neighbors will be removed from your set of neighbors after you relaunch IRI.
- ///
- /// The uris of the neighbors to add. The URI (Unique Resource Identification) format is "udp://IPADDRESS:PORT"
- /// containing the number of added Neighbors
- public AddNeighborsResponse AddNeighbors(params string[] uris)
- {
- return
- _genericIotaCoreApi.Request(
- new AddNeighborsRequest(uris.ToList()));
- }
-
- ///
- /// Removes the neighbor(s) from the node.
- ///
- /// The uris of the neighbors to add. The URI (Unique Resource Identification) format is "udp://IPADDRESS:PORT"
- /// A containing the number of removed neighbors
- public RemoveNeighborsResponse RemoveNeighbors(params string[] uris)
- {
- RemoveNeighborsRequest removeNeighborsRequest = new RemoveNeighborsRequest(uris.ToList());
- return _genericIotaCoreApi.Request(removeNeighborsRequest);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/IotaRequest.cs b/IotaApi.Standard/Core/IotaRequest.cs
deleted file mode 100644
index 5cd37d5..0000000
--- a/IotaApi.Standard/Core/IotaRequest.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class serves as base class for the different core API calls/requests
- ///
- public class IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The command.
- public IotaRequest(string command)
- {
- Command = command;
- }
-
- ///
- /// Gets or sets the command.
- ///
- ///
- /// The command.
- ///
- public string Command { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/IotaResponse.cs b/IotaApi.Standard/Core/IotaResponse.cs
deleted file mode 100644
index c14feb3..0000000
--- a/IotaApi.Standard/Core/IotaResponse.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the base class of different core API response classes
- ///
- public class IotaResponse
- {
- ///
- /// Gets or sets the duration.
- ///
- ///
- /// The duration.
- ///
- public long Duration { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/RemoveNeighborsRequest.cs b/IotaApi.Standard/Core/RemoveNeighborsRequest.cs
deleted file mode 100644
index 610249f..0000000
--- a/IotaApi.Standard/Core/RemoveNeighborsRequest.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core api request 'RemoveNeighbors'
- ///
- ///
- public class RemoveNeighborsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The uris.
- public RemoveNeighborsRequest(List uris) : base(Core.Command.RemoveNeighbors.GetCommandString())
- {
- Uris = uris;
- }
-
- ///
- /// Gets or sets the uris of the neighbours to remove
- ///
- ///
- /// The uris of the neighbours to remove.
- ///
- public List Uris { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Uris)}: {string.Join(",", Uris)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Core/StoreTransactionsRequest.cs b/IotaApi.Standard/Core/StoreTransactionsRequest.cs
deleted file mode 100644
index 5cb8f58..0000000
--- a/IotaApi.Standard/Core/StoreTransactionsRequest.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the core API request 'StoreTransactions'.
- /// It stores transactions into the local storage. The trytes to be used for this call are returned by attachToTangle.
- ///
- public class StoreTransactionsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The trytes.
- public StoreTransactionsRequest(List trytes) : base(Core.Command.StoreTransactions.GetCommandString())
- {
- Trytes = trytes;
- }
-
- ///
- /// Gets or sets the trytes.
- ///
- ///
- /// The trytes.
- ///
- public List Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Trytes)}: {Trytes}";
- }
- }
-}
diff --git a/IotaApi.Standard/Core/StoreTransactionsResponse.cs b/IotaApi.Standard/Core/StoreTransactionsResponse.cs
deleted file mode 100644
index cea9985..0000000
--- a/IotaApi.Standard/Core/StoreTransactionsResponse.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace Iota.Api.Standard.Core
-{
- ///
- /// This class represents the response of
- ///
- public class StoreTransactionsResponse
- {
- }
-}
diff --git a/IotaApi.Standard/Exception/IllegalAccessError.cs b/IotaApi.Standard/Exception/IllegalAccessError.cs
deleted file mode 100644
index 8d8d6c9..0000000
--- a/IotaApi.Standard/Exception/IllegalAccessError.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This exception occurs when certain core API calls on the node are disabled
- ///
- ///
- public class IllegalAccessError : System.Exception
- {
-
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Exception/InvalidAddressException.cs b/IotaApi.Standard/Exception/InvalidAddressException.cs
deleted file mode 100644
index b95ec9e..0000000
--- a/IotaApi.Standard/Exception/InvalidAddressException.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This exception occurs when an invalid address is provided
- ///
- ///
- public class InvalidAddressException : ArgumentException
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The address.
- public InvalidAddressException(string address) : base("The specified address '" + address + "' is invalid")
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Exception/InvalidBundleException.cs b/IotaApi.Standard/Exception/InvalidBundleException.cs
deleted file mode 100644
index 5b62c24..0000000
--- a/IotaApi.Standard/Exception/InvalidBundleException.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This excpetions occurs if an invalid bundle was found or provided
- ///
- ///
- public class InvalidBundleException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The message that describes the error.
- public InvalidBundleException(string message) : base(message)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Exception/InvalidSignatureException.cs b/IotaApi.Standard/Exception/InvalidSignatureException.cs
deleted file mode 100644
index 54cd8d4..0000000
--- a/IotaApi.Standard/Exception/InvalidSignatureException.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This exception occurs when an invalid signature is encountered
- ///
- ///
- public class InvalidSignatureException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public InvalidSignatureException() :base("Invalid signature found")
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Exception/InvalidTailTransactionException.cs b/IotaApi.Standard/Exception/InvalidTailTransactionException.cs
deleted file mode 100644
index 701f1b3..0000000
--- a/IotaApi.Standard/Exception/InvalidTailTransactionException.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This exception is thrown when an invalid tail transaction was encountered
- ///
- ///
- public class InvalidTailTransactionException : System.Exception
- {
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Exception/InvalidTryteException.cs b/IotaApi.Standard/Exception/InvalidTryteException.cs
deleted file mode 100644
index 8ea9ac8..0000000
--- a/IotaApi.Standard/Exception/InvalidTryteException.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This exception occurs when invalid trytes are encountered
- ///
- public class InvalidTryteException : System.Exception
- {
-
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Exception/InvisibleBundleTransactionException.cs b/IotaApi.Standard/Exception/InvisibleBundleTransactionException.cs
deleted file mode 100644
index 4665a41..0000000
--- a/IotaApi.Standard/Exception/InvisibleBundleTransactionException.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This exception occurs when a bundle or transaction is not visible in the tangle
- ///
- ///
- public class InvisibleBundleTransactionException : System.Exception
- {
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Exception/IotaApiException.cs b/IotaApi.Standard/Exception/IotaApiException.cs
deleted file mode 100644
index d8e7a50..0000000
--- a/IotaApi.Standard/Exception/IotaApiException.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This exception encapsulates an error that occured while communicating with the node (for example during a core API call)
- ///
- ///
- public class IotaApiException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The error.
- public IotaApiException(string error) : base(error)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Exception/NotEnoughBalanceException.cs b/IotaApi.Standard/Exception/NotEnoughBalanceException.cs
deleted file mode 100644
index b15aee2..0000000
--- a/IotaApi.Standard/Exception/NotEnoughBalanceException.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-namespace Iota.Api.Standard.Exception
-{
- ///
- /// This exception occurs when a transfer fails because their is not enough balance to perform the transfer
- ///
- ///
- public class NotEnoughBalanceException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public NotEnoughBalanceException() : base("Not enough balance")
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The total value.
- public NotEnoughBalanceException(long totalValue) : base("Not enough balance to transfer " + totalValue + " iota")
- {
-
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/IotaApi.Standard.csproj b/IotaApi.Standard/IotaApi.Standard.csproj
deleted file mode 100644
index c84f7fb..0000000
--- a/IotaApi.Standard/IotaApi.Standard.csproj
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
- netstandard2.0
- Iota.Api.Standard
- Iota.Api.Standard
-
-
-
-
-
-
-
-
-
-
diff --git a/IotaApi.Standard/IotaApi.cs b/IotaApi.Standard/IotaApi.cs
deleted file mode 100644
index b4cf883..0000000
--- a/IotaApi.Standard/IotaApi.cs
+++ /dev/null
@@ -1,1125 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Iota.Api.Standard.Core;
-using Iota.Api.Standard.Exception;
-using Iota.Api.Standard.Model;
-using Iota.Api.Standard.Pow;
-using Iota.Api.Standard.Utils;
-
-namespace Iota.Api.Standard
-{
- ///
- /// This class provides access to the core API methods and the proposed calls
- ///
- public class IotaApi : IotaCoreApi
- {
- private readonly ICurl _curl;
-
- ///
- /// Creates an api object that uses the specified connection settings to connect to a node
- ///
- /// hostname or API address of a node to interact with
- /// tcp/udp port
- public IotaApi(string host, int port) : this(host, port, new Kerl())
- {
- }
-
- ///
- /// Creates an api object that uses the specified connection settings to connect to a node
- ///
- /// hostname or API address of a node to interact with
- /// tcp/udp port
- ///
- /// a custom curl implementation to be used to perform the pow. Use the other constructor in order to
- /// use the default curl implementation provided by the library
- ///
- public IotaApi(string host, int port, ICurl curl) : base(host, port)
- {
- _curl = curl ?? throw new ArgumentNullException(nameof(curl));
- }
-
- ///
- /// Gets all possible inputs of a seed and returns them with the total balance.
- /// This is either done deterministically (by genearating all addresses until findTransactions is empty and doing
- /// getBalances),
- /// or by providing a key range to use for searching through.
- ///
- /// Tryte-encoded seed. It should be noted that this seed is not transferred
- /// The Security level of private key / seed.
- /// Starting key index
- /// Ending key index
- /// The minimum threshold of accumulated balances from the inputs that is required
- /// The inputs (see )
- public Inputs GetInputs(string seed, int security, int start, int end, long threshold)
- {
- InputValidator.CheckIfValidSeed(seed);
-
- seed = InputValidator.PadSeedIfNecessary(seed);
-
- if (security < 1)
- throw new ArgumentException("invalid security level provided");
-
- // If start value bigger than end, return error
- if (start > end)
- throw new ArgumentException("start must be smaller than end", nameof(start));
-
- // or if difference between end and start is bigger than 500 keys
- if (end - start > 500)
- throw new ArgumentException("total number of keys exceeded 500");
-
- // Case 1: start and end
- //
- // If start and end is defined by the user, simply iterate through the keys
- // and call getBalances
- if (end != 0)
- {
- var allAddresses = new string[end - start];
-
- for (var i = start; i < end; i++)
- {
- var address = IotaApiUtils.NewAddress(seed, security, i, false, _curl);
- allAddresses[i] = address;
- }
-
- return GetBalanceAndFormat(allAddresses, threshold, start, security);
- }
-
- // Case 2: iterate till threshold || end
- //
- // Either start from index: 0 or start (if defined) until threshold is reached.
- // Calls getNewAddress and deterministically generates and returns all addresses
- // We then do getBalance, format the output and return it
-
- var addresses = GetNewAddress(seed, security, start, false, 0, true);
- return GetBalanceAndFormat(addresses, threshold, start, security);
- }
-
- ///
- /// Gets the balances of the specified addresses and calculates the total balance till the threshold is reached.
- ///
- /// addresses
- /// the threshold
- /// start index
- ///
- /// an Inputs object
- ///
- /// is thrown if threshold exceeds the sum of balance of the specified
- /// addresses
- ///
- private Inputs GetBalanceAndFormat(
- string[] addresses,
- long threshold, int start,
- int security)
- {
- if (security < 1)
- throw new ArgumentException("invalid security level provided");
-
- var getBalancesResponse = GetBalances(addresses.ToList(), 100);
-
- var balances = getBalancesResponse.Balances;
-
- var inputs = new Inputs {InputsList = new List(), TotalBalance = 0};
-
- var threshholdReached = threshold == 0;
-
- for (var i = 0; i < addresses.Length; i++)
- if (balances[i] > 0)
- {
- inputs.InputsList.Add(new Input
- {
- Address = addresses[i],
- Balance = balances[i],
- KeyIndex = start + i,
- Security = security
- });
-
- inputs.TotalBalance += balances[i];
-
- if (inputs.TotalBalance >= threshold)
- {
- threshholdReached = true;
- break;
- }
- }
-
- if (threshholdReached)
- return inputs;
-
-
- throw new NotEnoughBalanceException();
- }
-
- ///
- /// Main purpose of this function is to get an array of transfer objects as input, and then prepare the transfer by
- /// generating the correct bundle,
- /// as well as choosing and signing the inputs if necessary (if it's a value transfer). The output of this function is
- /// an array of the raw transaction data (trytes)
- ///
- /// 81-tryte encoded address of recipient
- ///
- /// the transfers to prepare
- /// Optional (default null). The inputs
- ///
- /// Optional (default null). if defined, this address will be used for sending the remainder
- /// value (of the inputs) to.
- ///
- ///
- /// a list containing the trytes of the new bundle
- public List PrepareTransfers(
- string seed, int security,
- Transfer[] transfers,
- string remainderAddress,
- List inputs,
- bool validateInputs)
- {
- // validate seed
- if (!InputValidator.IsValidSeed(seed))
- throw new IllegalStateException("Invalid seed provided.");
-
-
- if(security<1)
- throw new ArgumentException("Invalid security level provided.");
-
- // Input validation of transfers object
- InputValidator.CheckTransferArray(transfers);
-
- // Create a new bundle
- var bundle = new Bundle();
- var signatureFragments = new List();
-
- long totalValue = 0;
- var tag = "";
-
- //
- // Iterate over all transfers, get totalValue
- // and prepare the signatureFragments, message and tag
- //
- foreach (var transfer in transfers)
- {
- // remove the checksum of the address if provided
- transfer.Address = transfer.Address.RemoveChecksum();
-
- var signatureMessageLength = 1;
-
- // If message longer than 2187 trytes, increase signatureMessageLength (add 2nd transaction)
- if (transfer.Message.Length > Constants.MessageLength)
- {
- // Get total length, message / maxLength (2187 trytes)
- signatureMessageLength += (int) Math.Floor((double) transfer.Message.Length / Constants.MessageLength);
-
- var msgCopy = transfer.Message;
-
- // While there is still a message, copy it
- while (!string.IsNullOrEmpty(msgCopy))
- {
- var fragment = msgCopy.Substring(0, 2187 > msgCopy.Length ? msgCopy.Length : 2187);
- msgCopy = msgCopy.Substring(2187, msgCopy.Length - 2187);
-
- // Pad remainder of fragment
- while (fragment.Length < 2187) fragment += '9';
-
- signatureFragments.Add(fragment);
- }
- }
- else
- {
- // Else, get single fragment with 2187 of 9's trytes
- var fragment = string.Empty;
-
- if (!string.IsNullOrEmpty(transfer.Message))
- fragment = transfer.Message.Substring(0,
- transfer.Message.Length < 2187 ? transfer.Message.Length : 2187);
-
- while (fragment.Length < 2187) fragment += '9';
-
- signatureFragments.Add(fragment);
- }
-
- // get current timestamp in seconds
- var timestamp = (long)Math.Floor((double)IotaApiUtils.CreateTimeStampNow()/1000);
-
- // If no tag defined, get 27 tryte tag.
-
- tag = string.IsNullOrEmpty(transfer.Tag) ? "999999999999999999999999999" : transfer.Tag;
-
-
- // Pad for required 27 tryte length
- while (tag.Length < 27) tag += '9';
-
-
- // Add first entries to the bundle
- // Slice the address in case the user provided a checksummed one
- bundle.AddEntry(signatureMessageLength, transfer.Address, transfer.Value, tag, timestamp);
- // Sum up total value
- totalValue += transfer.Value;
- }
-
- // Get inputs if we are sending tokens
- if (totalValue != 0)
- if (inputs != null && inputs.Count > 0)
- {
- // Get list if addresses of the provided inputs
- var inputAddresses = new List();
- foreach (var input in inputs) inputAddresses.Add(input.Address);
-
- var balances = GetBalances(inputAddresses, 100);
-
- var confirmedInputs = new List();
-
- long totalBalance = 0;
- for (var i = 0; i < balances.Balances.Count; i++)
- {
- var thisBalance = balances.Balances[i];
- totalBalance += thisBalance;
-
- // If input has balance, add it to confirmedInputs
- if (thisBalance > 0)
- {
- var inputEl = inputs[i];
- inputEl.Balance = thisBalance;
-
- confirmedInputs.Add(inputEl);
- }
- }
-
- // Return not enough balance error
- if (totalValue > totalBalance) throw new NotEnoughBalanceException(totalValue);
-
- return AddRemainder(seed, security, confirmedInputs, bundle, tag, totalValue, remainderAddress,
- signatureFragments);
- }
-
- // Case 2: Get inputs deterministically
- //
- // If no inputs provided, derive the addresses from the seed and
- // confirm that the inputs exceed the threshold
- else
- {
- var inputList = GetInputs(seed, security, 0, 0, (int) totalValue).InputsList;
- return AddRemainder(seed, security, inputList, bundle, tag, totalValue, remainderAddress,
- signatureFragments);
- }
-
- // If no input required, don't sign and simply finalize the bundle
- bundle.FinalizeBundle(_curl.Clone());
- bundle.AddTrytes(signatureFragments);
-
- var bundleTrytes = new List();
- bundle.Transactions.ForEach(tx => bundleTrytes.Add(tx.ToTransactionTrytes()));
-
- bundleTrytes.Reverse();
- return bundleTrytes;
- }
-
-
- private List AddRemainder(
- string seed,
- int security,
- List inputs,
- Bundle bundle,
- string tag,
- long totalValue,
- string remainderAddress,
- List signatureFragments)
- {
- var totalTransferValue = totalValue;
-
- foreach (var input in inputs)
- {
- var thisBalance = input.Balance;
- var toSubtract = 0 - thisBalance;
- var timestamp = IotaApiUtils.CreateTimeStampNow();
-
- // Add input as bundle entry
- bundle.AddEntry(security, input.Address, toSubtract, tag, timestamp);
- // If there is a remainder value
- // Add extra output to send remaining funds to
-
- if (thisBalance >= totalTransferValue)
- {
- var remainder = thisBalance - totalTransferValue;
-
- // If user has provided remainder address
- // Use it to send remaining funds to
- if (remainder > 0 && remainderAddress != null)
- {
- // Remainder bundle entry
- bundle.AddEntry(1, remainderAddress, remainder, tag, timestamp);
-
- // function for signing inputs
- IotaApiUtils.SignInputsAndReturn(seed, inputs, bundle, signatureFragments, _curl);
- }
- else if (remainder > 0)
- {
- // Generate a new Address by calling getNewAddress
- // ReSharper disable RedundantArgumentDefaultValue
- var address = GetNewAddress(seed, security, 0, false, 0, false)[0];
- // ReSharper restore RedundantArgumentDefaultValue
-
- // Remainder bundle entry
- bundle.AddEntry(1, address, remainder, tag, timestamp);
-
- // function for signing inputs
- return IotaApiUtils.SignInputsAndReturn(seed, inputs, bundle, signatureFragments, _curl);
- }
- else
- {
- // If there is no remainder, do not add transaction to bundle
- // simply sign and return
- return IotaApiUtils.SignInputsAndReturn(seed, inputs, bundle, signatureFragments, _curl);
- }
- }
- // If multiple inputs provided, subtract the totalTransferValue by
- // the inputs balance
- else
- {
- totalTransferValue -= thisBalance;
- }
- }
-
- throw new NotEnoughBalanceException(totalValue);
- }
-
-
- ///
- /// Generates a new address from a seed and returns the remainderAddress. This is either done deterministically, or by
- /// providing the index of the new remainderAddress
- ///
- /// Tryte-encoded seed. It should be noted that this seed is not transferred
- ///
- ///
- /// Optional (default null). Key index to start search from. If the index is provided, the generation
- /// of the address is not deterministic.
- ///
- /// Optional (default false). Adds 9-tryte address checksum
- /// Optional (default 1)Total number of addresses to generate.
- ///
- /// If true, it returns all addresses which were deterministically generated (until
- /// findTransactions returns null)
- ///
- /// an array of strings with the specifed number of addresses
- public string[] GetNewAddress(string seed, int security, int index = 0, bool checksum = false, int total = 0,
- bool returnAll = false)
- {
- var allAdresses = new List();
-
- // TODO make two different functions out of this
-
- // Case 1: total
- //
- // If total number of addresses to generate is supplied, simply generate
- // and return the list of all addresses
- if (total > 0)
- {
- // Increase index with each iteration
- for (var i = index; i < index + total; i++)
- allAdresses.Add(IotaApiUtils.NewAddress(seed, security, i, checksum, new Kerl()));
-
- return allAdresses.ToArray();
- }
-
- // Case 2: no total provided
- //
- // Continue calling findTransactions to see if address was already created
- // if null, return list of addresses
- //
-
- var addresses = new List();
-
- for (var i = index;; i++)
- {
- var newAddress = IotaApiUtils.NewAddress(seed, security, i, checksum, new Kerl());
- var response = FindTransactionsByAddresses(newAddress);
-
- if (returnAll) addresses.Add(newAddress);
-
- if (response.Hashes.Count == 0)
- break;
- }
-
- return addresses.ToArray();
- }
-
- ///
- /// Gets the transfers which are associated with a seed.
- /// The transfers are determined by either calculating deterministically which addresses were already used,
- /// or by providing a list of indexes to get the transfers from.
- ///
- /// tryte-encoded seed. It should be noted that this seed is not transferred
- /// If True, it gets the inclusion states of the transfers.
- ///
- /// the address start index
- /// the address end index
- /// An Array of Bundle object that represent the transfers
- public Bundle[] GetTransfers(string seed, int security, int? start, int? end, bool inclusionStates = false)
- {
- InputValidator.CheckIfValidSeed(seed);
- seed = InputValidator.PadSeedIfNecessary(seed);
-
- if (!start.HasValue)
- start = 0;
- if (!end.HasValue)
- end = 0;
-
- // If start value bigger than end, return error
- // or if difference between end and start is bigger than 500 keys
- if (start.Value > end.Value || end.Value > start + 500)
- throw new System.Exception("Invalid inputs provided: start, end");
-
- // first call findTransactions
- // If a transaction is non tail, get the tail transactions associated with it
- // add it to the list of tail transactions
-
- var addresses = GetNewAddress(seed, security, start.Value, false,
- end.Value, true);
-
-
- var bundles = BundlesFromAddresses(addresses, inclusionStates);
- return bundles;
- }
-
- private Bundle[] BundlesFromAddresses(string[] addresses, bool inclusionStates)
- {
- var trxs = FindTransactionObjects(addresses);
- // set of tail transactions
- var tailTransactions = new List();
- var nonTailBundleHashes = new List();
-
- foreach (var trx in trxs)
- // Sort tail and nonTails
- if (trx.CurrentIndex == 0)
- {
- tailTransactions.Add(trx.Hash);
- }
- else
- {
- if (nonTailBundleHashes.IndexOf(trx.Bundle) == -1) nonTailBundleHashes.Add(trx.Bundle);
- }
-
- var bundleObjects = FindTransactionObjectsByBundle(nonTailBundleHashes.ToArray());
- foreach (var trx in bundleObjects)
- // Sort tail and nonTails
- if (trx.CurrentIndex == 0)
- if (tailTransactions.IndexOf(trx.Hash) == -1)
- tailTransactions.Add(trx.Hash);
-
- var finalBundles = new List();
- var tailTxArray = tailTransactions.ToArray();
-
- // If inclusionStates, get the confirmation status
- // of the tail transactions, and thus the bundles
- GetInclusionStatesResponse gisr = null;
- if (inclusionStates)
- {
- try
- {
- gisr = GetLatestInclusion(tailTxArray);
- }
- catch (IllegalAccessError)
- {
- // suppress exception (the check is done below)
- }
-
- if (gisr == null || gisr.States == null || gisr.States.Count == 0)
- throw new ArgumentException("Inclusion states not found");
- }
-
-
- var finalInclusionStates = gisr;
-
- Parallel.ForEach(tailTransactions, param =>
- {
- try
- {
- var b = GetBundle(param);
-
- if (inclusionStates)
- {
- var thisInclusion = finalInclusionStates != null &&
- finalInclusionStates.States[tailTxArray.ToList().IndexOf(param)];
- foreach (var t in b.Transactions) t.Persistance = thisInclusion;
- }
-
- finalBundles.Add(b);
- }
- catch (System.Exception ex)
- {
- Console.WriteLine("Bundle error: " + ex.Message);
- }
- });
-
- finalBundles.Sort();
- var returnValue = new Bundle[finalBundles.Count];
- for (var i = 0; i < finalBundles.Count; i++)
- returnValue[i] = new Bundle(finalBundles[i].Transactions, finalBundles[i].Transactions.Count);
- return returnValue;
- }
-
- ///
- /// Finds the transaction objects.
- ///
- /// The addresses.
- /// a list of transactions
- public List FindTransactionObjects(string[] addresses)
- {
- var addressesWithoutChecksum =
- addresses.Select(address => address.RemoveChecksum()).ToList();
-
- var ftr = FindTransactions(addressesWithoutChecksum, null, null, null);
- if (ftr?.Hashes == null)
- return null;
-
- // get the transaction objects of the transactions
- return GetTransactionsObjects(ftr.Hashes.ToArray());
- }
-
- ///
- /// Gets the transactions objects.
- ///
- /// The hashes in trytes
- /// a list of transactions
- public List GetTransactionsObjects(string[] hashes)
- {
- if (!InputValidator.IsArrayOfHashes(hashes))
- throw new IllegalStateException("Not an Array of Hashes: " + hashes);
-
- var trytesResponse = GetTrytes(hashes);
-
- var trxs = new List();
-
- foreach (var tryte in trytesResponse.Trytes) trxs.Add(new Transaction(tryte, _curl));
- return trxs;
- }
-
- ///
- /// Finds the transaction objects by bundle.
- ///
- /// The bundles.
- /// a list of Transaction objects
- public List FindTransactionObjectsByBundle(string[] bundles)
- {
- var ftr = FindTransactions(null, null, null, bundles.ToList());
- if (ftr == null || ftr.Hashes == null)
- return null;
-
- // get the transaction objects of the transactions
- return GetTransactionsObjects(ftr.Hashes.ToArray());
- }
-
-
- ///
- /// Replays the bundle.
- ///
- /// The transaction.
- /// The depth.
- /// The minimum weight magnitude.
- /// an array of boolean that indicate which transactions have been replayed successfully
- public bool[] ReplayBundle(string transaction, int depth, int minWeightMagnitude)
- {
- //StopWatch stopWatch = new StopWatch();
-
- var bundleTrytes = new List();
-
- var bundle = GetBundle(transaction);
-
- bundle.Transactions.ForEach(t => bundleTrytes.Add(t.ToTransactionTrytes()));
-
- var trxs = SendTrytes(bundleTrytes.ToArray(), depth, minWeightMagnitude).ToList();
-
- var successful = new bool[trxs.Count];
-
- for (var i = 0; i < trxs.Count; i++)
- {
- var response = FindTransactionsByBundles(trxs[i].Bundle);
- successful[i] = response.Hashes.Count != 0;
- }
-
- return successful;
- }
-
- ///
- /// Finds the transactions by bundles.
- ///
- /// The bundles.
- /// a FindTransactionsResponse containing the transactions, see
- public FindTransactionsResponse FindTransactionsByBundles(params string[] bundles)
- {
- return FindTransactions(null, null, null, bundles.ToList());
- }
-
- ///
- /// Finds the transactions by approvees.
- ///
- /// The approvees.
- /// a FindTransactionsResponse containing the transactions, see
- public FindTransactionsResponse FindTransactionsByApprovees(params string[] approvees)
- {
- return FindTransactions(null, null, approvees.ToList(), null);
- }
-
-
- ///
- /// Finds the transactions by digests.
- ///
- /// The bundles.
- /// a FindTransactionsResponse containing the transactions, see
- public FindTransactionsResponse FindTransactionsByDigests(params string[] bundles)
- {
- return FindTransactions(null, bundles.ToList(), null, null);
- }
-
- ///
- /// Finds the transactions by addresses.
- ///
- /// The addresses.
- /// a FindTransactionsResponse containing the transactions, see
- public FindTransactionsResponse FindTransactionsByAddresses(params string[] addresses)
- {
- var addressesWithoutChecksum = new List();
- foreach (var address in addresses)
- {
- var address0 = address.RemoveChecksum();
- addressesWithoutChecksum.Add(address0);
- }
-
- return FindTransactions(addressesWithoutChecksum, null, null, null);
- }
-
- ///
- /// Gets the latest inclusion.
- ///
- /// The hashes.
- /// a GetInclusionStatesResponse cotaining the inclusion state of the specified hashes
- public GetInclusionStatesResponse GetLatestInclusion(string[] hashes)
- {
- string[] latestMilestone = {GetNodeInfo().LatestSolidSubtangleMilestone};
- return GetInclusionStates(hashes, latestMilestone);
- }
-
-
- ///
- /// Wrapper function that basically does prepareTransfers, as well as attachToTangle and finally, it broadcasts and
- /// stores the transactions locally.
- ///
- /// tryte-encoded seed
- ///
- /// depth
- /// The minimum weight magnitude
- /// Array of transfer objects
- /// Optional (default null). List of inputs used for funding the transfer
- ///
- /// Optional (default null). If defined, this address will be used for sending the remainder value
- /// (of the inputs) to
- ///
- ///
- ///
- /// an array of the boolean that indicates which Transactions where sent successully
- public bool[] SendTransfer(
- string seed, int security, int depth,
- int minWeightMagnitude, Transfer[] transfers,
- Input[] inputs, string remainderAddress,
- bool validateInputs, bool validateInputAddresses)
- {
- var trytes = PrepareTransfers(seed, security, transfers,
- remainderAddress, inputs?.ToList(), validateInputs);
- var trxs = SendTrytes(trytes.ToArray(), depth, minWeightMagnitude);
-
- var successful = new bool[trxs.Length];
-
- for (var i = 0; i < trxs.Length; i++)
- {
- var response = FindTransactionsByBundles(trxs[i].Bundle);
-
- successful[i] = response.Hashes.Count != 0;
- }
-
- return successful;
- }
-
- ///
- /// Sends the trytes.
- ///
- /// The trytes.
- /// The depth.
- /// Optional (default 14). The minimum weight magnitude.
- /// an Array of Transactions
- public Transaction[] SendTrytes(string[] trytes, int depth, int minWeightMagnitude = 14)
- {
- var transactionsToApproveResponse = GetTransactionsToApprove(depth);
-
- var attachToTangleResponse =
- AttachToTangle(transactionsToApproveResponse.TrunkTransaction,
- transactionsToApproveResponse.BranchTransaction, trytes, minWeightMagnitude);
- try
- {
- BroadcastAndStore(attachToTangleResponse.Trytes);
- }
- catch (System.Exception)
- {
- return new Transaction[0];
- }
-
- var trx = new List();
-
- foreach (var tx in attachToTangleResponse.Trytes) trx.Add(new Transaction(tx, _curl));
- return trx.ToArray();
- }
-
- ///
- /// This function returns the bundle which is associated with a transaction. Input can by any type of transaction (tail
- /// and non-tail).
- /// If there are conflicting bundles (because of a replay for example) it will return multiple bundles.
- /// It also does important validation checking (signatures, sum, order) to ensure that the correct bundle is returned.
- ///
- /// the transaction encoded in trytes
- /// an array of bundle, if there are multiple arrays it means that there are conflicting bundles.
- public Bundle GetBundle(string transaction)
- {
- if (!InputValidator.IsHash(transaction))
- {
- throw new ArgumentException("Invalid hashes provided.");
- }
-
- var bundle = TraverseBundle(transaction, null, new Bundle());
-
- if (bundle == null)
- throw new ArgumentException("Unknown Bundle");
-
- long totalSum = 0;
- var bundleHash = bundle.Transactions[0].Bundle;
-
- ICurl curl = new Kerl();
- curl.Reset();
-
- var signaturesToValidate = new List();
-
- for (var index = 0; index < bundle.Transactions.Count; index++)
- {
- var bundleTransaction = bundle.Transactions[index];
- var bundleValue = bundleTransaction.Value;
- totalSum += bundleValue;
-
- if (bundleTransaction.CurrentIndex != index)
- throw new InvalidBundleException("The index of the bundle " + bundleTransaction.CurrentIndex +
- " did not match the expected index " + index);
-
- // Get the transaction trytes
- var thisTxTrytes = bundleTransaction.ToTransactionTrytes().Substring(2187, 162);
-
- // Absorb bundle hash + value + timestamp + lastIndex + currentIndex trytes.
- curl.Absorb(Converter.ToTrits(thisTxTrytes));
-
- // Check if input transaction
- if (bundleValue < 0)
- {
- var address = bundleTransaction.Address;
- var sig = new Signature {Address = address};
- sig.SignatureFragments.Add(bundleTransaction.SignatureMessageFragment);
-
- // Find the subsequent txs with the remaining signature fragment
- for (var i = index + 1; i < bundle.Transactions.Count; i++)
- {
- var newBundleTx = bundle.Transactions[i];
-
- // Check if new tx is part of the signature fragment
- if (newBundleTx.Address == address && newBundleTx.Value == 0)
- {
- if (sig.SignatureFragments.IndexOf(newBundleTx.SignatureMessageFragment) == -1)
- sig.SignatureFragments.Add(newBundleTx.SignatureMessageFragment);
- }
-
- }
-
- signaturesToValidate.Add(sig);
- }
- }
-
- // Check for total sum, if not equal 0 return error
- if (totalSum != 0)
- throw new InvalidBundleException("Invalid Bundle Sum");
-
- var bundleFromTrxs = new int[243];
- curl.Squeeze(bundleFromTrxs);
- var bundleFromTxString = Converter.ToTrytes(bundleFromTrxs);
-
- // Check if bundle hash is the same as returned by tx object
- if (!bundleFromTxString.Equals(bundleHash))
- throw new InvalidBundleException("Invalid Bundle Hash");
- // Last tx in the bundle should have currentIndex === lastIndex
- bundle.Length = bundle.Transactions.Count;
- if (
- !bundle.Transactions[bundle.Length - 1].CurrentIndex.Equals(
- bundle.Transactions[bundle.Length - 1].LastIndex))
- throw new InvalidBundleException("Invalid Bundle");
-
- // Validate the signatures
- foreach (var aSignaturesToValidate in signaturesToValidate)
- {
- var signatureFragments = aSignaturesToValidate.SignatureFragments.ToArray();
- var address = aSignaturesToValidate.Address;
- var isValidSignature = new Signing().ValidateSignatures(address, signatureFragments, bundleHash);
-
- if (!isValidSignature)
- throw new InvalidSignatureException();
- }
-
- return bundle;
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public AccountData GetAccountData(String seed, int security, int index, bool checksum, int total,
- bool returnAll, int start, int end, bool inclusionStates, long threshold)
- {
-
- if (start > end || end > (start + 1000))
- {
- throw new ArgumentException("Invalid input provided.");
- }
-
- var addresses = GetNewAddress(seed, security, index, checksum, total, returnAll);
- var bundle = GetTransfers(seed, security, start, end, inclusionStates);
- var inputs = GetInputs(seed, security, start, end, threshold);
-
- return new AccountData(new List(addresses), bundle, inputs.InputsList, inputs.TotalBalance);
- }
-
- ///
- /// Wrapper function that broadcasts and stores the specified trytes
- ///
- /// trytes
- public void BroadcastAndStore(List trytes)
- {
- BroadcastTransactions(trytes);
- StoreTransactions(trytes);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public List InitiateTransfer(
- int securitySum, string inputAddress, string remainderAddress,
- List transfers, bool testMode)
- {
- // validate input address
- if (!InputValidator.IsAddress(inputAddress))
- throw new ArgumentException("Invalid addresses provided.");
-
- // validate remainder address
- if (remainderAddress != null && !InputValidator.IsAddress(remainderAddress))
- {
- throw new ArgumentException("Invalid addresses provided.");
- }
-
- // Input validation of transfers object
- if (!InputValidator.IsTransfersCollectionValid(transfers))
- {
- throw new ArgumentException("Invalid transfers provided.");
- }
-
- // Create a new bundle
- Bundle bundle = new Bundle();
-
- long totalValue = 0;
- List signatureFragments = new List();
- String tag = "";
- //
-
- // Iterate over all transfers, get totalValue
- // and prepare the signatureFragments, message and tag
- foreach (Transfer transfer in transfers)
- {
-
- // remove the checksum of the address if provided
- if (transfer.Address.IsValidChecksum())
- {
- transfer.Address = transfer.Address.RemoveChecksum();
- }
-
- int signatureMessageLength = 1;
-
- // If message longer than 2187 trytes, increase signatureMessageLength (add next transaction)
- if (transfer.Message.Length > Constants.MessageLength)
- {
-
- // Get total length, message / maxLength (2187 trytes)
- signatureMessageLength += (int)Math.Floor((double)transfer.Message.Length / Constants.MessageLength);
-
- String msgCopy = transfer.Message;
-
- // While there is still a message, copy it
-
- while (!string.IsNullOrEmpty(msgCopy))
- {
-
- string fragment = msgCopy.Substring(0, Constants.MessageLength);
- msgCopy = msgCopy.Substring(Constants.MessageLength, msgCopy.Length - Constants.MessageLength);
-
- // Pad remainder of fragment
- fragment = fragment.PadRight(Constants.MessageLength, '9');
-
-
- signatureFragments.Add(fragment);
- }
-
- }
- else
- {
-
- // Else, get single fragment with 2187 of 9's trytes
- String fragment = transfer.Message;
-
- if (transfer.Message.Length < Constants.MessageLength)
- {
- fragment = fragment.PadRight(Constants.MessageLength, '9');
- }
-
- signatureFragments.Add(fragment);
-
- }
-
- tag = transfer.Tag;
-
- // pad for required 27 tryte length
- if (transfer.Tag.Length < Constants.TagLength)
- {
- tag = tag.PadRight(Constants.TagLength, '9');
- }
-
- // get current timestamp in seconds
- long timestamp = (long)Math.Floor(GetCurrentTimestampInSeconds());
-
- // Add first entry to the bundle
- bundle.AddEntry(signatureMessageLength, transfer.Address, transfer.Value, tag, timestamp);
- // Sum up total value
- totalValue += transfer.Value;
- }
-
- // Get inputs if we are sending tokens
- if (totalValue != 0)
- {
- GetBalancesResponse balancesResponse = GetBalances(new List { inputAddress }, 100);
- var balances = balancesResponse.Balances;
-
- long totalBalance = 0;
-
- foreach (var balance in balances)
- {
- totalBalance += balance;
- }
-
- // get current timestamp in seconds
- long timestamp = (long)Math.Floor(GetCurrentTimestampInSeconds());
-
- // bypass the balance checks during unit testing
- if (testMode)
- totalBalance += 1000;
-
- if (totalBalance > 0)
- {
-
- long toSubtract = 0 - totalBalance;
-
- // Add input as bundle entry
- // Only a single entry, signatures will be added later
- bundle.AddEntry(securitySum, inputAddress, toSubtract, tag, timestamp);
- }
- // Return not enough balance error
- if (totalValue > totalBalance)
- {
- throw new IllegalStateException("Not enough balance.");
- }
-
- // If there is a remainder value
- // Add extra output to send remaining funds to
- if (totalBalance > totalValue)
- {
-
- long remainder = totalBalance - totalValue;
-
- // Remainder bundle entry if necessary
- if (remainderAddress == null)
- {
- throw new IllegalStateException("No remainder address defined.");
- }
-
- bundle.AddEntry(1, remainderAddress, remainder, tag, timestamp);
- }
-
- bundle.FinalizeBundle(new Curl(CurlMode.CurlP81));
- bundle.AddTrytes(signatureFragments);
-
- return bundle.Transactions;
- }
- else
- {
- throw new System.Exception("Invalid value transfer: the transfer does not require a signature.");
- }
- }
-
- private Bundle TraverseBundle(string trunkTransaction, string bundleHash, Bundle bundle)
- {
- var gtr = GetTrytes(trunkTransaction);
-
- if (gtr.Trytes.Count == 0)
- throw new InvisibleBundleTransactionException();
-
- var trytes = gtr.Trytes[0];
-
- var transaction = new Transaction(trytes, _curl);
-
- // If first transaction to search is not a tail, return error
- if (bundleHash == null && transaction.CurrentIndex != 0) throw new InvalidTailTransactionException();
-
- // If no bundle hash, define it
- if (bundleHash == null) bundleHash = transaction.Bundle;
-
- // If different bundle hash, return with bundle
- if (bundleHash != transaction.Bundle) return bundle;
-
- // If only one bundle element, return
- if (transaction.LastIndex == 0 && transaction.CurrentIndex == 0)
- return new Bundle(new List { transaction }, 1);
-
- // Define new trunkTransaction for search
- var trunkTx = transaction.TrunkTransaction;
-
- // Add transaction object to bundle
- bundle.Transactions.Add(transaction);
-
- // Continue traversing with new trunkTx
- return TraverseBundle(trunkTx, bundleHash, bundle);
- }
-
- private double GetCurrentTimestampInSeconds()
- {
- DateTime now = DateTime.UtcNow;
- DateTime epoch = new DateTime
- (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-
- return (now - epoch).TotalSeconds;
- }
- }
-
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Model/AccountData.cs b/IotaApi.Standard/Model/AccountData.cs
deleted file mode 100644
index 2099d85..0000000
--- a/IotaApi.Standard/Model/AccountData.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Model
-{
- ///
- ///
- ///
- public class AccountData
- {
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public AccountData(List addresses,
- Bundle[] transferBundle, List inputList, long totalBalance)
- {
- Addresses = addresses;
- TransferBundle = transferBundle;
- InputList = inputList;
- TotalBalance = totalBalance;
- }
-
- ///
- ///
- ///
- public List Addresses { get; set; }
-
- ///
- ///
- ///
- public Bundle[] TransferBundle { get; set; }
-
- ///
- ///
- ///
- public List InputList { get; set; }
-
- ///
- ///
- ///
- public long TotalBalance { get; set; }
- }
-}
diff --git a/IotaApi.Standard/Model/Bundle.cs b/IotaApi.Standard/Model/Bundle.cs
deleted file mode 100644
index fcb15bf..0000000
--- a/IotaApi.Standard/Model/Bundle.cs
+++ /dev/null
@@ -1,223 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Iota.Api.Standard.Pow;
-using Iota.Api.Standard.Utils;
-
-namespace Iota.Api.Standard.Model
-{
- ///
- /// This class represents a Bundle, a set of transactions
- ///
- public class Bundle : IComparable
- {
- ///
- /// Initializes a new instance of the class without transactions.
- ///
- public Bundle() : this(new List(), 0)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The transactions.
- /// The length.
- public Bundle(List transactions, int length)
- {
- Transactions = transactions;
- Length = length;
- }
-
- ///
- /// Gets the at the specified index.
- ///
- ///
- /// The .
- ///
- /// The index.
- ///
- public Transaction this[int index] => Transactions[index];
-
- ///
- /// Gets or sets the transactions.
- ///
- ///
- /// The transactions.
- ///
- public List Transactions { get; set; }
-
- ///
- /// Gets or sets the length of the bundle
- ///
- ///
- /// The length.
- ///
- public int Length { get; set; }
-
- ///
- /// Compares the current object with another object of the same type.
- ///
- /// An object to compare with this object.
- ///
- /// A value that indicates the relative order of the objects being compared. The return value has the following
- /// meanings: Value Meaning Less than zero This object is less than the parameter.Zero This
- /// object is equal to . Greater than zero This object is greater than
- /// .
- ///
- public int CompareTo(Bundle other)
- {
- var timeStamp1 = Transactions[0].Timestamp;
- var timeStamp2 = other.Transactions[0].Timestamp;
-
- if (timeStamp1 < timeStamp2)
- return -1;
- if (timeStamp1 > timeStamp2)
- return 1;
- return 0;
- }
-
- ///
- /// Adds a bundle entry
- ///
- /// Length of the signature message.
- /// The address.
- /// The value.
- /// The tag.
- /// The timestamp.
- public void AddEntry(int signatureMessageLength, string address, long value, string tag, long timestamp)
- {
- for (var i = 0; i < signatureMessageLength; i++)
- {
- var trx = new Transaction(address, i == 0 ? value : 0, tag, timestamp);
- Transactions.Add(trx);
- }
- }
-
- ///
- /// Adds the trytes.
- ///
- /// The signature fragments.
- public void AddTrytes(List signatureFragments)
- {
- var emptySignatureFragment = "";
- var emptyHash = Constants.EmptyHash;
- long emptyTimestamp = 999999999L;
-
- while (emptySignatureFragment.Length < 2187) emptySignatureFragment += '9';
-
- for (var i = 0; i < Transactions.Count; i++)
- {
- var transaction = Transactions[i];
-
- // Fill empty signatureMessageFragment
- transaction.SignatureMessageFragment = signatureFragments.Count <= i ||
- string.IsNullOrEmpty(signatureFragments[i])
- ? emptySignatureFragment
- : signatureFragments[i];
- // Fill empty trunkTransaction
- transaction.TrunkTransaction = emptyHash;
-
- // Fill empty branchTransaction
- transaction.BranchTransaction = emptyHash;
-
- transaction.AttachmentTimestamp = emptyTimestamp;
- transaction.AttachmentTimestampLowerBound = emptyTimestamp;
- transaction.AttachmentTimestampUpperBound = emptyTimestamp;
- // Fill empty nonce
- transaction.Nonce = "999999999999999999999999999";
- }
- }
-
-
- ///
- /// Normalizeds the bundle.
- ///
- /// The bundle hash.
- ///
- public int[] NormalizedBundle(string bundleHash)
- {
- var normalizedBundle = new int[81];
-
- for (var i = 0; i < 3; i++)
- {
- long sum = 0;
- for (var j = 0; j < 27; j++)
- sum +=
- normalizedBundle[i * 27 + j] =
- Converter.ToValue(Converter.ToTrits("" + bundleHash[i * 27 + j]));
-
- if (sum >= 0)
- {
- while (sum-- > 0)
- for (var j = 0; j < 27; j++)
- if (normalizedBundle[i * 27 + j] > -13)
- {
- normalizedBundle[i * 27 + j]--;
- break;
- }
- }
- else
- {
- while (sum++ < 0)
- for (var j = 0; j < 27; j++)
- if (normalizedBundle[i * 27 + j] < 13)
- {
- normalizedBundle[i * 27 + j]++;
- break;
- }
- }
- }
-
- return normalizedBundle;
- }
-
-
- ///
- /// Finalizes the bundle using the specified curl implementation
- ///
- /// The custom curl.
- public void FinalizeBundle(ICurl customCurl)
- {
- customCurl.Reset();
-
- for (var i = 0; i < Transactions.Count; i++)
- {
- var valueTrits = Converter.ToTrits(Transactions[i].Value, 81);
-
- var timestampTrits = Converter.ToTrits(Transactions[i].Timestamp, 27);
-
- var currentIndexTrits = Converter.ToTrits(Transactions[i].CurrentIndex = i, 27);
-
- var lastIndexTrits = Converter.ToTrits(
- Transactions[i].LastIndex = Transactions.Count - 1, 27);
-
- var stringToConvert = Transactions[i].Address
- + Converter.ToTrytes(valueTrits)
- + Transactions[i].Tag +
- Converter.ToTrytes(timestampTrits)
- + Converter.ToTrytes(currentIndexTrits) +
- Converter.ToTrytes(lastIndexTrits);
-
- var t = Converter.ToTrits(stringToConvert);
- customCurl.Absorb(t, 0, t.Length);
- }
-
- var hash = new int[243];
- customCurl.Squeeze(hash, 0, hash.Length);
- var hashInTrytes = Converter.ToTrytes(hash);
-
- foreach (var transaction in Transactions) transaction.Bundle = hashInTrytes;
- }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Transactions)}: {string.Join(",", Transactions)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Model/Inputs.cs b/IotaApi.Standard/Model/Inputs.cs
deleted file mode 100644
index 4e318d8..0000000
--- a/IotaApi.Standard/Model/Inputs.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Iota.Api.Standard.Model
-{
- ///
- /// This class represents the Inputs
- ///
- public class Inputs
- {
- ///
- /// Gets or sets the inputs list.
- ///
- ///
- /// The inputs list.
- ///
- public List InputsList { get; set; }
-
- ///
- /// Gets or sets the total balance.
- ///
- ///
- /// The total balance.
- ///
- public long TotalBalance { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return
- $"Inputs:\n {string.Join(",", InputsList.Select(i => "[" + i + "]" + "\n"))}{nameof(TotalBalance)}: {TotalBalance}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Model/Signature.cs b/IotaApi.Standard/Model/Signature.cs
deleted file mode 100644
index 3dc248e..0000000
--- a/IotaApi.Standard/Model/Signature.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Model
-{
- ///
- /// Thic class represents a signature
- ///
- public class Signature
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public Signature()
- {
- SignatureFragments = new List();
- }
-
- ///
- /// Gets or sets the address.
- ///
- ///
- /// The address.
- ///
- public string Address { get; set; }
-
- ///
- /// Gets or sets the signature fragments.
- ///
- ///
- /// The signature fragments.
- ///
- public List SignatureFragments { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Address)}: {Address}, {nameof(SignatureFragments)}: {string.Join(",", SignatureFragments)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Model/Transfer.cs b/IotaApi.Standard/Model/Transfer.cs
deleted file mode 100644
index 9f3839b..0000000
--- a/IotaApi.Standard/Model/Transfer.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-namespace Iota.Api.Standard.Model
-{
- ///
- /// This class represents a Transfer
- ///
- public class Transfer
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The address.
- /// The value.
- /// The message.
- /// The tag.
- public Transfer(string address, long value, string message, string tag)
- {
- Address = address;
- Value = value;
- Message = message;
- Tag = tag;
- }
-
- ///
- /// Gets or sets the address.
- ///
- ///
- /// The address.
- ///
- public string Address { get; set; }
-
- ///
- /// Gets or sets the hash.
- ///
- ///
- /// The hash.
- ///
- public string Hash { get; set; }
-
- ///
- /// Gets or sets the persistence.
- ///
- ///
- /// The persistence.
- ///
- public int Persistence { get; set; }
-
- ///
- /// Gets or sets the timestamp.
- ///
- ///
- /// The timestamp.
- ///
- public string Timestamp { get; set; }
-
- ///
- /// Gets or sets the value.
- ///
- ///
- /// The value.
- ///
- public long Value { get; set; }
-
- ///
- /// Gets or sets the message.
- ///
- ///
- /// The message.
- ///
- public string Message { get; set; }
-
- ///
- /// Gets or sets the tag.
- ///
- ///
- /// The tag.
- ///
- public string Tag { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Address)}: {Address}, {nameof(Hash)}: {Hash}, {nameof(Message)}: {Message}, {nameof(Persistence)}: {Persistence}, {nameof(Tag)}: {Tag}, {nameof(Timestamp)}: {Timestamp}, {nameof(Value)}: {Value}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Pow/Curl.cs b/IotaApi.Standard/Pow/Curl.cs
deleted file mode 100644
index 43b506c..0000000
--- a/IotaApi.Standard/Pow/Curl.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-using System;
-using System.ComponentModel;
-using Iota.Api.Standard.Utils;
-
-namespace Iota.Api.Standard.Pow
-{
- ///
- /// (c) 2016 Come-from-Beyond
- /// Curl belongs to the sponge function family.
- ///
- public class Curl : Sponge
- {
- private const int StateLength = 3 * HashLength;
-
- private const int NumberOfRoundsP81 = 81;
- private const int NumberOfRoundsP27 = 27;
-
- private static readonly int[] TruthTable = {1, 0, -1, 2, 1, -1, 0, 2, -1, 1, 0};
- private readonly int _numberOfRounds;
- private readonly int[] _scratchpad = new int[StateLength];
- private readonly long[] _stateHigh;
- private readonly long[] _stateLow;
-
- ///
- ///
- ///
- ///
- ///
- public Curl(bool pair, CurlMode mode)
- {
- switch (mode)
- {
- case CurlMode.CurlP27:
- _numberOfRounds = NumberOfRoundsP27;
- break;
- case CurlMode.CurlP81:
- _numberOfRounds = NumberOfRoundsP81;
- break;
- default:
- throw new InvalidEnumArgumentException("Only Curl-P-27 and Curl-P-81 are supported.");
- }
-
- if (pair)
- {
- _stateHigh = new long[StateLength];
- _stateLow = new long[StateLength];
- State = null;
- Set();
- }
- else
- {
- State = new int[StateLength];
- _stateHigh = null;
- _stateLow = null;
- }
- }
-
- ///
- ///
- ///
- ///
- public Curl(CurlMode mode)
- {
- switch (mode)
- {
- case CurlMode.CurlP27:
- _numberOfRounds = NumberOfRoundsP27;
- break;
- case CurlMode.CurlP81:
- _numberOfRounds = NumberOfRoundsP81;
- break;
- default:
- throw new InvalidEnumArgumentException("Only Curl-P-27 and Curl-P-81 are supported.");
- }
-
- State = new int[StateLength];
- _stateHigh = null;
- _stateLow = null;
- }
-
- ///
- /// Gets or sets the state.
- ///
- ///
- /// The state.
- ///
- public int[] State { get; set; }
-
- ///
- /// Absorbs the specified trits.
- ///
- /// The trits.
- /// The offset to start from.
- /// The length.
- /// the ICurl instance (used for method chaining)
- public override void Absorb(int[] trits, int offset, int length)
- {
- do
- {
- Array.Copy(trits, offset, State, 0, length < HashLength ? length : HashLength);
- Transform();
- offset += HashLength;
- } while ((length -= HashLength) > 0);
- }
-
- private void Transform()
- {
- var scratchpadIndex = 0;
-
- for (var round = 0; round < _numberOfRounds; round++)
- {
- Array.Copy(State, 0, _scratchpad, 0, StateLength);
- for (var stateIndex = 0; stateIndex < StateLength; stateIndex++)
- {
- var prevScratchpadIndex = scratchpadIndex;
- if (scratchpadIndex < 365)
- scratchpadIndex += 364;
- else
- scratchpadIndex += -365;
-
- State[stateIndex] =
- TruthTable[
- _scratchpad[prevScratchpadIndex]
- + (_scratchpad[scratchpadIndex] << 2)
- + 5];
- }
- }
- }
-
- ///
- /// Resets this state.
- ///
- ///
- /// the ICurl instance (used for method chaining)
- ///
- public override void Reset()
- {
- for (var stateIndex = 0; stateIndex < StateLength; stateIndex++) State[stateIndex] = 0;
- }
-
- ///
- ///
- ///
- ///
- public void Reset(bool pair)
- {
- if (pair)
- Set();
- else
- Reset();
- }
-
- ///
- /// Squeezes the specified trits.
- ///
- /// The trits.
- /// The offset to start from.
- /// The length.
- ///
- /// the squeezed trits
- ///
- public override void Squeeze(int[] trits, int offset, int length)
- {
- do
- {
- Array.Copy(State, 0, trits, offset, length < HashLength ? length : HashLength);
- Transform();
- offset += HashLength;
- } while ((length -= HashLength) > 0);
- }
-
- ///
- /// Clones this instance.
- ///
- /// a new instance
- public override ICurl Clone()
- {
- return new Curl(CurlMode.CurlP81);
- }
-
- ///
- ///
- ///
- ///
- ///
- public void Absorb(Tuple pair, int offset, int length)
- {
- int o = offset, l = length;
- do
- {
- Array.Copy(pair.Item1, o, _stateLow, 0, l < HashLength ? l : HashLength);
- Array.Copy(pair.Item2, o, _stateHigh, 0, l < HashLength ? l : HashLength);
-
- PairTransform();
- o += HashLength;
- } while ((l -= HashLength) > 0);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- public Tuple Squeeze(Tuple pair, int offset, int length)
- {
- int o = offset, l = length;
- var low = pair.Item1;
- var hi = pair.Item2;
- do
- {
- Array.Copy(_stateLow, 0, low, o, l < HashLength ? l : HashLength);
- Array.Copy(_stateHigh, 0, hi, o, l < HashLength ? l : HashLength);
-
- PairTransform();
- o += HashLength;
- } while ((l -= HashLength) > 0);
-
- return new Tuple(low, hi);
- }
-
- #region Private
-
- private void Set()
- {
- for (var i = 0; i < _stateLow.Length; i++) _stateLow[i] = (long) Converter.HIGH_LONG_BITS;
-
- for (var i = 0; i < _stateHigh.Length; i++) _stateHigh[i] = (long) Converter.HIGH_LONG_BITS;
- }
-
- private void PairTransform()
- {
- var curlScratchpadLow = new long[StateLength];
- var curlScratchpadHigh = new long[StateLength];
- var curlScratchpadIndex = 0;
- for (var round = _numberOfRounds; round-- > 0;)
- {
- Array.Copy(_stateLow, 0, curlScratchpadLow, 0, StateLength);
- Array.Copy(_stateHigh, 0, curlScratchpadHigh, 0, StateLength);
- for (var curlStateIndex = 0; curlStateIndex < StateLength; curlStateIndex++)
- {
- var alpha = curlScratchpadLow[curlScratchpadIndex];
- var beta = curlScratchpadHigh[curlScratchpadIndex];
- var gamma = curlScratchpadHigh[curlScratchpadIndex += curlScratchpadIndex < 365 ? 364 : -365];
- var delta = (alpha | ~gamma) & (curlScratchpadLow[curlScratchpadIndex] ^ beta);
- _stateLow[curlStateIndex] = ~delta;
- _stateHigh[curlStateIndex] = (alpha ^ gamma) | delta;
- }
- }
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Pow/CurlMode.cs b/IotaApi.Standard/Pow/CurlMode.cs
deleted file mode 100644
index dfe7448..0000000
--- a/IotaApi.Standard/Pow/CurlMode.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace Iota.Api.Standard.Pow
-{
- ///
- ///
- ///
- public enum CurlMode
- {
- ///
- ///
- ///
- CurlP81,
- ///
- ///
- ///
- CurlP27,
- ///
- ///
- ///
- Kerl
- }
-}
diff --git a/IotaApi.Standard/Pow/ICurl.cs b/IotaApi.Standard/Pow/ICurl.cs
deleted file mode 100644
index 9232b20..0000000
--- a/IotaApi.Standard/Pow/ICurl.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-namespace Iota.Api.Standard.Pow
-{
- ///
- /// This interface abstracts the curl hashing algorithm
- ///
- public interface ICurl
- {
- ///
- /// Absorbs the specified trits.
- ///
- /// The trits.
- /// The offset to start from.
- /// The length.
- /// the ICurl instance (used for method chaining)
- void Absorb(int[] trits, int offset, int length);
-
- ///
- /// Absorbs the specified trits.
- ///
- /// The trits.
- /// the ICurl instance (used for method chaining)
- void Absorb(int[] trits);
-
- ///
- /// Squeezes the specified trits.
- ///
- /// The trits.
- /// The offset to start from.
- /// The length.
- /// the squeezed trits
- void Squeeze(int[] trits, int offset, int length);
-
- ///
- /// Squeezes the specified trits.
- ///
- /// The trits.
- /// the squeezed trits
- void Squeeze(int[] trits);
-
-
- ///
- /// Resets this state.
- ///
- /// the ICurl instance (used for method chaining)
- void Reset();
-
- ///
- ///
- ///
- ///
- ICurl Clone();
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Pow/PearlDiver.cs b/IotaApi.Standard/Pow/PearlDiver.cs
deleted file mode 100644
index 7ed9d7a..0000000
--- a/IotaApi.Standard/Pow/PearlDiver.cs
+++ /dev/null
@@ -1,244 +0,0 @@
-using System;
-using System.Threading.Tasks;
-
-namespace Iota.Api.Standard.Pow
-{
- ///
- /// (c) 2016 Come-from-Beyond
- /// See https://github.com/iotaledger/iri/blob/dev/src/main/java/com/iota/iri/hash/PearlDiver.java
- ///
- public class PearlDiver
- {
- private const int TransactionLength = 8019;
- private const int NumberOfRoundsp81 = 81;
-
- private const int CurlHashLength = 243;
- private const int CurlStateLength = CurlHashLength * 3;
-
- private const long HighBits = -1;
- private const long LowBits = 0;
- private static readonly object SyncObj = new object();
-
- private State _state;
-
- ///
- ///
- ///
- ///
- ///
- ///
- // ReSharper disable once RedundantAssignment
- public bool Search(int[] transactionTrits, int minWeightMagnitude, int numberOfThreads)
- {
- if (transactionTrits.Length != TransactionLength)
- throw new ArgumentException($"Invalid transaction trits length: {transactionTrits.Length}");
-
- if (minWeightMagnitude < 0 || minWeightMagnitude > CurlHashLength)
- throw new ArgumentException($"Invalid min weight magnitude: {minWeightMagnitude}");
-
- lock (SyncObj)
- {
- _state = State.Running;
- }
-
- var midCurlStateLow = new long[CurlStateLength];
- var midCurlStateHigh = new long[CurlStateLength];
-
- // step1
- {
- for (var i = CurlHashLength; i < CurlStateLength; i++)
- {
- midCurlStateLow[i] = HighBits;
- midCurlStateHigh[i] = HighBits;
- }
-
- var offset = 0;
- var curlScratchpadLowStep1 = new long[CurlStateLength];
- var curlScratchpadHighStep1 = new long[CurlStateLength];
-
- for (var i = (TransactionLength - CurlHashLength) / CurlHashLength; i-- > 0;)
- {
- for (var j = 0; j < CurlHashLength; j++)
- switch (transactionTrits[offset++])
- {
- case 0:
- midCurlStateLow[j] = HighBits;
- midCurlStateHigh[j] = HighBits;
- break;
- case 1:
- midCurlStateLow[j] = LowBits;
- midCurlStateHigh[j] = HighBits;
- break;
- default:
- midCurlStateLow[j] = HighBits;
- midCurlStateHigh[j] = LowBits;
- break;
- }
-
- Transform(midCurlStateLow, midCurlStateHigh,
- curlScratchpadLowStep1, curlScratchpadHighStep1);
- }
-
- for (var i = 0; i < 162; i++)
- switch (transactionTrits[offset++])
- {
- case 0:
- midCurlStateLow[i] = HighBits;
- midCurlStateHigh[i] = HighBits;
- break;
- case 1:
- midCurlStateLow[i] = LowBits;
- midCurlStateHigh[i] = HighBits;
- break;
- default:
- midCurlStateLow[i] = HighBits;
- midCurlStateHigh[i] = LowBits;
- break;
- }
-
- unchecked
- {
- midCurlStateLow[162 + 0] =
- (long) 0b1101101101101101101101101101101101101101101101101101101101101101L;
- midCurlStateHigh[162 + 0] =
- (long) 0b1011011011011011011011011011011011011011011011011011011011011011L;
- midCurlStateLow[162 + 1] =
- (long) 0b1111000111111000111111000111111000111111000111111000111111000111L;
- midCurlStateHigh[162 + 1] =
- (long) 0b1000111111000111111000111111000111111000111111000111111000111111L;
- midCurlStateLow[162 + 2] =
- 0b0111111111111111111000000000111111111111111111000000000111111111L;
- midCurlStateHigh[162 + 2] =
- (long) 0b1111111111000000000111111111111111111000000000111111111111111111L;
- midCurlStateLow[162 + 3] =
- (long) 0b1111111111000000000000000000000000000111111111111111111111111111L;
- midCurlStateHigh[162 + 3] =
- 0b0000000000111111111111111111111111111111111111111111111111111111L;
- }
- }
-
- // step2
- if (numberOfThreads <= 0) numberOfThreads = Math.Max(Environment.ProcessorCount - 1, 1);
-
- Parallel.For(0, numberOfThreads, threadIndex =>
- {
- var midCurlStateCopyLow = new long[CurlStateLength];
- var midCurlStateCopyHigh = new long[CurlStateLength];
- Array.Copy(midCurlStateLow, 0, midCurlStateCopyLow, 0, CurlStateLength);
- Array.Copy(midCurlStateHigh, 0, midCurlStateCopyHigh, 0, CurlStateLength);
- for (var i = threadIndex; i > 0; i--)
- Increment(midCurlStateCopyLow, midCurlStateCopyHigh, 162 + CurlHashLength / 9,
- 162 + CurlHashLength / 9 * 2);
-
- var curlStateLow = new long[CurlStateLength];
- var curlStateHigh = new long[CurlStateLength];
- var curlScratchpadLowStep2 = new long[CurlStateLength];
- var curlScratchpadHighStep2 = new long[CurlStateLength];
- long outMask = 1;
-
- while (_state == State.Running)
- {
- Increment(midCurlStateCopyLow, midCurlStateCopyHigh, 162 + CurlHashLength / 9 * 2,
- CurlHashLength);
-
- Array.Copy(midCurlStateCopyLow, 0, curlStateLow, 0, CurlStateLength);
- Array.Copy(midCurlStateCopyHigh, 0, curlStateHigh, 0, CurlStateLength);
-
- Transform(curlStateLow, curlStateHigh, curlScratchpadLowStep2, curlScratchpadHighStep2);
-
- var mask = HighBits;
- for (var i = minWeightMagnitude; i-- > 0;)
- {
- mask &= ~(curlStateLow[CurlHashLength - 1 - i] ^ curlStateHigh[CurlHashLength - 1 - i]);
- if (mask == 0) break;
- }
-
- if (mask == 0) continue;
-
- //sync
- lock (SyncObj)
- {
- if (_state == State.Running)
- {
- _state = State.Completed;
- while ((outMask & mask) == 0) outMask <<= 1;
-
- for (var i = 0; i < CurlHashLength; i++)
- transactionTrits[TransactionLength - CurlHashLength + i] =
- (midCurlStateCopyLow[i] & outMask) == 0 ? 1
- : (midCurlStateCopyHigh[i] & outMask) == 0 ? -1 : 0;
- }
- }
-
- break;
- }
- });
-
- return _state == State.Completed;
- }
-
- ///
- ///
- public void Cancel()
- {
- lock (SyncObj)
- {
- _state = State.Cancelled;
- }
- }
-
- private static void Transform(long[] curlStateLow, long[] curlStateHigh,
- long[] curlScratchpadLow, long[] curlScratchpadHigh)
- {
- var curlScratchpadIndex = 0;
- for (var round = 0; round < NumberOfRoundsp81; round++)
- {
- Array.Copy(curlStateLow, 0, curlScratchpadLow, 0, CurlStateLength);
- Array.Copy(curlStateHigh, 0, curlScratchpadHigh, 0, CurlStateLength);
-
- for (var curlStateIndex = 0; curlStateIndex < CurlStateLength; curlStateIndex++)
- {
- var alpha = curlScratchpadLow[curlScratchpadIndex];
- var beta = curlScratchpadHigh[curlScratchpadIndex];
- if (curlScratchpadIndex < 365)
- curlScratchpadIndex += 364;
- else
- curlScratchpadIndex -= 365;
-
- var gamma = curlScratchpadHigh[curlScratchpadIndex];
- var delta = (alpha | (~gamma)) & (curlScratchpadLow[curlScratchpadIndex] ^ beta);
-
- curlStateLow[curlStateIndex] = ~delta;
- curlStateHigh[curlStateIndex] = (alpha ^ gamma) | delta;
- }
- }
- }
-
- private static void Increment(long[] midCurlStateCopyLow,
- long[] midCurlStateCopyHigh, int fromIndex, int toIndex)
- {
- for (var i = fromIndex; i < toIndex; i++)
- if (midCurlStateCopyLow[i] == LowBits)
- {
- midCurlStateCopyLow[i] = HighBits;
- midCurlStateCopyHigh[i] = LowBits;
- }
- else
- {
- if (midCurlStateCopyHigh[i] == LowBits)
- midCurlStateCopyHigh[i] = HighBits;
- else
- midCurlStateCopyLow[i] = LowBits;
-
- break;
- }
- }
-
- private enum State
- {
- Running,
- Cancelled,
- Completed
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Pow/PearlDiverLocalPoW.cs b/IotaApi.Standard/Pow/PearlDiverLocalPoW.cs
deleted file mode 100644
index 2d892a9..0000000
--- a/IotaApi.Standard/Pow/PearlDiverLocalPoW.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using Iota.Api.Standard.Core;
-using Iota.Api.Standard.Exception;
-using Iota.Api.Standard.Utils;
-
-namespace Iota.Api.Standard.Pow
-{
- ///
- ///
- public class PearlDiverLocalPoW : ILocalPoW
- {
- private readonly PearlDiver _pearlDiver = new PearlDiver();
-
- ///
- ///
- ///
- ///
- ///
- ///
- public string PerformPoW(string trytes, int minWeightMagnitude)
- {
- var trits = Converter.ToTrits(trytes);
-
- if (!_pearlDiver.Search(trits, minWeightMagnitude, 0))
- throw new IllegalStateException("PearlDiver search failed");
-
- return Converter.ToTrytes(trits);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/ArrayUtils.cs b/IotaApi.Standard/Utils/ArrayUtils.cs
deleted file mode 100644
index 49f95b9..0000000
--- a/IotaApi.Standard/Utils/ArrayUtils.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Iota.Api.Standard.Utils
-{
- internal class ArrayUtils
- {
- public static IEnumerable SliceRow(T[,] array, int row)
- {
- for (var i = array.GetLowerBound(1); i <= array.GetUpperBound(1); i++)
- {
- yield return array[row, i];
- }
- }
-
- public static T[] SubArray(T[] data, int startIndex, int endIndex)
- {
- int length = endIndex - startIndex;
- T[] result = new T[endIndex - startIndex];
- Array.Copy(data, startIndex, result, 0, length);
- return result;
- }
-
- public static T[] SubArray2(T[] data, int index, int length)
- {
- T[] result = new T[length];
- Array.Copy(data, index, result, 0, length);
- return result;
- }
- }
-}
diff --git a/IotaApi.Standard/Utils/BigIntConverter.cs b/IotaApi.Standard/Utils/BigIntConverter.cs
deleted file mode 100644
index 4fdd2d0..0000000
--- a/IotaApi.Standard/Utils/BigIntConverter.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-using System;
-using Org.BouncyCastle.Math;
-
-namespace Iota.Api.Standard.Utils
-{
- ///
- ///
- ///
- public class BigIntConverter
- {
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static BigInteger BigIntFromTrits(int[] trits, int offset, int size)
- {
- var value = BigInteger.Zero;
-
- for (var i = size; i-- > 0;)
- value = value.Multiply(BigInteger.ValueOf(Converter.Radix)).Add(BigInteger.ValueOf(trits[offset + i]));
-
- return value;
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static BigInteger BigIntFromBytes(byte[] bytes, int offset, int size)
- {
- return new BigInteger(bytes, offset, size);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static void TritsFromBigInt(BigInteger value, int[] destination, int offset, int size)
- {
- if (destination.Length - offset < size) throw new ArgumentException("Destination array has invalid size");
-
- var absoluteValue = value.CompareTo(BigInteger.Zero) < 0 ? value.Negate() : value;
- for (var i = 0; i < size; i++)
- {
- var divRemainder = absoluteValue.DivideAndRemainder(BigInteger.ValueOf(Converter.Radix));
- var remainder = divRemainder[1].IntValue;
- absoluteValue = divRemainder[0];
-
- if (remainder > Converter.MaxTritValue)
- {
- remainder = Converter.MinTritValue;
- absoluteValue = absoluteValue.Add(BigInteger.One);
- }
-
- destination[offset + i] = remainder;
- }
-
- if (value.CompareTo(BigInteger.Zero) < 0)
- for (var i = 0; i < size; i++)
- destination[offset + i] = -destination[offset + i];
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static void BytesFromBigInt(BigInteger value, byte[] destination, int offset,int size)
- {
- if (destination.Length - offset < size)
- throw new ArgumentException("Destination array has invalid size.");
-
- var bytes = value.ToByteArray();
- var i = 0;
- while (i + bytes.Length < size) destination[i++] = (byte) ((sbyte) bytes[0] < 0 ? -1 : 0);
-
- for (var j = bytes.Length; j-- > 0;) destination[i++] = bytes[bytes.Length - 1 - j];
- }
- }
-}
diff --git a/IotaApi.Standard/Utils/Checksum.cs b/IotaApi.Standard/Utils/Checksum.cs
deleted file mode 100644
index 1ac1cea..0000000
--- a/IotaApi.Standard/Utils/Checksum.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-using Iota.Api.Standard.Exception;
-using Iota.Api.Standard.Pow;
-
-namespace Iota.Api.Standard.Utils
-{
- ///
- /// This class defines utility methods to add/remove the checksum to/from an address
- ///
- public static class Checksum
- {
- ///
- /// Adds the checksum to the specified address
- ///
- /// An address without checksum
- /// The address with the appended checksum
- /// is thrown when an invalid address is provided
- public static string AddChecksum(string address)
- {
- InputValidator.CheckAddress(address);
- var addressWithChecksum = address;
- addressWithChecksum += CalculateChecksum(address);
- return addressWithChecksum;
- }
-
-
- ///
- /// Removes the checksum from the specified address with checksum
- ///
- /// The address with checksum or without checksum.
- /// the specified address without checksum
- /// is thrown when the specified address is not an address with checksum
- public static string RemoveChecksum(this string address)
- {
- if (IsAddressWithChecksum(address)) return GetAddress(address);
-
- if (IsAddressWithoutChecksum(address)) return address;
-
- throw new InvalidAddressException(address);
- }
-
-
- internal static string GetAddress(string addressWithChecksum)
- {
- return addressWithChecksum.Substring(0, Constants.AddressLengthWithoutChecksum);
- }
-
- ///
- /// Determines whether the specified address with checksum has a valid checksum.
- ///
- /// The address with checksum.
- ///
- /// true if the specified address with checksum has a valid checksum [the specified address with checksum];
- /// otherwise, false.
- ///
- public static bool IsValidChecksum(this string addressWithChecksum)
- {
- var addressWithoutChecksum = RemoveChecksum(addressWithChecksum);
- var adressWithRecalculateChecksum = addressWithoutChecksum + CalculateChecksum(addressWithoutChecksum);
- return adressWithRecalculateChecksum.Equals(addressWithChecksum);
- }
-
-
- private static bool IsAddressWithChecksum(string addressWithChecksum)
- {
- return InputValidator.IsAddress(addressWithChecksum) &&
- addressWithChecksum.Length == Constants.AddressLengthWithChecksum;
- }
-
- private static bool IsAddressWithoutChecksum(string address)
- {
- return InputValidator.CheckAddress(address) && address.Length == Constants.AddressLengthWithoutChecksum;
- }
-
- private static string CalculateChecksum(string address)
- {
- // TODO inject curl
- ICurl curl = new Kerl();
- curl.Reset();
- curl.Absorb(Converter.ToTrits(address));
- var checksumTrits = new int[Sponge.HashLength];
- curl.Squeeze(checksumTrits);
- var checksum = Converter.ToTrytes(checksumTrits);
- return checksum.Substring(72, 9);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/Constants.cs b/IotaApi.Standard/Utils/Constants.cs
deleted file mode 100644
index 76abcb0..0000000
--- a/IotaApi.Standard/Utils/Constants.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-namespace Iota.Api.Standard.Utils
-{
- ///
- /// This class defines different constants that are used accros the library
- ///
- public static class Constants
- {
- ///
- /// This String contains all possible characters of the tryte alphabet
- ///
- public static readonly string TryteAlphabet = "9ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
- ///
- /// The maximum seed length
- ///
- public static readonly int SeedLengthMax = 81;
-
- ///
- /// This String represents the empty hash consisting of '9'
- ///
- public static readonly string EmptyHash =
- "999999999999999999999999999999999999999999999999999999999999999999999999999999999";
-
- ///
- /// The length of an address without checksum
- ///
- public static readonly int AddressLengthWithoutChecksum = 81;
-
- ///
- /// The address length with checksum
- ///
- public static readonly int AddressLengthWithChecksum = 90;
-
- ///
- /// The length of an message
- ///
- public static int MessageLength = 2187;
- ///
- ///
- ///
- public static int TagLength = 27;
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/Converter.cs b/IotaApi.Standard/Utils/Converter.cs
deleted file mode 100644
index 711dc66..0000000
--- a/IotaApi.Standard/Utils/Converter.cs
+++ /dev/null
@@ -1,378 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Iota.Api.Standard.Utils
-{
- ///
- /// This class provides a set of utility methods to are used to convert between different formats
- ///
- public class Converter
- {
- // ReSharper disable InconsistentNaming
- ///
- ///
- ///
- public static readonly uint HIGH_INTEGER_BITS = 0xFFFFFFFF;
-
- ///
- ///
- ///
- public static readonly ulong HIGH_LONG_BITS = 0xFFFFFFFFFFFFFFFFL;
- // ReSharper restore InconsistentNaming
-
- ///
- /// The radix
- ///
- public static readonly int Radix = 3;
-
- ///
- /// The maximum trit value
- ///
- public static readonly int MaxTritValue = (Radix - 1) / 2;
-
- ///
- /// The minimum trit value
- ///
- public static readonly int MinTritValue = -MaxTritValue;
-
- ///
- /// The number of trits in a byte
- ///
- public static readonly int NumberOfTritsInAByte = 5;
-
- ///
- /// The number of trits in a tryte
- ///
- public static readonly int NumberOfTritsInATryte = 3;
-
- static readonly int[][] ByteToTritsMappings = new int[243][]; //why 243? max 121
- static readonly int[][] TryteToTritsMappings = new int[27][];
-
- static Converter()
- {
- int[] trits = new int[NumberOfTritsInAByte];
-
- for (int i = 0; i < 243; i++)
- {
- ByteToTritsMappings[i] = new int[NumberOfTritsInAByte];
- ByteToTritsMappings[i] = new int[NumberOfTritsInAByte];
- Array.Copy(trits, ByteToTritsMappings[i], NumberOfTritsInAByte);
- Increment(trits, NumberOfTritsInAByte);
- }
-
- for (int i = 0; i < 27; i++)
- {
- TryteToTritsMappings[i] = new int[NumberOfTritsInATryte];
- Array.Copy(trits, TryteToTritsMappings[i], NumberOfTritsInATryte);
- Increment(trits, NumberOfTritsInATryte);
- }
- }
-
- ///
- /// Converts the specified trits array to bytes
- ///
- /// The trits.
- /// The offset to start from.
- /// The size.
- ///
- public static byte[] ToBytes(int[] trits, int offset, int size)
- {
- byte[] bytes = new byte[(size + NumberOfTritsInAByte - 1) / NumberOfTritsInAByte];
- for (int i = 0; i < bytes.Length; i++)
- {
- int value = 0;
- for (
- int j = (size - i * NumberOfTritsInAByte) < 5
- ? (size - i * NumberOfTritsInAByte)
- : NumberOfTritsInAByte;
- j-- > 0;)
- {
- value = value * Radix + trits[offset + i * NumberOfTritsInAByte + j];
- }
-
- bytes[i] = (byte) value;
- }
-
- return bytes;
- }
-
- ///
- /// Converts the specified trits to trytes
- ///
- /// The trits.
- ///
- public static byte[] ToBytes(int[] trits)
- {
- return ToBytes(trits, 0, trits.Length);
- }
-
- ///
- /// Gets the trits from the specified bytes and stores it into the provided trits array
- ///
- /// The bytes.
- /// The trits.
- public static void GetTrits(sbyte[] bytes, int[] trits)
- {
- int offset = 0;
- for (int i = 0; i < bytes.Length && offset < trits.Length; i++)
- {
- Array.Copy(
- ByteToTritsMappings[bytes[i] < 0 ? (bytes[i] + ByteToTritsMappings.Length) : bytes[i]], 0,
- trits, offset,
- trits.Length - offset < NumberOfTritsInAByte
- ? (trits.Length - offset)
- : NumberOfTritsInAByte);
-
- offset += NumberOfTritsInAByte;
- }
-
- while (offset < trits.Length)
- {
- trits[offset++] = 0;
- }
- }
-
- ///
- /// Converts the specified trinary encoded string into a trits array of the specified length.
- /// If the trytes string results in a shorter then specified trits array, then the remainder is padded we zeroes
- ///
- /// The trytes.
- /// The length.
- /// a trits array
- public static int[] ToTrits(string trytes, int length)
- {
- int[] tritss = ToTrits(trytes);
-
- List tritsList = new List();
-
- foreach (int i in tritss)
- tritsList.Add(i);
-
- while (tritsList.Count < length)
- tritsList.Add(0);
-
- return tritsList.ToArray();
- }
-
-
- ///
- /// Converts the specified trinary encoded trytes string to trits
- ///
- /// The trytes.
- ///
- public static int[] ToTrits(string trytes)
- {
- int[] d = new int[3 * trytes.Length];
- for (int i = 0; i < trytes.Length; i++)
- {
- Array.Copy(TryteToTritsMappings[Constants.TryteAlphabet.IndexOf(trytes[i])], 0, d,
- i * NumberOfTritsInATryte, NumberOfTritsInATryte);
- }
-
- return d;
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- public static int[] ToTrits(long trytes, int length)
- {
- int[] tritss = ToTrits(trytes);
-
- List tritsList = new List(tritss);
-
- while (tritsList.Count < length)
- tritsList.Add(0);
-
- return tritsList.ToArray();
- }
-
- ///
- ///
- ///
- ///
- ///
- public static int[] ToTrits(long trytes)
- {
- if (trytes == 0)
- return new[] {0};
-
- var tritsList = new List();
-
- while (trytes != 0)
- {
- var remainder = (int) (trytes % Radix);
- trytes /= Radix;
-
- if (remainder > MaxTritValue)
- {
- remainder = MinTritValue;
- trytes += 1;
- }
- else if (remainder < MinTritValue)
- {
- remainder = MaxTritValue;
- trytes -= 1;
- }
-
- tritsList.Add(remainder);
- }
-
- return tritsList.ToArray();
- }
-
- ///
- /// Copies the trits from the input string into the destination array
- ///
- /// The input string
- /// The destination array.
- ///
- public static int[] CopyTrits(string input, int[] destination)
- {
- for (int i = 0; i < input.Length; i++)
- {
- int index = Constants.TryteAlphabet.IndexOf(input[i]);
- destination[i * 3] = TryteToTritsMappings[index][0];
- destination[i * 3 + 1] = TryteToTritsMappings[index][1];
- destination[i * 3 + 2] = TryteToTritsMappings[index][2];
- }
-
- return destination;
- }
-
- ///
- /// Copies the trits in long representation into the destination array
- ///
- /// The value.
- /// The destination array.
- /// The offset from which copying is started.
- /// The size.
- public static void CopyTrits(long value, int[] destination, int offset, int size)
- {
- long absoluteValue = value < 0 ? -value : value;
- for (int i = 0; i < size; i++)
- {
- int remainder = (int) (absoluteValue % Radix);
- absoluteValue /= Radix;
- if (remainder > MaxTritValue)
- {
- remainder = MinTritValue;
- absoluteValue++;
- }
-
- destination[offset + i] = remainder;
- }
-
- if (value < 0)
- {
- for (int i = 0; i < size; i++)
- {
- destination[offset + i] = -destination[offset + i];
- }
- }
- }
-
- ///
- /// Converts the trits array to a trytes string
- ///
- /// The trits.
- /// The offset from which copying is started.
- /// The size.
- /// a trytes string
- public static string ToTrytes(int[] trits, int offset, int size)
- {
- StringBuilder trytes = new StringBuilder();
- for (int i = 0; i < (size + NumberOfTritsInATryte - 1) / NumberOfTritsInATryte; i++)
- {
- int j = trits[offset + i * 3] + trits[offset + i * 3 + 1] * 3 + trits[offset + i * 3 + 2] * 9;
- if (j < 0)
- {
- j += Constants.TryteAlphabet.Length;
- }
-
- trytes.Append(Constants.TryteAlphabet[j]);
- }
-
- return trytes.ToString();
- }
-
- ///
- /// Converts the trits array to a trytes string
- ///
- /// The trits.
- /// a trytes string
- public static string ToTrytes(int[] trits)
- {
- return ToTrytes(trits, 0, trits.Length);
- }
-
- ///
- /// Converts the specified trits array to trytes in integer representation
- ///
- /// The trits.
- /// The offset.
- /// trytes in integer representation
- public static int ToTryteValue(int[] trits, int offset)
- {
- return trits[offset] + trits[offset + 1] * 3 + trits[offset + 2] * 9;
- }
-
- ///
- /// Converts the specified trits to its corresponding integer value
- ///
- /// The trits.
- /// an integer value representing the corresponding trits
- public static int ToValue(int[] trits)
- {
- int value = 0;
-
- for (int i = trits.Length; i-- > 0;)
- {
- value = value * 3 + trits[i];
- }
-
- return value;
- }
-
- ///
- /// Converts the specified trits to its corresponding integer value
- ///
- /// The trits.
- ///
- public static long ToLongValue(int[] trits)
- {
- long value = 0;
-
- for (int i = trits.Length; i-- > 0;)
- {
- value = value * 3 + trits[i];
- }
-
- return value;
- }
-
- ///
- /// Increments the specified trits.
- ///
- /// The trits.
- /// The size.
- public static void Increment(int[] trits, int size)
- {
- for (int i = 0; i < size; i++)
- {
- if (++trits[i] > MaxTritValue)
- {
- trits[i] = MinTritValue;
- }
- else
- {
- break;
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/FixedBigIntConverter.cs b/IotaApi.Standard/Utils/FixedBigIntConverter.cs
deleted file mode 100644
index 4c24a43..0000000
--- a/IotaApi.Standard/Utils/FixedBigIntConverter.cs
+++ /dev/null
@@ -1,312 +0,0 @@
-using System;
-using Iesi.Collections.Generic;
-using Iota.Api.Standard.Exception;
-
-namespace Iota.Api.Standard.Utils
-{
- ///
- ///
- ///
- public class FixedBigIntConverter
- {
- //243:3 384:2
- private const int TritsLength = 243;
-
- private const int BitLength = 384;
- private const int ByteLength = BitLength / 8;
- private const int IntLength = ByteLength / 4;
-
- /// hex representation of (3^242-1)/2
- private static readonly int[] Half3 =
- {
- unchecked((int) 0xa5ce8964), unchecked ((int) 0x9f007669),
- 0x1484504f, 0x3ade00d9,
- 0x0c24486e, 0x50979d57,
- 0x79a4c702, 0x48bbae36,
- unchecked ((int) 0xa9f6808b), unchecked ((int) 0xaa06a805),
- unchecked ((int) 0xa87fabdf), 0x5e69ebef
- };
-
- ///
- ///
- ///
- ///
- ///
- public static void FromTritsToBytes(int[] trits, byte[] bytes)
- {
- if (trits.Length != TritsLength)
- throw new ArgumentException("trits array has invalid size");
-
- if (bytes.Length != ByteLength)
- throw new ArgumentException("bytes array has invalid size");
-
- var baseHalf3 = new int[IntLength];
-
- var setUniqueNumbers = new LinkedHashSet();
- foreach (var x in trits) setUniqueNumbers.Add(x);
-
- if (setUniqueNumbers.Count == 1 && setUniqueNumbers.Contains(-1))
- {
- baseHalf3 = (int[]) Half3.Clone();
- BigIntNot(baseHalf3);
- BigIntAdd(baseHalf3, 1);
- }
- else
- {
- var size = IntLength;
- for (var i = TritsLength - 1; i-- > 0;)
- {
- {
- // Multiply by radix
- var sz = size;
- var carry = 0;
-
- for (var j = 0; j < sz; j++)
- {
- // full_mul
- var v = ToUnsignedLong(baseHalf3[j]) * 3 +
- ToUnsignedLong(carry);
- carry = (int) ((v >> (sizeof(int) * 8)) & 0xFFFFFFFF);
- baseHalf3[j] = (int) (v & 0xFFFFFFFF);
- }
-
- if (carry > 0)
- {
- baseHalf3[sz] = carry;
- size += 1;
- }
- }
-
- var inValue = trits[i] + 1;
- {
- // Add
- var sz = BigIntAdd(baseHalf3, inValue);
- if (sz > size) size = sz;
- }
- }
-
- if (Sum(baseHalf3) != 0)
- if (BigIntCmp(Half3, baseHalf3) <= 0)
- {
- // base is >= HALF_3.
- // just do base - HALF_3
- baseHalf3 = BigIntSub(baseHalf3, Half3);
- }
- else
- {
- // we don't have a wrapping sub.
- // so we need to be clever.
- baseHalf3 = BigIntSub(Half3, baseHalf3);
- BigIntNot(baseHalf3);
- BigIntAdd(baseHalf3, 1);
- }
- }
-
-
- // output
- for (var i = 0; i < IntLength; i++)
- {
- bytes[i * 4 + 0] = (byte) ((baseHalf3[IntLength - 1 - i] & 0xFF000000) >> 24);
- bytes[i * 4 + 1] = (byte) ((baseHalf3[IntLength - 1 - i] & 0x00FF0000) >> 16);
- bytes[i * 4 + 2] = (byte) ((baseHalf3[IntLength - 1 - i] & 0x0000FF00) >> 8);
- bytes[i * 4 + 3] = (byte) ((baseHalf3[IntLength - 1 - i] & 0x000000FF) >> 0);
- }
- }
-
- ///
- ///
- ///
- ///
- ///
- public static void FromBytesToTrits(byte[] bytes, int[] trits)
- {
- if (bytes.Length != ByteLength)
- throw new ArgumentException("bytes array has invalid size");
-
- if (trits.Length != TritsLength)
- throw new ArgumentException("trits array has invalid size");
-
- var bigIntValue = new int[IntLength];
-
- for (var i = 0; i < IntLength; i++)
- {
- bigIntValue[IntLength - 1 - i] = ToUnsignedInt(bytes[i * 4]) << 24;
- bigIntValue[IntLength - 1 - i] |= ToUnsignedInt(bytes[i * 4 + 1]) << 16;
- bigIntValue[IntLength - 1 - i] |= ToUnsignedInt(bytes[i * 4 + 2]) << 8;
- bigIntValue[IntLength - 1 - i] |= ToUnsignedInt(bytes[i * 4 + 3]);
- }
-
- if (BigIntCmp(bigIntValue, Half3) == 0)
- {
- var val = 0;
- if (bigIntValue[0] > 0)
- val = -1;
- else if (bigIntValue[0] < 0) val = 1;
-
- for (var i = 0; i < TritsLength - 1; i++) trits[i] = val;
- }
- else
- {
- var flipTrits = false;
- // See if we have a positive or negative two's complement number.
- if (ToUnsignedLong(bigIntValue[IntLength - 1]) >> 31 != 0)
- {
- // negative value.
- BigIntNot(bigIntValue);
- if (BigIntCmp(bigIntValue, Half3) > 0)
- {
- bigIntValue = BigIntSub(bigIntValue, Half3);
- flipTrits = true;
- }
- else
- {
- BigIntAdd(bigIntValue, 1);
- bigIntValue = BigIntSub(Half3, bigIntValue);
- }
- }
- else
- {
- // positive. we need to shift right by HALF_3
- bigIntValue = BigIntAdd(Half3, bigIntValue);
- }
-
- var size = IntLength;
-
- for (var i = 0; i < TritsLength - 1; i++)
- {
- int remainder;
- {
- //div_rem
- remainder = 0;
-
- for (var j = size - 1; j >= 0; j--)
- {
- var lhs = (ToUnsignedLong(remainder) << 32) | ToUnsignedLong(bigIntValue[j]);
- var rhs = 3;
-
- var q = (int) (lhs / rhs);
- var r = (int) (lhs % rhs);
- bigIntValue[j] = q;
- remainder = r;
- }
- }
- trits[i] = remainder - 1;
- }
-
- if (flipTrits)
- for (var i = 0; i < TritsLength; i++)
- trits[i] = -trits[i];
- }
- }
-
-
- #region Private Method
-
- private static int ToUnsignedInt(byte x)
- {
- return x & 0xff;
- }
-
- private static long ToUnsignedLong(int i)
- {
- return i & 0xFFFFFFFFL;
- }
-
- private static int Sum(int[] toSum)
- {
- var sum = 0;
- foreach (var t in toSum) sum += t;
-
- return sum;
- }
-
- private static void BigIntNot(int[] baseValue)
- {
- for (var i = 0; i < baseValue.Length; i++) baseValue[i] = ~baseValue[i];
- }
-
- private static int BigIntAdd(int[] baseValue, int rh)
- {
- var res = FullAdd(baseValue[0], rh, false);
- baseValue[0] = res.Item1;
-
- var j = 1;
- while (res.Item2)
- {
- res = FullAdd(baseValue[j], 0, true);
- baseValue[j] = res.Item1;
- j += 1;
- }
-
- return j;
- }
-
- private static int[] BigIntAdd(int[] lh, int[] rh)
- {
- var outValue = new int[IntLength];
- var carry = false;
- for (var i = 0; i < IntLength; i++)
- {
- var ret = FullAdd(lh[i], rh[i], carry);
- outValue[i] = ret.Item1;
- carry = ret.Item2;
- }
-
- if (carry) throw new IllegalStateException("Exceeded max value.");
-
- return outValue;
- }
-
- private static int BigIntCmp(int[] lh, int[] rh)
- {
- for (var i = IntLength - 1; i >= 0; i--)
- {
- var a = ToUnsignedLong(lh[i]);
- var b = ToUnsignedLong(rh[i]);
-
- var ret = a.CompareTo(b);
- if (ret != 0) return ret;
- }
-
- return 0;
- }
-
- private static int[] BigIntSub(int[] lh, int[] rh)
- {
- var outValue = new int[IntLength];
- var noborrow = true;
-
- for (var i = 0; i < IntLength; i++)
- {
- var ret = FullAdd(lh[i], ~rh[i], noborrow);
- outValue[i] = ret.Item1;
- noborrow = ret.Item2;
- }
-
- if (!noborrow) throw new IllegalStateException("noborrow");
-
- return outValue;
- }
-
- private static Tuple FullAdd(int ia, int ib, bool carry)
- {
- var a = ToUnsignedLong(ia);
- var b = ToUnsignedLong(ib);
-
- var v = a + b;
- var l = v >> 32;
- var r = v & 0xFFFFFFFF;
- var carry1 = l != 0;
-
- if (carry) v = r + 1;
-
- l = (v >> 32) & 0xFFFFFFFF;
- r = v & 0xFFFFFFFF;
- var carry2 = l != 0;
-
- return new Tuple((int) r, carry1 || carry2);
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/InputValidator.cs b/IotaApi.Standard/Utils/InputValidator.cs
deleted file mode 100644
index 372f9f8..0000000
--- a/IotaApi.Standard/Utils/InputValidator.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Text.RegularExpressions;
-using Iota.Api.Standard.Exception;
-using Iota.Api.Standard.Model;
-using RestSharp.Extensions;
-
-namespace Iota.Api.Standard.Utils
-{
- ///
- /// This class provides methods to validate the parameters of different iota API methods
- ///
- public static class InputValidator
- {
- ///
- /// Determines whether the specified string is an adrdress.
- ///
- /// The address.
- ///
- /// true if the specified string is an address; otherwise, false.
- ///
- public static bool IsAddress(string address)
- {
- if (address.Length == Constants.AddressLengthWithoutChecksum ||
- address.Length == Constants.AddressLengthWithChecksum)
- {
- return IsTrytes(address, address.Length);
- }
- return false;
- }
-
- ///
- ///
- ///
- ///
- ///
- public static bool IsHash(string hash)
- {
- return IsTrytes(hash, 81);
- }
-
- ///
- /// Checks whether the specified address is an address and throws and exception if the address is invalid
- ///
- /// address to check
- /// exception which is thrown when the address is invalid
- public static bool CheckAddress(string address)
- {
- if (!IsAddress(address))
- throw new InvalidAddressException(address);
-
- return true;
- }
-
- ///
- /// Determines whether the specified string represents an integer value.
- ///
- /// The value.
- ///
- /// true the specified string represents an integer value; otherwise, false.
- ///
- public static bool IsValue(string value)
- {
- // ReSharper disable once NotAccessedVariable
- long tempValue;
- return long.TryParse(value, out tempValue);
- //return Regex.IsMatch(value, @"^(-){0,1}\d+$");
- }
-
- ///
- /// Determines whether the specified array contains only valid hashes
- ///
- /// The hashes.
- ///
- /// true the specified array contains only valid hashes; otherwise, false.
- ///
- public static bool IsArrayOfHashes(string[] hashes)
- {
- if (hashes == null)
- return false;
-
- foreach (string hash in hashes)
- {
- // Check if address with checksum
- if (hash.Length == 90)
- {
- if (!IsTrytes(hash, 90))
- {
- return false;
- }
- }
- else
- {
- if (!IsTrytes(hash, 81))
- {
- return false;
- }
- }
- }
- return true;
- }
-
- ///
- /// Determines whether the specified string contains only characters from the trytes alphabet (see )
- ///
- /// The trytes.
- /// The length.
- ///
- /// true if the specified trytes are trytes otherwise, false.
- ///
- public static bool IsTrytes(string trytes, int length)
- {
- string regex = "^[9A-Z]{" + (length == 0 ? "0," : length.ToString()) + "}$";
- var regexTrytes = new Regex(regex);
- return regexTrytes.IsMatch(trytes);
- }
-
- ///
- /// Determines whether the specified string array contains only trytes
- ///
- /// The trytes.
- /// The length.
- ///
- /// true if the specified array contains only valid trytes otherwise, false.
- ///
- public static bool IsArrayOfTrytes(string[] trytes, int length )
- {
- return trytes.ToList().TrueForAll(element => IsTrytes(element, length));
- }
-
- ///
- /// Determines whether the specified transfers are valid
- ///
- /// The transfers.
- ///
- /// true if the specified transfers are valid; otherwise, false.
- ///
- public static bool IsTransfersCollectionValid(ICollection transfers)
- {
- foreach (Transfer transfer in transfers)
- {
- if (!IsValidTransfer(transfer))
- {
- return false;
- }
- }
- return true;
- }
-
- ///
- /// Determines whether the specified transfer is valid.
- ///
- /// The transfer.
- ///
- /// true if the specified transfer is valid; otherwise, false.
- ///
- public static bool IsValidTransfer(Transfer transfer)
- {
- if (!IsAddress(transfer.Address))
- {
- return false;
- }
-
- // Check if message is correct trytes of any length
- if (!IsTrytes(transfer.Message, 0))
- {
- return false;
- }
-
- // Check if tag is correct trytes of {0,27} trytes
- return IsTrytes(transfer.Tag, 27);
- }
-
- ///
- /// Checks the specified specified transfers are valid. If not, an exception is thrown.
- ///
- /// The transactions array.
- /// Not a transfer array
- public static void CheckTransferArray(Transfer[] transactionsArray)
- {
- if (!IsTransfersCollectionValid(transactionsArray.ToList()))
- throw new System.Exception("Not a transfer array");
- }
-
- ///
- /// Checks if the seed is valid. If not, an exception is thrown.
- ///
- /// The seed.
- ///
- /// Invalid Seed: Format not in trytes
- /// or
- /// Invalid Seed: Seed too long
- ///
- public static void CheckIfValidSeed(string seed)
- {
- // validate the seed
- if (!IsTrytes(seed, 0))
- {
- throw new IllegalStateException("Invalid Seed: Format not in trytes");
- }
-
- // validate & if needed pad seed
- if (seed.Length > 81)
- {
- throw new IllegalStateException("Invalid Seed: Seed too long");
- }
- }
-
- ///
- /// Pads the seed if necessary.
- ///
- /// The seed.
- ///
- public static string PadSeedIfNecessary(string seed)
- {
- while (seed.Length < Constants.AddressLengthWithoutChecksum) seed += 9;
- return seed;
- }
-
- ///
- /// Checks if the specified array is an array of trytes. If not an exception is thrown.
- ///
- /// The trytes.
- ///
- public static void CheckIfArrayOfTrytes(string[] trytes)
- {
- if(!IsArrayOfTrytes(trytes, 2673))
- throw new InvalidTryteException();
- }
-
- ///
- /// Determines whether the specified string consist only of '9'.
- ///
- /// The trytes.
- /// The length.
- ///
- /// true if the specified string consist only of '9'; otherwise, false.
- ///
- public static bool IsNinesTrytes(string trytes, int length)
- {
- return trytes.Matches("^[9]{" + (length == 0 ? "0," : length.ToString()) + "}$");
- }
-
- ///
- ///
- ///
- ///
- ///
- public static bool IsValidSeed(string seed)
- {
- return IsTrytes(seed, seed.Length);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/IotaApiUtils.cs b/IotaApi.Standard/Utils/IotaApiUtils.cs
deleted file mode 100644
index 15906ea..0000000
--- a/IotaApi.Standard/Utils/IotaApiUtils.cs
+++ /dev/null
@@ -1,132 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Iota.Api.Standard.Model;
-using Iota.Api.Standard.Pow;
-
-namespace Iota.Api.Standard.Utils
-{
- ///
- ///
- ///
- public class IotaApiUtils
- {
- ///
- /// Generates a new address
- ///
- /// The tryte-encoded seed. It should be noted that this seed is not transferred.
- /// The secuirty level of private key / seed.
- /// The index to start search from. If the index is provided, the generation of the address is not deterministic.
- /// The adds 9-tryte address checksum
- /// The curl instance.
- /// An String with address.
- public static string NewAddress(string seed, int security, int index, bool checksum, ICurl curl)
- {
- if (security < 1)
- throw new ArgumentException("invalid security level provided");
-
- Signing signing = new Signing(curl);
- int[] key = signing.Key(Converter.ToTrits(seed), index, security);
- int[] digests = signing.Digests(key);
- int[] addressTrits = signing.Address(digests);
-
- string address = Converter.ToTrytes(addressTrits);
-
- if (checksum)
- address = Checksum.AddChecksum(address);
-
- return address;
- }
-
- internal static List SignInputsAndReturn(string seed,
- List inputs,
- Bundle bundle,
- List signatureFragments, ICurl curl)
- {
- bundle.FinalizeBundle(curl);
- bundle.AddTrytes(signatureFragments);
-
- // SIGNING OF INPUTS
- //
- // Here we do the actual signing of the inputs
- // Iterate over all bundle transactions, find the inputs
- // Get the corresponding private key and calculate the signatureFragment
- for (int i = 0; i < bundle.Transactions.Count; i++)
- {
- if (bundle.Transactions[i].Value < 0)
- {
- string thisAddress = bundle.Transactions[i].Address;
-
- // Get the corresponding keyIndex of the address
- int keyIndex = 0;
- foreach (Input input in inputs)
- {
- if (input.Address.Equals(thisAddress))
- {
- keyIndex = input.KeyIndex;
- break;
- }
- }
-
- string bundleHash = bundle.Transactions[i].Bundle;
-
- // Get corresponding private key of address
- int[] key = new Signing(curl).Key(Converter.ToTrits(seed), keyIndex, 2);
-
- // First 6561 trits for the firstFragment
- int[] firstFragment = ArrayUtils.SubArray2(key, 0, 6561);
-
- // Get the normalized bundle hash
- int[] normalizedBundleHash = bundle.NormalizedBundle(bundleHash);
-
- // First bundle fragment uses 27 trytes
- int[] firstBundleFragment = ArrayUtils.SubArray2(normalizedBundleHash, 0, 27);
-
- // Calculate the new signatureFragment with the first bundle fragment
- int[] firstSignedFragment = new Signing(curl).SignatureFragment(firstBundleFragment, firstFragment);
-
- // Convert signature to trytes and assign the new signatureFragment
- bundle.Transactions[i].SignatureMessageFragment = Converter.ToTrytes(firstSignedFragment);
-
- // Because the signature is > 2187 trytes, we need to
- // find the second transaction to add the remainder of the signature
- for (int j = 0; j < bundle.Transactions.Count; j++)
- {
- // Same address as well as value = 0 (as we already spent the input)
- if (bundle.Transactions[j].Address.Equals(thisAddress) &&
- bundle.Transactions[j].Value == 0)
- {
- // Use the second 6562 trits
- int[] secondFragment = ArrayUtils.SubArray2(key, 6561, 6561);
-
- // The second 27 to 54 trytes of the bundle hash
- int[] secondBundleFragment = ArrayUtils.SubArray2(normalizedBundleHash, 27, 27);
-
- // Calculate the new signature
- int[] secondSignedFragment = new Signing(curl).SignatureFragment(secondBundleFragment,
- secondFragment);
-
- // Convert signature to trytes and assign it again to this bundle entry
- bundle.Transactions[j].SignatureMessageFragment = (Converter.ToTrytes(secondSignedFragment));
- }
- }
- }
- }
-
- List bundleTrytes = new List();
-
- // Convert all bundle entries into trytes
- foreach (Transaction tx in bundle.Transactions)
- {
- bundleTrytes.Add(tx.ToTransactionTrytes());
- }
-
- bundleTrytes.Reverse();
- return bundleTrytes;
- }
-
- internal static long CreateTimeStampNow()
- {
- return (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/IotaUnitConverter.cs b/IotaApi.Standard/Utils/IotaUnitConverter.cs
deleted file mode 100644
index 893699a..0000000
--- a/IotaApi.Standard/Utils/IotaUnitConverter.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-
-namespace Iota.Api.Standard.Utils
-{
- ///
- /// This class provides methods to convert Iota to different units
- ///
- public class IotaUnitConverter
- {
- ///
- /// Convert the iota amount
- ///
- /// amount
- /// the source unit e.g. the unit of amount
- /// the target unit
- /// the specified amount in the target unit
- public static double ConvertUnits(long amount, IotaUnits fromUnit, IotaUnits toUnit)
- {
- long amountInSource = (long) (amount*Math.Pow(10, (int) fromUnit));
- return ConvertUnits(amountInSource, toUnit);
- }
-
- private static double ConvertUnits(long amount, IotaUnits toUnit)
- {
- int base10NormalizationExponent = (int) toUnit;
- return (amount/Math.Pow(10, base10NormalizationExponent));
- }
-
- ///
- /// Finds the optimal unit to display the specified amount in
- ///
- /// amount
- /// the optimal IotaUnit
- public static IotaUnits FindOptimalIotaUnitToDisplay(long amount)
- {
- int length = (amount).ToString().Length;
-
- if (amount < 0)
- {
- // do not count "-" sign
- length -= 1;
- }
-
- IotaUnits units = IotaUnits.Iota;
-
- if (length >= 1 && length <= 3)
- {
- units = IotaUnits.Iota;
- }
- else if (length > 3 && length <= 6)
- {
- units = IotaUnits.Kilo;
- }
- else if (length > 6 && length <= 9)
- {
- units = IotaUnits.Mega;
- }
- else if (length > 9 && length <= 12)
- {
- units = IotaUnits.Giga;
- }
- else if (length > 12 && length <= 15)
- {
- units = IotaUnits.Terra;
- }
- else if (length > 15 && length <= 18)
- {
- units = IotaUnits.Peta;
- }
- return units;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/IotaUnits.cs b/IotaApi.Standard/Utils/IotaUnits.cs
deleted file mode 100644
index f3787ed..0000000
--- a/IotaApi.Standard/Utils/IotaUnits.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-namespace Iota.Api.Standard.Utils
-{
- ///
- /// Iota Units
- ///
- public enum IotaUnits
- {
- ///
- /// The corresponding value is in iota. Same as 'None' ()
- ///
- Iota = 0,
-
- ///
- /// The corresponding value is in iota. Same as 'Iota' ()
- ///
- None = 0,
-
- ///
- /// 10^3
- ///
- Kilo = 3,
-
- ///
- /// 10^6
- ///
- Mega = 6,
-
- ///
- /// 10^9
- ///
- Giga = 9,
-
- ///
- /// 10^12
- ///
- Terra = 12,
-
- ///
- /// 10^15
- ///
- Peta = 15,
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/Multisig.cs b/IotaApi.Standard/Utils/Multisig.cs
deleted file mode 100644
index 8dcccbd..0000000
--- a/IotaApi.Standard/Utils/Multisig.cs
+++ /dev/null
@@ -1,191 +0,0 @@
-using System;
-using Iota.Api.Standard.Model;
-using Iota.Api.Standard.Pow;
-
-namespace Iota.Api.Standard.Utils
-{
- ///
- ///
- public class Multisig
- {
- private readonly ICurl _curl;
- private readonly Signing _signing;
-
- ///
- ///
- ///
- public Multisig(ICurl curl)
- {
- _curl = curl;
- _curl.Reset();
- _signing = new Signing();
- }
-
- ///
- ///
- public Multisig() : this(new Kerl())
- {
- }
-
- ///
- ///
- /// Tryte-encoded seed. It should be noted that this seed is not transferred.
- /// Secuirty level of private key / seed.
- ///
- /// Key index to start search from. If the index is provided, the generation of the address is not
- /// deterministic.
- ///
- /// trytes
- public string GetDigest(string seed, int security, int index)
- {
- var key = _signing.Key(Converter.ToTrits(seed, 243), index, security);
- return Converter.ToTrytes(_signing.Digests(key));
- }
-
- ///
- /// Gets the key value of a seed
- ///
- /// Tryte-encoded seed. It should be noted that this seed is not transferred
- ///
- /// Key index to start search from. If the index is provided, the generation of the address is not
- /// deterministic.
- ///
- /// Secuirty level of private key / seed.
- /// trytes
- public string GetKey(string seed, int index, int security)
- {
- return Converter.ToTrytes(
- _signing.Key(Converter.ToTrits(seed, 81 * security),
- index, security));
- }
-
- ///
- ///
- /// digest trytes
- public void AddAddressDigest(string[] digests)
- {
- foreach (var digest in digests)
- {
- // Get trits of digest
- var digestTrits = Converter.ToTrits(digest);
-
- // Absorb digest
- _curl.Absorb(digestTrits, 0, digestTrits.Length);
- }
- }
-
- ///
- /// Generates a new address
- ///
- /// address
- public string FinalizeAddress()
- {
- var addressTrits = new int[243];
- _curl.Squeeze(addressTrits);
-
- // Convert trits into trytes and return the address
- return Converter.ToTrytes(addressTrits);
- }
-
- ///
- ///
- ///
- ///
- ///
- public bool ValidateAddress(string multisigAddress, int[][] digests)
- {
- // initialize Curl with the provided state
- _curl.Reset();
-
- foreach (var digest in digests) _curl.Absorb(digest);
-
- var addressTrits = new int[243];
- _curl.Squeeze(addressTrits);
-
- // Convert trits into trytes and return the address
- return Converter.ToTrytes(addressTrits).Equals(multisigAddress);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- public Bundle AddSignature(Bundle bundleToSign, string inputAddress, string keyTrytes)
- {
- // Get the security used for the private key
- // 1 security level = 2187 trytes
- var security = keyTrytes.Length / Constants.MessageLength;
-
- // convert private key trytes into trits
- var key = Converter.ToTrits(keyTrytes);
-
-
- // First get the total number of already signed transactions
- // use that for the bundle hash calculation as well as knowing
- // where to add the signature
- var numSignedTxs = 0;
-
-
- for (var i = 0; i < bundleToSign.Transactions.Count; i++)
- if (bundleToSign.Transactions[i].Address.Equals(inputAddress))
- if (!InputValidator.IsNinesTrytes(bundleToSign.Transactions[i].SignatureMessageFragment,
- bundleToSign.Transactions[i].SignatureMessageFragment.Length))
- {
- numSignedTxs++;
- }
- // Else sign the transactions
- else
- {
- var bundleHash = bundleToSign.Transactions[i].Bundle;
-
- // First 6561 trits for the firstFragment
- var firstFragment = new int[6561];
- Array.Copy(key, firstFragment, 6561);
-
- // Get the normalized bundle hash
- var normalizedBundleFragments = new int[3][];
- for (var n = 0; n < 3; n++) normalizedBundleFragments[n] = new int[27];
-
- var normalizedBundleHash = bundleToSign.NormalizedBundle(bundleHash);
-
-
- // Split hash into 3 fragments
- for (var k = 0; k < 3; k++)
- Array.Copy(normalizedBundleHash, k * 27, normalizedBundleFragments[k], 0, 27);
-
-
- // First bundle fragment uses 27 trytes
- var firstBundleFragment = normalizedBundleFragments[numSignedTxs % 3];
-
- // Calculate the new signatureFragment with the first bundle fragment
- var firstSignedFragment = _signing.SignatureFragment(firstBundleFragment, firstFragment);
-
- // Convert signature to trytes and assign the new signatureFragment
- bundleToSign.Transactions[i].SignatureMessageFragment = Converter.ToTrytes(firstSignedFragment);
-
- for (var j = 1; j < security; j++)
- {
- // Next 6561 trits for the firstFragment
- var nextFragment = new int[6561];
- Array.Copy(key, 6561 * j, nextFragment, 0, 6561);
-
- // Use the next 27 trytes
- var nextBundleFragment = normalizedBundleFragments[(numSignedTxs + j) % 3];
-
- // Calculate the new signatureFragment with the first bundle fragment
- var nextSignedFragment = _signing.SignatureFragment(nextBundleFragment, nextFragment);
-
- // Convert signature to trytes and add new bundle entry at i + j position
- // Assign the signature fragment
- bundleToSign.Transactions[i + j].SignatureMessageFragment = Converter.ToTrytes(nextSignedFragment);
- }
-
- break;
- }
-
- return bundleToSign;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/Rest/JsonSerializer.cs b/IotaApi.Standard/Utils/Rest/JsonSerializer.cs
deleted file mode 100644
index 6fdf5c9..0000000
--- a/IotaApi.Standard/Utils/Rest/JsonSerializer.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-#region License
-
-// Copyright 2010 John Sheehan
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#endregion
-
-#region Acknowledgements
-
-// Original JsonSerializer contributed by Daniel Crenna (@dimebrain)
-
-#endregion
-
-using System;
-using System.IO;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Serialization;
-using RestSharp.Serializers;
-
-namespace Iota.Api.Standard.Utils.Rest
-{
- ///
- /// Default JSON serializer for request bodies
- /// Doesn't currently use the SerializeAs attribute, defers to Newtonsoft's attributes
- ///
- internal class JsonSerializer : ISerializer
- {
- private readonly Newtonsoft.Json.JsonSerializer _serializer;
-
- ///
- /// Default serializer
- ///
- public JsonSerializer()
- {
- ContentType = "application/json";
- _serializer = new Newtonsoft.Json.JsonSerializer
- {
- MissingMemberHandling = MissingMemberHandling.Ignore,
- NullValueHandling = NullValueHandling.Include,
- DefaultValueHandling = DefaultValueHandling.Include
- };
- }
-
- ///
- /// Default serializer with overload for allowing custom Json.NET settings
- ///
- public JsonSerializer(Newtonsoft.Json.JsonSerializer serializer)
- {
- ContentType = "application/json";
- _serializer = serializer;
- }
-
- ///
- /// Serialize the object as JSON
- ///
- /// Object to serialize
- /// JSON as String
- public string Serialize(object obj)
- {
- using (var stringWriter = new StringWriter())
- {
- using (var jsonTextWriter = new JsonTextWriter(stringWriter))
- {
- //jsonTextWriter.Formatting = Formatting.Indented;
- //jsonTextWriter.QuoteChar = '"';
- _serializer.ContractResolver = new LowercaseContractResolver();
-
- _serializer.Serialize(jsonTextWriter, obj);
-
- var result = stringWriter.ToString();
- return result;
- }
- }
- }
-
- public class LowercaseContractResolver : DefaultContractResolver
- {
- protected override string ResolvePropertyName(string name)
- {
- // first letter small to match API naming conventions
- return Char.ToLowerInvariant(name[0]) + name.Substring(1);
- }
- }
-
- ///
- /// Unused for JSON Serialization
- ///
- public string DateFormat { get; set; }
-
- ///
- /// Unused for JSON Serialization
- ///
- public string RootElement { get; set; }
-
- ///
- /// Unused for JSON Serialization
- ///
- public string Namespace { get; set; }
-
- ///
- /// Content type for serialized content
- ///
- public string ContentType { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.Standard/Utils/Rest/JsonWebClient.cs b/IotaApi.Standard/Utils/Rest/JsonWebClient.cs
deleted file mode 100644
index bc011a8..0000000
--- a/IotaApi.Standard/Utils/Rest/JsonWebClient.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-using System;
-using System.IO;
-using System.Net;
-using System.Net.Cache;
-using System.Text;
-using Iota.Api.Standard.Core;
-using Iota.Api.Standard.Exception;
-using Newtonsoft.Json;
-
-namespace Iota.Api.Standard.Utils.Rest
-{
- internal class JsonWebClient
- {
- public TResponse GetPOSTResponseSync(Uri uri, string data)
- {
- Console.WriteLine("request: " + data);
-
- HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);
-
- request.ContentType = "application/json";
- request.Accept = "application/json";
- request.Method = "POST";
- request.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
- request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
- request.Headers.Add("X-IOTA-API-Version", "1");
- request.Headers.Add("Origin", "iota.lib.csharp");
- request.Headers.Add("Accept-Language", "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4 ");
- request.KeepAlive = false;
- request.Timeout = 300000;
- request.ReadWriteTimeout = 300000;
-
- UTF8Encoding encoding = new UTF8Encoding();
- byte[] bytes = encoding.GetBytes(data);
-
- request.ContentLength = bytes.Length;
-
- Stream requestStream = request.GetRequestStream();
- {
- // Send the data.
- requestStream.Write(bytes, 0, bytes.Length);
- }
-
- try
- {
- using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
- {
- using (Stream stream = response.GetResponseStream())
- {
- StreamReader reader = new StreamReader(stream, Encoding.UTF8);
- string responseString = reader.ReadToEnd();
-
- if (response.StatusCode == HttpStatusCode.OK)
- {
- Console.WriteLine("response: " + responseString);
- return JsonConvert.DeserializeObject(responseString);
- }
-
- throw new IotaApiException(JsonConvert.DeserializeObject(responseString).Error);
- }
- }
- }
- catch (WebException ex)
- {
- Console.WriteLine("catched: " + ex + ex.Message);
-
- using (var stream = ex.Response.GetResponseStream())
- using (var reader = new StreamReader(stream))
- {
- String errorResponse = reader.ReadToEnd();
- throw new IotaApiException(JsonConvert.DeserializeObject(errorResponse).Error);
- }
- }
- }
-
- public void GetPOSTResponseAsync(Uri uri, string data, Action callback)
- {
- HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);
-
- request.Method = "POST";
- request.ContentType = "application-type/json;charset=utf-8";
-
- UTF8Encoding encoding = new UTF8Encoding();
- byte[] bytes = encoding.GetBytes(data);
-
- request.ContentLength = bytes.Length;
-
- using (Stream requestStream = request.GetRequestStream())
- {
- // Send the data.
- requestStream.Write(bytes, 0, bytes.Length);
- }
-
- request.BeginGetResponse((x) =>
- {
- using (HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(x))
- {
- if (callback != null)
- {
- using (Stream stream = response.GetResponseStream())
- {
- StreamReader reader = new StreamReader(stream, Encoding.UTF8);
- string responseString = reader.ReadToEnd();
- callback(JsonConvert.DeserializeObject(responseString));
- }
- }
- }
- }, request);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaApi.sln b/IotaApi.sln
deleted file mode 100644
index 0bccfcf..0000000
--- a/IotaApi.sln
+++ /dev/null
@@ -1,43 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.27428.2015
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IotaCSharpApi", "IotaCSharpApi\IotaCSharpApi.csproj", "{FC2C2F96-49EA-4046-95BD-3B570BDD1E13}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IotaCSharpApiUnitTests", "IotaCSharpApiUnitTests\IotaCSharpApiUnitTests.csproj", "{FAE71C0D-C373-4401-B9DE-BC3DC1D4E435}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IotaApi.Standard", "IotaApi.Standard\IotaApi.Standard.csproj", "{8E8D67DF-1A0E-45AA-8DE7-CBAD2EF4B900}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IotaApi.Standard.Tests", "IotaApi.Standard.Tests\IotaApi.Standard.Tests.csproj", "{1797EB77-756A-4B7C-94FD-FC86B7EB7930}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {FC2C2F96-49EA-4046-95BD-3B570BDD1E13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {FC2C2F96-49EA-4046-95BD-3B570BDD1E13}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {FC2C2F96-49EA-4046-95BD-3B570BDD1E13}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {FC2C2F96-49EA-4046-95BD-3B570BDD1E13}.Release|Any CPU.Build.0 = Release|Any CPU
- {FAE71C0D-C373-4401-B9DE-BC3DC1D4E435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {FAE71C0D-C373-4401-B9DE-BC3DC1D4E435}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {FAE71C0D-C373-4401-B9DE-BC3DC1D4E435}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {FAE71C0D-C373-4401-B9DE-BC3DC1D4E435}.Release|Any CPU.Build.0 = Release|Any CPU
- {8E8D67DF-1A0E-45AA-8DE7-CBAD2EF4B900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {8E8D67DF-1A0E-45AA-8DE7-CBAD2EF4B900}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {8E8D67DF-1A0E-45AA-8DE7-CBAD2EF4B900}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {8E8D67DF-1A0E-45AA-8DE7-CBAD2EF4B900}.Release|Any CPU.Build.0 = Release|Any CPU
- {1797EB77-756A-4B7C-94FD-FC86B7EB7930}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {1797EB77-756A-4B7C-94FD-FC86B7EB7930}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {1797EB77-756A-4B7C-94FD-FC86B7EB7930}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {1797EB77-756A-4B7C-94FD-FC86B7EB7930}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {953B5A71-F598-4C42-A718-80390ACB8FF8}
- EndGlobalSection
-EndGlobal
diff --git a/IotaApi.sln.DotSettings b/IotaApi.sln.DotSettings
deleted file mode 100644
index 6cfdce0..0000000
--- a/IotaApi.sln.DotSettings
+++ /dev/null
@@ -1,2 +0,0 @@
-
- POST
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/AddNeighborsRequest.cs b/IotaCSharpApi/Api/Core/AddNeighborsRequest.cs
deleted file mode 100644
index 08e51bc..0000000
--- a/IotaCSharpApi/Api/Core/AddNeighborsRequest.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
-
- ///
- /// This class represents the core API request 'AddNeighbors'.
- /// It is used to add a neighbor to the node
- ///
- ///
- public class AddNeighborsRequest : IotaRequest
- {
- ///
- /// Gets or sets the uris.
- ///
- ///
- /// The uris.
- ///
- public List Uris { get; set; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The uris of the neighbors to add.
- public AddNeighborsRequest(List uris) : base(Core.Command.AddNeighbors.GetCommandString())
- {
- Uris = uris;
- }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Uris)}: {string.Join(",", Uris)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/AddNeighborsResponse.cs b/IotaCSharpApi/Api/Core/AddNeighborsResponse.cs
deleted file mode 100644
index 1257e4f..0000000
--- a/IotaCSharpApi/Api/Core/AddNeighborsResponse.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
-
- ///
- /// Response of
- ///
- public class AddNeighborsResponse
- {
- ///
- /// Gets the number of added neighbors.
- ///
- ///
- /// The number of added neighbors.
- ///
- public long AddedNeighbors { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(AddedNeighbors)}: {AddedNeighbors}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/AttachToTangleRequest.cs b/IotaCSharpApi/Api/Core/AttachToTangleRequest.cs
deleted file mode 100644
index d78fa74..0000000
--- a/IotaCSharpApi/Api/Core/AttachToTangleRequest.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
-
- ///
- /// This class represents the core API request 'AttachToTangle'.
- /// It is used to attach trytes to the tangle.
- ///
- public class AttachToTangleRequest : IotaRequest
- {
- private const int MinWeightMagnitudeMin = 18;
- private int _minWeightMagnitude = MinWeightMagnitudeMin;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The trunk transaction.
- /// The branch transaction.
- /// The trytes.
- /// The minimum weight magnitude.
- public AttachToTangleRequest(string trunkTransaction, string branchTransaction, string[] trytes,
- int minWeightMagnitude = 18) : base(Core.Command.AttachToTangle.GetCommandString())
- {
- TrunkTransaction = trunkTransaction;
- BranchTransaction = branchTransaction;
- Trytes = trytes;
- MinWeightMagnitude = minWeightMagnitude;
-
- if (Trytes == null)
- Trytes = new string[0];
- }
-
- ///
- /// Proof of Work intensity. Minimum value is 18
- ///
- public int MinWeightMagnitude
- {
- get { return _minWeightMagnitude; }
- set
- {
- if (value > MinWeightMagnitudeMin)
- _minWeightMagnitude = value;
- }
- }
-
- ///
- /// Trunk transaction to approve.
- ///
- public string TrunkTransaction { get; set; }
-
- ///
- /// Branch transaction to approve.
- ///
- public string BranchTransaction { get; set; }
-
- ///
- /// List of trytes (raw transaction data) to attach to the tangle.
- ///
- public string[] Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(MinWeightMagnitude)}: {MinWeightMagnitude}, {nameof(TrunkTransaction)}: {TrunkTransaction}, {nameof(BranchTransaction)}: {BranchTransaction}, {nameof(Trytes)}: {Trytes}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/AttachToTangleResponse.cs b/IotaCSharpApi/Api/Core/AttachToTangleResponse.cs
deleted file mode 100644
index 6c91c0f..0000000
--- a/IotaCSharpApi/Api/Core/AttachToTangleResponse.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// Response of
- ///
- public class AttachToTangleResponse
- {
- ///
- /// Gets or sets the trytes.
- ///
- ///
- /// The trytes.
- ///
- public List Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Trytes)}: {string.Join(",", Trytes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/BroadcastTransactionsRequest.cs b/IotaCSharpApi/Api/Core/BroadcastTransactionsRequest.cs
deleted file mode 100644
index 0a8b6ec..0000000
--- a/IotaCSharpApi/Api/Core/BroadcastTransactionsRequest.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// Broadcast a list of transactions to all neighbors. The input trytes for this call are provided by attachToTangle
- ///
- public class BroadcastTransactionsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The trytes.
- public BroadcastTransactionsRequest(List trytes)
- : base(Core.Command.BroadcastTransactions.GetCommandString())
- {
- Trytes = trytes;
- }
-
- ///
- /// Gets or sets the trytes representing the transactions
- ///
- ///
- /// The trytes.
- ///
- public List Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Trytes)}: {string.Join(",", Trytes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/BroadcastTransactionsResponse.cs b/IotaCSharpApi/Api/Core/BroadcastTransactionsResponse.cs
deleted file mode 100644
index 36d4b39..0000000
--- a/IotaCSharpApi/Api/Core/BroadcastTransactionsResponse.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// Response of
- ///
- public class BroadcastTransactionsResponse
- {
- // empty
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/Command.cs b/IotaCSharpApi/Api/Core/Command.cs
deleted file mode 100644
index 11df00f..0000000
--- a/IotaCSharpApi/Api/Core/Command.cs
+++ /dev/null
@@ -1,96 +0,0 @@
-using System.ComponentModel;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This enumeration defines the core API call commands
- ///
- public enum Command
- {
- ///
- /// Adds neighbours to the node
- ///
- [Description("addNeighbors")] AddNeighbors,
-
- ///
- /// Attaches to the tangle
- ///
- [Description("attachToTangle")] AttachToTangle,
-
- ///
- /// Broadcasts transactions
- ///
- [Description("broadcastTransactions")] BroadcastTransactions,
-
- ///
- /// Finds the transactions using different search criteria
- ///
- [Description("findTransactions")] FindTransactions,
-
- ///
- /// Gets the balances
- ///
- [Description("getBalances")] GetBalances,
-
- ///
- /// Gets the inclusion state
- ///
- [Description("getInclusionStates")] GetInclusionStates,
-
- ///
- /// Gets the neighbours of the node
- ///
- [Description("getNeighbors")] GetNeighbors,
-
- ///
- /// Get information about the node.
- ///
- [Description("getNodeInfo")] GetNodeInfo,
-
- ///
- /// Gets the tips of the node
- ///
- [Description("getTips")] GetTips,
-
- ///
- /// Gets the transactions to approve
- ///
- [Description("getTransactionsToApprove")] GetTransactionsToApprove,
-
- ///
- /// Gets the trytes
- ///
- [Description("getTrytes")] GetTrytes,
-
- ///
- /// Interrupt attaching to the tangle
- ///
- [Description("interruptAttachingToTangle")] InterruptAttachingToTangle,
-
- ///
- /// Removes neighbours from the node
- ///
- [Description("removeNeighbors")] RemoveNeighbors,
-
- ///
- /// Stores transactions
- ///
- [Description("storeTransactions")] StoreTransactions,
-
- ///
- /// Get Missing Transactions
- ///
- [Description("getMissingTransactions")] GetMissingTransactions,
-
- ///
- /// Check Consistency
- ///
- [Description("checkConsistency")] CheckConsistency,
-
- ///
- /// Were Addresses SpentFrom
- ///
- [Description("wereAddressesSpentFrom")] WereAddressesSpentFrom,
-
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/EnumHelper.cs b/IotaCSharpApi/Api/Core/EnumHelper.cs
deleted file mode 100644
index c6967e7..0000000
--- a/IotaCSharpApi/Api/Core/EnumHelper.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Reflection;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// Helper class that extracts the command string corresponding to the different s
- ///
- public static class EnumHelper
- {
- ///
- /// Retrieve the description on the enum
- ///
- /// The Enumeration
- /// A string representing the friendly name
- public static string GetCommandString(this Enum en)
- {
- Type type = en.GetType();
-
- MemberInfo[] memInfo = type.GetMember(en.ToString());
-
- if (memInfo.Length > 0)
- {
- object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
-
- if (attrs.Length > 0)
- {
- return ((DescriptionAttribute) attrs[0]).Description;
- }
- }
-
- return en.ToString();
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/ErrorResponse.cs b/IotaCSharpApi/Api/Core/ErrorResponse.cs
deleted file mode 100644
index c9382c1..0000000
--- a/IotaCSharpApi/Api/Core/ErrorResponse.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- internal class ErrorResponse
- {
- public string Error { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/FindTransactionsRequest.cs b/IotaCSharpApi/Api/Core/FindTransactionsRequest.cs
deleted file mode 100644
index 8ddbf79..0000000
--- a/IotaCSharpApi/Api/Core/FindTransactionsRequest.cs
+++ /dev/null
@@ -1,103 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core api request 'FindTransactions'
- ///
- public class FindTransactionsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The bundles.
- /// The addresses.
- /// The tags.
- /// The approvees.
- public FindTransactionsRequest(List bundles, List addresses, List tags,
- List approvees) : base(Core.Command.FindTransactions.GetCommandString())
- {
- Bundles = bundles;
- Addresses = addresses;
- Tags = tags;
- Approvees = approvees;
-
- if (Bundles == null)
- Bundles = new List();
- if (Addresses == null)
- Addresses = new List();
- if (Tags == null)
- Tags = new List();
- if (Approvees == null)
- Approvees = new List();
- }
-
- ///
- /// Gets or sets the bundles.
- ///
- ///
- /// The bundles.
- ///
- public List Bundles { get; set; }
-
- ///
- /// Gets or sets the addresses.
- ///
- ///
- /// The addresses.
- ///
- public List Addresses { get; set; }
-
- ///
- /// Gets or sets the tags.
- ///
- ///
- /// The tags.
- ///
- public List Tags { get; set; }
-
- ///
- /// Gets or sets the approvees.
- ///
- ///
- /// The approvees.
- ///
- public List Approvees { get; set; }
-
- ///
- ///
- ///
- ///
- public bool ShouldSerializeBundles()
- {
- return Bundles.Count > 0;
- }
-
- ///
- ///
- ///
- ///
- public bool ShouldSerializeAddresses()
- {
- return Addresses.Count > 0;
- }
-
- ///
- ///
- ///
- ///
- public bool ShouldSerializeTags()
- {
- return Tags.Count > 0;
- }
-
- ///
- ///
- ///
- ///
- public bool ShouldSerializeApprovees()
- {
- return Approvees.Count > 0;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/FindTransactionsResponse.cs b/IotaCSharpApi/Api/Core/FindTransactionsResponse.cs
deleted file mode 100644
index 0216f74..0000000
--- a/IotaCSharpApi/Api/Core/FindTransactionsResponse.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// Response of
- ///
- public class FindTransactionsResponse
- {
- ///
- /// Gets or sets the hashes.
- ///
- ///
- /// The hashes.
- ///
- public List Hashes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Hashes)}: {string.Join(",",Hashes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GenericIotaCoreApi.cs b/IotaCSharpApi/Api/Core/GenericIotaCoreApi.cs
deleted file mode 100644
index 8d0e718..0000000
--- a/IotaCSharpApi/Api/Core/GenericIotaCoreApi.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-using System;
-using Iota.Lib.CSharp.Api.Utils.Rest;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents a generic version of the core API that is used internally
- ///
- ///
- public class GenericIotaCoreApi : IGenericIotaCoreApi
- {
- private readonly string _host;
- private readonly int _port;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The host.
- /// The port.
- public GenericIotaCoreApi(string host, int port)
- {
- _host = host;
- _port = port;
- }
-
- ///
- /// Gets the hostname.
- ///
- ///
- /// The hostname.
- ///
- public string Hostname => _host;
-
- ///
- /// Gets the port.
- ///
- ///
- /// The port.
- ///
- public int Port => _port;
-
- ///
- /// Requests the specified request.
- ///
- /// The type of the request.
- /// The type of the response.
- /// The request.
- ///
- public TResponse Request(TRequest request) where TResponse : new()
- {
- JsonWebClient jsonWebClient = new JsonWebClient();
- return jsonWebClient.GetPOSTResponseSync(new Uri(CreateBaseUrl()),
- new JsonSerializer().Serialize(request));
- }
-
- ///
- /// Requests the specified request asynchronously
- ///
- /// The type of the request.
- /// The type of the response.
- /// The request.
- /// The response action.
- public void RequestAsync(TRequest request, Action responseAction)
- where TResponse : new()
- {
- JsonWebClient jsonWebClient = new JsonWebClient();
- jsonWebClient.GetPOSTResponseAsync(new Uri(CreateBaseUrl()),
- new JsonSerializer().Serialize(request), responseAction);
- }
-
- private string CreateBaseUrl()
- {
- return "http://" + _host + ":" + _port;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetBalancesRequest.cs b/IotaCSharpApi/Api/Core/GetBalancesRequest.cs
deleted file mode 100644
index 3c15f0b..0000000
--- a/IotaCSharpApi/Api/Core/GetBalancesRequest.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core api request 'GetBalances'
- ///
- public class GetBalancesRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The addresses.
- /// The threshold.
- public GetBalancesRequest(List addresses, long threshold = 100)
- : base(Core.Command.GetBalances.GetCommandString())
- {
- Addresses = addresses;
- Threshold = threshold;
- }
-
- ///
- /// Gets the threshold.
- ///
- ///
- /// The threshold.
- ///
- public long Threshold { get; }
-
- ///
- /// Gets the addresses.
- ///
- ///
- /// The addresses.
- ///
- public List Addresses { get; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Threshold)}: {Threshold}, {nameof(Addresses)}: {string.Join(",",Addresses)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetBalancesResponse.cs b/IotaCSharpApi/Api/Core/GetBalancesResponse.cs
deleted file mode 100644
index cb411e6..0000000
--- a/IotaCSharpApi/Api/Core/GetBalancesResponse.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// Response of
- ///
- public class GetBalancesResponse : IotaResponse
- {
- ///
- /// Gets or sets the balances.
- ///
- ///
- /// The balances.
- ///
- public List Balances { get; set; }
-
- ///
- /// Gets or sets the references.
- ///
- ///
- /// The references.
- ///
- public List References { get; set; }
-
- ///
- /// Gets or sets the index of the milestone.
- ///
- ///
- /// The index of the milestone.
- ///
- public int MilestoneIndex { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return
- $"{nameof(Balances)}: {string.Join(",", Balances)}, {nameof(References)}: {string.Join(",", References)}, {nameof(MilestoneIndex)}: {MilestoneIndex}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetInclusionStatesRequest.cs b/IotaCSharpApi/Api/Core/GetInclusionStatesRequest.cs
deleted file mode 100644
index 09b100a..0000000
--- a/IotaCSharpApi/Api/Core/GetInclusionStatesRequest.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core API request 'GetInclusionStates'
- ///
- ///
- public class GetInclusionStatesRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The transactions.
- /// The tips.
- public GetInclusionStatesRequest(string[] transactions, string[] tips)
- : base(Core.Command.GetInclusionStates.GetCommandString())
- {
- Transactions = transactions;
- Tips = tips;
- }
-
- ///
- /// Gets the transactions.
- ///
- ///
- /// The transactions.
- ///
- public string[] Transactions { get; }
-
- ///
- /// Gets the tips.
- ///
- ///
- /// The tips.
- ///
- public string[] Tips { get; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Transactions)}: {Transactions}, {nameof(Tips)}: {Tips}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetInclusionStatesResponse.cs b/IotaCSharpApi/Api/Core/GetInclusionStatesResponse.cs
deleted file mode 100644
index f17b50c..0000000
--- a/IotaCSharpApi/Api/Core/GetInclusionStatesResponse.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the response of
- ///
- ///
- public class GetInclusionStatesResponse : IotaResponse
- {
- ///
- /// Gets or sets the states.
- ///
- ///
- /// The states.
- ///
- public List States { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetNeighborsRequest.cs b/IotaCSharpApi/Api/Core/GetNeighborsRequest.cs
deleted file mode 100644
index 2056c79..0000000
--- a/IotaCSharpApi/Api/Core/GetNeighborsRequest.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core API request 'GetNeighbors'
- ///
- ///
- public class GetNeighborsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public GetNeighborsRequest() : base(Core.Command.GetNeighbors.GetCommandString())
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetNeighborsResponse.cs b/IotaCSharpApi/Api/Core/GetNeighborsResponse.cs
deleted file mode 100644
index 08448d4..0000000
--- a/IotaCSharpApi/Api/Core/GetNeighborsResponse.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System.Collections.Generic;
-using Iota.Lib.CSharp.Api.Model;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// Response of
- ///
- public class GetNeighborsResponse
- {
- ///
- /// Gets or sets the neighbors.
- ///
- ///
- /// The neighbors.
- ///
- public List Neighbors { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetNodeInfoRequest.cs b/IotaCSharpApi/Api/Core/GetNodeInfoRequest.cs
deleted file mode 100644
index 5445c81..0000000
--- a/IotaCSharpApi/Api/Core/GetNodeInfoRequest.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// Returns information about your node
- ///
- public class GetNodeInfoRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public GetNodeInfoRequest() : base(Core.Command.GetNodeInfo.GetCommandString())
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetNodeInfoResponse.cs b/IotaCSharpApi/Api/Core/GetNodeInfoResponse.cs
deleted file mode 100644
index cad5fd8..0000000
--- a/IotaCSharpApi/Api/Core/GetNodeInfoResponse.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the response of
- ///
- ///
- public class GetNodeInfoResponse : IotaResponse
- {
- ///
- /// Name of the IOTA software you're currently using (IRI stands for Initial Reference Implementation).
- ///
- public string AppName { get; set; }
-
- ///
- /// The version of the IOTA software you're currently running.
- ///
- public string AppVersion { get; set; }
-
- ///
- /// Available cores on your machine for JRE.
- ///
- public int JreAvailableProcessors { get; set; }
-
- ///
- /// The amount of free memory in the Java Virtual Machine.
- ///
- public long JreFreeMemory { get; set; }
-
- ///
- /// The maximum amount of memory that the Java virtual machine will attempt to use.
- ///
- public long JreMaxMemory { get; set; }
-
- ///
- /// The total amount of memory in the Java virtual machine.
- ///
- public long JreTotalMemory { get; set; }
-
- ///
- /// Latest milestone that was signed off by the coordinator.
- ///
- public string LatestMilestone { get; set; }
-
- ///
- /// Index of the latest milestone.
- ///
- public long LatestMilestoneIndex { get; set; }
-
- ///
- /// The latest milestone which is solid and is used for sending transactions.
- /// For a milestone to become solid your local node must basically approve the subtangle of coordinator-approved transactions,
- /// and have a consistent view of all referenced transactions.
- ///
- public string LatestSolidSubtangleMilestone { get; set; }
-
- ///
- /// Index of the latest solid subtangle.
- ///
- public long LatestSolidSubtangleMilestoneIndex { get; set; }
-
- ///
- /// Number of neighbors you are directly connected with.
- ///
- public long Neighbors { get; set; }
-
- ///
- /// Packets which are currently queued up
- ///
- public long PacketsQueueSize { get; set; }
-
- ///
- /// Current UNIX timestamp.
- ///
- public long Time { get; set; }
-
- ///
- /// Number of tips in the network.
- ///
- public long Tips { get; set; }
-
- ///
- /// Transactions to request during syncing process.
- ///
- public long TransactionsToRequest { get; set; }
-
- ///
- /// java runtime environment version.
- ///
- ///
- /// The jre version.
- ///
- public string JreVersion { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return
- $"{nameof(AppName)}: {AppName}, {nameof(AppVersion)}: {AppVersion}, {nameof(JreAvailableProcessors)}: {JreAvailableProcessors}, {nameof(JreFreeMemory)}: {JreFreeMemory}, {nameof(JreMaxMemory)}: {JreMaxMemory}, {nameof(JreTotalMemory)}: {JreTotalMemory}, {nameof(LatestMilestone)}: {LatestMilestone}, {nameof(LatestMilestoneIndex)}: {LatestMilestoneIndex}, {nameof(LatestSolidSubtangleMilestone)}: {LatestSolidSubtangleMilestone}, {nameof(LatestSolidSubtangleMilestoneIndex)}: {LatestSolidSubtangleMilestoneIndex}, {nameof(Neighbors)}: {Neighbors}, {nameof(PacketsQueueSize)}: {PacketsQueueSize}, {nameof(Time)}: {Time}, {nameof(Tips)}: {Tips}, {nameof(TransactionsToRequest)}: {TransactionsToRequest}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetTipsRequest.cs b/IotaCSharpApi/Api/Core/GetTipsRequest.cs
deleted file mode 100644
index a08d6ee..0000000
--- a/IotaCSharpApi/Api/Core/GetTipsRequest.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core API request 'GetTips'
- ///
- public class GetTipsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public GetTipsRequest() : base(Core.Command.GetTips.GetCommandString())
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetTipsResponse.cs b/IotaCSharpApi/Api/Core/GetTipsResponse.cs
deleted file mode 100644
index 094a7eb..0000000
--- a/IotaCSharpApi/Api/Core/GetTipsResponse.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the response of
- ///
- public class GetTipsResponse : IotaResponse
- {
- ///
- /// Gets or sets the hashes.
- ///
- ///
- /// The hashes.
- ///
- public List Hashes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Hashes)}: {string.Join(",", Hashes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetTransactionsToApproveRequest.cs b/IotaCSharpApi/Api/Core/GetTransactionsToApproveRequest.cs
deleted file mode 100644
index 15dc874..0000000
--- a/IotaCSharpApi/Api/Core/GetTransactionsToApproveRequest.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core API call 'GetTransactionsToApprove'
- ///
- public class GetTransactionsToApproveRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The depth.
- public GetTransactionsToApproveRequest(int depth)
- : base(Core.Command.GetTransactionsToApprove.GetCommandString())
- {
- Depth = depth;
- }
-
- ///
- /// Gets the depth.
- ///
- ///
- /// The depth.
- ///
- public int Depth { get; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Depth)}: {Depth}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetTransactionsToApproveResponse.cs b/IotaCSharpApi/Api/Core/GetTransactionsToApproveResponse.cs
deleted file mode 100644
index 5bdca42..0000000
--- a/IotaCSharpApi/Api/Core/GetTransactionsToApproveResponse.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the response of
- ///
- public class GetTransactionsToApproveResponse : IotaResponse
- {
- ///
- /// Gets or sets the trunk transaction.
- ///
- ///
- /// The trunk transaction.
- ///
- public string TrunkTransaction { get; set; }
-
- ///
- /// Gets or sets the branch transaction.
- ///
- ///
- /// The branch transaction.
- ///
- public string BranchTransaction { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(TrunkTransaction)}: {TrunkTransaction}, {nameof(BranchTransaction)}: {BranchTransaction}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetTrytesRequest.cs b/IotaCSharpApi/Api/Core/GetTrytesRequest.cs
deleted file mode 100644
index 31c13f0..0000000
--- a/IotaCSharpApi/Api/Core/GetTrytesRequest.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core API request 'GetTrytes'
- ///
- public class GetTrytesRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public GetTrytesRequest() : base(Core.Command.GetTrytes.GetCommandString())
- {
-
- }
-
- ///
- /// Gets or sets the hashes.
- ///
- ///
- /// The hashes.
- ///
- public string[] Hashes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Hashes)}: {string.Join(",", Hashes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/GetTrytesResponse.cs b/IotaCSharpApi/Api/Core/GetTrytesResponse.cs
deleted file mode 100644
index 541f03b..0000000
--- a/IotaCSharpApi/Api/Core/GetTrytesResponse.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the response of
- ///
- public class GetTrytesResponse
- {
-
- ///
- /// Gets or sets the trytes.
- ///
- ///
- /// The trytes.
- ///
- public List Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Trytes)}: {string.Join(",", Trytes)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/IGenericIotaCoreApi.cs b/IotaCSharpApi/Api/Core/IGenericIotaCoreApi.cs
deleted file mode 100644
index 7cfde6a..0000000
--- a/IotaCSharpApi/Api/Core/IGenericIotaCoreApi.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This interface abstracts a generic version of the core api that is used internally.
- ///
- public interface IGenericIotaCoreApi
- {
- ///
- /// Gets the hostname.
- ///
- ///
- /// The hostname.
- ///
- string Hostname { get; }
-
- ///
- /// Gets the port.
- ///
- ///
- /// The port.
- ///
- int Port { get; }
-
- ///
- /// Requests the specified request.
- ///
- /// The type of the request.
- /// The type of the response.
- /// The request.
- ///
- TResponse Request(TRequest request) where TResponse : new();
-
- ///
- /// Requests the specified request asynchronously
- ///
- /// The type of the request.
- /// The type of the response.
- /// The request.
- /// The response action.
- void RequestAsync(TRequest request, Action responseAction)
- where TResponse : new();
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/ILocalPoW.cs b/IotaCSharpApi/Api/Core/ILocalPoW.cs
deleted file mode 100644
index b791dfe..0000000
--- a/IotaCSharpApi/Api/Core/ILocalPoW.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- ///
- ///
- public interface ILocalPoW
- {
- ///
- ///
- ///
- ///
- ///
- ///
- string PerformPoW(string trytes, int minWeightMagnitude);
- }
-}
diff --git a/IotaCSharpApi/Api/Core/InterruptAttachingToTangleRequest.cs b/IotaCSharpApi/Api/Core/InterruptAttachingToTangleRequest.cs
deleted file mode 100644
index cd204fc..0000000
--- a/IotaCSharpApi/Api/Core/InterruptAttachingToTangleRequest.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core api request 'InterruptAttachingToTangle'
- ///
- public class InterruptAttachingToTangleRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public InterruptAttachingToTangleRequest() : base(Core.Command.InterruptAttachingToTangle.GetCommandString())
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/InterruptAttachingToTangleResponse.cs b/IotaCSharpApi/Api/Core/InterruptAttachingToTangleResponse.cs
deleted file mode 100644
index ff466db..0000000
--- a/IotaCSharpApi/Api/Core/InterruptAttachingToTangleResponse.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the response of
- ///
- ///
- public class InterruptAttachingToTangleResponse : IotaResponse
- {
-
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/IotaCoreApi.cs b/IotaCSharpApi/Api/Core/IotaCoreApi.cs
deleted file mode 100644
index 3808983..0000000
--- a/IotaCSharpApi/Api/Core/IotaCoreApi.cs
+++ /dev/null
@@ -1,258 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Iota.Lib.CSharp.Api.Model;
-using Iota.Lib.CSharp.Api.Utils;
-using RestSharp.Extensions;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class provides access to the Iota core API
- ///
- public class IotaCoreApi
- {
- private readonly IGenericIotaCoreApi _genericIotaCoreApi;
-
- ///
- ///
- ///
- public ILocalPoW LocalPow { get; set; }
-
- ///
- /// Creates a core api object that uses the specified connection settings to connect to a node
- ///
- /// hostname or API address of a node to interact with
- /// tcp/udp port
- public IotaCoreApi(string host, int port)
- {
- _genericIotaCoreApi = new GenericIotaCoreApi(host, port);
- }
-
- ///
- /// Attaches the specified transactions (trytes) to the Tangle by doing Proof of Work.
- /// You need to supply branchTransaction as well as trunkTransaction
- /// (basically the tips which you're going to validate and reference with this transaction)
- /// - both of which you'll get through the getTransactionsToApprove API call.
- ///
- /// Trunk transaction to approve.
- /// Branch transaction to approve.
- /// List of trytes (raw transaction data) to attach to the tangle.
- /// Proof of Work intensity. Minimum value is 18
- /// The returned value contains a different set of tryte values which you can input into broadcastTransactions and storeTransactions.
- /// The returned tryte value, the last 243 trytes basically consist of the: trunkTransaction + branchTransaction + nonce.
- /// These are valid trytes which are then accepted by the network.
- public AttachToTangleResponse AttachToTangle(string trunkTransaction, string branchTransaction,
- string[] trytes, int minWeightMagnitude = 18)
- {
- if (!InputValidator.IsHash(trunkTransaction))
- throw new ArgumentException("Invalid hashes provided.");
-
- if (!InputValidator.IsHash(branchTransaction))
- throw new ArgumentException("Invalid hashes provided.");
-
- if (!InputValidator.IsArrayOfTrytes(trytes, 2673))
- throw new ArgumentException("Invalid trytes provided.");
-
- if (LocalPow != null)
- {
- var response = new AttachToTangleResponse
- {
- Trytes = new List()
- };
-
- string previousTransaction = null;
- foreach (var t in trytes)
- {
- var txn = new Transaction(t)
- {
- TrunkTransaction = previousTransaction ?? trunkTransaction,
- BranchTransaction = previousTransaction == null ? branchTransaction : trunkTransaction
- };
-
- if (string.IsNullOrEmpty(txn.Tag) || txn.Tag.Matches("9*"))
- txn.Tag = txn.ObsoleteTag;
- txn.AttachmentTimestamp = IotaApiUtils.CreateTimeStampNow();
- txn.AttachmentTimestampLowerBound = 0;
- txn.AttachmentTimestampUpperBound = 3_812_798_742_493L;
-
- var resultTrytes = LocalPow.PerformPoW(txn.ToTransactionTrytes(), minWeightMagnitude);
-
- previousTransaction = new Transaction(resultTrytes).Hash;
-
- response.Trytes.Add(resultTrytes);
- }
-
- return response;
- }
-
- AttachToTangleRequest attachToTangleRequest = new AttachToTangleRequest(trunkTransaction, branchTransaction,
- trytes, minWeightMagnitude);
- return _genericIotaCoreApi.Request(attachToTangleRequest);
- }
-
- ///
- /// Broadcasts the transactions.
- ///
- /// The transactions in trytes representation
- /// the BroadcastTransactionsResponse
- public BroadcastTransactionsResponse BroadcastTransactions(List trytes)
- {
- return
- _genericIotaCoreApi.Request(
- new BroadcastTransactionsRequest(trytes));
- }
-
- ///
- /// Finds the transactions using the specified arguments as search criteria
- ///
- /// The addresses.
- /// The tags.
- /// The approves.
- /// The bundles.
- /// a FindTransactionsResponse, see
- public FindTransactionsResponse FindTransactions(List addresses, List tags,
- List approves, List bundles)
- {
- var findTransactionsRequest = new FindTransactionsRequest(bundles, addresses, tags, approves);
- return
- _genericIotaCoreApi.Request(findTransactionsRequest);
- }
-
- ///
- /// Gets the balances.
- ///
- /// The addresses.
- /// The threshold.
- /// It returns the confirmed balance which a list of addresses have at the latest confirmed milestone.
- /// In addition to the balances, it also returns the milestone as well as the index with which the confirmed balance was determined.
- /// The balances is returned as a list in the same order as the addresses were provided as input.
- public GetBalancesResponse GetBalances(List addresses, long threshold)
- {
- List addressesWithoutChecksum = new List();
- foreach (var address in addresses)
- {
- string address0 = address.RemoveChecksum();
- addressesWithoutChecksum.Add(address0);
- }
-
- GetBalancesRequest getBalancesRequest = new GetBalancesRequest(addressesWithoutChecksum, threshold);
- return _genericIotaCoreApi.Request(getBalancesRequest);
- }
-
- ///
- /// Gets the inclusion states of the specified transactions
- ///
- /// The transactions.
- /// The milestones.
- /// a GetInclusionStatesResponse, see
- public GetInclusionStatesResponse GetInclusionStates(string[] transactions, string[] milestones)
- {
- return
- _genericIotaCoreApi.Request(
- new GetInclusionStatesRequest(transactions, milestones));
- }
-
- ///
- /// Stores the specified transactions in trytes into the local storage. The trytes to be used for this call are returned by attachToTangle.
- ///
- /// The trytes representing the transactions
- /// a
- public StoreTransactionsResponse StoreTransactions(List trytes)
- {
- return
- _genericIotaCoreApi.Request(
- new StoreTransactionsRequest(trytes));
- }
-
- ///
- /// Gets the node information.
- ///
- /// a containing information about the node.
- public GetNodeInfoResponse GetNodeInfo()
- {
- return _genericIotaCoreApi.Request(new GetNodeInfoRequest());
- }
-
- ///
- /// Gets the tips.
- ///
- /// a containing a list of tips
- public GetTipsResponse GetTips()
- {
- GetTipsRequest getTipsRequest = new GetTipsRequest();
- return _genericIotaCoreApi.Request(getTipsRequest);
- }
-
- ///
- /// Gets the transactions to approve.
- ///
- /// The depth is the number of bundles to go back to determine the transactions for approval.
- /// The higher your depth value, the more "babysitting" you do for the network (as you have to confirm more transactions).
- /// trunkTransaction and branchTransaction (result of the Tip selection)
- public GetTransactionsToApproveResponse GetTransactionsToApprove(int depth)
- {
- GetTransactionsToApproveRequest getTransactionsToApproveRequest = new GetTransactionsToApproveRequest(depth);
- return
- _genericIotaCoreApi.Request(
- getTransactionsToApproveRequest);
- }
-
- ///
- /// Gets the raw transaction data (trytes) of a specific transaction.
- /// These trytes can then be easily converted into the actual transaction object using the constructor of Transaction
- ///
- /// The hashes of the transactions
- /// a containing a list of trytes
- public GetTrytesResponse GetTrytes(params string[] hashes)
- {
- GetTrytesRequest getTrytesRequest = new GetTrytesRequest() {Hashes = hashes};
- return _genericIotaCoreApi.Request(getTrytesRequest);
- }
-
- ///
- /// Interrupts and completely aborts the attachToTangle process.
- ///
- /// an
- public InterruptAttachingToTangleResponse InterruptAttachingToTangle()
- {
- InterruptAttachingToTangleRequest request = new InterruptAttachingToTangleRequest();
- return
- _genericIotaCoreApi.Request(
- request);
- }
-
- ///
- /// Gets the neighbors the node is connected to
- ///
- /// A containing the set of neighbors the node is connected to as well as their activity count. The activity counter is reset after restarting IRI.
- public GetNeighborsResponse GetNeighbors()
- {
- GetNeighborsRequest getNeighborsRequest = new GetNeighborsRequest();
- return _genericIotaCoreApi.Request(getNeighborsRequest);
- }
-
- ///
- /// Adds the neighbor(s) to the node. It should be noted that this is only temporary, and the added neighbors will be removed from your set of neighbors after you relaunch IRI.
- ///
- /// The uris of the neighbors to add. The URI (Unique Resource Identification) format is "udp://IPADDRESS:PORT"
- /// containing the number of added Neighbors
- public AddNeighborsResponse AddNeighbors(params string[] uris)
- {
- return
- _genericIotaCoreApi.Request(
- new AddNeighborsRequest(uris.ToList()));
- }
-
- ///
- /// Removes the neighbor(s) from the node.
- ///
- /// The uris of the neighbors to add. The URI (Unique Resource Identification) format is "udp://IPADDRESS:PORT"
- /// A containing the number of removed neighbors
- public RemoveNeighborsResponse RemoveNeighbors(params string[] uris)
- {
- RemoveNeighborsRequest removeNeighborsRequest = new RemoveNeighborsRequest(uris.ToList());
- return _genericIotaCoreApi.Request(removeNeighborsRequest);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/IotaRequest.cs b/IotaCSharpApi/Api/Core/IotaRequest.cs
deleted file mode 100644
index 0c564ee..0000000
--- a/IotaCSharpApi/Api/Core/IotaRequest.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class serves as base class for the different core API calls/requests
- ///
- public class IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The command.
- public IotaRequest(string command)
- {
- this.Command = command;
- }
-
- ///
- /// Gets or sets the command.
- ///
- ///
- /// The command.
- ///
- public string Command { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/IotaResponse.cs b/IotaCSharpApi/Api/Core/IotaResponse.cs
deleted file mode 100644
index 4735094..0000000
--- a/IotaCSharpApi/Api/Core/IotaResponse.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the base class of different core API response classes
- ///
- public class IotaResponse
- {
- ///
- /// Gets or sets the duration.
- ///
- ///
- /// The duration.
- ///
- public long Duration { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/RemoveNeighborsRequest.cs b/IotaCSharpApi/Api/Core/RemoveNeighborsRequest.cs
deleted file mode 100644
index b448a9c..0000000
--- a/IotaCSharpApi/Api/Core/RemoveNeighborsRequest.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core api request 'RemoveNeighbors'
- ///
- ///
- public class RemoveNeighborsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The uris.
- public RemoveNeighborsRequest(List uris) : base(Core.Command.RemoveNeighbors.GetCommandString())
- {
- Uris = uris;
- }
-
- ///
- /// Gets or sets the uris of the neighbours to remove
- ///
- ///
- /// The uris of the neighbours to remove.
- ///
- public List Uris { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Uris)}: {string.Join(",", Uris)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/RemoveNeighborsResponse.cs b/IotaCSharpApi/Api/Core/RemoveNeighborsResponse.cs
deleted file mode 100644
index 2dded81..0000000
--- a/IotaCSharpApi/Api/Core/RemoveNeighborsResponse.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the response of
- ///
- public class RemoveNeighborsResponse
- {
- ///
- /// Gets or sets the number of removed neighbors.
- ///
- ///
- /// The removed neighbors.
- ///
- public long RemovedNeighbors { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(RemovedNeighbors)}: {RemovedNeighbors}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/StoreTransactionsRequest.cs b/IotaCSharpApi/Api/Core/StoreTransactionsRequest.cs
deleted file mode 100644
index b015009..0000000
--- a/IotaCSharpApi/Api/Core/StoreTransactionsRequest.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the core API request 'StoreTransactions'.
- /// It stores transactions into the local storage. The trytes to be used for this call are returned by attachToTangle.
- ///
- public class StoreTransactionsRequest : IotaRequest
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The trytes.
- public StoreTransactionsRequest(List trytes) : base(Core.Command.StoreTransactions.GetCommandString())
- {
- this.Trytes = trytes;
- }
-
- ///
- /// Gets or sets the trytes.
- ///
- ///
- /// The trytes.
- ///
- public List Trytes { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Trytes)}: {Trytes}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Core/StoreTransactionsResponse.cs b/IotaCSharpApi/Api/Core/StoreTransactionsResponse.cs
deleted file mode 100644
index 6a52d20..0000000
--- a/IotaCSharpApi/Api/Core/StoreTransactionsResponse.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Core
-{
- ///
- /// This class represents the response of
- ///
- public class StoreTransactionsResponse
- {
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/IllegalAccessError.cs b/IotaCSharpApi/Api/Exception/IllegalAccessError.cs
deleted file mode 100644
index 03825d0..0000000
--- a/IotaCSharpApi/Api/Exception/IllegalAccessError.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception occurs when certain core API calls on the node are disabled
- ///
- ///
- public class IllegalAccessError : System.Exception
- {
-
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/IllegalStateException.cs b/IotaCSharpApi/Api/Exception/IllegalStateException.cs
deleted file mode 100644
index 4a547c1..0000000
--- a/IotaCSharpApi/Api/Exception/IllegalStateException.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception occurs when an illegal state is encountered
- ///
- ///
- public class IllegalStateException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The error.
- public IllegalStateException(string error):base(error)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/InvalidAddressException.cs b/IotaCSharpApi/Api/Exception/InvalidAddressException.cs
deleted file mode 100644
index 83d2273..0000000
--- a/IotaCSharpApi/Api/Exception/InvalidAddressException.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception occurs when an invalid address is provided
- ///
- ///
- public class InvalidAddressException : ArgumentException
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The address.
- public InvalidAddressException(string address) : base("The specified address '" + address + "' is invalid")
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/InvalidBundleException.cs b/IotaCSharpApi/Api/Exception/InvalidBundleException.cs
deleted file mode 100644
index 1cc180a..0000000
--- a/IotaCSharpApi/Api/Exception/InvalidBundleException.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This excpetions occurs if an invalid bundle was found or provided
- ///
- ///
- public class InvalidBundleException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The message that describes the error.
- public InvalidBundleException(string message) : base(message)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/InvalidSignatureException.cs b/IotaCSharpApi/Api/Exception/InvalidSignatureException.cs
deleted file mode 100644
index 6ddb479..0000000
--- a/IotaCSharpApi/Api/Exception/InvalidSignatureException.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception occurs when an invalid signature is encountered
- ///
- ///
- public class InvalidSignatureException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public InvalidSignatureException() :base("Invalid signature found")
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/InvalidTailTransactionException.cs b/IotaCSharpApi/Api/Exception/InvalidTailTransactionException.cs
deleted file mode 100644
index 2084449..0000000
--- a/IotaCSharpApi/Api/Exception/InvalidTailTransactionException.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception is thrown when an invalid tail transaction was encountered
- ///
- ///
- public class InvalidTailTransactionException : System.Exception
- {
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/InvalidTryteException.cs b/IotaCSharpApi/Api/Exception/InvalidTryteException.cs
deleted file mode 100644
index 79a85ea..0000000
--- a/IotaCSharpApi/Api/Exception/InvalidTryteException.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception occurs when invalid trytes are encountered
- ///
- public class InvalidTryteException : System.Exception
- {
-
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/InvisibleBundleTransactionException.cs b/IotaCSharpApi/Api/Exception/InvisibleBundleTransactionException.cs
deleted file mode 100644
index 58f23c1..0000000
--- a/IotaCSharpApi/Api/Exception/InvisibleBundleTransactionException.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception occurs when a bundle or transaction is not visible in the tangle
- ///
- ///
- public class InvisibleBundleTransactionException : System.Exception
- {
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/IotaApiException.cs b/IotaCSharpApi/Api/Exception/IotaApiException.cs
deleted file mode 100644
index 1d52a4b..0000000
--- a/IotaCSharpApi/Api/Exception/IotaApiException.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception encapsulates an error that occured while communicating with the node (for example during a core API call)
- ///
- ///
- public class IotaApiException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The error.
- public IotaApiException(string error) : base(error)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Exception/NotEnoughBalanceException.cs b/IotaCSharpApi/Api/Exception/NotEnoughBalanceException.cs
deleted file mode 100644
index 3255cdc..0000000
--- a/IotaCSharpApi/Api/Exception/NotEnoughBalanceException.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Exception
-{
- ///
- /// This exception occurs when a transfer fails because their is not enough balance to perform the transfer
- ///
- ///
- public class NotEnoughBalanceException : System.Exception
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public NotEnoughBalanceException() : base("Not enough balance")
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The total value.
- public NotEnoughBalanceException(long totalValue) : base("Not enough balance to transfer " + totalValue + " iota")
- {
-
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/IotaApi.cs b/IotaCSharpApi/Api/IotaApi.cs
deleted file mode 100644
index fe68696..0000000
--- a/IotaCSharpApi/Api/IotaApi.cs
+++ /dev/null
@@ -1,1124 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Iota.Lib.CSharp.Api.Core;
-using Iota.Lib.CSharp.Api.Exception;
-using Iota.Lib.CSharp.Api.Model;
-using Iota.Lib.CSharp.Api.Pow;
-using Iota.Lib.CSharp.Api.Utils;
-
-namespace Iota.Lib.CSharp.Api
-{
- ///
- /// This class provides access to the core API methods and the proposed calls
- ///
- public class IotaApi : IotaCoreApi
- {
- private readonly ICurl _curl;
-
- ///
- /// Creates an api object that uses the specified connection settings to connect to a node
- ///
- /// hostname or API address of a node to interact with
- /// tcp/udp port
- public IotaApi(string host, int port) : this(host, port, new Kerl())
- {
- }
-
- ///
- /// Creates an api object that uses the specified connection settings to connect to a node
- ///
- /// hostname or API address of a node to interact with
- /// tcp/udp port
- ///
- /// a custom curl implementation to be used to perform the pow. Use the other constructor in order to
- /// use the default curl implementation provided by the library
- ///
- public IotaApi(string host, int port, ICurl curl) : base(host, port)
- {
- _curl = curl ?? throw new ArgumentNullException(nameof(curl));
- }
-
- ///
- /// Gets all possible inputs of a seed and returns them with the total balance.
- /// This is either done deterministically (by genearating all addresses until findTransactions is empty and doing
- /// getBalances),
- /// or by providing a key range to use for searching through.
- ///
- /// Tryte-encoded seed. It should be noted that this seed is not transferred
- /// The Security level of private key / seed.
- /// Starting key index
- /// Ending key index
- /// The minimum threshold of accumulated balances from the inputs that is required
- /// The inputs (see )
- public Inputs GetInputs(string seed, int security, int start, int end, long threshold)
- {
- InputValidator.CheckIfValidSeed(seed);
-
- seed = InputValidator.PadSeedIfNecessary(seed);
-
- if (security < 1)
- throw new ArgumentException("invalid security level provided");
-
- // If start value bigger than end, return error
- if (start > end)
- throw new ArgumentException("start must be smaller than end", nameof(start));
-
- // or if difference between end and start is bigger than 500 keys
- if (end - start > 500)
- throw new ArgumentException("total number of keys exceeded 500");
-
- // Case 1: start and end
- //
- // If start and end is defined by the user, simply iterate through the keys
- // and call getBalances
- if (end != 0)
- {
- var allAddresses = new string[end - start];
-
- for (var i = start; i < end; i++)
- {
- var address = IotaApiUtils.NewAddress(seed, security, i, false, _curl);
- allAddresses[i] = address;
- }
-
- return GetBalanceAndFormat(allAddresses, threshold, start, security);
- }
-
- // Case 2: iterate till threshold || end
- //
- // Either start from index: 0 or start (if defined) until threshold is reached.
- // Calls getNewAddress and deterministically generates and returns all addresses
- // We then do getBalance, format the output and return it
-
- var addresses = GetNewAddress(seed, security, start, false, 0, true);
- return GetBalanceAndFormat(addresses, threshold, start, security);
- }
-
- ///
- /// Gets the balances of the specified addresses and calculates the total balance till the threshold is reached.
- ///
- /// addresses
- /// the threshold
- /// start index
- ///
- /// an Inputs object
- ///
- /// is thrown if threshold exceeds the sum of balance of the specified
- /// addresses
- ///
- private Inputs GetBalanceAndFormat(
- string[] addresses,
- long threshold, int start,
- int security)
- {
- if (security < 1)
- throw new ArgumentException("invalid security level provided");
-
- var getBalancesResponse = GetBalances(addresses.ToList(), 100);
-
- var balances = getBalancesResponse.Balances;
-
- var inputs = new Inputs {InputsList = new List(), TotalBalance = 0};
-
- var threshholdReached = threshold == 0;
-
- for (var i = 0; i < addresses.Length; i++)
- if (balances[i] > 0)
- {
- inputs.InputsList.Add(new Input
- {
- Address = addresses[i],
- Balance = balances[i],
- KeyIndex = start + i,
- Security = security
- });
-
- inputs.TotalBalance += balances[i];
-
- if (inputs.TotalBalance >= threshold)
- {
- threshholdReached = true;
- break;
- }
- }
-
- if (threshholdReached)
- return inputs;
-
-
- throw new NotEnoughBalanceException();
- }
-
- ///
- /// Main purpose of this function is to get an array of transfer objects as input, and then prepare the transfer by
- /// generating the correct bundle,
- /// as well as choosing and signing the inputs if necessary (if it's a value transfer). The output of this function is
- /// an array of the raw transaction data (trytes)
- ///
- /// 81-tryte encoded address of recipient
- ///
- /// the transfers to prepare
- /// Optional (default null). The inputs
- ///
- /// Optional (default null). if defined, this address will be used for sending the remainder
- /// value (of the inputs) to.
- ///
- ///
- /// a list containing the trytes of the new bundle
- public List PrepareTransfers(
- string seed, int security,
- Transfer[] transfers,
- string remainderAddress,
- List inputs,
- bool validateInputs)
- {
- // validate seed
- if (!InputValidator.IsValidSeed(seed))
- throw new IllegalStateException("Invalid seed provided.");
-
-
- if(security<1)
- throw new ArgumentException("Invalid security level provided.");
-
- // Input validation of transfers object
- InputValidator.CheckTransferArray(transfers);
-
- // Create a new bundle
- var bundle = new Bundle();
- var signatureFragments = new List();
-
- long totalValue = 0;
- var tag = "";
-
- //
- // Iterate over all transfers, get totalValue
- // and prepare the signatureFragments, message and tag
- //
- foreach (var transfer in transfers)
- {
- // remove the checksum of the address if provided
- transfer.Address = transfer.Address.RemoveChecksum();
-
- var signatureMessageLength = 1;
-
- // If message longer than 2187 trytes, increase signatureMessageLength (add 2nd transaction)
- if (transfer.Message.Length > Constants.MessageLength)
- {
- // Get total length, message / maxLength (2187 trytes)
- signatureMessageLength += (int) Math.Floor((double) transfer.Message.Length / Constants.MessageLength);
-
- var msgCopy = transfer.Message;
-
- // While there is still a message, copy it
- while (!string.IsNullOrEmpty(msgCopy))
- {
- var fragment = msgCopy.Substring(0, 2187 > msgCopy.Length ? msgCopy.Length : 2187);
- msgCopy = msgCopy.Substring(2187, msgCopy.Length - 2187);
-
- // Pad remainder of fragment
- while (fragment.Length < 2187) fragment += '9';
-
- signatureFragments.Add(fragment);
- }
- }
- else
- {
- // Else, get single fragment with 2187 of 9's trytes
- var fragment = string.Empty;
-
- if (!string.IsNullOrEmpty(transfer.Message))
- fragment = transfer.Message.Substring(0,
- transfer.Message.Length < 2187 ? transfer.Message.Length : 2187);
-
- while (fragment.Length < 2187) fragment += '9';
-
- signatureFragments.Add(fragment);
- }
-
- // get current timestamp in seconds
- var timestamp = (long)Math.Floor((double)IotaApiUtils.CreateTimeStampNow()/1000);
-
- // If no tag defined, get 27 tryte tag.
-
- tag = string.IsNullOrEmpty(transfer.Tag) ? "999999999999999999999999999" : transfer.Tag;
-
-
- // Pad for required 27 tryte length
- while (tag.Length < 27) tag += '9';
-
-
- // Add first entries to the bundle
- // Slice the address in case the user provided a checksummed one
- bundle.AddEntry(signatureMessageLength, transfer.Address, transfer.Value, tag, timestamp);
- // Sum up total value
- totalValue += transfer.Value;
- }
-
- // Get inputs if we are sending tokens
- if (totalValue != 0)
- if (inputs != null && inputs.Count > 0)
- {
- // Get list if addresses of the provided inputs
- var inputAddresses = new List();
- foreach (var input in inputs) inputAddresses.Add(input.Address);
-
- var balances = GetBalances(inputAddresses, 100);
-
- var confirmedInputs = new List();
-
- long totalBalance = 0;
- for (var i = 0; i < balances.Balances.Count; i++)
- {
- var thisBalance = balances.Balances[i];
- totalBalance += thisBalance;
-
- // If input has balance, add it to confirmedInputs
- if (thisBalance > 0)
- {
- var inputEl = inputs[i];
- inputEl.Balance = thisBalance;
-
- confirmedInputs.Add(inputEl);
- }
- }
-
- // Return not enough balance error
- if (totalValue > totalBalance) throw new NotEnoughBalanceException(totalValue);
-
- return AddRemainder(seed, security, confirmedInputs, bundle, tag, totalValue, remainderAddress,
- signatureFragments);
- }
-
- // Case 2: Get inputs deterministically
- //
- // If no inputs provided, derive the addresses from the seed and
- // confirm that the inputs exceed the threshold
- else
- {
- var inputList = GetInputs(seed, security, 0, 0, (int) totalValue).InputsList;
- return AddRemainder(seed, security, inputList, bundle, tag, totalValue, remainderAddress,
- signatureFragments);
- }
-
- // If no input required, don't sign and simply finalize the bundle
- bundle.FinalizeBundle(_curl.Clone());
- bundle.AddTrytes(signatureFragments);
-
- var bundleTrytes = new List();
- bundle.Transactions.ForEach(tx => bundleTrytes.Add(tx.ToTransactionTrytes()));
-
- bundleTrytes.Reverse();
- return bundleTrytes;
- }
-
-
- private List AddRemainder(
- string seed,
- int security,
- List inputs,
- Bundle bundle,
- string tag,
- long totalValue,
- string remainderAddress,
- List signatureFragments)
- {
- var totalTransferValue = totalValue;
-
- foreach (var input in inputs)
- {
- var thisBalance = input.Balance;
- var toSubtract = 0 - thisBalance;
- var timestamp = IotaApiUtils.CreateTimeStampNow();
-
- // Add input as bundle entry
- bundle.AddEntry(security, input.Address, toSubtract, tag, timestamp);
- // If there is a remainder value
- // Add extra output to send remaining funds to
-
- if (thisBalance >= totalTransferValue)
- {
- var remainder = thisBalance - totalTransferValue;
-
- // If user has provided remainder address
- // Use it to send remaining funds to
- if (remainder > 0 && remainderAddress != null)
- {
- // Remainder bundle entry
- bundle.AddEntry(1, remainderAddress, remainder, tag, timestamp);
-
- // function for signing inputs
- IotaApiUtils.SignInputsAndReturn(seed, inputs, bundle, signatureFragments, _curl);
- }
- else if (remainder > 0)
- {
- // Generate a new Address by calling getNewAddress
- // ReSharper disable RedundantArgumentDefaultValue
- var address = GetNewAddress(seed, security, 0, false, 0, false)[0];
- // ReSharper restore RedundantArgumentDefaultValue
-
- // Remainder bundle entry
- bundle.AddEntry(1, address, remainder, tag, timestamp);
-
- // function for signing inputs
- return IotaApiUtils.SignInputsAndReturn(seed, inputs, bundle, signatureFragments, _curl);
- }
- else
- {
- // If there is no remainder, do not add transaction to bundle
- // simply sign and return
- return IotaApiUtils.SignInputsAndReturn(seed, inputs, bundle, signatureFragments, _curl);
- }
- }
- // If multiple inputs provided, subtract the totalTransferValue by
- // the inputs balance
- else
- {
- totalTransferValue -= thisBalance;
- }
- }
-
- throw new NotEnoughBalanceException(totalValue);
- }
-
-
- ///
- /// Generates a new address from a seed and returns the remainderAddress. This is either done deterministically, or by
- /// providing the index of the new remainderAddress
- ///
- /// Tryte-encoded seed. It should be noted that this seed is not transferred
- ///
- ///
- /// Optional (default null). Key index to start search from. If the index is provided, the generation
- /// of the address is not deterministic.
- ///
- /// Optional (default false). Adds 9-tryte address checksum
- /// Optional (default 1)Total number of addresses to generate.
- ///
- /// If true, it returns all addresses which were deterministically generated (until
- /// findTransactions returns null)
- ///
- /// an array of strings with the specifed number of addresses
- public string[] GetNewAddress(string seed, int security, int index = 0, bool checksum = false, int total = 0,
- bool returnAll = false)
- {
- var allAdresses = new List();
-
- // TODO make two different functions out of this
-
- // Case 1: total
- //
- // If total number of addresses to generate is supplied, simply generate
- // and return the list of all addresses
- if (total > 0)
- {
- // Increase index with each iteration
- for (var i = index; i < index + total; i++)
- allAdresses.Add(IotaApiUtils.NewAddress(seed, security, i, checksum, new Kerl()));
-
- return allAdresses.ToArray();
- }
-
- // Case 2: no total provided
- //
- // Continue calling findTransactions to see if address was already created
- // if null, return list of addresses
- //
-
- var addresses = new List();
-
- for (var i = index;; i++)
- {
- var newAddress = IotaApiUtils.NewAddress(seed, security, i, checksum, new Kerl());
- var response = FindTransactionsByAddresses(newAddress);
-
- if (returnAll) addresses.Add(newAddress);
-
- if (response.Hashes.Count == 0)
- break;
- }
-
- return addresses.ToArray();
- }
-
- ///
- /// Gets the transfers which are associated with a seed.
- /// The transfers are determined by either calculating deterministically which addresses were already used,
- /// or by providing a list of indexes to get the transfers from.
- ///
- /// tryte-encoded seed. It should be noted that this seed is not transferred
- /// If True, it gets the inclusion states of the transfers.
- ///
- /// the address start index
- /// the address end index
- /// An Array of Bundle object that represent the transfers
- public Bundle[] GetTransfers(string seed, int security, int? start, int? end, bool inclusionStates = false)
- {
- InputValidator.CheckIfValidSeed(seed);
- seed = InputValidator.PadSeedIfNecessary(seed);
-
- if (!start.HasValue)
- start = 0;
- if (!end.HasValue)
- end = 0;
-
- // If start value bigger than end, return error
- // or if difference between end and start is bigger than 500 keys
- if (start.Value > end.Value || end.Value > start + 500)
- throw new System.Exception("Invalid inputs provided: start, end");
-
- // first call findTransactions
- // If a transaction is non tail, get the tail transactions associated with it
- // add it to the list of tail transactions
-
- var addresses = GetNewAddress(seed, security, start.Value, false,
- end.Value, true);
-
-
- var bundles = BundlesFromAddresses(addresses, inclusionStates);
- return bundles;
- }
-
- private Bundle[] BundlesFromAddresses(string[] addresses, bool inclusionStates)
- {
- var trxs = FindTransactionObjects(addresses);
- // set of tail transactions
- var tailTransactions = new List();
- var nonTailBundleHashes = new List();
-
- foreach (var trx in trxs)
- // Sort tail and nonTails
- if (trx.CurrentIndex == 0)
- {
- tailTransactions.Add(trx.Hash);
- }
- else
- {
- if (nonTailBundleHashes.IndexOf(trx.Bundle) == -1) nonTailBundleHashes.Add(trx.Bundle);
- }
-
- var bundleObjects = FindTransactionObjectsByBundle(nonTailBundleHashes.ToArray());
- foreach (var trx in bundleObjects)
- // Sort tail and nonTails
- if (trx.CurrentIndex == 0)
- if (tailTransactions.IndexOf(trx.Hash) == -1)
- tailTransactions.Add(trx.Hash);
-
- var finalBundles = new List();
- var tailTxArray = tailTransactions.ToArray();
-
- // If inclusionStates, get the confirmation status
- // of the tail transactions, and thus the bundles
- GetInclusionStatesResponse gisr = null;
- if (inclusionStates)
- {
- try
- {
- gisr = GetLatestInclusion(tailTxArray);
- }
- catch (IllegalAccessError)
- {
- // suppress exception (the check is done below)
- }
-
- if (gisr == null || gisr.States == null || gisr.States.Count == 0)
- throw new ArgumentException("Inclusion states not found");
- }
-
-
- var finalInclusionStates = gisr;
-
- Parallel.ForEach(tailTransactions, param =>
- {
- try
- {
- var b = GetBundle(param);
-
- if (inclusionStates)
- {
- var thisInclusion = finalInclusionStates != null &&
- finalInclusionStates.States[tailTxArray.ToList().IndexOf(param)];
- foreach (var t in b.Transactions) t.Persistance = thisInclusion;
- }
-
- finalBundles.Add(b);
- }
- catch (System.Exception ex)
- {
- Console.WriteLine("Bundle error: " + ex.Message);
- }
- });
-
- finalBundles.Sort();
- var returnValue = new Bundle[finalBundles.Count];
- for (var i = 0; i < finalBundles.Count; i++)
- returnValue[i] = new Bundle(finalBundles[i].Transactions, finalBundles[i].Transactions.Count);
- return returnValue;
- }
-
- ///
- /// Finds the transaction objects.
- ///
- /// The addresses.
- /// a list of transactions
- public List FindTransactionObjects(string[] addresses)
- {
- var addressesWithoutChecksum =
- addresses.Select(address => address.RemoveChecksum()).ToList();
-
- var ftr = FindTransactions(addressesWithoutChecksum, null, null, null);
- if (ftr?.Hashes == null)
- return null;
-
- // get the transaction objects of the transactions
- return GetTransactionsObjects(ftr.Hashes.ToArray());
- }
-
- ///
- /// Gets the transactions objects.
- ///
- /// The hashes in trytes
- /// a list of transactions
- public List GetTransactionsObjects(string[] hashes)
- {
- if (!InputValidator.IsArrayOfHashes(hashes))
- throw new IllegalStateException("Not an Array of Hashes: " + hashes);
-
- var trytesResponse = GetTrytes(hashes);
-
- var trxs = new List();
-
- foreach (var tryte in trytesResponse.Trytes) trxs.Add(new Transaction(tryte, _curl));
- return trxs;
- }
-
- ///
- /// Finds the transaction objects by bundle.
- ///
- /// The bundles.
- /// a list of Transaction objects
- public List FindTransactionObjectsByBundle(string[] bundles)
- {
- var ftr = FindTransactions(null, null, null, bundles.ToList());
- if (ftr == null || ftr.Hashes == null)
- return null;
-
- // get the transaction objects of the transactions
- return GetTransactionsObjects(ftr.Hashes.ToArray());
- }
-
-
- ///
- /// Replays the bundle.
- ///
- /// The transaction.
- /// The depth.
- /// The minimum weight magnitude.
- /// an array of boolean that indicate which transactions have been replayed successfully
- public bool[] ReplayBundle(string transaction, int depth, int minWeightMagnitude)
- {
- //StopWatch stopWatch = new StopWatch();
-
- var bundleTrytes = new List();
-
- var bundle = GetBundle(transaction);
-
- bundle.Transactions.ForEach(t => bundleTrytes.Add(t.ToTransactionTrytes()));
-
- var trxs = SendTrytes(bundleTrytes.ToArray(), depth, minWeightMagnitude).ToList();
-
- var successful = new bool[trxs.Count];
-
- for (var i = 0; i < trxs.Count; i++)
- {
- var response = FindTransactionsByBundles(trxs[i].Bundle);
- successful[i] = response.Hashes.Count != 0;
- }
-
- return successful;
- }
-
- ///
- /// Finds the transactions by bundles.
- ///
- /// The bundles.
- /// a FindTransactionsResponse containing the transactions, see
- public FindTransactionsResponse FindTransactionsByBundles(params string[] bundles)
- {
- return FindTransactions(null, null, null, bundles.ToList());
- }
-
- ///
- /// Finds the transactions by approvees.
- ///
- /// The approvees.
- /// a FindTransactionsResponse containing the transactions, see
- public FindTransactionsResponse FindTransactionsByApprovees(params string[] approvees)
- {
- return FindTransactions(null, null, approvees.ToList(), null);
- }
-
-
- ///
- /// Finds the transactions by digests.
- ///
- /// The bundles.
- /// a FindTransactionsResponse containing the transactions, see
- public FindTransactionsResponse FindTransactionsByDigests(params string[] bundles)
- {
- return FindTransactions(null, bundles.ToList(), null, null);
- }
-
- ///
- /// Finds the transactions by addresses.
- ///
- /// The addresses.
- /// a FindTransactionsResponse containing the transactions, see
- public FindTransactionsResponse FindTransactionsByAddresses(params string[] addresses)
- {
- var addressesWithoutChecksum = new List();
- foreach (var address in addresses)
- {
- var address0 = address.RemoveChecksum();
- addressesWithoutChecksum.Add(address0);
- }
-
- return FindTransactions(addressesWithoutChecksum, null, null, null);
- }
-
- ///
- /// Gets the latest inclusion.
- ///
- /// The hashes.
- /// a GetInclusionStatesResponse cotaining the inclusion state of the specified hashes
- public GetInclusionStatesResponse GetLatestInclusion(string[] hashes)
- {
- string[] latestMilestone = {GetNodeInfo().LatestSolidSubtangleMilestone};
- return GetInclusionStates(hashes, latestMilestone);
- }
-
-
- ///
- /// Wrapper function that basically does prepareTransfers, as well as attachToTangle and finally, it broadcasts and
- /// stores the transactions locally.
- ///
- /// tryte-encoded seed
- ///
- /// depth
- /// The minimum weight magnitude
- /// Array of transfer objects
- /// Optional (default null). List of inputs used for funding the transfer
- ///
- /// Optional (default null). If defined, this address will be used for sending the remainder value
- /// (of the inputs) to
- ///
- ///
- ///
- /// an array of the boolean that indicates which Transactions where sent successully
- public bool[] SendTransfer(
- string seed, int security, int depth,
- int minWeightMagnitude, Transfer[] transfers,
- Input[] inputs, string remainderAddress,
- bool validateInputs, bool validateInputAddresses)
- {
- var trytes = PrepareTransfers(seed, security, transfers,
- remainderAddress, inputs?.ToList(), validateInputs);
- var trxs = SendTrytes(trytes.ToArray(), depth, minWeightMagnitude);
-
- var successful = new bool[trxs.Length];
-
- for (var i = 0; i < trxs.Length; i++)
- {
- var response = FindTransactionsByBundles(trxs[i].Bundle);
-
- successful[i] = response.Hashes.Count != 0;
- }
-
- return successful;
- }
-
- ///
- /// Sends the trytes.
- ///
- /// The trytes.
- /// The depth.
- /// Optional (default 14). The minimum weight magnitude.
- /// an Array of Transactions
- public Transaction[] SendTrytes(string[] trytes, int depth, int minWeightMagnitude = 14)
- {
- var transactionsToApproveResponse = GetTransactionsToApprove(depth);
-
- var attachToTangleResponse =
- AttachToTangle(transactionsToApproveResponse.TrunkTransaction,
- transactionsToApproveResponse.BranchTransaction, trytes, minWeightMagnitude);
- try
- {
- BroadcastAndStore(attachToTangleResponse.Trytes);
- }
- catch (System.Exception)
- {
- return new Transaction[0];
- }
-
- var trx = new List();
-
- foreach (var tx in attachToTangleResponse.Trytes) trx.Add(new Transaction(tx, _curl));
- return trx.ToArray();
- }
-
- ///
- /// This function returns the bundle which is associated with a transaction. Input can by any type of transaction (tail
- /// and non-tail).
- /// If there are conflicting bundles (because of a replay for example) it will return multiple bundles.
- /// It also does important validation checking (signatures, sum, order) to ensure that the correct bundle is returned.
- ///
- /// the transaction encoded in trytes
- /// an array of bundle, if there are multiple arrays it means that there are conflicting bundles.
- public Bundle GetBundle(string transaction)
- {
- if (!InputValidator.IsHash(transaction))
- {
- throw new ArgumentException("Invalid hashes provided.");
- }
-
- var bundle = TraverseBundle(transaction, null, new Bundle());
-
- if (bundle == null)
- throw new ArgumentException("Unknown Bundle");
-
- long totalSum = 0;
- var bundleHash = bundle.Transactions[0].Bundle;
-
- ICurl curl = new Kerl();
- curl.Reset();
-
- var signaturesToValidate = new List();
-
- for (var index = 0; index < bundle.Transactions.Count; index++)
- {
- var bundleTransaction = bundle.Transactions[index];
- var bundleValue = bundleTransaction.Value;
- totalSum += bundleValue;
-
- if (bundleTransaction.CurrentIndex != index)
- throw new InvalidBundleException("The index of the bundle " + bundleTransaction.CurrentIndex +
- " did not match the expected index " + index);
-
- // Get the transaction trytes
- var thisTxTrytes = bundleTransaction.ToTransactionTrytes().Substring(2187, 162);
-
- // Absorb bundle hash + value + timestamp + lastIndex + currentIndex trytes.
- curl.Absorb(Converter.ToTrits(thisTxTrytes));
-
- // Check if input transaction
- if (bundleValue < 0)
- {
- var address = bundleTransaction.Address;
- var sig = new Signature {Address = address};
- sig.SignatureFragments.Add(bundleTransaction.SignatureMessageFragment);
-
- // Find the subsequent txs with the remaining signature fragment
- for (var i = index + 1; i < bundle.Transactions.Count; i++)
- {
- var newBundleTx = bundle.Transactions[i];
-
- // Check if new tx is part of the signature fragment
- if (newBundleTx.Address == address && newBundleTx.Value == 0)
- {
- if (sig.SignatureFragments.IndexOf(newBundleTx.SignatureMessageFragment) == -1)
- sig.SignatureFragments.Add(newBundleTx.SignatureMessageFragment);
- }
-
- }
-
- signaturesToValidate.Add(sig);
- }
- }
-
- // Check for total sum, if not equal 0 return error
- if (totalSum != 0)
- throw new InvalidBundleException("Invalid Bundle Sum");
-
- var bundleFromTrxs = new int[243];
- curl.Squeeze(bundleFromTrxs);
- var bundleFromTxString = Converter.ToTrytes(bundleFromTrxs);
-
- // Check if bundle hash is the same as returned by tx object
- if (!bundleFromTxString.Equals(bundleHash))
- throw new InvalidBundleException("Invalid Bundle Hash");
- // Last tx in the bundle should have currentIndex === lastIndex
- bundle.Length = bundle.Transactions.Count;
- if (
- !bundle.Transactions[bundle.Length - 1].CurrentIndex.Equals(
- bundle.Transactions[bundle.Length - 1].LastIndex))
- throw new InvalidBundleException("Invalid Bundle");
-
- // Validate the signatures
- foreach (var aSignaturesToValidate in signaturesToValidate)
- {
- var signatureFragments = aSignaturesToValidate.SignatureFragments.ToArray();
- var address = aSignaturesToValidate.Address;
- var isValidSignature = new Signing().ValidateSignatures(address, signatureFragments, bundleHash);
-
- if (!isValidSignature)
- throw new InvalidSignatureException();
- }
-
- return bundle;
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public AccountData GetAccountData(String seed, int security, int index, bool checksum, int total,
- bool returnAll, int start, int end, bool inclusionStates, long threshold)
- {
-
- if (start > end || end > (start + 1000))
- {
- throw new ArgumentException("Invalid input provided.");
- }
-
- var addresses = GetNewAddress(seed, security, index, checksum, total, returnAll);
- var bundle = GetTransfers(seed, security, start, end, inclusionStates);
- var inputs = GetInputs(seed, security, start, end, threshold);
-
- return new AccountData(new List(addresses), bundle, inputs.InputsList, inputs.TotalBalance);
- }
-
- ///
- /// Wrapper function that broadcasts and stores the specified trytes
- ///
- /// trytes
- public void BroadcastAndStore(List trytes)
- {
- BroadcastTransactions(trytes);
- StoreTransactions(trytes);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public List InitiateTransfer(
- int securitySum, string inputAddress, string remainderAddress,
- List transfers, bool testMode)
- {
- // validate input address
- if (!InputValidator.IsAddress(inputAddress))
- throw new ArgumentException("Invalid addresses provided.");
-
- // validate remainder address
- if (remainderAddress != null && !InputValidator.IsAddress(remainderAddress))
- {
- throw new ArgumentException("Invalid addresses provided.");
- }
-
- // Input validation of transfers object
- if (!InputValidator.IsTransfersCollectionValid(transfers))
- {
- throw new ArgumentException("Invalid transfers provided.");
- }
-
- // Create a new bundle
- Bundle bundle = new Bundle();
-
- long totalValue = 0;
- List signatureFragments = new List();
- String tag = "";
- //
-
- // Iterate over all transfers, get totalValue
- // and prepare the signatureFragments, message and tag
- foreach (Transfer transfer in transfers)
- {
-
- // remove the checksum of the address if provided
- if (transfer.Address.IsValidChecksum())
- {
- transfer.Address = transfer.Address.RemoveChecksum();
- }
-
- int signatureMessageLength = 1;
-
- // If message longer than 2187 trytes, increase signatureMessageLength (add next transaction)
- if (transfer.Message.Length > Constants.MessageLength)
- {
-
- // Get total length, message / maxLength (2187 trytes)
- signatureMessageLength += (int)Math.Floor((double)transfer.Message.Length / Constants.MessageLength);
-
- String msgCopy = transfer.Message;
-
- // While there is still a message, copy it
-
- while (!string.IsNullOrEmpty(msgCopy))
- {
-
- string fragment = msgCopy.Substring(0, Constants.MessageLength);
- msgCopy = msgCopy.Substring(Constants.MessageLength, msgCopy.Length - Constants.MessageLength);
-
- // Pad remainder of fragment
- fragment = fragment.PadRight(Constants.MessageLength, '9');
-
-
- signatureFragments.Add(fragment);
- }
-
- }
- else
- {
-
- // Else, get single fragment with 2187 of 9's trytes
- String fragment = transfer.Message;
-
- if (transfer.Message.Length < Constants.MessageLength)
- {
- fragment = fragment.PadRight(Constants.MessageLength, '9');
- }
-
- signatureFragments.Add(fragment);
-
- }
-
- tag = transfer.Tag;
-
- // pad for required 27 tryte length
- if (transfer.Tag.Length < Constants.TagLength)
- {
- tag = tag.PadRight(Constants.TagLength, '9');
- }
-
- // get current timestamp in seconds
- long timestamp = (long)Math.Floor(GetCurrentTimestampInSeconds());
-
- // Add first entry to the bundle
- bundle.AddEntry(signatureMessageLength, transfer.Address, transfer.Value, tag, timestamp);
- // Sum up total value
- totalValue += transfer.Value;
- }
-
- // Get inputs if we are sending tokens
- if (totalValue != 0)
- {
- GetBalancesResponse balancesResponse = GetBalances(new List { inputAddress }, 100);
- var balances = balancesResponse.Balances;
-
- long totalBalance = 0;
-
- foreach (var balance in balances)
- {
- totalBalance += balance;
- }
-
- // get current timestamp in seconds
- long timestamp = (long)Math.Floor(GetCurrentTimestampInSeconds());
-
- // bypass the balance checks during unit testing
- if (testMode)
- totalBalance += 1000;
-
- if (totalBalance > 0)
- {
-
- long toSubtract = 0 - totalBalance;
-
- // Add input as bundle entry
- // Only a single entry, signatures will be added later
- bundle.AddEntry(securitySum, inputAddress, toSubtract, tag, timestamp);
- }
- // Return not enough balance error
- if (totalValue > totalBalance)
- {
- throw new IllegalStateException("Not enough balance.");
- }
-
- // If there is a remainder value
- // Add extra output to send remaining funds to
- if (totalBalance > totalValue)
- {
-
- long remainder = totalBalance - totalValue;
-
- // Remainder bundle entry if necessary
- if (remainderAddress == null)
- {
- throw new IllegalStateException("No remainder address defined.");
- }
-
- bundle.AddEntry(1, remainderAddress, remainder, tag, timestamp);
- }
-
- bundle.FinalizeBundle(new Curl(CurlMode.CurlP81));
- bundle.AddTrytes(signatureFragments);
-
- return bundle.Transactions;
- }
- else
- {
- throw new System.Exception("Invalid value transfer: the transfer does not require a signature.");
- }
- }
-
- private Bundle TraverseBundle(string trunkTransaction, string bundleHash, Bundle bundle)
- {
- var gtr = GetTrytes(trunkTransaction);
-
- if (gtr.Trytes.Count == 0)
- throw new InvisibleBundleTransactionException();
-
- var trytes = gtr.Trytes[0];
-
- var transaction = new Transaction(trytes, _curl);
-
- // If first transaction to search is not a tail, return error
- if (bundleHash == null && transaction.CurrentIndex != 0) throw new InvalidTailTransactionException();
-
- // If no bundle hash, define it
- if (bundleHash == null) bundleHash = transaction.Bundle;
-
- // If different bundle hash, return with bundle
- if (bundleHash != transaction.Bundle) return bundle;
-
- // If only one bundle element, return
- if (transaction.LastIndex == 0 && transaction.CurrentIndex == 0)
- return new Bundle(new List { transaction }, 1);
-
- // Define new trunkTransaction for search
- var trunkTx = transaction.TrunkTransaction;
-
- // Add transaction object to bundle
- bundle.Transactions.Add(transaction);
-
- // Continue traversing with new trunkTx
- return TraverseBundle(trunkTx, bundleHash, bundle);
- }
-
- private double GetCurrentTimestampInSeconds()
- {
- DateTime now = DateTime.UtcNow;
- DateTime epoch = new DateTime
- (1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-
- return (now - epoch).TotalSeconds;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Model/AccountData.cs b/IotaCSharpApi/Api/Model/AccountData.cs
deleted file mode 100644
index 2a7c296..0000000
--- a/IotaCSharpApi/Api/Model/AccountData.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Model
-{
- ///
- ///
- ///
- public class AccountData
- {
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public AccountData(List addresses,
- Bundle[] transferBundle, List inputList, long totalBalance)
- {
- Addresses = addresses;
- TransferBundle = transferBundle;
- InputList = inputList;
- TotalBalance = totalBalance;
- }
-
- ///
- ///
- ///
- public List Addresses { get; set; }
-
- ///
- ///
- ///
- public Bundle[] TransferBundle { get; set; }
-
- ///
- ///
- ///
- public List InputList { get; set; }
-
- ///
- ///
- ///
- public long TotalBalance { get; set; }
- }
-}
diff --git a/IotaCSharpApi/Api/Model/Input.cs b/IotaCSharpApi/Api/Model/Input.cs
deleted file mode 100644
index a73b95e..0000000
--- a/IotaCSharpApi/Api/Model/Input.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Model
-{
- ///
- /// This class represents an Input
- ///
- public class Input
- {
- ///
- /// Gets or sets the address.
- ///
- ///
- /// The address.
- ///
- public string Address { get; set; }
-
- ///
- /// Gets or sets the balance.
- ///
- ///
- /// The balance.
- ///
- public long Balance { get; set; }
-
- ///
- /// Gets or sets the index of the key.
- ///
- ///
- /// The index of the key.
- ///
- public int KeyIndex { get; set; }
-
- ///
- /// Get or sets the security.
- ///
- ///
- /// The security.
- ///
- public int Security { get; set; }
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Address)}: {Address}, {nameof(Balance)}: {Balance}, {nameof(KeyIndex)}: {KeyIndex}, {nameof(Security)}: {Security}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Model/Inputs.cs b/IotaCSharpApi/Api/Model/Inputs.cs
deleted file mode 100644
index 52041a7..0000000
--- a/IotaCSharpApi/Api/Model/Inputs.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Iota.Lib.CSharp.Api.Model
-{
- ///
- /// This class represents the Inputs
- ///
- public class Inputs
- {
- ///
- /// Gets or sets the inputs list.
- ///
- ///
- /// The inputs list.
- ///
- public List InputsList { get; set; }
-
- ///
- /// Gets or sets the total balance.
- ///
- ///
- /// The total balance.
- ///
- public long TotalBalance { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return
- $"Inputs:\n {string.Join(",", InputsList.Select(i => "[" + i + "]" + "\n"))}{nameof(TotalBalance)}: {TotalBalance}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Model/Neighbor.cs b/IotaCSharpApi/Api/Model/Neighbor.cs
deleted file mode 100644
index 6fefe2f..0000000
--- a/IotaCSharpApi/Api/Model/Neighbor.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Model
-{
- ///
- /// This class represents a neigbhor
- ///
- public class Neighbor
- {
- ///
- /// Gets or sets the address.
- ///
- ///
- /// The address.
- ///
- public string Address { get; set; }
-
- ///
- /// Gets or sets the number of all transactions.
- ///
- ///
- /// The number of all transactions.
- ///
- public long NumberOfAllTransactions { get; set; }
-
- ///
- /// Gets or sets the number of invalid transactions.
- ///
- ///
- /// The number of invalid transactions.
- ///
- public long NumberOfInvalidTransactions { get; set; }
-
- ///
- /// Gets or sets the number of new transactions.
- ///
- ///
- /// The number of new transactions.
- ///
- public long NumberOfNewTransactions { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Address)}: {Address}, {nameof(NumberOfAllTransactions)}: {NumberOfAllTransactions}, {nameof(NumberOfInvalidTransactions)}: {NumberOfInvalidTransactions}, {nameof(NumberOfNewTransactions)}: {NumberOfNewTransactions}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Model/Signature.cs b/IotaCSharpApi/Api/Model/Signature.cs
deleted file mode 100644
index 75dbdec..0000000
--- a/IotaCSharpApi/Api/Model/Signature.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Model
-{
- ///
- /// Thic class represents a signature
- ///
- public class Signature
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public Signature()
- {
- SignatureFragments = new List();
- }
-
- ///
- /// Gets or sets the address.
- ///
- ///
- /// The address.
- ///
- public string Address { get; set; }
-
- ///
- /// Gets or sets the signature fragments.
- ///
- ///
- /// The signature fragments.
- ///
- public List SignatureFragments { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Address)}: {Address}, {nameof(SignatureFragments)}: {string.Join(",", SignatureFragments)}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Model/Transaction.cs b/IotaCSharpApi/Api/Model/Transaction.cs
deleted file mode 100644
index 761ca29..0000000
--- a/IotaCSharpApi/Api/Model/Transaction.cs
+++ /dev/null
@@ -1,267 +0,0 @@
-using System;
-using Iota.Lib.CSharp.Api.Pow;
-using Iota.Lib.CSharp.Api.Utils;
-
-namespace Iota.Lib.CSharp.Api.Model
-{
- ///
- /// This class represents an iota transaction
- ///
- public class Transaction
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public Transaction()
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The trytes representing the transaction
- /// The curl implementation.
- ///
- /// trytes must non-null
- /// or
- /// position " + i + "must not be '9'
- ///
- public Transaction(string trytes, ICurl curl)
- {
- if (string.IsNullOrEmpty(trytes)) throw new ArgumentException("trytes must non-null");
-
- // validity check
- for (var i = 2279; i < 2295; i++)
- if (trytes[i] != '9')
- throw new ArgumentException("position " + i + "must not be '9'");
-
- var transactionTrits = Converter.ToTrits(trytes);
- var hash = new int[243];
-
- // generate the correct transaction hash
- curl.Reset();
- curl.Absorb(transactionTrits, 0, transactionTrits.Length);
- curl.Squeeze(hash, 0, hash.Length);
-
- Hash = Converter.ToTrytes(hash);
- SignatureMessageFragment = trytes.Substring(0, 2187);
- Address = trytes.Substring(2187, 2268 - 2187);
- Value = Converter.ToLongValue(ArrayUtils.SubArray(transactionTrits, 6804, 6837));
- ObsoleteTag = trytes.Substring(2295, 2322 - 2295);
- Timestamp = Converter.ToLongValue(ArrayUtils.SubArray(transactionTrits, 6966, 6993));
- CurrentIndex = Converter.ToLongValue(ArrayUtils.SubArray(transactionTrits, 6993, 7020));
- LastIndex = Converter.ToLongValue(ArrayUtils.SubArray(transactionTrits, 7020, 7047));
- Bundle = trytes.Substring(2349, 2430 - 2349);
- TrunkTransaction = trytes.Substring(2430, 2511 - 2430);
- BranchTransaction = trytes.Substring(2511, 2592 - 2511);
- Tag = trytes.Substring(2592, 2619 - 2592);
- AttachmentTimestamp = Converter.ToLongValue(ArrayUtils.SubArray(transactionTrits, 7857, 7884));
- AttachmentTimestampLowerBound = Converter.ToLongValue(ArrayUtils.SubArray(transactionTrits, 7884, 7911));
- AttachmentTimestampUpperBound = Converter.ToLongValue(ArrayUtils.SubArray(transactionTrits, 7911, 7938));
- Nonce = trytes.Substring(2646, 2673 - 2646);
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The trytes representing the transaction
- public Transaction(string trytes) : this(trytes, new Curl(CurlMode.CurlP81))
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The address.
- /// The value.
- /// The tag.
- /// The timestamp.
- public Transaction(string address, long value, string tag, long timestamp)
- {
- Address = address;
- Value = value;
- Tag = tag;
- ObsoleteTag = tag;
- Timestamp = timestamp;
- }
-
- ///
- /// Gets or sets the hash.
- ///
- ///
- /// The hash.
- ///
- public string Hash { get; set; }
-
- ///
- /// Gets or sets the signature fragment.
- ///
- ///
- /// The signature fragment.
- ///
- public string SignatureMessageFragment { get; set; }
-
- ///
- /// Gets or sets the address.
- ///
- ///
- /// The address.
- ///
- public string Address { get; set; }
-
- ///
- /// Gets or sets the value.
- ///
- ///
- /// The value.
- ///
- public long Value { get; set; }
-
- ///
- /// Gets or sets the tag.
- ///
- ///
- /// The tag.
- ///
- public string ObsoleteTag { get; set; }
-
- ///
- /// Gets or sets the timestamp.
- ///
- ///
- /// The timestamp.
- ///
- public long Timestamp { get; set; }
-
- ///
- /// Gets or sets the index of the current.
- ///
- ///
- /// The index of the current.
- ///
- public long CurrentIndex { get; set; }
-
- ///
- /// Gets or sets the last index.
- ///
- ///
- /// The last index.
- ///
- public long LastIndex { get; set; }
-
- ///
- /// Gets or sets the bundle.
- ///
- ///
- /// The bundle.
- ///
- public string Bundle { get; set; }
-
- ///
- /// Gets or sets the trunk transaction.
- ///
- ///
- /// The trunk transaction.
- ///
- public string TrunkTransaction { get; set; }
-
- ///
- /// Gets or sets the branch transaction.
- ///
- ///
- /// The branch transaction.
- ///
- public string BranchTransaction { get; set; }
-
- ///
- ///
- public string Tag { get; set; }
-
- ///
- ///
- public long AttachmentTimestamp { get; set; }
-
- ///
- ///
- public long AttachmentTimestampLowerBound { get; set; }
-
- ///
- ///
- public long AttachmentTimestampUpperBound { get; set; }
-
- ///
- /// Gets or sets the nonce.
- ///
- ///
- /// The nonce.
- ///
- public string Nonce { get; set; }
-
-
- ///
- /// Gets or sets a value indicating whether this is persistance.
- ///
- ///
- /// true if persistance; otherwise, false.
- ///
- public bool Persistance { get; set; }
-
- ///
- /// Converts the transaction to the corresponding trytes representation
- ///
- ///
- public string ToTransactionTrytes()
- {
- var valueTrits = Converter.ToTrits(Value, 81);
- var timestampTrits = Converter.ToTrits(Timestamp, 27);
- var currentIndexTrits = Converter.ToTrits(CurrentIndex, 27);
- var lastIndexTrits = Converter.ToTrits(LastIndex, 27);
- var attachmentTimestampTrits = Converter.ToTrits(AttachmentTimestamp, 27);
- var attachmentTimestampLowerBoundTrits = Converter.ToTrits(AttachmentTimestampLowerBound, 27);
- var attachmentTimestampUpperBoundTrits = Converter.ToTrits(AttachmentTimestampUpperBound, 27);
-
- if (string.IsNullOrEmpty(Tag))
- Tag = ObsoleteTag;
-
- return SignatureMessageFragment
- + Address
- + Converter.ToTrytes(valueTrits)
- + ObsoleteTag
- + Converter.ToTrytes(timestampTrits)
- + Converter.ToTrytes(currentIndexTrits)
- + Converter.ToTrytes(lastIndexTrits)
- + Bundle
- + TrunkTransaction
- + BranchTransaction
- + Tag
- + Converter.ToTrytes(attachmentTimestampTrits)
- + Converter.ToTrytes(attachmentTimestampLowerBoundTrits)
- + Converter.ToTrytes(attachmentTimestampUpperBoundTrits)
- + Nonce;
- }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return
- $@"{nameof(Value)}: {Value},
-{nameof(Persistance)}: {Value},
-{nameof(Tag)}: {Tag},
-{nameof(Hash)}: {Hash},
-{nameof(SignatureMessageFragment)}: {SignatureMessageFragment},
-{nameof(Address)}: {Address},
-{nameof(Timestamp)}: {Timestamp},
-{nameof(Bundle)}: {Bundle},
-{nameof(TrunkTransaction)}: {TrunkTransaction},
-{nameof(BranchTransaction)}: {BranchTransaction},
-{nameof(LastIndex)}: {LastIndex},
-{nameof(CurrentIndex)}: {CurrentIndex},
-{nameof(Nonce)}: {Nonce}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Model/Transfer.cs b/IotaCSharpApi/Api/Model/Transfer.cs
deleted file mode 100644
index 46bb1d3..0000000
--- a/IotaCSharpApi/Api/Model/Transfer.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Model
-{
- ///
- /// This class represents a Transfer
- ///
- public class Transfer
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// The address.
- /// The value.
- /// The message.
- /// The tag.
- public Transfer(string address, long value, string message, string tag)
- {
- Address = address;
- Value = value;
- Message = message;
- Tag = tag;
- }
-
- ///
- /// Gets or sets the address.
- ///
- ///
- /// The address.
- ///
- public string Address { get; set; }
-
- ///
- /// Gets or sets the hash.
- ///
- ///
- /// The hash.
- ///
- public string Hash { get; set; }
-
- ///
- /// Gets or sets the persistence.
- ///
- ///
- /// The persistence.
- ///
- public int Persistence { get; set; }
-
- ///
- /// Gets or sets the timestamp.
- ///
- ///
- /// The timestamp.
- ///
- public string Timestamp { get; set; }
-
- ///
- /// Gets or sets the value.
- ///
- ///
- /// The value.
- ///
- public long Value { get; set; }
-
- ///
- /// Gets or sets the message.
- ///
- ///
- /// The message.
- ///
- public string Message { get; set; }
-
- ///
- /// Gets or sets the tag.
- ///
- ///
- /// The tag.
- ///
- public string Tag { get; set; }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return $"{nameof(Address)}: {Address}, {nameof(Hash)}: {Hash}, {nameof(Message)}: {Message}, {nameof(Persistence)}: {Persistence}, {nameof(Tag)}: {Tag}, {nameof(Timestamp)}: {Timestamp}, {nameof(Value)}: {Value}";
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Pow/Curl.cs b/IotaCSharpApi/Api/Pow/Curl.cs
deleted file mode 100644
index 090750b..0000000
--- a/IotaCSharpApi/Api/Pow/Curl.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-using System;
-using System.ComponentModel;
-using Iota.Lib.CSharp.Api.Utils;
-
-namespace Iota.Lib.CSharp.Api.Pow
-{
- ///
- /// (c) 2016 Come-from-Beyond
- /// Curl belongs to the sponge function family.
- ///
- public class Curl : Sponge
- {
- private const int StateLength = 3 * HashLength;
-
- private const int NumberOfRoundsP81 = 81;
- private const int NumberOfRoundsP27 = 27;
-
- private static readonly int[] TruthTable = {1, 0, -1, 2, 1, -1, 0, 2, -1, 1, 0};
- private readonly int _numberOfRounds;
- private readonly int[] _scratchpad = new int[StateLength];
- private readonly long[] _stateHigh;
- private readonly long[] _stateLow;
-
- ///
- ///
- ///
- ///
- ///
- public Curl(bool pair, CurlMode mode)
- {
- switch (mode)
- {
- case CurlMode.CurlP27:
- _numberOfRounds = NumberOfRoundsP27;
- break;
- case CurlMode.CurlP81:
- _numberOfRounds = NumberOfRoundsP81;
- break;
- default:
- throw new InvalidEnumArgumentException("Only Curl-P-27 and Curl-P-81 are supported.");
- }
-
- if (pair)
- {
- _stateHigh = new long[StateLength];
- _stateLow = new long[StateLength];
- State = null;
- Set();
- }
- else
- {
- State = new int[StateLength];
- _stateHigh = null;
- _stateLow = null;
- }
- }
-
- ///
- ///
- ///
- ///
- public Curl(CurlMode mode)
- {
- switch (mode)
- {
- case CurlMode.CurlP27:
- _numberOfRounds = NumberOfRoundsP27;
- break;
- case CurlMode.CurlP81:
- _numberOfRounds = NumberOfRoundsP81;
- break;
- default:
- throw new InvalidEnumArgumentException("Only Curl-P-27 and Curl-P-81 are supported.");
- }
-
- State = new int[StateLength];
- _stateHigh = null;
- _stateLow = null;
- }
-
- ///
- /// Gets or sets the state.
- ///
- ///
- /// The state.
- ///
- public int[] State { get; set; }
-
- ///
- /// Absorbs the specified trits.
- ///
- /// The trits.
- /// The offset to start from.
- /// The length.
- /// the ICurl instance (used for method chaining)
- public override void Absorb(int[] trits, int offset, int length)
- {
- do
- {
- Array.Copy(trits, offset, State, 0, length < HashLength ? length : HashLength);
- Transform();
- offset += HashLength;
- } while ((length -= HashLength) > 0);
- }
-
- private void Transform()
- {
- var scratchpadIndex = 0;
-
- for (var round = 0; round < _numberOfRounds; round++)
- {
- Array.Copy(State, 0, _scratchpad, 0, StateLength);
- for (var stateIndex = 0; stateIndex < StateLength; stateIndex++)
- {
- var prevScratchpadIndex = scratchpadIndex;
- if (scratchpadIndex < 365)
- scratchpadIndex += 364;
- else
- scratchpadIndex += -365;
-
- State[stateIndex] =
- TruthTable[
- _scratchpad[prevScratchpadIndex]
- + (_scratchpad[scratchpadIndex] << 2)
- + 5];
- }
- }
- }
-
- ///
- /// Resets this state.
- ///
- ///
- /// the ICurl instance (used for method chaining)
- ///
- public override void Reset()
- {
- for (var stateIndex = 0; stateIndex < StateLength; stateIndex++) State[stateIndex] = 0;
- }
-
- ///
- ///
- ///
- ///
- public void Reset(bool pair)
- {
- if (pair)
- Set();
- else
- Reset();
- }
-
- ///
- /// Squeezes the specified trits.
- ///
- /// The trits.
- /// The offset to start from.
- /// The length.
- ///
- /// the squeezed trits
- ///
- public override void Squeeze(int[] trits, int offset, int length)
- {
- do
- {
- Array.Copy(State, 0, trits, offset, length < HashLength ? length : HashLength);
- Transform();
- offset += HashLength;
- } while ((length -= HashLength) > 0);
- }
-
- ///
- /// Clones this instance.
- ///
- /// a new instance
- public override ICurl Clone()
- {
- return new Curl(CurlMode.CurlP81);
- }
-
- ///
- ///
- ///
- ///
- ///
- public void Absorb(Tuple pair, int offset, int length)
- {
- int o = offset, l = length;
- do
- {
- Array.Copy(pair.Item1, o, _stateLow, 0, l < HashLength ? l : HashLength);
- Array.Copy(pair.Item2, o, _stateHigh, 0, l < HashLength ? l : HashLength);
-
- PairTransform();
- o += HashLength;
- } while ((l -= HashLength) > 0);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- public Tuple Squeeze(Tuple pair, int offset, int length)
- {
- int o = offset, l = length;
- var low = pair.Item1;
- var hi = pair.Item2;
- do
- {
- Array.Copy(_stateLow, 0, low, o, l < HashLength ? l : HashLength);
- Array.Copy(_stateHigh, 0, hi, o, l < HashLength ? l : HashLength);
-
- PairTransform();
- o += HashLength;
- } while ((l -= HashLength) > 0);
-
- return new Tuple(low, hi);
- }
-
- #region Private
-
- private void Set()
- {
- for (var i = 0; i < _stateLow.Length; i++) _stateLow[i] = (long) Converter.HIGH_LONG_BITS;
-
- for (var i = 0; i < _stateHigh.Length; i++) _stateHigh[i] = (long) Converter.HIGH_LONG_BITS;
- }
-
- private void PairTransform()
- {
- var curlScratchpadLow = new long[StateLength];
- var curlScratchpadHigh = new long[StateLength];
- var curlScratchpadIndex = 0;
- for (var round = _numberOfRounds; round-- > 0;)
- {
- Array.Copy(_stateLow, 0, curlScratchpadLow, 0, StateLength);
- Array.Copy(_stateHigh, 0, curlScratchpadHigh, 0, StateLength);
- for (var curlStateIndex = 0; curlStateIndex < StateLength; curlStateIndex++)
- {
- var alpha = curlScratchpadLow[curlScratchpadIndex];
- var beta = curlScratchpadHigh[curlScratchpadIndex];
- var gamma = curlScratchpadHigh[curlScratchpadIndex += curlScratchpadIndex < 365 ? 364 : -365];
- var delta = (alpha | ~gamma) & (curlScratchpadLow[curlScratchpadIndex] ^ beta);
- _stateLow[curlStateIndex] = ~delta;
- _stateHigh[curlStateIndex] = (alpha ^ gamma) | delta;
- }
- }
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Pow/CurlMode.cs b/IotaCSharpApi/Api/Pow/CurlMode.cs
deleted file mode 100644
index c41ef13..0000000
--- a/IotaCSharpApi/Api/Pow/CurlMode.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Pow
-{
- ///
- ///
- ///
- public enum CurlMode
- {
- ///
- ///
- ///
- CurlP81,
- ///
- ///
- ///
- CurlP27,
- ///
- ///
- ///
- Kerl
- }
-}
diff --git a/IotaCSharpApi/Api/Pow/ICurl.cs b/IotaCSharpApi/Api/Pow/ICurl.cs
deleted file mode 100644
index 5885e86..0000000
--- a/IotaCSharpApi/Api/Pow/ICurl.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Pow
-{
- ///
- /// This interface abstracts the curl hashing algorithm
- ///
- public interface ICurl
- {
- ///
- /// Absorbs the specified trits.
- ///
- /// The trits.
- /// The offset to start from.
- /// The length.
- /// the ICurl instance (used for method chaining)
- void Absorb(int[] trits, int offset, int length);
-
- ///
- /// Absorbs the specified trits.
- ///
- /// The trits.
- /// the ICurl instance (used for method chaining)
- void Absorb(int[] trits);
-
- ///
- /// Squeezes the specified trits.
- ///
- /// The trits.
- /// The offset to start from.
- /// The length.
- /// the squeezed trits
- void Squeeze(int[] trits, int offset, int length);
-
- ///
- /// Squeezes the specified trits.
- ///
- /// The trits.
- /// the squeezed trits
- void Squeeze(int[] trits);
-
-
- ///
- /// Resets this state.
- ///
- /// the ICurl instance (used for method chaining)
- void Reset();
-
- ///
- ///
- ///
- ///
- ICurl Clone();
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Pow/Kerl.cs b/IotaCSharpApi/Api/Pow/Kerl.cs
deleted file mode 100644
index 84e8349..0000000
--- a/IotaCSharpApi/Api/Pow/Kerl.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-using System;
-using Iota.Lib.CSharp.Api.Exception;
-using Iota.Lib.CSharp.Api.Utils;
-using Org.BouncyCastle.Crypto.Digests;
-
-namespace Iota.Lib.CSharp.Api.Pow
-{
- ///
- ///
- public class Kerl : Sponge
- {
- private const int BitHashLength = 384;
- private const int ByteHashLength = BitHashLength / 8;
-
- private readonly byte[] _byteState;
-
- private readonly KeccakDigest _keccak;
- private readonly int[] _tritState;
-
- ///
- ///
- ///
- public Kerl()
- {
- _keccak = new KeccakDigest(BitHashLength);
- _byteState = new byte[ByteHashLength];
- _tritState = new int[HashLength];
- }
-
- ///
- ///
- ///
- ///
- public override void Reset()
- {
- _keccak.Reset();
- }
-
- ///
- ///
- ///
- ///
- public override ICurl Clone()
- {
- return new Kerl();
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public override void Absorb(int[] trits, int offset, int length)
- {
- if (length % 243 != 0)
- throw new IllegalStateException("Illegal length: " + length);
-
- do
- {
- //copy trits[offset:offset+length]
- Array.Copy(trits, offset, _tritState, 0, HashLength);
-
- //convert to bits
- _tritState[HashLength - 1] = 0;
- FixedBigIntConverter.FromTritsToBytes(_tritState, _byteState);
- //BigIntConverter.BytesFromBigInt(
- // BigIntConverter.BigIntFromTrits(_tritState, 0, HashLength),
- // _byteState, 0, ByteHashLength);
-
- //run keccak
- _keccak.BlockUpdate(_byteState, 0, _byteState.Length);
- offset += HashLength;
- } while ((length -= HashLength) > 0);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public override void Squeeze(int[] trits, int offset, int length)
- {
- if (length % 243 != 0) throw new IllegalStateException("Illegal length: " + length);
-
- do
- {
- _keccak.DoFinal(_byteState, 0);
-
- //convert to trits
- FixedBigIntConverter.FromBytesToTrits(_byteState, _tritState);
- //BigIntConverter.TritsFromBigInt(
- // BigIntConverter.BigIntFromBytes(_byteState, 0, ByteHashLength),
- // _tritState, 0, HashLength);
-
- //copy with offset
- _tritState[HashLength - 1] = 0;
- Array.Copy(_tritState, 0, trits, offset, HashLength);
-
- //calculate hash again
- for (var i = _byteState.Length; i-- > 0;) _byteState[i] = (byte) (_byteState[i] ^ 0xFF);
-
- _keccak.BlockUpdate(_byteState, 0, _byteState.Length);
- offset += HashLength;
- } while ((length -= HashLength) > 0);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Pow/PearlDiverLocalPoW.cs b/IotaCSharpApi/Api/Pow/PearlDiverLocalPoW.cs
deleted file mode 100644
index 77bdc96..0000000
--- a/IotaCSharpApi/Api/Pow/PearlDiverLocalPoW.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-using Iota.Lib.CSharp.Api.Core;
-using Iota.Lib.CSharp.Api.Exception;
-using Iota.Lib.CSharp.Api.Utils;
-
-namespace Iota.Lib.CSharp.Api.Pow
-{
- ///
- ///
- public class PearlDiverLocalPoW : ILocalPoW
- {
- private readonly PearlDiver _pearlDiver = new PearlDiver();
-
- ///
- ///
- ///
- ///
- ///
- ///
- public string PerformPoW(string trytes, int minWeightMagnitude)
- {
- var trits = Converter.ToTrits(trytes);
-
- if (!_pearlDiver.Search(trits, minWeightMagnitude, 0))
- throw new IllegalStateException("PearlDiver search failed");
-
- return Converter.ToTrytes(trits);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Pow/Sponge.cs b/IotaCSharpApi/Api/Pow/Sponge.cs
deleted file mode 100644
index 129419e..0000000
--- a/IotaCSharpApi/Api/Pow/Sponge.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Pow
-{
- ///
- ///
- ///
- public abstract class Sponge : ICurl
- {
-
- ///
- ///
- ///
- public const int HashLength = 243;
-
- ///
- ///
- ///
- ///
- ///
- ///
- public abstract void Absorb(int[] trits, int offset, int length);
-
- ///
- ///
- ///
- ///
- public void Absorb(int[] trits) => Absorb(trits,0,trits.Length);
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public abstract void Squeeze(int[] trits, int offset, int length);
-
- ///
- ///
- ///
- ///
- ///
- public void Squeeze(int[] trits) => Squeeze(trits,0,trits.Length);
-
- ///
- ///
- ///
- ///
- public abstract void Reset();
-
- ///
- ///
- ///
- ///
- public abstract ICurl Clone();
- }
-}
diff --git a/IotaCSharpApi/Api/Utils/ArrayUtils.cs b/IotaCSharpApi/Api/Utils/ArrayUtils.cs
deleted file mode 100644
index d893719..0000000
--- a/IotaCSharpApi/Api/Utils/ArrayUtils.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Iota.Lib.CSharp.Api.Utils
-{
- internal class ArrayUtils
- {
- public static IEnumerable SliceRow(T[,] array, int row)
- {
- for (var i = array.GetLowerBound(1); i <= array.GetUpperBound(1); i++)
- {
- yield return array[row, i];
- }
- }
-
- public static T[] SubArray(T[] data, int startIndex, int endIndex)
- {
- int length = endIndex - startIndex;
- T[] result = new T[endIndex - startIndex];
- Array.Copy(data, startIndex, result, 0, length);
- return result;
- }
-
- public static T[] SubArray2(T[] data, int index, int length)
- {
- T[] result = new T[length];
- Array.Copy(data, index, result, 0, length);
- return result;
- }
- }
-}
diff --git a/IotaCSharpApi/Api/Utils/BigIntConverter.cs b/IotaCSharpApi/Api/Utils/BigIntConverter.cs
deleted file mode 100644
index 298e0b9..0000000
--- a/IotaCSharpApi/Api/Utils/BigIntConverter.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-using System;
-using Org.BouncyCastle.Math;
-
-namespace Iota.Lib.CSharp.Api.Utils
-{
- ///
- ///
- ///
- public class BigIntConverter
- {
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static BigInteger BigIntFromTrits(int[] trits, int offset, int size)
- {
- var value = BigInteger.Zero;
-
- for (var i = size; i-- > 0;)
- value = value.Multiply(BigInteger.ValueOf(Converter.Radix)).Add(BigInteger.ValueOf(trits[offset + i]));
-
- return value;
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static BigInteger BigIntFromBytes(byte[] bytes, int offset, int size)
- {
- return new BigInteger(bytes, offset, size);
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static void TritsFromBigInt(BigInteger value, int[] destination, int offset, int size)
- {
- if (destination.Length - offset < size) throw new ArgumentException("Destination array has invalid size");
-
- var absoluteValue = value.CompareTo(BigInteger.Zero) < 0 ? value.Negate() : value;
- for (var i = 0; i < size; i++)
- {
- var divRemainder = absoluteValue.DivideAndRemainder(BigInteger.ValueOf(Converter.Radix));
- var remainder = divRemainder[1].IntValue;
- absoluteValue = divRemainder[0];
-
- if (remainder > Converter.MaxTritValue)
- {
- remainder = Converter.MinTritValue;
- absoluteValue = absoluteValue.Add(BigInteger.One);
- }
-
- destination[offset + i] = remainder;
- }
-
- if (value.CompareTo(BigInteger.Zero) < 0)
- for (var i = 0; i < size; i++)
- destination[offset + i] = -destination[offset + i];
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static void BytesFromBigInt(BigInteger value, byte[] destination, int offset,int size)
- {
- if (destination.Length - offset < size)
- throw new ArgumentException("Destination array has invalid size.");
-
- var bytes = value.ToByteArray();
- var i = 0;
- while (i + bytes.Length < size) destination[i++] = (byte) ((sbyte) bytes[0] < 0 ? -1 : 0);
-
- for (var j = bytes.Length; j-- > 0;) destination[i++] = bytes[bytes.Length - 1 - j];
- }
- }
-}
diff --git a/IotaCSharpApi/Api/Utils/Checksum.cs b/IotaCSharpApi/Api/Utils/Checksum.cs
deleted file mode 100644
index 964f7a8..0000000
--- a/IotaCSharpApi/Api/Utils/Checksum.cs
+++ /dev/null
@@ -1,86 +0,0 @@
-using Iota.Lib.CSharp.Api.Exception;
-using Iota.Lib.CSharp.Api.Pow;
-
-namespace Iota.Lib.CSharp.Api.Utils
-{
- ///
- /// This class defines utility methods to add/remove the checksum to/from an address
- ///
- public static class Checksum
- {
- ///
- /// Adds the checksum to the specified address
- ///
- /// An address without checksum
- /// The address with the appended checksum
- /// is thrown when an invalid address is provided
- public static string AddChecksum(string address)
- {
- InputValidator.CheckAddress(address);
- var addressWithChecksum = address;
- addressWithChecksum += CalculateChecksum(address);
- return addressWithChecksum;
- }
-
-
- ///
- /// Removes the checksum from the specified address with checksum
- ///
- /// The address with checksum or without checksum.
- /// the specified address without checksum
- /// is thrown when the specified address is not an address with checksum
- public static string RemoveChecksum(this string address)
- {
- if (IsAddressWithChecksum(address)) return GetAddress(address);
-
- if (IsAddressWithoutChecksum(address)) return address;
-
- throw new InvalidAddressException(address);
- }
-
-
- internal static string GetAddress(string addressWithChecksum)
- {
- return addressWithChecksum.Substring(0, Constants.AddressLengthWithoutChecksum);
- }
-
- ///
- /// Determines whether the specified address with checksum has a valid checksum.
- ///
- /// The address with checksum.
- ///
- /// true if the specified address with checksum has a valid checksum [the specified address with checksum];
- /// otherwise, false.
- ///
- public static bool IsValidChecksum(this string addressWithChecksum)
- {
- var addressWithoutChecksum = RemoveChecksum(addressWithChecksum);
- var adressWithRecalculateChecksum = addressWithoutChecksum + CalculateChecksum(addressWithoutChecksum);
- return adressWithRecalculateChecksum.Equals(addressWithChecksum);
- }
-
-
- private static bool IsAddressWithChecksum(string addressWithChecksum)
- {
- return InputValidator.IsAddress(addressWithChecksum) &&
- addressWithChecksum.Length == Constants.AddressLengthWithChecksum;
- }
-
- private static bool IsAddressWithoutChecksum(string address)
- {
- return InputValidator.CheckAddress(address) && address.Length == Constants.AddressLengthWithoutChecksum;
- }
-
- private static string CalculateChecksum(string address)
- {
- // TODO inject curl
- ICurl curl = new Kerl();
- curl.Reset();
- curl.Absorb(Converter.ToTrits(address));
- var checksumTrits = new int[Sponge.HashLength];
- curl.Squeeze(checksumTrits);
- var checksum = Converter.ToTrytes(checksumTrits);
- return checksum.Substring(72, 9);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/Constants.cs b/IotaCSharpApi/Api/Utils/Constants.cs
deleted file mode 100644
index ba1121f..0000000
--- a/IotaCSharpApi/Api/Utils/Constants.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Utils
-{
- ///
- /// This class defines different constants that are used accros the library
- ///
- public static class Constants
- {
- ///
- /// This String contains all possible characters of the tryte alphabet
- ///
- public static readonly string TryteAlphabet = "9ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
- ///
- /// The maximum seed length
- ///
- public static readonly int SeedLengthMax = 81;
-
- ///
- /// This String represents the empty hash consisting of '9'
- ///
- public static readonly string EmptyHash =
- "999999999999999999999999999999999999999999999999999999999999999999999999999999999";
-
- ///
- /// The length of an address without checksum
- ///
- public static readonly int AddressLengthWithoutChecksum = 81;
-
- ///
- /// The address length with checksum
- ///
- public static readonly int AddressLengthWithChecksum = 90;
-
- ///
- /// The length of an message
- ///
- public static int MessageLength = 2187;
- ///
- ///
- ///
- public static int TagLength = 27;
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/Converter.cs b/IotaCSharpApi/Api/Utils/Converter.cs
deleted file mode 100644
index 0625819..0000000
--- a/IotaCSharpApi/Api/Utils/Converter.cs
+++ /dev/null
@@ -1,378 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Iota.Lib.CSharp.Api.Utils
-{
- ///
- /// This class provides a set of utility methods to are used to convert between different formats
- ///
- public class Converter
- {
- // ReSharper disable InconsistentNaming
- ///
- ///
- ///
- public static readonly uint HIGH_INTEGER_BITS = 0xFFFFFFFF;
-
- ///
- ///
- ///
- public static readonly ulong HIGH_LONG_BITS = 0xFFFFFFFFFFFFFFFFL;
- // ReSharper restore InconsistentNaming
-
- ///
- /// The radix
- ///
- public static readonly int Radix = 3;
-
- ///
- /// The maximum trit value
- ///
- public static readonly int MaxTritValue = (Radix - 1) / 2;
-
- ///
- /// The minimum trit value
- ///
- public static readonly int MinTritValue = -MaxTritValue;
-
- ///
- /// The number of trits in a byte
- ///
- public static readonly int NumberOfTritsInAByte = 5;
-
- ///
- /// The number of trits in a tryte
- ///
- public static readonly int NumberOfTritsInATryte = 3;
-
- static readonly int[][] ByteToTritsMappings = new int[243][]; //why 243? max 121
- static readonly int[][] TryteToTritsMappings = new int[27][];
-
- static Converter()
- {
- int[] trits = new int[NumberOfTritsInAByte];
-
- for (int i = 0; i < 243; i++)
- {
- ByteToTritsMappings[i] = new int[NumberOfTritsInAByte];
- ByteToTritsMappings[i] = new int[NumberOfTritsInAByte];
- Array.Copy(trits, ByteToTritsMappings[i], NumberOfTritsInAByte);
- Increment(trits, NumberOfTritsInAByte);
- }
-
- for (int i = 0; i < 27; i++)
- {
- TryteToTritsMappings[i] = new int[NumberOfTritsInATryte];
- Array.Copy(trits, TryteToTritsMappings[i], NumberOfTritsInATryte);
- Increment(trits, NumberOfTritsInATryte);
- }
- }
-
- ///
- /// Converts the specified trits array to bytes
- ///
- /// The trits.
- /// The offset to start from.
- /// The size.
- ///
- public static byte[] ToBytes(int[] trits, int offset, int size)
- {
- byte[] bytes = new byte[(size + NumberOfTritsInAByte - 1) / NumberOfTritsInAByte];
- for (int i = 0; i < bytes.Length; i++)
- {
- int value = 0;
- for (
- int j = (size - i * NumberOfTritsInAByte) < 5
- ? (size - i * NumberOfTritsInAByte)
- : NumberOfTritsInAByte;
- j-- > 0;)
- {
- value = value * Radix + trits[offset + i * NumberOfTritsInAByte + j];
- }
-
- bytes[i] = (byte) value;
- }
-
- return bytes;
- }
-
- ///
- /// Converts the specified trits to trytes
- ///
- /// The trits.
- ///
- public static byte[] ToBytes(int[] trits)
- {
- return ToBytes(trits, 0, trits.Length);
- }
-
- ///
- /// Gets the trits from the specified bytes and stores it into the provided trits array
- ///
- /// The bytes.
- /// The trits.
- public static void GetTrits(sbyte[] bytes, int[] trits)
- {
- int offset = 0;
- for (int i = 0; i < bytes.Length && offset < trits.Length; i++)
- {
- Array.Copy(
- ByteToTritsMappings[bytes[i] < 0 ? (bytes[i] + ByteToTritsMappings.Length) : bytes[i]], 0,
- trits, offset,
- trits.Length - offset < NumberOfTritsInAByte
- ? (trits.Length - offset)
- : NumberOfTritsInAByte);
-
- offset += NumberOfTritsInAByte;
- }
-
- while (offset < trits.Length)
- {
- trits[offset++] = 0;
- }
- }
-
- ///
- /// Converts the specified trinary encoded string into a trits array of the specified length.
- /// If the trytes string results in a shorter then specified trits array, then the remainder is padded we zeroes
- ///
- /// The trytes.
- /// The length.
- /// a trits array
- public static int[] ToTrits(string trytes, int length)
- {
- int[] tritss = ToTrits(trytes);
-
- List tritsList = new List();
-
- foreach (int i in tritss)
- tritsList.Add(i);
-
- while (tritsList.Count < length)
- tritsList.Add(0);
-
- return tritsList.ToArray();
- }
-
-
- ///
- /// Converts the specified trinary encoded trytes string to trits
- ///
- /// The trytes.
- ///
- public static int[] ToTrits(string trytes)
- {
- int[] d = new int[3 * trytes.Length];
- for (int i = 0; i < trytes.Length; i++)
- {
- Array.Copy(TryteToTritsMappings[Constants.TryteAlphabet.IndexOf(trytes[i])], 0, d,
- i * NumberOfTritsInATryte, NumberOfTritsInATryte);
- }
-
- return d;
- }
-
- ///
- ///
- ///
- ///
- ///
- ///
- public static int[] ToTrits(long trytes, int length)
- {
- int[] tritss = ToTrits(trytes);
-
- List tritsList = new List(tritss);
-
- while (tritsList.Count < length)
- tritsList.Add(0);
-
- return tritsList.ToArray();
- }
-
- ///
- ///
- ///
- ///
- ///
- public static int[] ToTrits(long trytes)
- {
- if (trytes == 0)
- return new[] {0};
-
- var tritsList = new List();
-
- while (trytes != 0)
- {
- var remainder = (int) (trytes % Radix);
- trytes /= Radix;
-
- if (remainder > MaxTritValue)
- {
- remainder = MinTritValue;
- trytes += 1;
- }
- else if (remainder < MinTritValue)
- {
- remainder = MaxTritValue;
- trytes -= 1;
- }
-
- tritsList.Add(remainder);
- }
-
- return tritsList.ToArray();
- }
-
- ///
- /// Copies the trits from the input string into the destination array
- ///
- /// The input string
- /// The destination array.
- ///
- public static int[] CopyTrits(string input, int[] destination)
- {
- for (int i = 0; i < input.Length; i++)
- {
- int index = Constants.TryteAlphabet.IndexOf(input[i]);
- destination[i * 3] = TryteToTritsMappings[index][0];
- destination[i * 3 + 1] = TryteToTritsMappings[index][1];
- destination[i * 3 + 2] = TryteToTritsMappings[index][2];
- }
-
- return destination;
- }
-
- ///
- /// Copies the trits in long representation into the destination array
- ///
- /// The value.
- /// The destination array.
- /// The offset from which copying is started.
- /// The size.
- public static void CopyTrits(long value, int[] destination, int offset, int size)
- {
- long absoluteValue = value < 0 ? -value : value;
- for (int i = 0; i < size; i++)
- {
- int remainder = (int) (absoluteValue % Radix);
- absoluteValue /= Radix;
- if (remainder > MaxTritValue)
- {
- remainder = MinTritValue;
- absoluteValue++;
- }
-
- destination[offset + i] = remainder;
- }
-
- if (value < 0)
- {
- for (int i = 0; i < size; i++)
- {
- destination[offset + i] = -destination[offset + i];
- }
- }
- }
-
- ///
- /// Converts the trits array to a trytes string
- ///
- /// The trits.
- /// The offset from which copying is started.
- /// The size.
- /// a trytes string
- public static string ToTrytes(int[] trits, int offset, int size)
- {
- StringBuilder trytes = new StringBuilder();
- for (int i = 0; i < (size + NumberOfTritsInATryte - 1) / NumberOfTritsInATryte; i++)
- {
- int j = trits[offset + i * 3] + trits[offset + i * 3 + 1] * 3 + trits[offset + i * 3 + 2] * 9;
- if (j < 0)
- {
- j += Constants.TryteAlphabet.Length;
- }
-
- trytes.Append(Constants.TryteAlphabet[j]);
- }
-
- return trytes.ToString();
- }
-
- ///
- /// Converts the trits array to a trytes string
- ///
- /// The trits.
- /// a trytes string
- public static string ToTrytes(int[] trits)
- {
- return ToTrytes(trits, 0, trits.Length);
- }
-
- ///
- /// Converts the specified trits array to trytes in integer representation
- ///
- /// The trits.
- /// The offset.
- /// trytes in integer representation
- public static int ToTryteValue(int[] trits, int offset)
- {
- return trits[offset] + trits[offset + 1] * 3 + trits[offset + 2] * 9;
- }
-
- ///
- /// Converts the specified trits to its corresponding integer value
- ///
- /// The trits.
- /// an integer value representing the corresponding trits
- public static int ToValue(int[] trits)
- {
- int value = 0;
-
- for (int i = trits.Length; i-- > 0;)
- {
- value = value * 3 + trits[i];
- }
-
- return value;
- }
-
- ///
- /// Converts the specified trits to its corresponding integer value
- ///
- /// The trits.
- ///
- public static long ToLongValue(int[] trits)
- {
- long value = 0;
-
- for (int i = trits.Length; i-- > 0;)
- {
- value = value * 3 + trits[i];
- }
-
- return value;
- }
-
- ///
- /// Increments the specified trits.
- ///
- /// The trits.
- /// The size.
- public static void Increment(int[] trits, int size)
- {
- for (int i = 0; i < size; i++)
- {
- if (++trits[i] > MaxTritValue)
- {
- trits[i] = MinTritValue;
- }
- else
- {
- break;
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/InputValidator.cs b/IotaCSharpApi/Api/Utils/InputValidator.cs
deleted file mode 100644
index 6956e63..0000000
--- a/IotaCSharpApi/Api/Utils/InputValidator.cs
+++ /dev/null
@@ -1,254 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Text.RegularExpressions;
-using Iota.Lib.CSharp.Api.Exception;
-using Iota.Lib.CSharp.Api.Model;
-using RestSharp.Extensions;
-
-namespace Iota.Lib.CSharp.Api.Utils
-{
- ///
- /// This class provides methods to validate the parameters of different iota API methods
- ///
- public static class InputValidator
- {
- ///
- /// Determines whether the specified string is an adrdress.
- ///
- /// The address.
- ///
- /// true if the specified string is an address; otherwise, false.
- ///
- public static bool IsAddress(string address)
- {
- if (address.Length == Constants.AddressLengthWithoutChecksum ||
- address.Length == Constants.AddressLengthWithChecksum)
- {
- return IsTrytes(address, address.Length);
- }
- return false;
- }
-
- ///
- ///
- ///
- ///
- ///
- public static bool IsHash(string hash)
- {
- return IsTrytes(hash, 81);
- }
-
- ///
- /// Checks whether the specified address is an address and throws and exception if the address is invalid
- ///
- /// address to check
- /// exception which is thrown when the address is invalid
- public static bool CheckAddress(string address)
- {
- if (!IsAddress(address))
- throw new InvalidAddressException(address);
-
- return true;
- }
-
- ///
- /// Determines whether the specified string represents an integer value.
- ///
- /// The value.
- ///
- /// true the specified string represents an integer value; otherwise, false.
- ///
- public static bool IsValue(string value)
- {
- // ReSharper disable once NotAccessedVariable
- long tempValue;
- return long.TryParse(value, out tempValue);
- //return Regex.IsMatch(value, @"^(-){0,1}\d+$");
- }
-
- ///
- /// Determines whether the specified array contains only valid hashes
- ///
- /// The hashes.
- ///
- /// true the specified array contains only valid hashes; otherwise, false.
- ///
- public static bool IsArrayOfHashes(string[] hashes)
- {
- if (hashes == null)
- return false;
-
- foreach (string hash in hashes)
- {
- // Check if address with checksum
- if (hash.Length == 90)
- {
- if (!IsTrytes(hash, 90))
- {
- return false;
- }
- }
- else
- {
- if (!IsTrytes(hash, 81))
- {
- return false;
- }
- }
- }
- return true;
- }
-
- ///
- /// Determines whether the specified string contains only characters from the trytes alphabet (see )
- ///
- /// The trytes.
- /// The length.
- ///
- /// true if the specified trytes are trytes otherwise, false.
- ///
- public static bool IsTrytes(string trytes, int length)
- {
- string regex = "^[9A-Z]{" + (length == 0 ? "0," : length.ToString()) + "}$";
- var regexTrytes = new Regex(regex);
- return regexTrytes.IsMatch(trytes);
- }
-
- ///
- /// Determines whether the specified string array contains only trytes
- ///
- /// The trytes.
- /// The length.
- ///
- /// true if the specified array contains only valid trytes otherwise, false.
- ///
- public static bool IsArrayOfTrytes(string[] trytes, int length )
- {
- return trytes.ToList().TrueForAll(element => IsTrytes(element, length));
- }
-
- ///
- /// Determines whether the specified transfers are valid
- ///
- /// The transfers.
- ///
- /// true if the specified transfers are valid; otherwise, false.
- ///
- public static bool IsTransfersCollectionValid(ICollection transfers)
- {
- foreach (Transfer transfer in transfers)
- {
- if (!IsValidTransfer(transfer))
- {
- return false;
- }
- }
- return true;
- }
-
- ///
- /// Determines whether the specified transfer is valid.
- ///
- /// The transfer.
- ///
- /// true if the specified transfer is valid; otherwise, false.
- ///
- public static bool IsValidTransfer(Transfer transfer)
- {
- if (!IsAddress(transfer.Address))
- {
- return false;
- }
-
- // Check if message is correct trytes of any length
- if (!IsTrytes(transfer.Message, 0))
- {
- return false;
- }
-
- // Check if tag is correct trytes of {0,27} trytes
- return IsTrytes(transfer.Tag, 27);
- }
-
- ///
- /// Checks the specified specified transfers are valid. If not, an exception is thrown.
- ///
- /// The transactions array.
- /// Not a transfer array
- public static void CheckTransferArray(Transfer[] transactionsArray)
- {
- if (!IsTransfersCollectionValid(transactionsArray.ToList()))
- throw new System.Exception("Not a transfer array");
- }
-
- ///
- /// Checks if the seed is valid. If not, an exception is thrown.
- ///
- /// The seed.
- ///
- /// Invalid Seed: Format not in trytes
- /// or
- /// Invalid Seed: Seed too long
- ///
- public static void CheckIfValidSeed(string seed)
- {
- // validate the seed
- if (!IsTrytes(seed, 0))
- {
- throw new IllegalStateException("Invalid Seed: Format not in trytes");
- }
-
- // validate & if needed pad seed
- if (seed.Length > 81)
- {
- throw new IllegalStateException("Invalid Seed: Seed too long");
- }
- }
-
- ///
- /// Pads the seed if necessary.
- ///
- /// The seed.
- ///
- public static string PadSeedIfNecessary(string seed)
- {
- while (seed.Length < Constants.AddressLengthWithoutChecksum) seed += 9;
- return seed;
- }
-
- ///
- /// Checks if the specified array is an array of trytes. If not an exception is thrown.
- ///
- /// The trytes.
- ///
- public static void CheckIfArrayOfTrytes(string[] trytes)
- {
- if(!IsArrayOfTrytes(trytes, 2673))
- throw new InvalidTryteException();
- }
-
- ///
- /// Determines whether the specified string consist only of '9'.
- ///
- /// The trytes.
- /// The length.
- ///
- /// true if the specified string consist only of '9'; otherwise, false.
- ///
- public static bool IsNinesTrytes(string trytes, int length)
- {
- return trytes.Matches("^[9]{" + (length == 0 ? "0," : length.ToString()) + "}$");
- }
-
- ///
- ///
- ///
- ///
- ///
- public static bool IsValidSeed(string seed)
- {
- return IsTrytes(seed, seed.Length);
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/IotaApiUtils.cs b/IotaCSharpApi/Api/Utils/IotaApiUtils.cs
deleted file mode 100644
index 5fa3ecc..0000000
--- a/IotaCSharpApi/Api/Utils/IotaApiUtils.cs
+++ /dev/null
@@ -1,132 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Iota.Lib.CSharp.Api.Model;
-using Iota.Lib.CSharp.Api.Pow;
-
-namespace Iota.Lib.CSharp.Api.Utils
-{
- ///
- ///
- ///
- public class IotaApiUtils
- {
- ///
- /// Generates a new address
- ///
- /// The tryte-encoded seed. It should be noted that this seed is not transferred.
- /// The secuirty level of private key / seed.
- /// The index to start search from. If the index is provided, the generation of the address is not deterministic.
- /// The adds 9-tryte address checksum
- /// The curl instance.
- /// An String with address.
- public static string NewAddress(string seed, int security, int index, bool checksum, ICurl curl)
- {
- if (security < 1)
- throw new ArgumentException("invalid security level provided");
-
- Signing signing = new Signing(curl);
- int[] key = signing.Key(Converter.ToTrits(seed), index, security);
- int[] digests = signing.Digests(key);
- int[] addressTrits = signing.Address(digests);
-
- string address = Converter.ToTrytes(addressTrits);
-
- if (checksum)
- address = Checksum.AddChecksum(address);
-
- return address;
- }
-
- internal static List SignInputsAndReturn(string seed,
- List inputs,
- Bundle bundle,
- List signatureFragments, ICurl curl)
- {
- bundle.FinalizeBundle(curl);
- bundle.AddTrytes(signatureFragments);
-
- // SIGNING OF INPUTS
- //
- // Here we do the actual signing of the inputs
- // Iterate over all bundle transactions, find the inputs
- // Get the corresponding private key and calculate the signatureFragment
- for (int i = 0; i < bundle.Transactions.Count; i++)
- {
- if (bundle.Transactions[i].Value < 0)
- {
- string thisAddress = bundle.Transactions[i].Address;
-
- // Get the corresponding keyIndex of the address
- int keyIndex = 0;
- foreach (Input input in inputs)
- {
- if (input.Address.Equals(thisAddress))
- {
- keyIndex = input.KeyIndex;
- break;
- }
- }
-
- string bundleHash = bundle.Transactions[i].Bundle;
-
- // Get corresponding private key of address
- int[] key = new Signing(curl).Key(Converter.ToTrits(seed), keyIndex, 2);
-
- // First 6561 trits for the firstFragment
- int[] firstFragment = ArrayUtils.SubArray2(key, 0, 6561);
-
- // Get the normalized bundle hash
- int[] normalizedBundleHash = bundle.NormalizedBundle(bundleHash);
-
- // First bundle fragment uses 27 trytes
- int[] firstBundleFragment = ArrayUtils.SubArray2(normalizedBundleHash, 0, 27);
-
- // Calculate the new signatureFragment with the first bundle fragment
- int[] firstSignedFragment = new Signing(curl).SignatureFragment(firstBundleFragment, firstFragment);
-
- // Convert signature to trytes and assign the new signatureFragment
- bundle.Transactions[i].SignatureMessageFragment = Converter.ToTrytes(firstSignedFragment);
-
- // Because the signature is > 2187 trytes, we need to
- // find the second transaction to add the remainder of the signature
- for (int j = 0; j < bundle.Transactions.Count; j++)
- {
- // Same address as well as value = 0 (as we already spent the input)
- if (bundle.Transactions[j].Address.Equals(thisAddress) &&
- bundle.Transactions[j].Value == 0)
- {
- // Use the second 6562 trits
- int[] secondFragment = ArrayUtils.SubArray2(key, 6561, 6561);
-
- // The second 27 to 54 trytes of the bundle hash
- int[] secondBundleFragment = ArrayUtils.SubArray2(normalizedBundleHash, 27, 27);
-
- // Calculate the new signature
- int[] secondSignedFragment = new Signing(curl).SignatureFragment(secondBundleFragment,
- secondFragment);
-
- // Convert signature to trytes and assign it again to this bundle entry
- bundle.Transactions[j].SignatureMessageFragment = (Converter.ToTrytes(secondSignedFragment));
- }
- }
- }
- }
-
- List bundleTrytes = new List();
-
- // Convert all bundle entries into trytes
- foreach (Transaction tx in bundle.Transactions)
- {
- bundleTrytes.Add(tx.ToTransactionTrytes());
- }
-
- bundleTrytes.Reverse();
- return bundleTrytes;
- }
-
- internal static long CreateTimeStampNow()
- {
- return (long) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/IotaUnitConverter.cs b/IotaCSharpApi/Api/Utils/IotaUnitConverter.cs
deleted file mode 100644
index 306a21a..0000000
--- a/IotaCSharpApi/Api/Utils/IotaUnitConverter.cs
+++ /dev/null
@@ -1,73 +0,0 @@
-using System;
-
-namespace Iota.Lib.CSharp.Api.Utils
-{
- ///
- /// This class provides methods to convert Iota to different units
- ///
- public class IotaUnitConverter
- {
- ///
- /// Convert the iota amount
- ///
- /// amount
- /// the source unit e.g. the unit of amount
- /// the target unit
- /// the specified amount in the target unit
- public static double ConvertUnits(long amount, IotaUnits fromUnit, IotaUnits toUnit)
- {
- long amountInSource = (long) (amount*Math.Pow(10, (int) fromUnit));
- return ConvertUnits(amountInSource, toUnit);
- }
-
- private static double ConvertUnits(long amount, IotaUnits toUnit)
- {
- int base10NormalizationExponent = (int) toUnit;
- return (amount/Math.Pow(10, base10NormalizationExponent));
- }
-
- ///
- /// Finds the optimal unit to display the specified amount in
- ///
- /// amount
- /// the optimal IotaUnit
- public static IotaUnits FindOptimalIotaUnitToDisplay(long amount)
- {
- int length = (amount).ToString().Length;
-
- if (amount < 0)
- {
- // do not count "-" sign
- length -= 1;
- }
-
- IotaUnits units = IotaUnits.Iota;
-
- if (length >= 1 && length <= 3)
- {
- units = IotaUnits.Iota;
- }
- else if (length > 3 && length <= 6)
- {
- units = IotaUnits.Kilo;
- }
- else if (length > 6 && length <= 9)
- {
- units = IotaUnits.Mega;
- }
- else if (length > 9 && length <= 12)
- {
- units = IotaUnits.Giga;
- }
- else if (length > 12 && length <= 15)
- {
- units = IotaUnits.Terra;
- }
- else if (length > 15 && length <= 18)
- {
- units = IotaUnits.Peta;
- }
- return units;
- }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/IotaUnits.cs b/IotaCSharpApi/Api/Utils/IotaUnits.cs
deleted file mode 100644
index 8b93120..0000000
--- a/IotaCSharpApi/Api/Utils/IotaUnits.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-namespace Iota.Lib.CSharp.Api.Utils
-{
- ///
- /// Iota Units
- ///
- public enum IotaUnits
- {
- ///
- /// The corresponding value is in iota. Same as 'None' ()
- ///
- Iota = 0,
-
- ///
- /// The corresponding value is in iota. Same as 'Iota' ()
- ///
- None = 0,
-
- ///
- /// 10^3
- ///
- Kilo = 3,
-
- ///
- /// 10^6
- ///
- Mega = 6,
-
- ///
- /// 10^9
- ///
- Giga = 9,
-
- ///
- /// 10^12
- ///
- Terra = 12,
-
- ///
- /// 10^15
- ///
- Peta = 15,
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/Rest/JsonSerializer.cs b/IotaCSharpApi/Api/Utils/Rest/JsonSerializer.cs
deleted file mode 100644
index fab77e9..0000000
--- a/IotaCSharpApi/Api/Utils/Rest/JsonSerializer.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-#region License
-
-// Copyright 2010 John Sheehan
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#endregion
-
-#region Acknowledgements
-
-// Original JsonSerializer contributed by Daniel Crenna (@dimebrain)
-
-#endregion
-
-using System;
-using System.IO;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Serialization;
-using RestSharp.Serializers;
-
-namespace Iota.Lib.CSharp.Api.Utils.Rest
-{
- ///
- /// Default JSON serializer for request bodies
- /// Doesn't currently use the SerializeAs attribute, defers to Newtonsoft's attributes
- ///
- internal class JsonSerializer : ISerializer
- {
- private readonly Newtonsoft.Json.JsonSerializer _serializer;
-
- ///
- /// Default serializer
- ///
- public JsonSerializer()
- {
- ContentType = "application/json";
- _serializer = new Newtonsoft.Json.JsonSerializer
- {
- MissingMemberHandling = MissingMemberHandling.Ignore,
- NullValueHandling = NullValueHandling.Include,
- DefaultValueHandling = DefaultValueHandling.Include
- };
- }
-
- ///
- /// Default serializer with overload for allowing custom Json.NET settings
- ///
- public JsonSerializer(Newtonsoft.Json.JsonSerializer serializer)
- {
- ContentType = "application/json";
- _serializer = serializer;
- }
-
- ///
- /// Serialize the object as JSON
- ///
- /// Object to serialize
- /// JSON as String
- public string Serialize(object obj)
- {
- using (var stringWriter = new StringWriter())
- {
- using (var jsonTextWriter = new JsonTextWriter(stringWriter))
- {
- //jsonTextWriter.Formatting = Formatting.Indented;
- //jsonTextWriter.QuoteChar = '"';
- _serializer.ContractResolver = new LowercaseContractResolver();
-
- _serializer.Serialize(jsonTextWriter, obj);
-
- var result = stringWriter.ToString();
- return result;
- }
- }
- }
-
- public class LowercaseContractResolver : DefaultContractResolver
- {
- protected override string ResolvePropertyName(string name)
- {
- // first letter small to match API naming conventions
- return Char.ToLowerInvariant(name[0]) + name.Substring(1);
- }
- }
-
- ///
- /// Unused for JSON Serialization
- ///
- public string DateFormat { get; set; }
-
- ///
- /// Unused for JSON Serialization
- ///
- public string RootElement { get; set; }
-
- ///
- /// Unused for JSON Serialization
- ///
- public string Namespace { get; set; }
-
- ///
- /// Content type for serialized content
- ///
- public string ContentType { get; set; }
- }
-}
\ No newline at end of file
diff --git a/IotaCSharpApi/Api/Utils/Rest/JsonWebClient.cs b/IotaCSharpApi/Api/Utils/Rest/JsonWebClient.cs
deleted file mode 100644
index 6065da2..0000000
--- a/IotaCSharpApi/Api/Utils/Rest/JsonWebClient.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-using System;
-using System.IO;
-using System.Net;
-using System.Net.Cache;
-using System.Text;
-using Iota.Lib.CSharp.Api.Core;
-using Iota.Lib.CSharp.Api.Exception;
-using Newtonsoft.Json;
-
-namespace Iota.Lib.CSharp.Api.Utils.Rest
-{
- internal class JsonWebClient
- {
- public TResponse GetPOSTResponseSync(Uri uri, string data)
- {
- Console.WriteLine("request: " + data);
-
- HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);
-
- request.ContentType = "application/json";
- request.Accept = "application/json";
- request.Method = "POST";
- request.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
- request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
- request.Headers.Add("X-IOTA-API-Version", "1");
- request.Headers.Add("Origin", "iota.lib.csharp");
- request.Headers.Add("Accept-Language", "de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4 ");
- request.KeepAlive = false;
- request.Timeout = 300000;
- request.ReadWriteTimeout = 300000;
-
- UTF8Encoding encoding = new UTF8Encoding();
- byte[] bytes = encoding.GetBytes(data);
-
- request.ContentLength = bytes.Length;
-
- Stream requestStream = request.GetRequestStream();
- {
- // Send the data.
- requestStream.Write(bytes, 0, bytes.Length);
- }
-
- try
- {
- using (HttpWebResponse response = (HttpWebResponse) request.GetResponse())
- {
- using (Stream stream = response.GetResponseStream())
- {
- StreamReader reader = new StreamReader(stream, Encoding.UTF8);
- string responseString = reader.ReadToEnd();
-
- if (response.StatusCode == HttpStatusCode.OK)
- {
- Console.WriteLine("response: " + responseString);
- return JsonConvert.DeserializeObject(responseString);
- }
-
- throw new IotaApiException(JsonConvert.DeserializeObject(responseString).Error);
- }
- }
- }
- catch (WebException ex)
- {
- Console.WriteLine("catched: " + ex + ex.Message);
-
- using (var stream = ex.Response.GetResponseStream())
- using (var reader = new StreamReader(stream))
- {
- String errorResponse = reader.ReadToEnd();
- throw new IotaApiException(JsonConvert.DeserializeObject(errorResponse).Error);
- }
- }
- }
-
- public void GetPOSTResponseAsync(Uri uri, string data, Action callback)
- {
- HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri);
-
- request.Method = "POST";
- request.ContentType = "application-type/json;charset=utf-8";
-
- UTF8Encoding encoding = new UTF8Encoding();
- byte[] bytes = encoding.GetBytes(data);
-
- request.ContentLength = bytes.Length;
-
- using (Stream requestStream = request.GetRequestStream())
- {
- // Send the data.
- requestStream.Write(bytes, 0, bytes.Length);
- }
-
- request.BeginGetResponse((x) =>
- {
- using (HttpWebResponse response = (HttpWebResponse) request.EndGetResponse(x))
- {
- if (callback != null)
- {
- using (Stream stream = response.GetResponseStream())
- {
- StreamReader reader = new StreamReader(stream, Encoding.UTF8);
- string responseString = reader.ReadToEnd();
- callback(JsonConvert.DeserializeObject