private IEnumerator FetchHighScore() { string url = "https://rinkeby.infura.io/v3/fbc0597d7f784931a68acca3eb26f65b"; string contractAddress = "0x1931d2436288c4489a7849a7eebda6dfb47d63d7"; for (int leaderboardIndex = 0; leaderboardIndex < 10; leaderboardIndex++) { // fetch leaderboard from eth smart contract var queryRequest = new QueryUnityRequest <LeaderboardFunctionBase, LeaderboardOutputDTOBase>(url, contractAddress); // keep trying until there's a result while (queryRequest.Result == null) { yield return(queryRequest.Query(new LeaderboardFunctionBase() { ReturnValue1 = leaderboardIndex }, contractAddress)); } // display on screen nameText.text = queryRequest.Result.User.ToString(); scoreText.text = queryRequest.Result.Score.ToString(); Transform entryTransform = Instantiate(highScoreRow, highScoreContainer); RectTransform entryRectTransform = entryTransform.GetComponent <RectTransform>(); entryRectTransform.anchoredPosition = new Vector2(0, -25 * leaderboardIndex); } highScoreRow.gameObject.SetActive(false); }
private IEnumerator FetchOwnerOf() { string url = "https://rinkeby.infura.io/v3/fbc0597d7f784931a68acca3eb26f65b"; string contractAddress = "0xcB04BF3E72C5448f1368084Bb312b2F0B2f6529f"; string userAddress = GetWalletAddress(); // "0xbC8C6d48aC0D36DE5D4d543b73e49E1Ec512A196"; // loop through user tokens var tokenIndex = 0; var tokenId = 1; while (tokenId != 0) { var queryRequest = new QueryUnityRequest <TokenOfOwnerByIndexFunction, TokenOfOwnerByIndexOutputDTO>(url, contractAddress); yield return(queryRequest.Query(new TokenOfOwnerByIndexFunction() { Owner = userAddress, Index = tokenIndex }, contractAddress)); tokenId = (int)queryRequest.Result.ReturnValue1; if (tokenId != 0) { Instantiate(NFTItems[tokenId], NFTLocations[tokenId].position, NFTLocations[tokenId].rotation); } tokenIndex++; } }
private IEnumerator CheckHighScore() { int leaderboardIndex = 4; var queryRequest = new QueryUnityRequest <LeaderboardFunction, LeaderboardOutputDTOBase>(url, contractAddress); yield return(queryRequest.Query(new LeaderboardFunction() { ReturnValue1 = leaderboardIndex }, contractAddress)); if (scoreValue != null) { if (Int64.Parse(scoreValue.GetComponent <Text>().text) > queryRequest.Result.Score) { highScorePanel.SetActive(true); Cursor.visible = true; playerNameInput.Select(); playerNameInput.onEndEdit.AddListener(delegate { StartCoroutine(SignAndSendTransaction()); }); } else if (Int64.Parse(scoreValue.GetComponent <Text>().text) < queryRequest.Result.Score) { gamePanel.SetActive(false); blurPanel.SetActive(true); gameOverPanel.SetActive(true); Cursor.visible = true; } } }
public IEnumerator getSubmissionCount() { var request = new QueryUnityRequest <GetSubmissionCountFunction, EthereumTypes.Uint256>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(request.Query(new GetSubmissionCountFunction(), address)); yield return(request.Result); }
public IEnumerator getRoundInfo(BigInteger roundIndex) { var request = new QueryUnityRequest <GetRoundInfoFunction, MatryxRound.RoundInfo>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(request.Query(new GetRoundInfoFunction() { RoundIndex = roundIndex }, address)); }
public IEnumerator getInfo() { var request = new QueryUnityRequest <GetInfoFunction, TournamentInfo>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(request.Query(new GetInfoFunction(), address)); owner = request.Result.owner.ToLower(); yield return(request.Result); }
public static IEnumerator getOwner(Async thread) { var queryRequest = new QueryUnityRequest <GetOwnerFunction, EthereumTypes.Address>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetOwnerFunction() { }, MatryxToken.address)); //Debug.Log("getOwner result: " + queryRequest.Result); }
public static IEnumerator getAvailableRewardForUser(string commitHash, string user) { var queryRequest = new QueryUnityRequest <GetAvailableRewardForUserFunction, EthereumTypes.Uint256>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetAvailableRewardForUserFunction() { CommitHash = commitHash, User = user }, MatryxCommit.address)); }
public static IEnumerator getCommitByContent(string content, Async thread = null) { var queryRequest = new QueryUnityRequest <GetCommitByContentFunction, CommitOutputDTO>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetCommitByContentFunction() { Content = content }, MatryxCommit.address)); yield return(queryRequest.Result); }
public IEnumerator isEntrant(string user) { var isEntrantRequest = new QueryUnityRequest <IsEntrantFunction, EthereumTypes.Bool>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(isEntrantRequest.Query(new IsEntrantFunction() { User = user }, address)); yield return(isEntrantRequest.Result); }
public IEnumerator getEntryFeePaid(string user) { var request = new QueryUnityRequest <GetEntryFeePaidFunction, EthereumTypes.Address>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(request.Query(new GetEntryFeePaidFunction() { User = user }, address)); yield return(request.Result); }
public IEnumerator getRoundState(BigInteger roundIndex) { var request = new QueryUnityRequest <GetRoundStateFunction, EthereumTypes.Uint256>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(request.Query(new GetRoundStateFunction() { RoundIndex = roundIndex }, address)); yield return(request.Result); }
public static IEnumerator balanceOf(string owner, Async thread = null) { var queryRequest = new QueryUnityRequest <BalanceOfFunction, EthereumTypes.Uint256>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new BalanceOfFunction() { Owner = owner }, MatryxToken.address)); yield return(queryRequest.Result.Value); }
public static IEnumerator getCommit(string commitHash, Async thread = null) { var queryRequest = new QueryUnityRequest <GetCommitFunction, CommitOutputDTO>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetCommitFunction() { CommitHash = Utils.HexStringToByteArray(commitHash) }, MatryxCommit.address)); yield return(queryRequest.Result.outCommit); }
public IEnumerator GetElapsedRateCR() { Debug.Log("Creating Elapsed Rate"); var queryRequest = new QueryUnityRequest <ParticipantRetryTimeFunction, ParticipantRetryTimeOutputDTO>(networkUrl, contractAddress); Debug.Log("Executing Elapsed Rate Query"); yield return(queryRequest.Query(new ParticipantRetryTimeFunction(), contractAddress)); Debug.Log($"Invoking Elapsed Rate Query Callback With Value: {queryRequest.Result.ReturnValue1}"); OnGetElapsedRate?.Invoke(queryRequest.Result.ReturnValue1); }
public static IEnumerator getSubmissionsForCommit(string commitHash, Async thread = null) { var queryRequest = new QueryUnityRequest <GetSubmissionsForCommitFunction, EthereumTypes.Bytes32Array>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetSubmissionsForCommitFunction() { CommitHash = commitHash }, MatryxCommit.address)); yield return(queryRequest.Result); }
public static IEnumerator getInitialCommits(Async thread = null) { var queryRequest = new QueryUnityRequest <GetInitialCommitsFunction, EthereumTypes.Bytes32Array>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetInitialCommitsFunction() { }, MatryxCommit.address)); yield return(queryRequest.Result); Debug.Log("Hello! Initial Commits are " + queryRequest.Result); }
public IEnumerator Query(QueryContext context) { var request = new QueryUnityRequest < GetSiteCountFunction, GetSiteCountOutputDTO>( context.url, context.account); yield return(request.Query(context.contractAddress)); count = (int)request.Result.Count; }
// TODO: // This logic was ripped from the Faucet class. We need to refactor so we can elegantly reuse the Faucet // in order to retain a single source of logic and reduce failure point complexity. Fortunately these are simply // read-only calls to the network, but it should be fixed sooner than later. private IEnumerator CheckCooldownCR(string userWalletAddress) { BigInteger elapsedRate; BigInteger elapsedTime; { Debug.Log("Creating Elapsed Rate"); var queryRequest = new QueryUnityRequest <ParticipantRetryTimeFunction, ParticipantRetryTimeOutputDTO>(faucet.NetworkUrl, faucet.ContractAddress); Debug.Log("Executing Elapsed Rate Query"); yield return(queryRequest.Query(new ParticipantRetryTimeFunction(), faucet.ContractAddress)); Debug.Log($"Invoking Elapsed Rate Query Callback With Value: {queryRequest.Result.ReturnValue1}"); elapsedRate = queryRequest.Result.ReturnValue1; } { Debug.Log("Creating ElapsedTimeQuery"); var queryRequest = new QueryUnityRequest <GetElapsedTimeFunction, GetElapsedTimeOutputDTO>(faucet.NetworkUrl, faucet.ContractAddress); Debug.Log("Executing ElapsedTimeQuery"); yield return(queryRequest.Query(new GetElapsedTimeFunction() { FromAddress = userWalletAddress, Participant = userWalletAddress }, faucet.ContractAddress)); Debug.Log($"Invoking ElapsedTimeQuery Callback with value: {queryRequest.Result.ReturnValue1}"); elapsedTime = queryRequest.Result.ReturnValue1; } if (elapsedTime < elapsedRate) { var timeRemaining = elapsedRate - elapsedTime; TerminateCoroutineExecution(new WalletValidationCoordinator.ValidationOutcome( WalletValidationCoordinator.ValidationOutcome.Code.TooSoon, timeRemaining )); } else { // TODO: // Check if there is enough ERC20 balance in the contract. // Other players could be playing at the same time, we need to ensure everyone gets the correct payout, // e.g. payout transaction is not reverted due to lack of funds. // Solution: // Scan the mempool for pending relevant transactions using https://www.blocknative.com/. // This way, we can calculate if there are enough funds for a game session based on // [contract amount] - [collective transaction total from all pending payouts]. // Bonus: // We can prevent an request spam attack where the same user plays multiple rounds in the same block. } }
/// <summary> /// Coroutine which queries some data from an ethereum smart contract. /// </summary> /// <typeparam name="TFunc"> The <see cref="ContractFunction"/> of the smart contract to execute which will return us some data. </typeparam> /// <typeparam name="TOut"> The <see cref="IFunctionOutputDTO"/> which represents the data which was returned from the <see cref="ContractFunction"/>. </typeparam> /// <param name="promise"> Promise of eventually returning the data from the contract query. </param> /// <param name="contractAddress"> The contract address to execute the <see cref="ContractFunction"/> on. </param> /// <param name="senderAddress"> The address of the sender requesting this data. </param> /// <param name="functionInput"> The input parameters of the <see cref="ContractFunction"/>. </param> private static IEnumerator _QueryContractCoroutine <TFunc, TOut>( EthCallPromise <TOut> promise, string contractAddress, string senderAddress, params object[] functionInput) where TFunc : ContractFunction where TOut : IFunctionOutputDTO, new() { var queryRequest = new QueryUnityRequest <TFunc, TOut>(EthereumNetworkManager.CurrentNetwork.NetworkUrl, senderAddress); yield return(queryRequest.Query(ContractFunction.CreateFunction <TFunc>(functionInput), contractAddress)); promise.Build(queryRequest, () => queryRequest.Result); }
public static IEnumerator getTournaments(Async thread = null) { var queryRequest = new QueryUnityRequest <GetTournamentsFunction, EthereumTypes.AddressArray>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetTournamentsFunction(), address)); yield return(queryRequest.Result); if (thread != null) { thread.pushEvent("getTournaments", queryRequest.Result); } }
public static IEnumerator getTotalBalance(Async thread = null) { var queryRequest = new QueryUnityRequest <GetTotalBalanceFunction, EthereumTypes.Uint256>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetTotalBalanceFunction(), address)); yield return(queryRequest.Result); if (thread != null) { thread.pushEvent("isSubmission", queryRequest.Result); } }
//function getInfo() external view returns(MatryxPlatform.Info); public static IEnumerator getInfo(Async thread = null) { var queryRequest = new QueryUnityRequest <GetInfoFunction, MatryxPlatformInfoDTO>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetInfoFunction(), address)); yield return(queryRequest.Result); if (thread != null) { thread.pushEvent("getInfo", queryRequest.Result); } }
public IEnumerator GetElapsedTimeCR() { Debug.Log("Creating ElapsedTimeQuery"); var queryRequest = new QueryUnityRequest <GetElapsedTimeFunction, GetElapsedTimeOutputDTO>(networkUrl, contractAddress); Debug.Log("Executing ElapsedTimeQuery"); yield return(queryRequest.Query(new GetElapsedTimeFunction() { FromAddress = gasWalletAddress, Participant = inputWalletAddress.text }, contractAddress)); Debug.Log($"Invoking ElapsedTimeQuery Callback with value: {queryRequest.Result.ReturnValue1}"); OnGetElapsedTime?.Invoke(queryRequest.Result.ReturnValue1); }
/// <summary> /// Coroutine which queries some data from an ethereum smart contract. /// </summary> /// <typeparam name="TFunc"> The <see cref="FunctionMessage"/> of the smart contract to execute which will return us some data. </typeparam> /// <typeparam name="TOut"> The <see cref="IFunctionOutputDTO"/> which represents the data which was returned from the <see cref="ContractFunction"/>. </typeparam> /// <param name="function"> The contract function to query data from. </param> /// <param name="promise"> Promise of eventually returning the data from the contract query. </param> /// <param name="contractAddress"> The contract address to execute the <see cref="FunctionMessage"/> on. </param> /// <param name="senderAddress"> The address of the sender requesting this data. </param> private static IEnumerator _QueryContractCoroutine <TFunc, TOut>( TFunc function, EthCallPromise <TOut> promise, string contractAddress, string senderAddress) where TFunc : FunctionMessage, new() where TOut : IFunctionOutputDTO, new() { function.SetDefaultFromAddressIfNotSet(senderAddress); var queryRequest = new QueryUnityRequest <TFunc, TOut>(NetworkProvider.GetNetworkChainUrl(), senderAddress); yield return(queryRequest.Query(function, contractAddress)); promise.Build(queryRequest, () => queryRequest.Result); }
public static IEnumerator isTournament(string tournamentAddress, Async thread = null) { var queryRequest = new QueryUnityRequest <IsTournamentFunction, EthereumTypes.Bool>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new IsTournamentFunction() { TournamentAddress = tournamentAddress }, address)); yield return(queryRequest.Result); if (thread != null) { thread.pushEvent("isTournament", queryRequest.Result); } }
public IEnumerator FetchCoinInformation() { // Create the queryRequest to the BalanceOfFunction of the 1155 coin var queryRequest = new QueryUnityRequest <BalanceOfFunction, BalanceOfOutputDTO>(infuriaUrl, userWallet); // BigInteger Rari ID of the coin we are looking for (Aqua Mars) var rarID = new BigInteger(rariIdOfCoin); //Send the account and Rari ID to the BalanceOfFunction, also send along the contract address of the Aqua Mars Coin yield return(queryRequest.Query(new BalanceOfFunction() { Account = userWallet, Id = rariIdOfCoin }, contractOfCoin)); numberOfCoinsUserHas = queryRequest.Result.ReturnValue1; }
public static IEnumerator getSubmission(string submissionHash, Async thread = null) { var queryRequest = new QueryUnityRequest <GetSubmissionFunction, MatryxSubmission.SubmissionOutputDTO>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new GetSubmissionFunction() { SubmissionHash = Utils.HexStringToByteArray(submissionHash) }, address)); yield return(queryRequest.Result); if (thread != null) { thread.pushEvent("getSubmission", queryRequest.Result); } }
public static IEnumerator isSubmission(string submissionHash, Async thread = null) { var queryRequest = new QueryUnityRequest <IsSubmissionFunction, EthereumTypes.Bool>(NetworkSettings.infuraProvider, NetworkSettings.currentAddress); yield return(queryRequest.Query(new IsSubmissionFunction() { SubmissionHash = Utils.HexStringToByteArray(submissionHash) }, address)); yield return(queryRequest.Result); if (thread != null) { thread.pushEvent("isSubmission", queryRequest.Result); } }
public IEnumerator Query(QueryContext context, int siteIndex) { var request = new QueryUnityRequest < GetSiteNameFunction, GetSiteNameOutputDTO>( context.url, context.account); yield return(request.Query( new GetSiteNameFunction { Index = siteIndex }, context.contractAddress)); name = request.Result.Name; }