这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
116f2f4
contribution edits
robGG1997 Apr 3, 2024
ee0917e
condition to run tests fixed
robGG1997 Apr 3, 2024
53c9f25
typo fix
robGG1997 Apr 3, 2024
6ff54d1
use deploy key for push
robGG1997 Apr 3, 2024
f39eddd
bot makes push instead of actor
robGG1997 Apr 3, 2024
15ad020
fixed syntax
robGG1997 Apr 3, 2024
26d722c
setup ssh keys added
robGG1997 Apr 3, 2024
a07151d
different way for setting up ssh
robGG1997 Apr 3, 2024
297c7dd
only play mode tests
robGG1997 Apr 3, 2024
d902b3b
reverted ssh setup method
robGG1997 Apr 3, 2024
c695eda
run workflow on dev not main!
robGG1997 Apr 3, 2024
b1f7ba8
revert pre commit check branch and change post push action branch to dev
robGG1997 Apr 3, 2024
7434347
added ssh key for checkout
robGG1997 Apr 3, 2024
ee9a9d9
removed tests for faster iteration
robGG1997 Apr 3, 2024
337a618
put back publish dlls
robGG1997 Apr 3, 2024
141b00d
check if latest commit isn't from github actions to avoid recursive a…
robGG1997 Apr 3, 2024
1cc3a47
small syntax fix
robGG1997 Apr 3, 2024
44438af
small syntax fix 2
robGG1997 Apr 3, 2024
bb84ab8
replace conditional fix for loop issue with commit skip ci keyword in…
robGG1997 Apr 3, 2024
2da4827
put tests back in
robGG1997 Apr 3, 2024
7b2c8ef
on push workflow call now back to from main
robGG1997 Apr 3, 2024
8f2dc13
test again
robGG1997 Apr 3, 2024
9bce586
reverted actor from bot to user and removed ssh setup
robGG1997 Apr 3, 2024
76d9812
revert post push workflow file target back to main
robGG1997 Apr 3, 2024
e0e95b5
chore: fix typos (#918)
xiaoxianBoy Apr 9, 2024
138e54e
Auto Commit [skip ci]
rob1997 Apr 9, 2024
e579b89
Metamask SDK fixes (#922)
rob1997 Apr 12, 2024
03270af
Auto Commit [skip ci]
kantagara Apr 12, 2024
e60f66a
Merge branch 'main' into dev
rob1997 Apr 23, 2024
d57532c
Auto Commit [skip ci]
rob1997 Apr 23, 2024
6d69769
Package built-in dependencies fix (#925)
oleksandrchainsafe Apr 29, 2024
665fd5d
Auto Commit [skip ci]
oleksandrchainsafe Apr 29, 2024
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
2 changes: 1 addition & 1 deletion Modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IWeb3ServiceCollection UseJsonRpcProvider(this IWeb3ServiceCollect
serviceCollection.AssertServiceNotBound<IEvmProvider>();

// register Service with IEvmProvider as a Contract Type
// and JsonRpcProvider as Implmentation Type
// and JsonRpcProvider as Implementation Type
serviceCollection.AddSingleton<IEvmProvider, JsonRpcProvider>();
return serviceCollection;
}
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SecurePlayerPrefs


/**
* Initializes the encryptor. If its the frist time, it will generate
* Initializes the encryptor. If its the first time, it will generate
* a random 3 digit number and puts it between private key and its appendix.
* If this was initialized on this device before, it will load it and create
* the private key.
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static async Task<bool> SignVerify(Web3 web3, string message)
var msgHash = new Sha3Keccack().CalculateHash(Encoding.UTF8.GetBytes(msg));
var signature = MessageSigner.ExtractEcdsaSignature(signatureString);
var key = EthECKey.RecoverFromSignature(signature, msgHash);
return key.GetPublicAddress() == playerAccount;
return key.GetPublicAddress().ToLower() == playerAccount.ToLower();
}

public static string EcdsaSignTransaction(string _privateKey, string _transaction, string _chainId)
Expand Down
4 changes: 2 additions & 2 deletions scripts/data/published_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
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
Packages/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/:Chainsafe.Gaming.Chainlink;ChainSafe.Gaming.Lootboxes.Chainlink;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.InProcessTransactionExecutor.Unity;ChainSafe.Gaming.Marketplace
Packages/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/:Chainsafe.Gaming.Chainlink;ChainSafe.Gaming.Lootboxes.Chainlink
10 changes: 9 additions & 1 deletion src/ChainSafe.Gaming.MetaMask.Unity/MetaMaskProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using ChainSafe.Gaming.Web3;
using ChainSafe.Gaming.Web3.Analytics;
using ChainSafe.Gaming.Web3.Core.Logout;
using ChainSafe.Gaming.Web3.Environment;
using UnityEngine;
using Object = UnityEngine.Object;
Expand All @@ -10,7 +11,7 @@ namespace ChainSafe.Gaming.MetaMask.Unity
/// <summary>
/// Concrete implementation of <see cref="IMetaMaskProvider"/>.
/// </summary>
public class MetaMaskProvider : IMetaMaskProvider
public class MetaMaskProvider : IMetaMaskProvider, ILogoutHandler
{
private readonly ILogWriter logWriter;

Expand Down Expand Up @@ -86,5 +87,12 @@ public async Task<T> Request<T>(string method, params object[] parameters)
{
return await metaMaskController.Request<T>(method, parameters);
}

public Task OnLogout()
{
Object.Destroy(metaMaskController.gameObject);

return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ChainSafe.Gaming.Web3.Build;
using ChainSafe.Gaming.Web3.Core.Logout;
using Microsoft.Extensions.DependencyInjection;

namespace ChainSafe.Gaming.MetaMask.Unity
Expand All @@ -18,7 +19,7 @@ public static IWeb3ServiceCollection UseMetaMask(this IWeb3ServiceCollection col
collection.AssertServiceNotBound<IMetaMaskProvider>();

// wallet
collection.AddSingleton<IMetaMaskProvider, MetaMaskProvider>();
collection.AddSingleton<ILogoutHandler, IMetaMaskProvider, MetaMaskProvider>();

return collection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public async Task<TransactionResponse> SendTransaction(TransactionRequest transa

WCLogger.Log($"Transaction executed successfully. Hash: {hash}.");

await Task.Delay(TimeSpan.FromSeconds(1)); // hack: rpcProvider.GetTransaction can't find transaction by hash

return await rpcProvider.GetTransaction(hash);

bool ValidateResponseHash(string hash)
Expand Down
26 changes: 26 additions & 0 deletions src/ChainSafe.Gaming/Web3/Core/DelayUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Threading.Tasks;

namespace ChainSafe.Gaming.Web3.Core
{
/// <summary>
/// Utility class for delay operations.
/// </summary>
public static class DelayUtil
{
/// <summary>
/// Replicates Task.Delay behaviour. Works on a single-threaded platforms like Unity WebGL.
/// </summary>
/// <param name="delay">The time to wait.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task SafeDelay(TimeSpan delay) // TODO: use default method if platform supports multithreading
{
var start = DateTime.UtcNow;

while (DateTime.UtcNow - start < delay)
{
await Task.Yield();
}
}
}
}
38 changes: 26 additions & 12 deletions src/ChainSafe.Gaming/Web3/Core/Evm/RpcProviderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using ChainSafe.Gaming.Evm.Transactions;
using ChainSafe.Gaming.Web3;
using ChainSafe.Gaming.Web3.Core;
using Nethereum.Hex.HexConvertors.Extensions;
using Nethereum.Hex.HexTypes;
using Nethereum.RPC.Eth.DTOs;
Expand Down Expand Up @@ -289,38 +288,53 @@ public static async Task<HexBigInteger> EstimateGas(this IRpcProvider provider,
/// </summary>
/// <param name="provider">The RPC provider.</param>
/// <param name="transactionHash">The hash of the transaction to retrieve.</param>
/// <param name="timeOut">(Optional) The time after which the method will fail if we can't find the transaction by hash. 15 seconds by default.</param>
/// <returns>
/// A <see cref="Task"/> representing the asynchronous operation.
/// The task result contains the transaction details as a <see cref="TransactionResponse"/>.
/// </returns>
public static async Task<TransactionResponse> GetTransaction(this IRpcProvider provider, string transactionHash)
public static async Task<TransactionResponse> GetTransaction(this IRpcProvider provider, string transactionHash, TimeSpan? timeOut = null)
{
timeOut ??= TimeSpan.FromSeconds(15);

// Poll transaction till it's available on the given node
TransactionResponse transaction = null;
var parameters = new object[] { transactionHash };
var pollStartTime = DateTime.UtcNow;
while (DateTime.UtcNow - pollStartTime < timeOut)
{
transaction = await provider.Perform<TransactionResponse>("eth_getTransactionByHash", parameters);

var result = await provider.Perform<TransactionResponse>("eth_getTransactionByHash", parameters);
if (transaction != null)
{
break;
}

if (result == null)
await DelayUtil.SafeDelay(TimeSpan.FromSeconds(1));
}

if (transaction == null)
{
throw new Web3Exception("transaction not found");
throw new Web3Exception("Transaction not found.");
}

if (result.BlockNumber == null)
if (transaction.BlockNumber == null)
{
result.Confirmations = 0;
transaction.Confirmations = 0;
}
else if (result.Confirmations == null)
else if (transaction.Confirmations == null)
{
var blockNumber = await provider.GetBlockNumber();
var confirmations = (blockNumber.ToUlong() - result.BlockNumber.ToUlong()) + 1;
var confirmations = (blockNumber.ToUlong() - transaction.BlockNumber.ToUlong()) + 1;
if (confirmations <= 0)
{
confirmations = 1;
}

result.Confirmations = confirmations;
transaction.Confirmations = confirmations;
}

return result;
return transaction;
}

/// <summary>
Expand Down