这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ChainSafe.Gaming.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.SygmaClien
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.Marketplace", "src/ChainSafe.Gaming.Marketplace\ChainSafe.Gaming.Marketplace.csproj", "{E7A9FE35-BEFD-4569-B848-495E0B85B674}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.InProcessTransactionExecutor.Unity", "src\ChainSafe.Gaming.InProcessTransactionExecutor.Unity\ChainSafe.Gaming.InProcessTransactionExecutor.Unity.csproj", "{46C16E64-DC72-446D-B153-A2142691A151}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.HyperPlay", "src\ChainSafe.Gaming.HyperPlay\ChainSafe.Gaming.HyperPlay.csproj", "{0859E3E2-5AB9-4997-9DE7-368EAB89313B}"
EndProject
Global
Expand Down Expand Up @@ -149,12 +147,6 @@ Global
{E7A9FE35-BEFD-4569-B848-495E0B85B674}.Release|Any CPU.Build.0 = Release|Any CPU
{E7A9FE35-BEFD-4569-B848-495E0B85B674}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{E7A9FE35-BEFD-4569-B848-495E0B85B674}.Test|Any CPU.Build.0 = Debug|Any CPU
{46C16E64-DC72-446D-B153-A2142691A151}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46C16E64-DC72-446D-B153-A2142691A151}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46C16E64-DC72-446D-B153-A2142691A151}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46C16E64-DC72-446D-B153-A2142691A151}.Release|Any CPU.Build.0 = Release|Any CPU
{46C16E64-DC72-446D-B153-A2142691A151}.Test|Any CPU.ActiveCfg = Test|Any CPU
{46C16E64-DC72-446D-B153-A2142691A151}.Test|Any CPU.Build.0 = Test|Any CPU
{0859E3E2-5AB9-4997-9DE7-368EAB89313B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0859E3E2-5AB9-4997-9DE7-368EAB89313B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0859E3E2-5AB9-4997-9DE7-368EAB89313B}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ChainSafe.Gaming.Web3.Core;
using ChainSafe.Gaming.Web3.Core.Evm;
using ChainSafe.Gaming.Web3.Environment;
using Nethereum.JsonRpc.Client;
using Nethereum.Signer;
using UnityEngine;
using TWeb3Auth = Web3Auth;
Expand All @@ -26,20 +27,21 @@ public class Web3AuthWallet : ISigner, ITransactionExecutor, ILifecycleParticipa
private TWeb3Auth coreInstance;
private InProcessSigner signer;
private InProcessTransactionExecutor transactionExecutor;
private IMainThreadRunner mainThreadRunner;
private IClient rpcClient;
private readonly IAnalyticsClient analyticsClient;

/// <summary>
/// Initializes a new instance of the <see cref="Web3AuthWallet"/> class.
/// </summary>
/// <param name="config">The configuration for the Web3Auth wallet.</param>
/// <param name="chainConfig">The configuration for the target blockchain.</param>
/// <param name="rpcProvider">The RPC provider for blockchain interaction.</param>
public Web3AuthWallet(Web3AuthWalletConfig config, IRpcProvider rpcProvider, IMainThreadRunner mainThreadRunner, IAnalyticsClient analyticsClient)
/// <param name="rpcClient"></param>
/// <param name="analyticsClient"></param>
public Web3AuthWallet(Web3AuthWalletConfig config, IRpcProvider rpcProvider, IClient rpcClient, IAnalyticsClient analyticsClient)
{
this.config = config;
this.rpcProvider = rpcProvider;
this.mainThreadRunner = mainThreadRunner;
this.rpcClient = rpcClient;
this.analyticsClient = analyticsClient;
}

Expand Down Expand Up @@ -72,7 +74,7 @@ public async ValueTask WillStartAsync()
var signerConfig = new InProcessSignerConfig { PrivateKey = privateKey };
signer = new InProcessSigner(signerConfig);

transactionExecutor = new InProcessTransactionExecutor(signer, analyticsClient.ChainConfig, rpcProvider, mainThreadRunner, new RpcClientWrapper(analyticsClient.ChainConfig));
transactionExecutor = new InProcessTransactionExecutor(signer, analyticsClient.ChainConfig, rpcProvider, rpcClient);

