这是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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using ChainSafe.Gaming.Web3.Analytics;
using ChainSafe.Gaming.Web3.Core;
using ChainSafe.Gaming.Web3.Core.Evm;
using ChainSafe.Gaming.Web3.Environment;
using Nethereum.Signer;
using UnityEngine;
using TWeb3Auth = Web3Auth;
Expand All @@ -25,6 +26,7 @@ public class Web3AuthWallet : ISigner, ITransactionExecutor, ILifecycleParticipa
private TWeb3Auth coreInstance;
private InProcessSigner signer;
private InProcessTransactionExecutor transactionExecutor;
private IMainThreadRunner mainThreadRunner;
private readonly IAnalyticsClient analyticsClient;

/// <summary>
Expand All @@ -33,10 +35,11 @@ public class Web3AuthWallet : ISigner, ITransactionExecutor, ILifecycleParticipa
/// <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, IAnalyticsClient analyticsClient)
public Web3AuthWallet(Web3AuthWalletConfig config, IRpcProvider rpcProvider, IMainThreadRunner mainThreadRunner, IAnalyticsClient analyticsClient)
{
this.config = config;
this.rpcProvider = rpcProvider;
this.mainThreadRunner = mainThreadRunner;
this.analyticsClient = analyticsClient;
}

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

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

void Web3Auth_OnLogin(Web3AuthResponse response)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<CodeAnalysisRuleSet>../../global.ruleset</CodeAnalysisRuleSet>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;Test</Configurations>
<Platforms>AnyCPU</Platforms>
<RootNamespace>ChainSafe.Gaming.InProcessTransactionExecutor.Unity</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ChainSafe.Gaming.InProcessTransactionExecutor\ChainSafe.Gaming.InProcessTransactionExecutor.csproj" />
<ProjectReference Include="../ChainSafe.Gaming.InProcessTransactionExecutor/ChainSafe.Gaming.InProcessTransactionExecutor.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System;
using System.Net.Http;
using ChainSafe.Gaming.Web3;
using ChainSafe.Gaming.Web3.Environment;
using Nethereum.JsonRpc.Client;
using Nethereum.Unity.Rpc;

namespace ChainSafe.Gaming.InProcessTransactionExecutor.Unity
{
public class RpcClientWrapper : IRpcClientWrapper
{
private readonly IChainConfig chainConfig;

public RpcClientWrapper(IChainConfig chainConfig)
{
Client = new UnityWebRequestRpcTaskClient(new Uri(chainConfig.Rpc));
this.chainConfig = chainConfig;
}

public IClient Client { get; private set; }
public IClient Client => new RpcClient(new Uri(chainConfig.Rpc));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<CodeAnalysisRuleSet>../../global.ruleset</CodeAnalysisRuleSet>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;Test</Configurations>
<Platforms>AnyCPU</Platforms>
<RootNamespace>ChainSafe.Gaming.InProcessTransactionExecutor</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using ChainSafe.Gaming.Evm.Transactions;
using ChainSafe.Gaming.Web3;
using ChainSafe.Gaming.Web3.Core.Evm;
using ChainSafe.Gaming.Web3.Environment;
using Nethereum.Hex.HexTypes;
using Nethereum.RPC.Eth.DTOs;
using Nethereum.Web3.Accounts;
Expand All @@ -18,19 +19,21 @@ namespace ChainSafe.Gaming.InProcessTransactionExecutor
/// </summary>
public class InProcessTransactionExecutor : ITransactionExecutor
{
private readonly NWeb3 web3;
private readonly IRpcProvider rpcProvider;
private readonly string accountAddress;

private NWeb3 web3;

/// <summary>
/// Initializes a new instance of the <see cref="InProcessTransactionExecutor"/> class.
/// </summary>
/// <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>
/// <exception cref="Web3Exception">Throws exception if initializing instance fails.</exception>
public InProcessTransactionExecutor(ISigner signer, IChainConfig chainConfig, IRpcProvider rpcProvider, IRpcClientWrapper rpcClientWrapper)
public InProcessTransactionExecutor(ISigner signer, IChainConfig chainConfig, IRpcProvider rpcProvider, IMainThreadRunner mainThreadRunner, IRpcClientWrapper rpcClientWrapper)
{
// 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 @@ -39,19 +42,24 @@ public InProcessTransactionExecutor(ISigner signer, IChainConfig chainConfig, IR
throw new Web3Exception($"{nameof(InProcessTransactionExecutor)} only supports {nameof(InProcessSigner.InProcessSigner)}");
accountAddress = privateKey.GetPublicAddress();
var account = new Account(privateKey);
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

// Initialize Web3 on the main thread.
mainThreadRunner.Enqueue(() =>
{
throw new Web3Exception($"{nameof(IChainConfig)} should have at least one communication method set.");
}
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.");
}
});

this.rpcProvider = rpcProvider;
}
Expand Down
1 change: 1 addition & 0 deletions src/ChainSafe.Gaming.Unity/UnityDispatcherAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using ChainSafe.Gaming.Evm.Unity;
using ChainSafe.Gaming.Web3.Environment;

namespace ChainSafe.Gaming.Unity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;

namespace ChainSafe.Gaming.Unity
namespace ChainSafe.Gaming.Web3.Environment
{
public interface IMainThreadRunner
{
Expand Down