Skip to content

Commit

Permalink
Merge pull request #99 from WalletConnect/fix/relay-batch-updates
Browse files Browse the repository at this point in the history
Fix/relay batch updates
  • Loading branch information
gigajuwels authored Jun 13, 2023
2 parents 47886ef + f010f9c commit 054926e
Show file tree
Hide file tree
Showing 19 changed files with 621 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ public static RelayProtocols GetRelayProtocol(string protocol)
[JsonProperty("publish")]
public abstract string Publish { get; }

public abstract string BatchPublish { get; }

/// <summary>
/// The Subscribe action RPC method name
/// </summary>
[JsonProperty("subscribe")]
public abstract string Subscribe { get; }

public abstract string BatchSubscribe { get; }

/// <summary>
/// The Subscription action RPC method name
/// </summary>
Expand All @@ -79,6 +83,8 @@ public static RelayProtocols GetRelayProtocol(string protocol)
/// </summary>
[JsonProperty("unsubscribe")]
public abstract string Unsubscribe { get; }

public abstract string BatchUnsubscribe { get; }

/// <summary>
/// A class that defines all RelayProtocol definitions for the
Expand All @@ -94,6 +100,14 @@ public override string Publish
}
}

public override string BatchPublish
{
get
{
return "waku_batchPublish";
}
}

public override string Subscribe
{
get
Expand All @@ -102,6 +116,14 @@ public override string Subscribe
}
}

public override string BatchSubscribe
{
get
{
return "waku_batchSubscribe";
}
}

public override string Subscription
{
get
Expand All @@ -117,6 +139,14 @@ public override string Unsubscribe
return "waku_unsubscribe";
}
}

public override string BatchUnsubscribe
{
get
{
return "waku_batchUnsubscribe";
}
}
}

/// <summary>
Expand All @@ -133,6 +163,14 @@ public override string Publish
}
}

public override string BatchPublish
{
get
{
return "irn_batchPublish";
}
}

public override string Subscribe
{
get
Expand All @@ -141,6 +179,14 @@ public override string Subscribe
}
}

public override string BatchSubscribe
{
get
{
return "irn_batchSubscribe";
}
}

public override string Subscription
{
get
Expand All @@ -156,6 +202,14 @@ public override string Unsubscribe
return "irn_unsubscribe";
}
}

public override string BatchUnsubscribe
{
get
{
return "irn_batchUnsubscribe";
}
}
}

/// <summary>
Expand All @@ -172,6 +226,14 @@ public override string Publish
}
}

public override string BatchPublish
{
get
{
return "iridium_batchPublish";
}
}

public override string Subscribe
{
get
Expand All @@ -180,6 +242,14 @@ public override string Subscribe
}
}

public override string BatchSubscribe
{
get
{
return "iridium_batchSubscribe";
}
}

public override string Subscription
{
get
Expand All @@ -195,8 +265,16 @@ public override string Unsubscribe
return "iridium_unsubscribe";
}
}

public override string BatchUnsubscribe
{
get
{
return "iridium_batchUnsubscribe";
}
}
}