void Web3Auth_OnLogin(Web3AuthResponse response)
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/data/published_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Packages/io.chainsafe.web3-unity/Runtime/Libraries/:ADRaffy.ENSNormalize;Nethereum.Model;BouncyCastle.Crypto;Nethereum.RLP;ChainSafe.Gaming.Debugging;Nethereum.RPC;ChainSafe.Gaming.Gelato;ChainSafe.Gaming.SygmaClient;Nethereum.Signer.EIP712;ChainSafe.Gaming.InProcessSigner;Nethereum.Signer;ChainSafe.Gaming.InProcessTransactionExecutor;Nethereum.Util;ChainSafe.Gaming.Unity.ThirdParty;Nethereum.Web3;ChainSafe.Gaming.Unity;System.Buffers;ChainSafe.Gaming.WalletConnect;System.Memory;ChainSafe.Gaming;System.Numerics.Vectors;Microsoft.Bcl.AsyncInterfaces;System.Reactive;Microsoft.Extensions.DependencyInjection.Abstractions;System.Runtime.CompilerServices.Unsafe;Microsoft.Extensions.DependencyInjection;System.Runtime.InteropServices.WindowsRuntime;Microsoft.Extensions.Logging.Abstractions;System.Security.Cryptography.Cng;Microsoft.IdentityModel.Abstractions;System.Text.Encodings.Web;Microsoft.IdentityModel.Logging;System.Text.Json;Microsoft.IdentityModel.Tokens;System.Threading.Channels;NBitcoin;System.Threading.Tasks.Extensions;Nethereum.ABI;WalletConnectSharp.Auth;Nethereum.Accounts;WalletConnectSharp.Common;WalletConnectSharp.Events;Nethereum.BlockchainProcessing;WalletConnectSharp.Core;Nethereum.Contracts;WalletConnectSharp.Crypto;Nethereum.Hex;Nethereum.JsonRpc.Client;WalletConnectSharp.Network.Websocket;Nethereum.JsonRpc.IpcClient;WalletConnectSharp.Network;Nethereum.JsonRpc.RpcClient;WalletConnectSharp.Sign;Nethereum.KeyStore;WalletConnectSharp.Storage;Nethereum.Merkle.Patricia;WalletConnectSharp.Web3Wallet;Nethereum.Merkle;Websocket.Client;Nethereum.Metamask;Nethereum.Siwe.Core;Nethereum.Siwe;Nethereum.UI;Nethereum.Unity.Metamask;Nethereum.Unity;ChainSafe.Gaming.MetaMask;ChainSafe.Gaming.MetaMask.Unity;ChainSafe.Gaming.InProcessTransactionExecutor.Unity;ChainSafe.Gaming.Marketplace
Packages/io.chainsafe.web3-unity/Runtime/Libraries/:ADRaffy.ENSNormalize;Nethereum.Model;BouncyCastle.Crypto;Nethereum.RLP;ChainSafe.Gaming.Debugging;Nethereum.RPC;ChainSafe.Gaming.Gelato;ChainSafe.Gaming.SygmaClient;Nethereum.Signer.EIP712;ChainSafe.Gaming.InProcessSigner;Nethereum.Signer;ChainSafe.Gaming.InProcessTransactionExecutor;Nethereum.Util;ChainSafe.Gaming.Unity.ThirdParty;Nethereum.Web3;ChainSafe.Gaming.Unity;System.Buffers;ChainSafe.Gaming.WalletConnect;System.Memory;ChainSafe.Gaming;System.Numerics.Vectors;Microsoft.Bcl.AsyncInterfaces;System.Reactive;Microsoft.Extensions.DependencyInjection.Abstractions;System.Runtime.CompilerServices.Unsafe;Microsoft.Extensions.DependencyInjection;System.Runtime.InteropServices.WindowsRuntime;Microsoft.Extensions.Logging.Abstractions;System.Security.Cryptography.Cng;Microsoft.IdentityModel.Abstractions;System.Text.Encodings.Web;Microsoft.IdentityModel.Logging;System.Text.Json;Microsoft.IdentityModel.Tokens;System.Threading.Channels;NBitcoin;System.Threading.Tasks.Extensions;Nethereum.ABI;WalletConnectSharp.Auth;Nethereum.Accounts;WalletConnectSharp.Common;WalletConnectSharp.Events;Nethereum.BlockchainProcessing;WalletConnectSharp.Core;Nethereum.Contracts;WalletConnectSharp.Crypto;Nethereum.Hex;Nethereum.JsonRpc.Client;WalletConnectSharp.Network.Websocket;Nethereum.JsonRpc.IpcClient;WalletConnectSharp.Network;Nethereum.JsonRpc.RpcClient;WalletConnectSharp.Sign;Nethereum.KeyStore;WalletConnectSharp.Storage;Nethereum.Merkle.Patricia;WalletConnectSharp.Web3Wallet;Nethereum.Merkle;Websocket.Client;Nethereum.Metamask;Nethereum.Siwe.Core;Nethereum.Siwe;Nethereum.UI;Nethereum.Unity.Metamask;Nethereum.Unity;ChainSafe.Gaming.MetaMask;ChainSafe.Gaming.MetaMask.Unity;ChainSafe.Gaming.Marketplace
Packages/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/:Chainsafe.Gaming.Chainlink;ChainSafe.Gaming.Lootboxes.Chainlink
Packages/io.chainsafe.web3-unity.hyperplay/Runtime/Libraries/:ChainSafe.Gaming.HyperPlay

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using ChainSafe.Gaming.Web3.Core.Evm;
using ChainSafe.Gaming.Web3.Environment;
using Nethereum.Hex.HexTypes;
using Nethereum.JsonRpc.Client;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3.Accounts;
using NIpcClient = Nethereum.JsonRpc.IpcClient.IpcClient;
Expand All @@ -30,10 +31,9 @@ public class InProcessTransactionExecutor : ITransactionExecutor
/// <param name="signer">Injected <see cref="ISigner"/>.</param>
/// <param name="chainConfig">Injected <see cref="IChainConfig"/>.</param>
/// <param name="rpcProvider">Injected <see cref="IRpcProvider"/>.</param>
/// <param name="mainThreadRunner">Injected <see cref="IMainThreadRunner"/>.</param>
/// <param name="rpcClientWrapper">Injected <see cref="IRpcClientWrapper"/>.</param>
/// <param name="rpcClient">Injected <see cref="IClient"/>.</param>
/// <exception cref="Web3Exception">Throws exception if initializing instance fails.</exception>
public InProcessTransactionExecutor(ISigner signer, IChainConfig chainConfig, IRpcProvider rpcProvider, IMainThreadRunner mainThreadRunner, IRpcClientWrapper rpcClientWrapper)
public InProcessTransactionExecutor(ISigner signer, IChainConfig chainConfig, IRpcProvider rpcProvider, IClient rpcClient)
{
// It should be possible to set up other signers to work with this as well.
// However, does it make sense to let a remote wallet sign a transaction, but
Expand All @@ -43,23 +43,19 @@ public InProcessTransactionExecutor(ISigner signer, IChainConfig chainConfig, IR
accountAddress = privateKey.GetPublicAddress();
var account = new Account(privateKey);

// Initialize Web3 on the main thread.
mainThreadRunner.Enqueue(() =>
if (chainConfig.Rpc is not null && !string.Empty.Equals(chainConfig.Rpc))
{
if (chainConfig.Rpc is not null && !string.Empty.Equals(chainConfig.Rpc))
{
web3 = new NWeb3(account, rpcClientWrapper.Client);
}
else if (chainConfig.Ipc is not null && !string.Empty.Equals(chainConfig.Ipc))
{
var client = new NIpcClient(chainConfig.Rpc);
web3 = new NWeb3(client);
}
else
{
throw new Web3Exception($"{nameof(IChainConfig)} should have at least one communication method set.");
}
});
web3 = new NWeb3(account, rpcClient);
}
else if (chainConfig.Ipc is not null && !string.Empty.Equals(chainConfig.Ipc))
{
var client = new NIpcClient(chainConfig.Rpc);
web3 = new NWeb3(client);
}
else
{
throw new Web3Exception($"{nameof(IChainConfig)} should have at least one communication method set.");
}

this.rpcProvider = rpcProvider;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ChainSafe.Gaming.Web3.Build;
using ChainSafe.Gaming.Web3.Core.Evm;
using Microsoft.Extensions.DependencyInjection;
using Nethereum.JsonRpc.Client;

namespace ChainSafe.Gaming.InProcessTransactionExecutor.Unity
{
Expand All @@ -19,8 +20,6 @@ public static IWeb3ServiceCollection UseInProcessTransactionExecutor(this IWeb3S
collection.AssertServiceNotBound<ITransactionExecutor>();
collection.AddSingleton<ITransactionExecutor, InProcessTransactionExecutor>();

collection.AssertServiceNotBound<IRpcClientWrapper>();
collection.AddSingleton<IRpcClientWrapper, RpcClientWrapper>();
return collection;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ChainSafe.Gaming.Unity/ChainSafe.Gaming.Unity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ProjectReference Include="..\ChainSafe.Gaming.Debugging\ChainSafe.Gaming.Debugging.csproj" />
<ProjectReference Include="..\ChainSafe.Gaming\ChainSafe.Gaming.csproj" />
<ProjectReference Include="..\ChainSafe.Gaming.InProcessSigner\ChainSafe.Gaming.InProcessSigner.csproj" />
<ProjectReference Include="..\ChainSafe.Gaming.InProcessTransactionExecutor.Unity\ChainSafe.Gaming.InProcessTransactionExecutor.Unity.csproj" />
<ProjectReference Include="..\ChainSafe.Gaming.InProcessTransactionExecutor\ChainSafe.Gaming.InProcessTransactionExecutor.csproj" />
<ProjectReference Include="..\ChainSafe.Gaming.WalletConnect\ChainSafe.Gaming.WalletConnect.csproj" />
<ProjectReference Include="..\ChainSafe.Gaming.MetaMask.Unity\ChainSafe.Gaming.MetaMask.Unity.csproj" />
<ProjectReference Include="..\ChainSafe.Gaming.Unity.ThirdParty\ChainSafe.Gaming.Unity.ThirdParty.csproj" />
Expand Down
4 changes: 4 additions & 0 deletions src/ChainSafe.Gaming/Web3/Evm/JsonRpc/RpcClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using ChainSafe.Gaming.Web3.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Nethereum.JsonRpc.Client;

namespace ChainSafe.Gaming.Evm.JsonRpc
{
Expand Down Expand Up @@ -40,6 +41,9 @@ public static IWeb3ServiceCollection UseRpcProvider(this IWeb3ServiceCollection
collection.AssertServiceNotBound<IRpcProvider>();
collection.TryAddSingleton(DefaultClientConfig);
collection.AddSingleton<IRpcProvider, ILifecycleParticipant, RpcClientProvider>();

collection.AssertServiceNotBound<IClient>();
collection.AddSingleton<IClient, RpcClientProvider>();
return collection;
}
}
Expand Down
36 changes: 24 additions & 12 deletions src/ChainSafe.Gaming/Web3/Evm/JsonRpc/RpcClientProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
using ChainSafe.Gaming.Web3.Core;
using ChainSafe.Gaming.Web3.Environment;
using Nethereum.Hex.HexTypes;
using Nethereum.JsonRpc.Client;
using Nethereum.JsonRpc.Client.RpcMessages;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ChainSafe.Gaming.Evm.Providers
{
public class RpcClientProvider : IRpcProvider, ILifecycleParticipant
public class RpcClientProvider : ClientBase, IRpcProvider, ILifecycleParticipant
{
private readonly RpcClientConfig config;
private readonly Web3Environment environment;
Expand Down Expand Up @@ -100,19 +101,9 @@ public async Task<T> Perform<T>(string method, params object[] parameters)

try
{
var httpClient = environment.HttpClient;
var request = new RpcRequestMessage(Guid.NewGuid().ToString(), method, parameters);
var response =
(await httpClient.Post<RpcRequestMessage, RpcResponseMessage>(config.RpcNodeUrl, request))
.AssertSuccess();

if (response.HasError)
{
var error = response.Error;
var errorMessage =
$"RPC returned error for \"{method}\": {error.Code} {error.Message} {error.Data}";
throw new Web3Exception(errorMessage);
}
var response = await SendAsync(request);

var serializer = JsonSerializer.Create();
return serializer.Deserialize<T>(new JTokenReader(response.Result))!;
Expand All @@ -134,5 +125,26 @@ public async Task<T> Perform<T>(string method, params object[] parameters)
});
}
}

protected override async Task<RpcResponseMessage> SendAsync(RpcRequestMessage request, string route = null)
{
string body = JsonConvert.SerializeObject(request);

return await SendAsyncInternally<RpcResponseMessage>(body);
}

protected override async Task<RpcResponseMessage[]> SendAsync(RpcRequestMessage[] requests)
{
string body = JsonConvert.SerializeObject(requests);

return await SendAsyncInternally<RpcResponseMessage[]>(body);
}

private async Task<T> SendAsyncInternally<T>(string body)
{
var result = await environment.HttpClient.PostRaw(config.RpcNodeUrl, body, "application/json");

return JsonConvert.DeserializeObject<T>(result.Response);
}
}
}