diff --git a/Core Modules/WalletConnectSharp.Common/Logging/ILogger.cs b/Core Modules/WalletConnectSharp.Common/Logging/ILogger.cs
new file mode 100644
index 0000000..c8dee21
--- /dev/null
+++ b/Core Modules/WalletConnectSharp.Common/Logging/ILogger.cs
@@ -0,0 +1,11 @@
+namespace WalletConnectSharp.Common.Logging
+{
+ public interface ILogger
+ {
+ void Log(string message);
+
+ void LogError(string message);
+
+ void LogError(Exception e);
+ }
+}
diff --git a/Core Modules/WalletConnectSharp.Common/Logging/WCLogger.cs b/Core Modules/WalletConnectSharp.Common/Logging/WCLogger.cs
new file mode 100644
index 0000000..271e5e9
--- /dev/null
+++ b/Core Modules/WalletConnectSharp.Common/Logging/WCLogger.cs
@@ -0,0 +1,36 @@
+namespace WalletConnectSharp.Common.Logging
+{
+ public class WCLogger
+ {
+ public static ILogger Logger;
+
+ public static ILogger WithContext(string context)
+ {
+ return new WrapperLogger(Logger, context);
+ }
+
+ public static void Log(string message)
+ {
+ if (Logger == null)
+ return;
+
+ Logger.Log(message);
+ }
+
+ public static void LogError(string message)
+ {
+ if (Logger == null)
+ return;
+
+ Logger.LogError(message);
+ }
+
+ public static void LogError(Exception e)
+ {
+ if (Logger == null)
+ return;
+
+ Logger.LogError(e);
+ }
+ }
+}
diff --git a/Core Modules/WalletConnectSharp.Common/Logging/WrapperLogger.cs b/Core Modules/WalletConnectSharp.Common/Logging/WrapperLogger.cs
new file mode 100644
index 0000000..5e86f96
--- /dev/null
+++ b/Core Modules/WalletConnectSharp.Common/Logging/WrapperLogger.cs
@@ -0,0 +1,31 @@
+namespace WalletConnectSharp.Common.Logging;
+
+public class WrapperLogger : ILogger
+{
+ private ILogger _logger;
+ private string prefix;
+
+ public WrapperLogger(ILogger logger, string prefix)
+ {
+ _logger = logger;
+ this.prefix = prefix;
+ }
+
+ public void Log(string message)
+ {
+ if (_logger == null) return;
+ _logger.Log($"[{prefix}] {message}");
+ }
+
+ public void LogError(string message)
+ {
+ if (_logger == null) return;
+ _logger.LogError($"[{prefix}] {message}");
+ }
+
+ public void LogError(Exception e)
+ {
+ if (_logger == null) return;
+ _logger.LogError(e);
+ }
+}
diff --git a/Core Modules/WalletConnectSharp.Common/Model/Errors/SdkErrors.cs b/Core Modules/WalletConnectSharp.Common/Model/Errors/SdkErrors.cs
index 5133bd4..db44bf6 100644
--- a/Core Modules/WalletConnectSharp.Common/Model/Errors/SdkErrors.cs
+++ b/Core Modules/WalletConnectSharp.Common/Model/Errors/SdkErrors.cs
@@ -27,9 +27,9 @@ public static class SdkErrors
/// The error type message to generate
/// A dictionary (or anonymous type) of parameters for the error message
/// The error message as a string
- public static string MessageFromType(ErrorType type, object @params = null)
+ public static string MessageFromType(ErrorType type, Dictionary @params = null)
{
- return MessageFromType(type, null, @params.AsDictionary());
+ return MessageFromType(type, null, @params);
}
///
@@ -47,8 +47,8 @@ public static string MessageFromType(ErrorType type, string message = null, Dict
@params = new Dictionary();
}
- if (!string.IsNullOrWhiteSpace(message) && !@params.ContainsKey("message"))
- @params.Add("message", message);
+ if (!string.IsNullOrWhiteSpace(message))
+ @params.TryAdd("message", message);
string errorMessage;
switch (type)
@@ -231,4 +231,4 @@ private static string FormatErrorText(string formattedText, DictionaryThe error type of the exception
/// Additional (optional) parameters for the generated error message
/// A new exception
- public static WalletConnectException FromType(ErrorType type, object @params = null)
+ public static WalletConnectException FromType(ErrorType type, Dictionary @params = null)
{
- return FromType(type, null, @params.AsDictionary());
+ return FromType(type, null, @params);
}
}
-}
\ No newline at end of file
+}
diff --git a/Core Modules/WalletConnectSharp.Common/Utils/Clock.cs b/Core Modules/WalletConnectSharp.Common/Utils/Clock.cs
index 0393a92..99913e0 100644
--- a/Core Modules/WalletConnectSharp.Common/Utils/Clock.cs
+++ b/Core Modules/WalletConnectSharp.Common/Utils/Clock.cs
@@ -164,5 +164,19 @@ public static long Now()
{
return ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
}
+
+ ///
+ /// Current DateTime.Now as unix timestamp milliseconds
+ ///
+ ///
+ public static long NowMilliseconds()
+ {
+ return ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds();
+ }
+
+ public static TimeSpan AsTimeSpan(long seconds)
+ {
+ return TimeSpan.FromSeconds(seconds);
+ }
}
-}
\ No newline at end of file
+}
diff --git a/Core Modules/WalletConnectSharp.Common/Utils/DictionaryComparer.cs b/Core Modules/WalletConnectSharp.Common/Utils/DictionaryComparer.cs
new file mode 100644
index 0000000..6ebe73c
--- /dev/null
+++ b/Core Modules/WalletConnectSharp.Common/Utils/DictionaryComparer.cs
@@ -0,0 +1,30 @@
+namespace WalletConnectSharp.Common.Utils
+{
+ public class DictionaryComparer :
+ IEqualityComparer>
+ {
+ private IEqualityComparer valueComparer;
+ public DictionaryComparer(IEqualityComparer valueComparer = null)
+ {
+ this.valueComparer = valueComparer ?? EqualityComparer.Default;
+ }
+ public bool Equals(Dictionary x, Dictionary y)
+ {
+ if (x.Count != y.Count)
+ return false;
+ if (x.Keys.Except(y.Keys).Any())
+ return false;
+ if (y.Keys.Except(x.Keys).Any())
+ return false;
+ foreach (var pair in x)
+ if (!valueComparer.Equals(pair.Value, y[pair.Key]))
+ return false;
+ return true;
+ }
+
+ public int GetHashCode(Dictionary obj)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs b/Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs
index 4d562c5..e7ae344 100644
--- a/Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs
+++ b/Core Modules/WalletConnectSharp.Common/Utils/Extensions.cs
@@ -11,34 +11,6 @@ namespace WalletConnectSharp.Common.Utils
///
public static class Extensions
{
- ///
- /// Convert an anonymous type to a Dictionary
- ///
- /// The anonymous type instance to convert to a dictionary
- /// Enforce all keys to be lowercased
- /// A dictionary where each key is the property name of the anonymous type
- /// and each value is the property's value
- public static Dictionary AsDictionary(this object obj, bool enforceLowercase = true)
- {
- if (obj is Dictionary objects)
- return objects;
-
- var dict = new Dictionary(StringComparer.OrdinalIgnoreCase);
-
- if (obj != null)
- {
- foreach (PropertyInfo propertyDescriptor in obj.GetType().GetProperties())
- {
- object value = propertyDescriptor.GetValue(obj, null);
- var key = enforceLowercase ? propertyDescriptor.Name.ToLower() : propertyDescriptor.Name;
-
- dict.Add(key, value);
- }
- }
-
- return dict;
- }
-
///
/// Returns true if the given object is a numeric type
///
@@ -129,5 +101,12 @@ public static async Task WithTimeout(this Task task, TimeSpan timeout, string me
throw new TimeoutException(message.Replace("%t", timeout.ToString()));
}
}
+
+ public static bool SetEquals(this IEnumerable first, IEnumerable second,
+ IEqualityComparer comparer)
+ {
+ return new HashSet(second, comparer ?? EqualityComparer.Default)
+ .SetEquals(first);
+ }
}
-}
\ No newline at end of file
+}
diff --git a/Core Modules/WalletConnectSharp.Common/Utils/ListComparer.cs b/Core Modules/WalletConnectSharp.Common/Utils/ListComparer.cs
new file mode 100644
index 0000000..0a485f2
--- /dev/null
+++ b/Core Modules/WalletConnectSharp.Common/Utils/ListComparer.cs
@@ -0,0 +1,21 @@
+namespace WalletConnectSharp.Common.Utils
+{
+ public class ListComparer : IEqualityComparer>
+ {
+ private IEqualityComparer valueComparer;
+ public ListComparer(IEqualityComparer valueComparer = null)
+ {
+ this.valueComparer = valueComparer ?? EqualityComparer.Default;
+ }
+
+ public bool Equals(List x, List y)
+ {
+ return x.SetEquals(y, valueComparer);
+ }
+
+ public int GetHashCode(List obj)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Crypto.cs b/Core Modules/WalletConnectSharp.Crypto/Crypto.cs
index 5486724..6b1ecc8 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Crypto.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Crypto.cs
@@ -43,8 +43,8 @@ public class Crypto : ICrypto
private static readonly Encoding DATA_ENCODING = Encoding.UTF8;
private static readonly Encoding JSON_ENCODING = Encoding.UTF8;
- private const int TYPE_0 = 0;
- private const int TYPE_1 = 1;
+ public const int TYPE_0 = 0;
+ public const int TYPE_1 = 1;
private const int TYPE_LENGTH = 1;
private const int IV_LENGTH = 12;
private const int KEY_LENGTH = 32;
@@ -578,11 +578,20 @@ private void IsInitialized()
{
if (!this._initialized)
{
- throw WalletConnectException.FromType(ErrorType.NOT_INITIALIZED, new {Name});
+ throw WalletConnectException.FromType(ErrorType.NOT_INITIALIZED, new Dictionary()
+ {
+ { "Name", Name }
+ });
}
}
- private string HashKey(string key)
+ ///
+ /// Hash a hex key string using SHA256. The input key string must be a hex
+ /// string and the returned hash is represented as a hex string
+ ///
+ /// The input hex key string to hash using SHA256
+ /// The hash of the given input as a hex string
+ public string HashKey(string key)
{
using (SHA256 sha256 = SHA256.Create())
{
diff --git a/Core Modules/WalletConnectSharp.Crypto/Interfaces/ICrypto.cs b/Core Modules/WalletConnectSharp.Crypto/Interfaces/ICrypto.cs
index 32f5ea8..5ed84f4 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Interfaces/ICrypto.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Interfaces/ICrypto.cs
@@ -121,5 +121,13 @@ public interface ICrypto : IModule
///
/// The client id as a string
Task GetClientId();
+
+ ///
+ /// Hash a hex key string using SHA256. The input key string must be a hex
+ /// string and the returned hash is represented as a hex string
+ ///
+ /// The input hex key string to hash using SHA256
+ /// The hash of the given input as a hex string
+ string HashKey(string key);
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/KeyChain.cs b/Core Modules/WalletConnectSharp.Crypto/KeyChain.cs
index c3671af..511b57a 100644
--- a/Core Modules/WalletConnectSharp.Crypto/KeyChain.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/KeyChain.cs
@@ -142,7 +142,10 @@ public async Task Get(string tag)
if (!await Has(tag))
{
- throw WalletConnectException.FromType(ErrorType.NO_MATCHING_KEY, new {tag});
+ throw WalletConnectException.FromType(ErrorType.NO_MATCHING_KEY, new Dictionary()
+ {
+ {"tag", tag}
+ });
}
return this._keyChain[tag];
@@ -160,7 +163,10 @@ public async Task Delete(string tag)
if (!await Has(tag))
{
- throw WalletConnectException.FromType(ErrorType.NO_MATCHING_KEY, new {tag});
+ throw WalletConnectException.FromType(ErrorType.NO_MATCHING_KEY, new Dictionary()
+ {
+ {"tag", tag}
+ });
}
_keyChain.Remove(tag);
@@ -172,7 +178,10 @@ private void IsInitialized()
{
if (!this._initialized)
{
- throw WalletConnectException.FromType(ErrorType.NOT_INITIALIZED, new {Name});
+ throw WalletConnectException.FromType(ErrorType.NOT_INITIALIZED, new Dictionary()
+ {
+ {"Name", Name}
+ });
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/DecodeOptions.cs b/Core Modules/WalletConnectSharp.Crypto/Models/DecodeOptions.cs
index b071425..1bcec66 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/DecodeOptions.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/DecodeOptions.cs
@@ -11,6 +11,6 @@ public class DecodeOptions
/// The public key that received this encoded message
///
[JsonProperty("receiverPublicKey")]
- public string ReceiverPublicKey { get; set; }
+ public string ReceiverPublicKey;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/EncodeOptions.cs b/Core Modules/WalletConnectSharp.Crypto/Models/EncodeOptions.cs
index 498663d..3c280c0 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/EncodeOptions.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/EncodeOptions.cs
@@ -11,18 +11,18 @@ public class EncodeOptions
/// The envelope type to use
///
[JsonProperty("type")]
- public int Type { get; set; }
+ public int Type;
///
/// The public key that is sending the encoded message
///
[JsonProperty("senderPublicKey")]
- public string SenderPublicKey { get; set; }
+ public string SenderPublicKey;
///
/// The public key that is receiving the encoded message
///
[JsonProperty("receiverPublicKey")]
- public string ReceiverPublicKey { get; set; }
+ public string ReceiverPublicKey;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/EncodingParams.cs b/Core Modules/WalletConnectSharp.Crypto/Models/EncodingParams.cs
index bc28987..2e91cbf 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/EncodingParams.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/EncodingParams.cs
@@ -12,24 +12,24 @@ public class EncodingParams
/// The envelope type as raw bytes
///
[JsonProperty("type")]
- public byte[] Type { get; set; }
+ public byte[] Type;
///
/// The sealed encoded message as raw bytes
///
[JsonProperty("sealed")]
- public byte[] Sealed { get; set; }
+ public byte[] Sealed;
///
/// The IV of the encoded message as raw bytes
///
[JsonProperty("iv")]
- public byte[] Iv { get; set; }
+ public byte[] Iv;
///
/// The public key of the sender as raw bytes
///
[JsonProperty("senderPublicKey")]
- public byte[] SenderPublicKey { get; set; }
+ public byte[] SenderPublicKey;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/EncodingValidation.cs b/Core Modules/WalletConnectSharp.Crypto/Models/EncodingValidation.cs
index c4c4118..b0aa633 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/EncodingValidation.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/EncodingValidation.cs
@@ -11,18 +11,18 @@ public class EncodingValidation
/// The envelope type to validate
///
[JsonProperty("type")]
- public int Type { get; set; }
+ public int Type;
///
/// The sender public key to validate
///
[JsonProperty("senderPublicKey")]
- public string SenderPublicKey { get; set; }
+ public string SenderPublicKey;
///
/// The receiver public key to validate
///
[JsonProperty("receiverPublicKey")]
- public string ReceiverPublicKey { get; set; }
+ public string ReceiverPublicKey;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/EncryptParams.cs b/Core Modules/WalletConnectSharp.Crypto/Models/EncryptParams.cs
index 986b971..5cd154f 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/EncryptParams.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/EncryptParams.cs
@@ -11,30 +11,30 @@ public class EncryptParams
/// The message to encrypt
///
[JsonProperty("message")]
- public string Message { get; set; }
+ public string Message;
///
/// The Sym key to use for encrypting
///
[JsonProperty("symKey")]
- public string SymKey { get; set; }
+ public string SymKey;
///
/// The envelope type to use when encrypting
///
[JsonProperty("type")]
- public int Type { get; set; }
+ public int Type;
///
/// The IV to use for the encryption
///
[JsonProperty("iv")]
- public string Iv { get; set; }
+ public string Iv;
///
/// The public key of the sender of this encrypted message
///
[JsonProperty("senderPublicKey")]
- public string SenderPublicKey { get; set; }
+ public string SenderPublicKey;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTData.cs b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTData.cs
index 181e412..58345c9 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTData.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTData.cs
@@ -11,12 +11,12 @@ public class IridiumJWTData
/// The Iridium JWT header data
///
[JsonProperty("header")]
- public IridiumJWTHeader Header { get; set; }
+ public IridiumJWTHeader Header;
///
/// The Iridium JWT payload
///
[JsonProperty("payload")]
- public IridiumJWTPayload Payload { get; set; }
+ public IridiumJWTPayload Payload;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTDecoded.cs b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTDecoded.cs
index 8908f74..952eb27 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTDecoded.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTDecoded.cs
@@ -6,6 +6,6 @@ namespace WalletConnectSharp.Crypto.Models
public class IridiumJWTDecoded : IridiumJWTSigned
{
[JsonProperty("data")]
- public byte[] Data { get; set; }
+ public byte[] Data;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTHeader.cs b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTHeader.cs
index 42999c6..cc5f1aa 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTHeader.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTHeader.cs
@@ -5,6 +5,7 @@ namespace WalletConnectSharp.Crypto.Models
///
/// The header data for an Iridium JWT header
///
+ [Serializable]
public class IridiumJWTHeader
{
///
@@ -15,17 +16,15 @@ public class IridiumJWTHeader
Alg = "EdDSA",
Typ = "JWT"
};
-
+
///
/// The encoding algorithm to use
///
- [JsonProperty("alg")]
- public string Alg { get; set; }
-
+ [JsonProperty("alg")] public string Alg;
+
///
/// The encoding type to use
///
- [JsonProperty("typ")]
- public string Typ { get; set; }
+ [JsonProperty("typ")] public string Typ;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTPayload.cs b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTPayload.cs
index 30149c2..9897b3b 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTPayload.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTPayload.cs
@@ -5,36 +5,32 @@ namespace WalletConnectSharp.Crypto.Models
///
/// The data for an Iridium JWT payload
///
+ [Serializable]
public class IridiumJWTPayload
{
///
/// The iss value
///
- [JsonProperty("iss")]
- public string Iss { get; set; }
-
+ [JsonProperty("iss")] public string Iss;
+
///
/// The sub value
///
- [JsonProperty("sub")]
- public string Sub { get; set; }
-
+ [JsonProperty("sub")] public string Sub;
+
///
/// The aud value
///
- [JsonProperty("aud")]
- public string Aud { get; set; }
-
+ [JsonProperty("aud")] public string Aud;
+
///
/// The iat value
///
- [JsonProperty("iat")]
- public long Iat { get; set; }
-
+ [JsonProperty("iat")] public long Iat;
+
///
/// The exp value
///
- [JsonProperty("exp")]
- public long Exp { get; set; }
+ [JsonProperty("exp")] public long Exp;
}
}
diff --git a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTSigned.cs b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTSigned.cs
index 6b01948..e684da4 100644
--- a/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTSigned.cs
+++ b/Core Modules/WalletConnectSharp.Crypto/Models/IridiumJWTSigned.cs
@@ -8,6 +8,6 @@ namespace WalletConnectSharp.Crypto.Models
public class IridiumJWTSigned : IridiumJWTData
{
[JsonProperty("signature")]
- public byte[] Signature { get; set; }
+ public byte[] Signature;
}
}
diff --git a/Core Modules/WalletConnectSharp.Events/EventDelegator.cs b/Core Modules/WalletConnectSharp.Events/EventDelegator.cs
index a616d4d..da15cfc 100644
--- a/Core Modules/WalletConnectSharp.Events/EventDelegator.cs
+++ b/Core Modules/WalletConnectSharp.Events/EventDelegator.cs
@@ -4,6 +4,7 @@
using System.Reflection;
using Newtonsoft.Json;
using WalletConnectSharp.Common;
+using WalletConnectSharp.Common.Logging;
using WalletConnectSharp.Common.Model;
using WalletConnectSharp.Events.Model;
@@ -74,7 +75,7 @@ public void ListenFor(string eventId, Action callback)
/// The callback to invoke when the event is triggered
/// The type of event data the callback MUST be given
public void ListenFor(string eventId, EventHandler> callback)
- {
+ {
EventManager>.InstanceOf(Context).EventTriggers[eventId] += callback;
}
@@ -231,8 +232,10 @@ from type in assembly.GetTypes()
propagateEventMethod.Invoke(genericProvider, new object[] { eventId, eventData });
wasTriggered = true;
}
- catch (Exception)
+ catch (Exception e)
{
+ WCLogger.LogError(e);
+ WCLogger.Log($"[EventDelegator] Error Invoking EventFactory<{type.FullName}>.Provider.PropagateEvent({eventId}, {eventData})");
if (raiseOnException)
throw;
}
diff --git a/Core Modules/WalletConnectSharp.Network.Websocket/WalletConnectSharp.Network.Websocket.csproj b/Core Modules/WalletConnectSharp.Network.Websocket/WalletConnectSharp.Network.Websocket.csproj
index 428bd01..6070f63 100644
--- a/Core Modules/WalletConnectSharp.Network.Websocket/WalletConnectSharp.Network.Websocket.csproj
+++ b/Core Modules/WalletConnectSharp.Network.Websocket/WalletConnectSharp.Network.Websocket.csproj
@@ -19,6 +19,16 @@
Apache-2.0
+
+ TRACE
+WC_DEF_WEBSOCKET
+
+
+
+ TRACE
+WC_DEF_WEBSOCKET
+
+
diff --git a/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs b/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs
index 643c33d..487a631 100644
--- a/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs
+++ b/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnection.cs
@@ -36,6 +36,12 @@ public string Url
}
}
+ public bool IsPaused
+ {
+ get;
+ internal set;
+ }
+
///
/// The name of this websocket connection module
///
@@ -180,6 +186,9 @@ private async Task Register(string url)
private void OnOpen(WebsocketClient socket)
{
+ if (socket == null)
+ return;
+
socket.MessageReceived.Subscribe(OnPayload);
socket.DisconnectionHappened.Subscribe(OnDisconnect);
@@ -222,6 +231,8 @@ private void OnPayload(ResponseMessage obj)
}
if (string.IsNullOrWhiteSpace(json)) return;
+
+ //Console.WriteLine($"[{Name}] Got payload {json}");
Events.Trigger(WebsocketConnectionEvents.Payload, json);
}
@@ -322,7 +333,7 @@ private void OnError(IJsonRpcPayload ogPayload, Exception e)
? new IOException("Unavailable WS RPC url at " + _url) : e;
var message = exception.Message;
- var payload = new JsonRpcResponse(ogPayload.Id, new ErrorResponse()
+ var payload = new JsonRpcResponse(ogPayload.Id, new Error()
{
Code = exception.HResult,
Data = null,
diff --git a/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnectionBuilder.cs b/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnectionBuilder.cs
new file mode 100644
index 0000000..7bc1cec
--- /dev/null
+++ b/Core Modules/WalletConnectSharp.Network.Websocket/WebsocketConnectionBuilder.cs
@@ -0,0 +1,12 @@
+using WalletConnectSharp.Network.Interfaces;
+
+namespace WalletConnectSharp.Network.Websocket
+{
+ public class WebsocketConnectionBuilder : IConnectionBuilder
+ {
+ public Task CreateConnection(string url)
+ {
+ return Task.FromResult(new WebsocketConnection(url));
+ }
+ }
+}
diff --git a/Core Modules/WalletConnectSharp.Network/Interfaces/IConnectionBuilder.cs b/Core Modules/WalletConnectSharp.Network/Interfaces/IConnectionBuilder.cs
new file mode 100644
index 0000000..f7a49cd
--- /dev/null
+++ b/Core Modules/WalletConnectSharp.Network/Interfaces/IConnectionBuilder.cs
@@ -0,0 +1,7 @@
+namespace WalletConnectSharp.Network.Interfaces
+{
+ public interface IConnectionBuilder
+ {
+ Task CreateConnection(string url);
+ }
+}
diff --git a/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcConnection.cs b/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcConnection.cs
index 8693d69..33d72a5 100644
--- a/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcConnection.cs
+++ b/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcConnection.cs
@@ -24,6 +24,8 @@ public interface IJsonRpcConnection : IEvents, IDisposable
///
string Url { get; }
+ bool IsPaused { get; }
+
///
/// Open this connection
///
@@ -74,4 +76,4 @@ public interface IJsonRpcConnection : IEvents, IDisposable
/// A task that is performing the send
Task SendError(IJsonRpcError errorPayload, object context);
}
-}
\ No newline at end of file
+}
diff --git a/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcError.cs b/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcError.cs
index 02c99e3..d622751 100644
--- a/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcError.cs
+++ b/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcError.cs
@@ -11,7 +11,6 @@ public interface IJsonRpcError : IJsonRpcPayload
///
/// The error for this JSON RPC response or null if no error is present
///
- [JsonProperty("error")]
- ErrorResponse Error { get; }
+ Error Error { get; }
}
-}
\ No newline at end of file
+}
diff --git a/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcPayload.cs b/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcPayload.cs
index a4cc31d..59b7571 100644
--- a/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcPayload.cs
+++ b/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcPayload.cs
@@ -10,13 +10,11 @@ public interface IJsonRpcPayload
///
/// The unique id for this JSON RPC payload
///
- [JsonProperty("id")]
long Id { get; }
///
/// The version of this JSON RPC payload
///
- [JsonProperty("jsonrpc")]
string JsonRPC { get; }
}
-}
\ No newline at end of file
+}
diff --git a/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcResult.cs b/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcResult.cs
index 9dfeca1..94aacf3 100644
--- a/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcResult.cs
+++ b/Core Modules/WalletConnectSharp.Network/Interfaces/IJsonRpcResult.cs
@@ -12,7 +12,6 @@ public interface IJsonRpcResult : IJsonRpcError
///
/// The result data of the response to the request
///
- [JsonProperty("result")]
T Result { get; }
}
-}
\ No newline at end of file
+}
diff --git a/Core Modules/WalletConnectSharp.Network/Interfaces/IRequestArguments.cs b/Core Modules/WalletConnectSharp.Network/Interfaces/IRequestArguments.cs
index e7152fa..a74dfae 100644
--- a/Core Modules/WalletConnectSharp.Network/Interfaces/IRequestArguments.cs
+++ b/Core Modules/WalletConnectSharp.Network/Interfaces/IRequestArguments.cs
@@ -11,13 +11,11 @@ public interface IRequestArguments
///
/// The method for this request
///
- [JsonProperty("method")]
string Method { get; }
///
/// The parameter for this request
///
- [JsonProperty("params")]
T Params { get; }
}
-}
\ No newline at end of file
+}
diff --git a/Core Modules/WalletConnectSharp.Network/JsonRpcProvider.cs b/Core Modules/WalletConnectSharp.Network/JsonRpcProvider.cs
index 1b6c299..9082c96 100644
--- a/Core Modules/WalletConnectSharp.Network/JsonRpcProvider.cs
+++ b/Core Modules/WalletConnectSharp.Network/JsonRpcProvider.cs
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using WalletConnectSharp.Common;
+using WalletConnectSharp.Common.Logging;
using WalletConnectSharp.Common.Model.Errors;
using WalletConnectSharp.Events;
using WalletConnectSharp.Events.Model;
@@ -106,7 +107,9 @@ public async Task Connect(string connection)
Connecting = new TaskCompletionSource();
_connectingStarted = true;
+ WCLogger.Log("[JsonRpcProvider] Opening connection");
await this._connection.Open(connection);
+
FinalizeConnection(this._connection);
}
@@ -116,9 +119,10 @@ public async Task Connect(string connection)
/// The connection object to use to connect
public async Task Connect(IJsonRpcConnection connection)
{
- if (this._connection == connection && connection.Connected) return;
+ if (this._connection.Url == connection.Url && connection.Connected) return;
if (this._connection.Connected)
{
+ WCLogger.Log("Current connection still open, closing connection");
await this._connection.Close();
}
@@ -126,6 +130,7 @@ public async Task Connect(IJsonRpcConnection connection)
Connecting = new TaskCompletionSource();
_connectingStarted = true;
+ WCLogger.Log("[JsonRpcProvider] Opening connection");
await connection.Open();
FinalizeConnection(connection);
@@ -133,6 +138,7 @@ public async Task Connect(IJsonRpcConnection connection)
private void FinalizeConnection(IJsonRpcConnection connection)
{
+ WCLogger.Log("[JsonRpcProvider] Finalizing Connection, registering event listeners");
this._connection = connection;
RegisterEventListeners();
Events.Trigger(ProviderEvents.Connect, connection);
@@ -148,6 +154,8 @@ public async Task Connect()
{
if (_connection == null)
throw new Exception("No connection is set");
+
+ WCLogger.Log("[JsonRpcProvider] Connecting with given connection object");
await Connect(_connection);
}
@@ -172,10 +180,12 @@ public async Task Disconnect()
/// A Task that will resolve when a response is received
public async Task Request(IRequestArguments requestArgs, object context = null)
{
- if (IsConnecting)
+ WCLogger.Log("[JsonRpcProvider] Checking if connected");
+ if (IsConnecting)
await Connecting.Task;
else if (!_connectingStarted && !_connection.Connected)
{
+ WCLogger.Log("[JsonRpcProvider] Not connected, connecting now");
await Connect(_connection);
}
@@ -225,9 +235,11 @@ public async Task Request(IRequestArguments requestArgs, object co
_lastId = request.Id;
+ WCLogger.Log($"[JsonRpcProvider] Sending request {request.Method} with data {JsonConvert.SerializeObject(request)}");
//Console.WriteLine($"[{Name}] Sending request {request.Method} with data {JsonConvert.SerializeObject(request)}");
await _connection.SendRequest(request, context);
+ WCLogger.Log("[JsonRpcProvider] Awaiting request resuult");
await requestTask.Task;
return requestTask.Task.Result;
@@ -237,6 +249,7 @@ protected void RegisterEventListeners()
{
if (_hasRegisteredEventListeners) return;
+ WCLogger.Log($"[JsonRpcProvider] Registering event listeners on connection object with context {_connection.Events.Context}");
_connection.On("payload", OnPayload);
_connection.On