public static RelayProtocols DefaultProtocol => GetRelayProtocol(Default);
}
}
}
9 changes: 5 additions & 4 deletions Core Modules/WalletConnectSharp.Network/JsonRpcProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
using WalletConnectSharp.Common;
using WalletConnectSharp.Common.Model.Errors;
Expand Down Expand Up @@ -200,7 +197,9 @@ public async Task<TR> Request<T, TR>(IRequestArguments<T> requestArgs, object co
return;

var result = @event.EventData;


//Console.WriteLine($"[{Name}] Got response {JsonConvert.SerializeObject(result)}");

if (result.Error != null)
{
requestTask.SetException(new IOException(result.Error.Message));
Expand All @@ -217,6 +216,7 @@ public async Task<TR> Request<T, TR>(IRequestArguments<T> requestArgs, object co
return;

var exception = @event.EventData;
//Console.WriteLine($"[{Name}] Got Response Error {exception}");
if (exception != null)
{
requestTask.SetException(exception);
Expand All @@ -225,6 +225,7 @@ public async Task<TR> Request<T, TR>(IRequestArguments<T> requestArgs, object co

_lastId = request.Id;

//Console.WriteLine($"[{Name}] Sending request {request.Method} with data {JsonConvert.SerializeObject(request)}");
await _connection.SendRequest(request, context);

await requestTask.Task;
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DefaultVersion>2.0.4</DefaultVersion>
<DefaultVersion>2.0.5</DefaultVersion>
<DefaultTargetFrameworks>net6.0;netcoreapp3.1;netstandard2.1;</DefaultTargetFrameworks>
</PropertyGroup>
<PropertyGroup Label="C#">
Expand Down
2 changes: 1 addition & 1 deletion WalletConnectSharp.Core/Controllers/Expirer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public string StorageKey
{
get
{
return Core.STORAGE_PREFIX + Version + "//" + Name;
return WalletConnectCore.STORAGE_PREFIX + Version + "//" + Name;
}
}

Expand Down
2 changes: 1 addition & 1 deletion WalletConnectSharp.Core/Controllers/JsonRpcHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public string StorageKey
{
get
{
return Core.STORAGE_PREFIX + Version + "//" + Name;
return WalletConnectCore.STORAGE_PREFIX + Version + "//" + Name;
}
}

Expand Down
2 changes: 1 addition & 1 deletion WalletConnectSharp.Core/Controllers/MessageTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string StorageKey
{
get
{
return Core.STORAGE_PREFIX + Version + "//" + Name;
return WalletConnectCore.STORAGE_PREFIX + Version + "//" + Name;
}
}

Expand Down
2 changes: 1 addition & 1 deletion WalletConnectSharp.Core/Controllers/PairingStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PairingStore : Store<string, PairingStruct>, IPairingStore
/// Create a new instance of this module
/// </summary>
/// <param name="core">The <see cref="ICore"/> instance that will be used for <see cref="ICore.Storage"/></param>
public PairingStore(ICore core) : base(core, "pairing", WalletConnectSharp.Core.Core.STORAGE_PREFIX)
public PairingStore(ICore core) : base(core, "pairing", WalletConnectCore.STORAGE_PREFIX)
{
}
}
Expand Down
21 changes: 13 additions & 8 deletions WalletConnectSharp.Core/Controllers/Publisher.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalletConnectSharp.Common.Model.Relay;
using WalletConnectSharp.Common.Utils;
using WalletConnectSharp.Core.Interfaces;
using WalletConnectSharp.Core.Models.Heartbeat;
using WalletConnectSharp.Core.Models.Publisher;
using WalletConnectSharp.Core.Models.Relay;
using WalletConnectSharp.Events;
using WalletConnectSharp.Events.Model;
using WalletConnectSharp.Network.Models;

namespace WalletConnectSharp.Core.Controllers
Expand Down Expand Up @@ -106,7 +101,7 @@ protected Task RpcPublish(string topic, string message, long ttl, long tag, Prot
}
};

return this.Relayer.Provider.Request<RelayPublishRequest, object>(request, this);
return this.Relayer.Request<RelayPublishRequest, object>(request, this);
}

/// <summary>
Expand Down Expand Up @@ -149,8 +144,18 @@ public async Task Publish(string topic, string message, PublishOptions opts = nu

var hash = HashUtils.HashMessage(message);
queue.Add(hash, @params);
await RpcPublish(topic, message, @params.Options.TTL, @params.Options.Tag, @params.Options.Relay);
OnPublish(hash);
try
{
await RpcPublish(topic, message, @params.Options.TTL, @params.Options.Tag, @params.Options.Relay)
.WithTimeout(TimeSpan.FromSeconds(10));
this.Relayer.Events.Trigger(RelayerEvents.Publish, @params);
OnPublish(hash);
}
catch (Exception e)
{
this.Relayer.Events.Trigger<object>(RelayerEvents.ConnectionStalled, new object());
return;
}
}
}
}
Loading

0 comments on commit 054926e

Please sign in to comment.