diff --git a/Tests/WalletConnectSharp.Auth.Tests/AuthClientTest.cs b/Tests/WalletConnectSharp.Auth.Tests/AuthClientTest.cs index 57cd481..40aec8d 100644 --- a/Tests/WalletConnectSharp.Auth.Tests/AuthClientTest.cs +++ b/Tests/WalletConnectSharp.Auth.Tests/AuthClientTest.cs @@ -307,11 +307,9 @@ public async void TestCustomRequestExpiry() TaskCompletionSource resolve1 = new TaskCompletionSource(); - PeerA.Core.Relayer.ListenOnce(nameof(PeerA.Core.Relayer.OnPublishedMessage), (sender, args) => + PeerA.Core.Relayer.Publisher.ListenOnce(nameof(PeerA.Core.Relayer.Publisher.OnPublishedMessage), (sender, args) => { - var @event = (RequestArguments)args; - - Assert.Equal(expiry, @event.Params.TTL); + Assert.Equal(expiry, args.Options.TTL); resolve1.SetResult(true); }); @@ -409,7 +407,7 @@ public async void TestPing() receivedPeerPing.SetResult(true); }); - PeerA.Core.Pairing.ListenOnce(nameof(PeerA.Core.Pairing.PairingPinged), (sender, args) => + PeerA.Core.Pairing.ListenOnce(nameof(PeerA.Core.Pairing.PairingPinged), (sender, args) => { receivedClientPing.SetResult(true); }); @@ -445,7 +443,7 @@ public async void TestDisconnectedPairing() PeerB.AuthRequested += OnPeerBOnAuthRequested; - PeerB.Core.Pairing.ListenOnce(nameof(PeerB.Core.Pairing.PairingDeleted), (sender, args) => + PeerB.Core.Pairing.ListenOnce(nameof(PeerB.Core.Pairing.PairingDeleted), (sender, args) => { peerDeletedPairing.SetResult(true); }); diff --git a/Tests/WalletConnectSharp.Network.Tests/RelayTests.cs b/Tests/WalletConnectSharp.Network.Tests/RelayTests.cs index 6700e29..5084d17 100644 --- a/Tests/WalletConnectSharp.Network.Tests/RelayTests.cs +++ b/Tests/WalletConnectSharp.Network.Tests/RelayTests.cs @@ -117,7 +117,7 @@ public async void DoesNotDoubleRegisterListeners() var expectedDisconnectCount = 3; var disconnectCount = 0; - provider.On("disconnect", (_, __) => disconnectCount++); + provider.Disconnected += (_, _) => disconnectCount++; await provider.Connect(); await provider.Disconnect(); diff --git a/WalletConnectSharp.Core/Controllers/Publisher.cs b/WalletConnectSharp.Core/Controllers/Publisher.cs index 9c9a41d..59d1b0e 100644 --- a/WalletConnectSharp.Core/Controllers/Publisher.cs +++ b/WalletConnectSharp.Core/Controllers/Publisher.cs @@ -18,7 +18,9 @@ public class Publisher : IPublisher /// The EventDelegator this publisher module is using /// public EventDelegator Events { get; } - + + public event EventHandler OnPublishedMessage; + /// /// The Relayer this publisher module uses to publish messages /// @@ -63,6 +65,10 @@ public Publisher(IRelayer relayer) private void RegisterEventListeners() { +#pragma warning disable CS0618 // Old event system + this.OnPublishedMessage += Relayer.WrapEventHandler(RelayerEvents.Publish); +#pragma warning restore CS0618 // Old event system + Relayer.Core.HeartBeat.OnPulse += (_, _) => CheckQueue(); } @@ -98,6 +104,7 @@ private async void CheckQueue() var hash = HashUtils.HashMessage(@params.Message); await RpcPublish(@params.Topic, @params.Message, @params.Options.TTL, @params.Options.Tag, @params.Options.Relay); + this.OnPublishedMessage?.Invoke(this, @params); OnPublish(hash); } } @@ -178,6 +185,7 @@ public async Task Publish(string topic, string message, PublishOptions opts = nu { await RpcPublish(topic, message, @params.Options.TTL, @params.Options.Tag, @params.Options.Relay) .WithTimeout(TimeSpan.FromSeconds(45)); + this.OnPublishedMessage?.Invoke(this, @params); OnPublish(hash); } catch (Exception e) diff --git a/WalletConnectSharp.Core/Controllers/Relayer.cs b/WalletConnectSharp.Core/Controllers/Relayer.cs index ad97ba3..55831b4 100644 --- a/WalletConnectSharp.Core/Controllers/Relayer.cs +++ b/WalletConnectSharp.Core/Controllers/Relayer.cs @@ -56,7 +56,6 @@ public string Context public event EventHandler OnConnected; public event EventHandler OnDisconnected; public event EventHandler OnErrored; - public event EventHandler OnPublishedMessage; public event EventHandler OnMessageReceived; public event EventHandler OnTransportClosed; public event EventHandler OnConnectionStalled; @@ -189,7 +188,6 @@ private void WrapOldEvents() { this.OnTransportClosed += this.WrapEventHandler(RelayerEvents.TransportClosed); this.OnConnectionStalled += this.WrapEventHandler(RelayerEvents.ConnectionStalled); - this.OnPublishedMessage += this.WrapEventHandler(RelayerEvents.Publish); this.OnMessageReceived += this.WrapEventHandler(RelayerEvents.Message); this.OnConnected += this.WrapEventHandler(RelayerEvents.Connect); this.OnDisconnected += this.WrapEventHandler(RelayerEvents.Disconnect); @@ -382,8 +380,6 @@ public async Task Request(IRequestArguments request, object contex WCLogger.Log("[Relayer] Sending request through provider"); var result = await this.Provider.Request(request, context); - - this.OnPublishedMessage?.Invoke(this, request); return result; } diff --git a/WalletConnectSharp.Core/Interfaces/IPublisher.cs b/WalletConnectSharp.Core/Interfaces/IPublisher.cs index a0f2f9d..031a161 100644 --- a/WalletConnectSharp.Core/Interfaces/IPublisher.cs +++ b/WalletConnectSharp.Core/Interfaces/IPublisher.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using WalletConnectSharp.Common; +using WalletConnectSharp.Core.Models.Publisher; using WalletConnectSharp.Core.Models.Relay; using WalletConnectSharp.Events.Interfaces; @@ -11,6 +12,8 @@ namespace WalletConnectSharp.Core.Interfaces /// public interface IPublisher : IEvents, IModule { + event EventHandler OnPublishedMessage; + /// /// The IRelayer instance this publisher is using to publish messages /// diff --git a/WalletConnectSharp.Core/Interfaces/IRelayer.cs b/WalletConnectSharp.Core/Interfaces/IRelayer.cs index 69a696c..7a70452 100644 --- a/WalletConnectSharp.Core/Interfaces/IRelayer.cs +++ b/WalletConnectSharp.Core/Interfaces/IRelayer.cs @@ -18,8 +18,6 @@ public interface IRelayer : IEvents, IModule event EventHandler OnErrored; - event EventHandler OnPublishedMessage; - event EventHandler OnMessageReceived; event EventHandler OnTransportClosed; diff --git a/WalletConnectSharp.Sign/Engine.cs b/WalletConnectSharp.Sign/Engine.cs index 099e0a7..9fa75a9 100644 --- a/WalletConnectSharp.Sign/Engine.cs +++ b/WalletConnectSharp.Sign/Engine.cs @@ -309,7 +309,7 @@ public async Task Connect(ConnectOptions options) WCLogger.Log($"Created public key pair"); TaskCompletionSource approvalTask = new TaskCompletionSource(); - this.Events.ListenForOnce("session_connect", async (sender, e) => + this.SessionConnected += async (sender, session) => { logger.Log("Got session_connect event for session struct"); if (approvalTask.Task.IsCompleted) @@ -318,7 +318,6 @@ public async Task Connect(ConnectOptions options) return; } - var session = e.EventData; session.Self.PublicKey = publicKey; var completeSession = session with { RequiredNamespaces = requiredNamespaces }; await PrivateThis.SetExpiry(session.Topic, session.Expiry.Value); @@ -329,9 +328,9 @@ public async Task Connect(ConnectOptions options) await this.Client.Core.Pairing.UpdateMetadata(topic, session.Peer.Metadata); } approvalTask.SetResult(completeSession); - }); - - this.Events.ListenForOnce>("session_connect", (sender, e) => + }; + + this.SessionConnectionErrored += (sender, exception) => { logger.Log("Got session_connect event for rpc response"); if (approvalTask.Task.IsCompleted) @@ -339,13 +338,15 @@ public async Task Connect(ConnectOptions options) logger.Log("approval already received though, skipping"); return; } - - if (e.EventData.IsError) + + if (exception == null) { - logger.LogError("Got session_connect error " + e.EventData.Error.Message); - approvalTask.SetException(e.EventData.Error.ToException()); + return; } - }); + + logger.LogError("Got session_connect error " + exception.Message); + approvalTask.SetException(exception); + }; if (string.IsNullOrWhiteSpace(topic)) { diff --git a/WalletConnectSharp.Sign/Internals/EngineHandler.cs b/WalletConnectSharp.Sign/Internals/EngineHandler.cs index d2b02a4..249018c 100644 --- a/WalletConnectSharp.Sign/Internals/EngineHandler.cs +++ b/WalletConnectSharp.Sign/Internals/EngineHandler.cs @@ -177,6 +177,8 @@ async Task IEnginePrivate.OnSessionSettleResponse(string topic, JsonRpcResponse< var error = Error.FromErrorType(ErrorType.USER_DISCONNECTED); await this.Client.Session.Delete(topic, error); this.SessionRejected?.Invoke(this, session); + + // Still used do not remove this.Events.Trigger($"session_approve{id}", payload); } else @@ -225,6 +227,7 @@ async Task IEnginePrivate.OnSessionUpdateResponse(string topic, JsonRpcResponse< Id = id, Topic = topic, }); + // Still used, do not remove this.Events.Trigger($"session_update{id}", payload); } @@ -256,6 +259,7 @@ async Task IEnginePrivate.OnSessionExtendResponse(string topic, JsonRpcResponse< Topic = topic, Id = id }); + // Still used, do not remove this.Events.Trigger($"session_extend{id}", payload); } @@ -292,6 +296,7 @@ async Task IEnginePrivate.OnSessionPingResponse(string topic, JsonRpcResponse