diff --git a/.gitignore b/.gitignore index 2b736b4..74c62fe 100644 --- a/.gitignore +++ b/.gitignore @@ -97,7 +97,7 @@ publish/ # NuGet Packages Directory ## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ +packages/ # Windows Azure Build Output csx diff --git a/.vs/ProjectSettings.json b/.vs/ProjectSettings.json new file mode 100644 index 0000000..f8b4888 --- /dev/null +++ b/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": null +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..b63c7c0 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,8 @@ +{ + "ExpandedNodes": [ + "", + "\\IotaCSharpApi" + ], + "SelectedNode": "\\IotaApi.sln", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config new file mode 100644 index 0000000..4b9bf47 --- /dev/null +++ b/.vs/config/applicationhost.config @@ -0,0 +1,1031 @@ + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite new file mode 100644 index 0000000..d30d288 Binary files /dev/null and b/.vs/slnx.sqlite differ diff --git a/IotaCSharpApi/Api/Core/AddNeighborsRequest.cs b/IotaCSharpApi/Api/Core/AddNeighborsRequest.cs index 08e51bc..95139ba 100644 --- a/IotaCSharpApi/Api/Core/AddNeighborsRequest.cs +++ b/IotaCSharpApi/Api/Core/AddNeighborsRequest.cs @@ -2,13 +2,12 @@ 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 + /// + public class AddNeighborsRequest : IotaRequestBase { /// /// Gets or sets the uris. diff --git a/IotaCSharpApi/Api/Core/AddNeighborsResponse.cs b/IotaCSharpApi/Api/Core/AddNeighborsResponse.cs index 1257e4f..aed7926 100644 --- a/IotaCSharpApi/Api/Core/AddNeighborsResponse.cs +++ b/IotaCSharpApi/Api/Core/AddNeighborsResponse.cs @@ -1,10 +1,9 @@ namespace Iota.Lib.CSharp.Api.Core { - /// /// Response of /// - public class AddNeighborsResponse + public class AddNeighborsResponse : IotaResponseBase { /// /// Gets the number of added neighbors. diff --git a/IotaCSharpApi/Api/Core/AttachToTangleRequest.cs b/IotaCSharpApi/Api/Core/AttachToTangleRequest.cs index d78fa74..170e639 100644 --- a/IotaCSharpApi/Api/Core/AttachToTangleRequest.cs +++ b/IotaCSharpApi/Api/Core/AttachToTangleRequest.cs @@ -1,11 +1,10 @@ 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 + public class AttachToTangleRequest : IotaRequestBase { private const int MinWeightMagnitudeMin = 18; private int _minWeightMagnitude = MinWeightMagnitudeMin; diff --git a/IotaCSharpApi/Api/Core/AttachToTangleResponse.cs b/IotaCSharpApi/Api/Core/AttachToTangleResponse.cs index 6c91c0f..a402961 100644 --- a/IotaCSharpApi/Api/Core/AttachToTangleResponse.cs +++ b/IotaCSharpApi/Api/Core/AttachToTangleResponse.cs @@ -5,7 +5,7 @@ namespace Iota.Lib.CSharp.Api.Core /// /// Response of /// - public class AttachToTangleResponse + public class AttachToTangleResponse : IotaResponseBase { /// /// Gets or sets the trytes. diff --git a/IotaCSharpApi/Api/Core/BroadcastTransactionsRequest.cs b/IotaCSharpApi/Api/Core/BroadcastTransactionsRequest.cs index 0a8b6ec..b96febd 100644 --- a/IotaCSharpApi/Api/Core/BroadcastTransactionsRequest.cs +++ b/IotaCSharpApi/Api/Core/BroadcastTransactionsRequest.cs @@ -5,7 +5,7 @@ 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 + public class BroadcastTransactionsRequest : IotaRequestBase { /// /// Initializes a new instance of the class. diff --git a/IotaCSharpApi/Api/Core/BroadcastTransactionsResponse.cs b/IotaCSharpApi/Api/Core/BroadcastTransactionsResponse.cs index 36d4b39..d690a8b 100644 --- a/IotaCSharpApi/Api/Core/BroadcastTransactionsResponse.cs +++ b/IotaCSharpApi/Api/Core/BroadcastTransactionsResponse.cs @@ -3,7 +3,7 @@ /// /// Response of /// - public class BroadcastTransactionsResponse + public class BroadcastTransactionsResponse : IotaResponseBase { // empty } diff --git a/IotaCSharpApi/Api/Core/EnumHelper.cs b/IotaCSharpApi/Api/Core/EnumHelper.cs index c5b9a41..dda8c6e 100644 --- a/IotaCSharpApi/Api/Core/EnumHelper.cs +++ b/IotaCSharpApi/Api/Core/EnumHelper.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel; +using System.Linq; using System.Reflection; namespace Iota.Lib.CSharp.Api.Core @@ -20,11 +21,11 @@ public static string GetCommandString(this Enum en) MemberInfo[] memInfo = type.GetMember(en.ToString()); - if (memInfo != null && memInfo.Length > 0) + if (memInfo.Any()) { object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); - if (attrs != null && attrs.Length > 0) + if (attrs.Any()) { return ((DescriptionAttribute) attrs[0]).Description; } diff --git a/IotaCSharpApi/Api/Core/ErrorResponse.cs b/IotaCSharpApi/Api/Core/ErrorResponse.cs index c9382c1..c0e55ad 100644 --- a/IotaCSharpApi/Api/Core/ErrorResponse.cs +++ b/IotaCSharpApi/Api/Core/ErrorResponse.cs @@ -1,7 +1,13 @@ namespace Iota.Lib.CSharp.Api.Core { + /// + /// A simple class to hold an error message. + /// internal class ErrorResponse { + /// + /// A string representing the error that occurred. + /// 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 index 1e8ba82..076890f 100644 --- a/IotaCSharpApi/Api/Core/FindTransactionsRequest.cs +++ b/IotaCSharpApi/Api/Core/FindTransactionsRequest.cs @@ -5,7 +5,7 @@ namespace Iota.Lib.CSharp.Api.Core /// /// This class represents the core api request 'FindTransactions' /// - public class FindTransactionsRequest : IotaRequest + public class FindTransactionsRequest : IotaRequestBase { /// /// Initializes a new instance of the class. diff --git a/IotaCSharpApi/Api/Core/FindTransactionsResponse.cs b/IotaCSharpApi/Api/Core/FindTransactionsResponse.cs index c79a844..01e3994 100644 --- a/IotaCSharpApi/Api/Core/FindTransactionsResponse.cs +++ b/IotaCSharpApi/Api/Core/FindTransactionsResponse.cs @@ -5,7 +5,7 @@ namespace Iota.Lib.CSharp.Api.Core /// /// Response of /// - public class FindTransactionsResponse + public class FindTransactionsResponse : IotaResponseBase { /// /// Gets or sets the hashes. diff --git a/IotaCSharpApi/Api/Core/GetBalancesRequest.cs b/IotaCSharpApi/Api/Core/GetBalancesRequest.cs index 3c15f0b..b1cce8c 100644 --- a/IotaCSharpApi/Api/Core/GetBalancesRequest.cs +++ b/IotaCSharpApi/Api/Core/GetBalancesRequest.cs @@ -1,38 +1,38 @@ -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. - /// +using System.Collections.Generic; + +namespace Iota.Lib.CSharp.Api.Core +{ + /// + /// This class represents the core api request 'GetBalances' + /// + public class GetBalancesRequest : IotaRequestBase + { + /// + /// 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; } /// @@ -41,9 +41,9 @@ public GetBalancesRequest(List addresses, long threshold = 100) /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(Threshold)}: {Threshold}, {nameof(Addresses)}: {string.Join(",",Addresses)}"; - } - } + 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 index 81ff472..414059e 100644 --- a/IotaCSharpApi/Api/Core/GetBalancesResponse.cs +++ b/IotaCSharpApi/Api/Core/GetBalancesResponse.cs @@ -5,7 +5,7 @@ namespace Iota.Lib.CSharp.Api.Core /// /// Response of /// - public class GetBalancesResponse : IotaResponse + public class GetBalancesResponse : IotaResponseBase { /// /// Gets or sets the balances. diff --git a/IotaCSharpApi/Api/Core/GetInclusionStatesRequest.cs b/IotaCSharpApi/Api/Core/GetInclusionStatesRequest.cs index 09b100a..f0321ac 100644 --- a/IotaCSharpApi/Api/Core/GetInclusionStatesRequest.cs +++ b/IotaCSharpApi/Api/Core/GetInclusionStatesRequest.cs @@ -3,8 +3,8 @@ /// /// This class represents the core API request 'GetInclusionStates' /// - /// - public class GetInclusionStatesRequest : IotaRequest + /// + public class GetInclusionStatesRequest : IotaRequestBase { /// /// Initializes a new instance of the class. diff --git a/IotaCSharpApi/Api/Core/GetInclusionStatesResponse.cs b/IotaCSharpApi/Api/Core/GetInclusionStatesResponse.cs index f17b50c..a92dda9 100644 --- a/IotaCSharpApi/Api/Core/GetInclusionStatesResponse.cs +++ b/IotaCSharpApi/Api/Core/GetInclusionStatesResponse.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; - -namespace Iota.Lib.CSharp.Api.Core +using System.Collections.Generic; + +namespace Iota.Lib.CSharp.Api.Core { /// /// This class represents the response of /// - /// - public class GetInclusionStatesResponse : IotaResponse + /// + public class GetInclusionStatesResponse : IotaResponseBase { /// /// Gets or sets the states. @@ -14,6 +14,6 @@ public class GetInclusionStatesResponse : IotaResponse /// /// The states. /// - public List States { get; set; } - } + 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 index 2056c79..f7feed0 100644 --- a/IotaCSharpApi/Api/Core/GetNeighborsRequest.cs +++ b/IotaCSharpApi/Api/Core/GetNeighborsRequest.cs @@ -3,8 +3,8 @@ /// /// This class represents the core API request 'GetNeighbors' /// - /// - public class GetNeighborsRequest : IotaRequest + /// + public class GetNeighborsRequest : IotaRequestBase { /// /// Initializes a new instance of the class. diff --git a/IotaCSharpApi/Api/Core/GetNeighborsResponse.cs b/IotaCSharpApi/Api/Core/GetNeighborsResponse.cs index 08448d4..a49c087 100644 --- a/IotaCSharpApi/Api/Core/GetNeighborsResponse.cs +++ b/IotaCSharpApi/Api/Core/GetNeighborsResponse.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; -using Iota.Lib.CSharp.Api.Model; - -namespace Iota.Lib.CSharp.Api.Core -{ - /// - /// Response of - /// - public class GetNeighborsResponse +using System.Collections.Generic; +using Iota.Lib.CSharp.Api.Model; + +namespace Iota.Lib.CSharp.Api.Core +{ + /// + /// Response of + /// + public class GetNeighborsResponse : IotaResponseBase { /// /// Gets or sets the neighbors. @@ -14,6 +14,6 @@ public class GetNeighborsResponse /// /// The neighbors. /// - public List Neighbors { get; set; } - } + 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 index 5445c81..5f88b5d 100644 --- a/IotaCSharpApi/Api/Core/GetNodeInfoRequest.cs +++ b/IotaCSharpApi/Api/Core/GetNodeInfoRequest.cs @@ -3,7 +3,7 @@ /// /// Returns information about your node /// - public class GetNodeInfoRequest : IotaRequest + public class GetNodeInfoRequest : IotaRequestBase { /// /// Initializes a new instance of the class. diff --git a/IotaCSharpApi/Api/Core/GetNodeInfoResponse.cs b/IotaCSharpApi/Api/Core/GetNodeInfoResponse.cs index cad5fd8..a48d98f 100644 --- a/IotaCSharpApi/Api/Core/GetNodeInfoResponse.cs +++ b/IotaCSharpApi/Api/Core/GetNodeInfoResponse.cs @@ -3,8 +3,8 @@ /// /// This class represents the response of /// - /// - public class GetNodeInfoResponse : IotaResponse + /// + public class GetNodeInfoResponse : IotaResponseBase { /// /// Name of the IOTA software you're currently using (IRI stands for Initial Reference Implementation). diff --git a/IotaCSharpApi/Api/Core/GetTipsRequest.cs b/IotaCSharpApi/Api/Core/GetTipsRequest.cs index a08d6ee..65de727 100644 --- a/IotaCSharpApi/Api/Core/GetTipsRequest.cs +++ b/IotaCSharpApi/Api/Core/GetTipsRequest.cs @@ -1,15 +1,15 @@ -namespace Iota.Lib.CSharp.Api.Core -{ - /// - /// This class represents the core API request 'GetTips' - /// - public class GetTipsRequest : IotaRequest +namespace Iota.Lib.CSharp.Api.Core +{ + /// + /// This class represents the core API request 'GetTips' + /// + public class GetTipsRequest : IotaRequestBase { /// /// Initializes a new instance of the class. /// - public GetTipsRequest() : base(Core.Command.GetTips.GetCommandString()) - { - } - } + 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 index 094a7eb..ddcc1c6 100644 --- a/IotaCSharpApi/Api/Core/GetTipsResponse.cs +++ b/IotaCSharpApi/Api/Core/GetTipsResponse.cs @@ -1,18 +1,18 @@ -using System.Collections.Generic; - -namespace Iota.Lib.CSharp.Api.Core -{ +using System.Collections.Generic; + +namespace Iota.Lib.CSharp.Api.Core +{ /// - /// This class represents the response of - /// - public class GetTipsResponse : IotaResponse + /// This class represents the response of + /// + public class GetTipsResponse : IotaResponseBase { - /// - /// Gets or sets the hashes. - /// - /// - /// The hashes. - /// + /// + /// Gets or sets the hashes. + /// + /// + /// The hashes. + /// public List Hashes { get; set; } /// @@ -21,9 +21,9 @@ public class GetTipsResponse : IotaResponse /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(Hashes)}: {string.Join(",", Hashes)}"; - } - } + 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 index 15dc874..dcae4bb 100644 --- a/IotaCSharpApi/Api/Core/GetTransactionsToApproveRequest.cs +++ b/IotaCSharpApi/Api/Core/GetTransactionsToApproveRequest.cs @@ -1,18 +1,18 @@ -namespace Iota.Lib.CSharp.Api.Core -{ - /// - /// This class represents the core API call 'GetTransactionsToApprove' - /// - public class GetTransactionsToApproveRequest : IotaRequest +namespace Iota.Lib.CSharp.Api.Core +{ + /// + /// This class represents the core API call 'GetTransactionsToApprove' + /// + public class GetTransactionsToApproveRequest : IotaRequestBase { - /// - /// Initializes a new instance of the class. - /// - /// The depth. - public GetTransactionsToApproveRequest(int depth) - : base(Core.Command.GetTransactionsToApprove.GetCommandString()) - { - Depth = depth; + /// + /// Initializes a new instance of the class. + /// + /// The depth. + public GetTransactionsToApproveRequest(int depth) + : base(Core.Command.GetTransactionsToApprove.GetCommandString()) + { + Depth = depth; } /// @@ -29,9 +29,9 @@ public GetTransactionsToApproveRequest(int depth) /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(Depth)}: {Depth}"; - } - } + 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 index 5bdca42..67222a2 100644 --- a/IotaCSharpApi/Api/Core/GetTransactionsToApproveResponse.cs +++ b/IotaCSharpApi/Api/Core/GetTransactionsToApproveResponse.cs @@ -1,24 +1,24 @@ -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. - /// +namespace Iota.Lib.CSharp.Api.Core +{ + /// + /// This class represents the response of + /// + public class GetTransactionsToApproveResponse : IotaResponseBase + { + /// + /// 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; } /// @@ -27,9 +27,9 @@ public class GetTransactionsToApproveResponse : IotaResponse /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(TrunkTransaction)}: {TrunkTransaction}, {nameof(BranchTransaction)}: {BranchTransaction}"; - } - } + 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 index 31c13f0..ba0d081 100644 --- a/IotaCSharpApi/Api/Core/GetTrytesRequest.cs +++ b/IotaCSharpApi/Api/Core/GetTrytesRequest.cs @@ -1,16 +1,16 @@ -namespace Iota.Lib.CSharp.Api.Core -{ +namespace Iota.Lib.CSharp.Api.Core +{ /// - /// This class represents the core API request 'GetTrytes' - /// - public class GetTrytesRequest : IotaRequest + /// This class represents the core API request 'GetTrytes' + /// + public class GetTrytesRequest : IotaRequestBase { /// /// Initializes a new instance of the class. /// - public GetTrytesRequest() : base(Core.Command.GetTrytes.GetCommandString()) - { - + public GetTrytesRequest() : base(Core.Command.GetTrytes.GetCommandString()) + { + } /// @@ -27,9 +27,9 @@ public GetTrytesRequest() : base(Core.Command.GetTrytes.GetCommandString()) /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(Hashes)}: {string.Join(",", Hashes)}"; - } - } + 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 index 541f03b..bd7fb68 100644 --- a/IotaCSharpApi/Api/Core/GetTrytesResponse.cs +++ b/IotaCSharpApi/Api/Core/GetTrytesResponse.cs @@ -1,19 +1,19 @@ -using System.Collections.Generic; - -namespace Iota.Lib.CSharp.Api.Core -{ +using System.Collections.Generic; + +namespace Iota.Lib.CSharp.Api.Core +{ /// - /// This class represents the response of - /// - public class GetTrytesResponse + /// This class represents the response of + /// + public class GetTrytesResponse : IotaResponseBase { - /// - /// Gets or sets the trytes. - /// - /// - /// The trytes. - /// + /// + /// Gets or sets the trytes. + /// + /// + /// The trytes. + /// public List Trytes { get; set; } /// @@ -22,9 +22,9 @@ public class GetTrytesResponse /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(Trytes)}: {string.Join(",", Trytes)}"; - } - } + public override string ToString() + { + return $"{nameof(Trytes)}: {string.Join(",", Trytes)}"; + } + } } \ No newline at end of file diff --git a/IotaCSharpApi/Api/Core/InterruptAttachingToTangleRequest.cs b/IotaCSharpApi/Api/Core/InterruptAttachingToTangleRequest.cs index cd204fc..cf90586 100644 --- a/IotaCSharpApi/Api/Core/InterruptAttachingToTangleRequest.cs +++ b/IotaCSharpApi/Api/Core/InterruptAttachingToTangleRequest.cs @@ -1,15 +1,15 @@ -namespace Iota.Lib.CSharp.Api.Core -{ +namespace Iota.Lib.CSharp.Api.Core +{ /// - /// This class represents the core api request 'InterruptAttachingToTangle' - /// - public class InterruptAttachingToTangleRequest : IotaRequest + /// This class represents the core api request 'InterruptAttachingToTangle' + /// + public class InterruptAttachingToTangleRequest : IotaRequestBase { /// /// Initializes a new instance of the class. /// - public InterruptAttachingToTangleRequest() : base(Core.Command.InterruptAttachingToTangle.GetCommandString()) - { - } - } + 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 index ff466db..ad9d5f2 100644 --- a/IotaCSharpApi/Api/Core/InterruptAttachingToTangleResponse.cs +++ b/IotaCSharpApi/Api/Core/InterruptAttachingToTangleResponse.cs @@ -1,11 +1,11 @@ -namespace Iota.Lib.CSharp.Api.Core +namespace Iota.Lib.CSharp.Api.Core { /// /// This class represents the response of /// - /// - public class InterruptAttachingToTangleResponse : IotaResponse - { - - } + /// + public class InterruptAttachingToTangleResponse : IotaResponseBase + { + + } } \ No newline at end of file diff --git a/IotaCSharpApi/Api/Core/IotaRequestBase.cs b/IotaCSharpApi/Api/Core/IotaRequestBase.cs new file mode 100644 index 0000000..8f0c57a --- /dev/null +++ b/IotaCSharpApi/Api/Core/IotaRequestBase.cs @@ -0,0 +1,25 @@ +namespace Iota.Lib.CSharp.Api.Core +{ + /// + /// This class serves as base class for the different core API calls/requests + /// + public abstract class IotaRequestBase + { + /// + /// Initializes a new instance of the class. + /// + /// The command. + public IotaRequestBase(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/IotaResponseBase.cs b/IotaCSharpApi/Api/Core/IotaResponseBase.cs new file mode 100644 index 0000000..6f24c52 --- /dev/null +++ b/IotaCSharpApi/Api/Core/IotaResponseBase.cs @@ -0,0 +1,16 @@ +namespace Iota.Lib.CSharp.Api.Core +{ + /// + /// This class represents the base class of different core API response classes + /// + public abstract class IotaResponseBase + { + /// + /// 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 index b448a9c..e9ec239 100644 --- a/IotaCSharpApi/Api/Core/RemoveNeighborsRequest.cs +++ b/IotaCSharpApi/Api/Core/RemoveNeighborsRequest.cs @@ -5,8 +5,8 @@ namespace Iota.Lib.CSharp.Api.Core /// /// This class represents the core api request 'RemoveNeighbors' /// - /// - public class RemoveNeighborsRequest : IotaRequest + /// + public class RemoveNeighborsRequest : IotaRequestBase { /// /// Initializes a new instance of the class. diff --git a/IotaCSharpApi/Api/Core/RemoveNeighborsResponse.cs b/IotaCSharpApi/Api/Core/RemoveNeighborsResponse.cs index 2dded81..c7686c4 100644 --- a/IotaCSharpApi/Api/Core/RemoveNeighborsResponse.cs +++ b/IotaCSharpApi/Api/Core/RemoveNeighborsResponse.cs @@ -1,16 +1,16 @@ -namespace Iota.Lib.CSharp.Api.Core +namespace Iota.Lib.CSharp.Api.Core { /// /// This class represents the response of /// - public class RemoveNeighborsResponse + public class RemoveNeighborsResponse : IotaResponseBase { - /// - /// Gets or sets the number of removed neighbors. - /// - /// - /// The removed neighbors. - /// + /// + /// Gets or sets the number of removed neighbors. + /// + /// + /// The removed neighbors. + /// public long RemovedNeighbors { get; set; } /// @@ -19,9 +19,9 @@ public class RemoveNeighborsResponse /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(RemovedNeighbors)}: {RemovedNeighbors}"; - } - } + 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 index b015009..47a5b06 100644 --- a/IotaCSharpApi/Api/Core/StoreTransactionsRequest.cs +++ b/IotaCSharpApi/Api/Core/StoreTransactionsRequest.cs @@ -1,28 +1,28 @@ -using System.Collections.Generic; - -namespace Iota.Lib.CSharp.Api.Core -{ - /// +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 + /// It stores transactions into the local storage. The trytes to be used for this call are returned by attachToTangle. + /// + public class StoreTransactionsRequest : IotaRequestBase { /// /// Initializes a new instance of the class. /// /// The trytes. - public StoreTransactionsRequest(List trytes) : base(Core.Command.StoreTransactions.GetCommandString()) - { - this.Trytes = trytes; + public StoreTransactionsRequest(List trytes) : base(Core.Command.StoreTransactions.GetCommandString()) + { + this.Trytes = trytes; } - /// - /// Gets or sets the trytes. - /// - /// - /// The trytes. - /// + /// + /// Gets or sets the trytes. + /// + /// + /// The trytes. + /// public List Trytes { get; set; } /// @@ -31,9 +31,9 @@ public StoreTransactionsRequest(List trytes) : base(Core.Command.StoreTr /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(Trytes)}: {Trytes}"; - } - } + 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 index 6a52d20..be20c62 100644 --- a/IotaCSharpApi/Api/Core/StoreTransactionsResponse.cs +++ b/IotaCSharpApi/Api/Core/StoreTransactionsResponse.cs @@ -1,9 +1,9 @@ -namespace Iota.Lib.CSharp.Api.Core +namespace Iota.Lib.CSharp.Api.Core { /// /// This class represents the response of /// - public class StoreTransactionsResponse - { - } + public class StoreTransactionsResponse : IotaResponseBase + { + } } \ No newline at end of file diff --git a/IotaCSharpApi/Api/Exception/IllegalAccessError.cs b/IotaCSharpApi/Api/Exception/IllegalAccessError.cs index 03825d0..14565a6 100644 --- a/IotaCSharpApi/Api/Exception/IllegalAccessError.cs +++ b/IotaCSharpApi/Api/Exception/IllegalAccessError.cs @@ -6,6 +6,5 @@ /// 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 index 4a547c1..8625415 100644 --- a/IotaCSharpApi/Api/Exception/IllegalStateException.cs +++ b/IotaCSharpApi/Api/Exception/IllegalStateException.cs @@ -1,6 +1,4 @@ -using System; - -namespace Iota.Lib.CSharp.Api.Exception +namespace Iota.Lib.CSharp.Api.Exception { /// /// This exception occurs when an illegal state is encountered diff --git a/IotaCSharpApi/Api/Exception/InvalidTryteException.cs b/IotaCSharpApi/Api/Exception/InvalidTryteException.cs index 79a85ea..30d6fac 100644 --- a/IotaCSharpApi/Api/Exception/InvalidTryteException.cs +++ b/IotaCSharpApi/Api/Exception/InvalidTryteException.cs @@ -5,6 +5,5 @@ /// public class InvalidTryteException : System.Exception { - } } \ No newline at end of file diff --git a/IotaCSharpApi/Api/IotaApi.cs b/IotaCSharpApi/Api/IotaApi.cs index 7029097..0e926db 100644 --- a/IotaCSharpApi/Api/IotaApi.cs +++ b/IotaCSharpApi/Api/IotaApi.cs @@ -33,8 +33,9 @@ public class IotaApi : IotaCoreApi /// 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) { - if(curl == null) + if (curl == null) throw new ArgumentNullException(nameof(curl)); + this.curl = curl; } @@ -56,7 +57,7 @@ public Inputs GetInputs(string seed, int start, int end, long threshold = 100) // If start value bigger than end, return error if (start > end) - throw new ArgumentException("start must be smaller than end", "start"); + 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) @@ -162,17 +163,17 @@ public List PrepareTransfers(string seed, Transfer[] transfers, List 2187) + if (t.Message.Length > 2187) { // Get total length, message / maxLength (2187 trytes) - signatureMessageLength += (int) Math.Floor(((double) transfers[i].Message.Length/2187)); + signatureMessageLength += (int) Math.Floor(((double) t.Message.Length/2187)); - var msgCopy = transfers[i].Message; + var msgCopy = t.Message; // While there is still a message, copy it while (msgCopy != null) @@ -194,10 +195,10 @@ public List PrepareTransfers(string seed, Transfer[] transfers, List PrepareTransfers(string seed, Transfer[] transfers, List PrepareTransfers(string seed, Transfer[] transfers, List PrepareTransfers(string seed, Transfer[] transfers, List AddRemainder(string seed, List inputs, Bundle bundle, string tag, long totalValue, string remainderAddress, List signatureFragments) { @@ -356,7 +356,6 @@ private List AddRemainder(string seed, List inputs, Bundle bundle 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 /// @@ -446,11 +445,9 @@ public Bundle[] GetTransfers(string seed, int? start, int? end, bool inclusionSt // If a transaction is non tail, get the tail transactions associated with it // add it to the list of tail transactions - string[] addresses = GetNewAddress(seed, start.Value, false, - end.HasValue ? end.Value : end.Value - start.Value, true); - - + string[] addresses = GetNewAddress(seed, start.Value, false, end.Value, true); Bundle[] bundles = BundlesFromAddresses(addresses, inclusionStates); + return bundles; } @@ -496,6 +493,7 @@ private Bundle[] BundlesFromAddresses(string[] addresses, bool inclusionStates) // If inclusionStates, get the confirmation status // of the tail transactions, and thus the bundles GetInclusionStatesResponse gisr = null; + if (inclusionStates) { try @@ -506,14 +504,14 @@ private Bundle[] BundlesFromAddresses(string[] addresses, bool inclusionStates) { // suppress exception (the check is done below) } - if (gisr == null || gisr.States == null || gisr.States.Count == 0) + + if (gisr?.States == null || gisr.States.Count == 0) throw new ArgumentException("Inclusion states not found"); } - - + GetInclusionStatesResponse finalInclusionStates = gisr; - Parallel.ForEach(tailTransactions, (param) => + Parallel.ForEach(tailTransactions, param => { try { @@ -521,12 +519,14 @@ private Bundle[] BundlesFromAddresses(string[] addresses, bool inclusionStates) if (inclusionStates) { - bool thisInclusion = finalInclusionStates.States[tailTxArray.ToList().IndexOf(param)]; + bool thisInclusion = finalInclusionStates != null && finalInclusionStates.States[tailTxArray.ToList().IndexOf(param)]; + foreach (Transaction t in b.Transactions) { t.Persistance = thisInclusion; } } + finalBundles.Add(b); } catch (System.Exception ex) @@ -537,10 +537,12 @@ private Bundle[] BundlesFromAddresses(string[] addresses, bool inclusionStates) finalBundles.Sort(); Bundle[] returnValue = new Bundle[finalBundles.Count]; + for (int i = 0; i < finalBundles.Count; i++) { returnValue[i] = new Bundle(finalBundles[i].Transactions, finalBundles[i].Transactions.Count); } + return returnValue; } @@ -552,7 +554,7 @@ private Bundle[] BundlesFromAddresses(string[] addresses, bool inclusionStates) public List FindTransactionObjects(string[] adresses) { FindTransactionsResponse ftr = FindTransactions(adresses.ToList(), null, null, null); - if (ftr == null || ftr.Hashes == null) + if (ftr?.Hashes == null) return null; // get the transaction objects of the transactions @@ -579,6 +581,7 @@ public List GetTransactionsObjects(string[] hashes) { trxs.Add(new Transaction(tryte, curl)); } + return trxs; } @@ -597,7 +600,6 @@ public List FindTransactionObjectsByBundle(string[] bundles) return GetTransactionsObjects(ftr.Hashes.ToArray()); } - /// /// Replays the bundle. /// @@ -607,13 +609,11 @@ public List FindTransactionObjectsByBundle(string[] bundles) /// 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(); - List bundleTrytes = new List(); Bundle bundle = GetBundle(transaction); - bundle.Transactions.ForEach((t) => bundleTrytes.Add(t.ToTransactionTrytes())); + bundle.Transactions.ForEach(t => bundleTrytes.Add(t.ToTransactionTrytes())); List trxs = SendTrytes(bundleTrytes.ToArray(), depth, minWeightMagnitude).ToList(); @@ -648,7 +648,6 @@ public FindTransactionsResponse FindTransactionsByApprovees(params string[] appr return FindTransactions(null, null, approvees.ToList(), null); } - /// /// Finds the transactions by digests. /// @@ -680,7 +679,6 @@ public GetInclusionStatesResponse GetLatestInclusion(string[] hashes) return GetInclusionStates(hashes, latestMilestone); } - /// /// Wrapper function that basically does prepareTransfers, as well as attachToTangle and finally, it broadcasts and stores the transactions locally. /// @@ -702,7 +700,6 @@ public bool[] SendTransfer(string seed, int depth, int minWeightMagnitude, Trans for (int i = 0; i < trxs.Length; i++) { FindTransactionsResponse response = FindTransactionsByBundles(trxs[i].Bundle); - successful[i] = response.Hashes.Count != 0; } @@ -738,6 +735,7 @@ public Transaction[] SendTrytes(string[] trytes, int depth, int minWeightMagnitu { trx.Add(new Transaction(tx, curl)); } + return trx.ToArray(); } @@ -833,7 +831,6 @@ public Bundle GetBundle(string transaction) return bundle; } - private Bundle TraverseBundle(string trunkTransaction, string bundleHash, Bundle bundle) { GetTrytesResponse gtr = GetTrytes(trunkTransaction); diff --git a/IotaCSharpApi/Api/Model/Bundle.cs b/IotaCSharpApi/Api/Model/Bundle.cs index 6ac683c..fecc603 100644 --- a/IotaCSharpApi/Api/Model/Bundle.cs +++ b/IotaCSharpApi/Api/Model/Bundle.cs @@ -195,9 +195,9 @@ public void FinalizeBundle(ICurl customCurl) customCurl.Squeeze(hash, 0, hash.Length); string hashInTrytes = Converter.ToTrytes(hash); - for (int i = 0; i < Transactions.Count; i++) + foreach (Transaction t in Transactions) { - Transactions[i].Bundle = hashInTrytes; + t.Bundle = hashInTrytes; } } diff --git a/IotaCSharpApi/Api/Model/Input.cs b/IotaCSharpApi/Api/Model/Input.cs index 4c1c71e..94a9462 100644 --- a/IotaCSharpApi/Api/Model/Input.cs +++ b/IotaCSharpApi/Api/Model/Input.cs @@ -29,7 +29,6 @@ public class Input /// public int KeyIndex { get; set; } - /// /// Returns a that represents this instance. /// diff --git a/IotaCSharpApi/Api/Model/Neighbor.cs b/IotaCSharpApi/Api/Model/Neighbor.cs index 6fefe2f..c62dd6d 100644 --- a/IotaCSharpApi/Api/Model/Neighbor.cs +++ b/IotaCSharpApi/Api/Model/Neighbor.cs @@ -1,9 +1,9 @@ -namespace Iota.Lib.CSharp.Api.Model +namespace Iota.Lib.CSharp.Api.Model { /// /// This class represents a neigbhor /// - public class Neighbor + public class Neighbor { /// /// Gets or sets the address. @@ -11,8 +11,8 @@ public class Neighbor /// /// The address. /// - public string Address { get; set; } - + public string Address { get; set; } + /// /// Gets or sets the number of all transactions. /// @@ -29,12 +29,12 @@ public class Neighbor /// public long NumberOfInvalidTransactions { get; set; } - /// - /// Gets or sets the number of new transactions. - /// - /// - /// The number of new transactions. - /// + /// + /// Gets or sets the number of new transactions. + /// + /// + /// The number of new transactions. + /// public long NumberOfNewTransactions { get; set; } /// @@ -43,9 +43,9 @@ public class Neighbor /// /// A that represents this instance. /// - public override string ToString() - { - return $"{nameof(Address)}: {Address}, {nameof(NumberOfAllTransactions)}: {NumberOfAllTransactions}, {nameof(NumberOfInvalidTransactions)}: {NumberOfInvalidTransactions}, {nameof(NumberOfNewTransactions)}: {NumberOfNewTransactions}"; - } - } + 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/Utils/Checksum.cs b/IotaCSharpApi/Api/Utils/Checksum.cs index 6f74ae9..43b9f97 100644 --- a/IotaCSharpApi/Api/Utils/Checksum.cs +++ b/IotaCSharpApi/Api/Utils/Checksum.cs @@ -1,6 +1,5 @@ using Iota.Lib.CSharp.Api.Exception; - namespace Iota.Lib.CSharp.Api.Utils { /// @@ -14,15 +13,14 @@ public static class Checksum /// An address without checksum /// The address with the appended checksum /// is thrown when an invalid address is provided - public static string AddChecksum(string address) + public static string AddChecksum(this string address) { InputValidator.CheckAddress(address); string addressWithChecksum = address; addressWithChecksum += CalculateChecksum(address); return addressWithChecksum; } - - + /// /// Removes the checksum from the specified address with checksum /// @@ -37,8 +35,7 @@ public static string RemoveChecksum(this string addressWithChecksum) } throw new InvalidAddressException(addressWithChecksum); } - - + internal static string GetAddress(string addressWithChecksum) { return addressWithChecksum.Substring(0, Constants.AddressLengthWithoutChecksum); @@ -58,7 +55,6 @@ public static bool IsValidChecksum(this string addressWithChecksum) return adressWithRecalculateChecksum.Equals(addressWithChecksum); } - private static bool IsAddressWithChecksum(string addressWithChecksum) { return InputValidator.IsAddress(addressWithChecksum) && addressWithChecksum.Length == Constants.AddressLengthWithChecksum; diff --git a/IotaCSharpApi/Api/Utils/Converter.cs b/IotaCSharpApi/Api/Utils/Converter.cs index aab518f..510ee3b 100644 --- a/IotaCSharpApi/Api/Utils/Converter.cs +++ b/IotaCSharpApi/Api/Utils/Converter.cs @@ -67,6 +67,7 @@ static Converter() 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; @@ -102,6 +103,7 @@ public static byte[] ToBytes(int[] 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( @@ -113,6 +115,7 @@ public static void GetTrits(sbyte[] bytes, int[] trits) offset += NumberOfTritsInAByte; } + while (offset < trits.Length) { trits[offset++] = 0; @@ -127,11 +130,13 @@ public static void GetTrits(sbyte[] bytes, int[] trits) public static int[] ToTritsString(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; } diff --git a/IotaCSharpApi/Api/Utils/InputValidator.cs b/IotaCSharpApi/Api/Utils/InputValidator.cs index 835a466..e96751b 100644 --- a/IotaCSharpApi/Api/Utils/InputValidator.cs +++ b/IotaCSharpApi/Api/Utils/InputValidator.cs @@ -26,6 +26,7 @@ public static bool IsAddress(string address) { return IsTrytes(address, address.Length); } + return false; } @@ -82,6 +83,7 @@ public static bool IsArrayOfHashes(string[] hashes) } } } + return true; } @@ -129,6 +131,7 @@ public static bool IsTransfersCollectionValid(ICollection transfers) return false; } } + return true; } @@ -198,7 +201,9 @@ public static void CheckIfValidSeed(string seed) /// public static string PadSeedIfNecessary(string seed) { - while (seed.Length < Constants.AddressLengthWithoutChecksum) seed += 9; + while (seed.Length < Constants.AddressLengthWithoutChecksum) + seed += 9; + return seed; } diff --git a/IotaCSharpApi/Api/Utils/IotaApiUtils.cs b/IotaCSharpApi/Api/Utils/IotaApiUtils.cs index 5df8d56..48e624d 100644 --- a/IotaCSharpApi/Api/Utils/IotaApiUtils.cs +++ b/IotaCSharpApi/Api/Utils/IotaApiUtils.cs @@ -24,32 +24,24 @@ internal static string NewAddress(string seed, int index, bool checksum, ICurl c TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. - string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", - ts.Hours, ts.Minutes, ts.Seconds, - ts.Milliseconds/10); + string elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}"; Console.WriteLine(elapsedTime); int[] key = signing.Key(Converter.ToTrits(seed), index, 2); ts = stopWatch.Elapsed; - elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", - ts.Hours, ts.Minutes, ts.Seconds, - ts.Milliseconds/10); + elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}"; Console.WriteLine(elapsedTime); int[] digests = signing.Digests(key); ts = stopWatch.Elapsed; - elapsedTime = String.Format("After Digest {0:00}:{1:00}:{2:00}.{3:00}", - ts.Hours, ts.Minutes, ts.Seconds, - ts.Milliseconds/10); + elapsedTime = $"After Digest {ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}"; Console.WriteLine(elapsedTime); int[] addressTrits = signing.Address(digests); ts = stopWatch.Elapsed; - elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", - ts.Hours, ts.Minutes, ts.Seconds, - ts.Milliseconds/10); + elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}"; Console.WriteLine(elapsedTime); string address = Converter.ToTrytes(addressTrits); @@ -72,11 +64,11 @@ internal static List SignInputsAndReturn(string seed, // 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++) + foreach (Transaction t in bundle.Transactions) { - if (Int64.Parse(bundle.Transactions[i].Value) < 0) + if (Int64.Parse(t.Value) < 0) { - string thisAddress = bundle.Transactions[i].Address; + string thisAddress = t.Address; // Get the corresponding keyIndex of the address int keyIndex = 0; @@ -89,7 +81,7 @@ internal static List SignInputsAndReturn(string seed, } } - string bundleHash = bundle.Transactions[i].Bundle; + string bundleHash = t.Bundle; // Get corresponding private key of address int[] key = new Signing(curl).Key(Converter.ToTrits(seed), keyIndex, 2); @@ -107,15 +99,15 @@ internal static List SignInputsAndReturn(string seed, int[] firstSignedFragment = new Signing(curl).SignatureFragment(firstBundleFragment, firstFragment); // Convert signature to trytes and assign the new signatureFragment - bundle.Transactions[i].SignatureFragment = Converter.ToTrytes(firstSignedFragment); + t.SignatureFragment = 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++) + foreach (Transaction t1 in bundle.Transactions) { // Same address as well as value = 0 (as we already spent the input) - if (bundle.Transactions[j].Address.Equals(thisAddress) && - Int64.Parse(bundle.Transactions[j].Value) == 0) + if (t1.Address.Equals(thisAddress) && + Int64.Parse(t1.Value) == 0) { // Use the second 6562 trits int[] secondFragment = ArrayUtils.SubArray2(key, 6561, 6561); @@ -128,7 +120,7 @@ internal static List SignInputsAndReturn(string seed, secondFragment); // Convert signature to trytes and assign it again to this bundle entry - bundle.Transactions[j].SignatureFragment = (Converter.ToTrytes(secondSignedFragment)); + t1.SignatureFragment = (Converter.ToTrytes(secondSignedFragment)); } } } diff --git a/IotaCSharpApi/Api/Utils/IotaUnitConverter.cs b/IotaCSharpApi/Api/Utils/IotaUnitConverter.cs index 306a21a..e03c4ff 100644 --- a/IotaCSharpApi/Api/Utils/IotaUnitConverter.cs +++ b/IotaCSharpApi/Api/Utils/IotaUnitConverter.cs @@ -16,14 +16,14 @@ public class IotaUnitConverter /// 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)); + 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)); + int base10NormalizationExponent = (int)toUnit; + return amount / Math.Pow(10, base10NormalizationExponent); } /// @@ -33,7 +33,7 @@ private static double ConvertUnits(long amount, IotaUnits toUnit) /// the optimal IotaUnit public static IotaUnits FindOptimalIotaUnitToDisplay(long amount) { - int length = (amount).ToString().Length; + int length = amount.ToString().Length; if (amount < 0) { @@ -67,6 +67,7 @@ public static IotaUnits FindOptimalIotaUnitToDisplay(long amount) { units = IotaUnits.Peta; } + return units; } } diff --git a/IotaCSharpApi/Api/Utils/TrytesConverter.cs b/IotaCSharpApi/Api/Utils/TrytesConverter.cs index 96d39e0..a41063b 100644 --- a/IotaCSharpApi/Api/Utils/TrytesConverter.cs +++ b/IotaCSharpApi/Api/Utils/TrytesConverter.cs @@ -3,7 +3,6 @@ namespace Iota.Lib.CSharp.Api.Utils { - /// /// This class allows to convert between ASCII and tryte encoded strings /// @@ -40,8 +39,6 @@ public static string ToTrytes(string inputString) return trytes.ToString(); } - - /// /// Converts the specified tryte encoded String to ASCII /// diff --git a/IotaCSharpApi/App.config b/IotaCSharpApi/App.config index 9dfd41a..a0634f4 100644 --- a/IotaCSharpApi/App.config +++ b/IotaCSharpApi/App.config @@ -2,5 +2,5 @@ - + diff --git a/IotaCSharpApi/IotaCSharpApi.csproj b/IotaCSharpApi/IotaCSharpApi.csproj index fb3f6a3..2946308 100644 --- a/IotaCSharpApi/IotaCSharpApi.csproj +++ b/IotaCSharpApi/IotaCSharpApi.csproj @@ -1,6 +1,6 @@  - + Debug @@ -10,7 +10,7 @@ Properties Iota.Lib.CSharp IotaApi - v4.0 + v4.6.2 512 @@ -43,13 +43,11 @@ - - ..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll - True + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - ..\packages\RestSharp.105.2.3\lib\net4\RestSharp.dll - True + ..\packages\RestSharp.105.2.3\lib\net46\RestSharp.dll @@ -110,8 +108,8 @@ - - + + @@ -143,10 +141,10 @@ This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + + - +