public IEnumerator submit(Async.EventDelegate callback = null) { StatisticsTracking.StartEvent("Matryx", "Submission Creation"); ResultsMenu.transactionObject = this; var isEntrant = new Utils.CoroutineWithData <EthereumTypes.Bool>(MatryxCortex.Instance, tournament.isEntrant(NetworkSettings.currentAddress)); yield return(isEntrant); var tournamentInfo = new Utils.CoroutineWithData <TournamentInfo>(MatryxCortex.Instance, tournament.getInfo()); yield return(tournamentInfo); if (tournament.owner.Equals(NetworkSettings.currentAddress, System.StringComparison.CurrentCultureIgnoreCase)) { ResultsMenu.Instance.PostFailure(this, "You own this tournament; Unable to create submission."); yield break; } if (!isEntrant.result.Value) { var allowance = new Utils.CoroutineWithData <BigInteger>(MatryxCortex.Instance, MatryxToken.allowance(NetworkSettings.currentAddress, MatryxPlatform.address)); yield return(allowance); var balance = new Utils.CoroutineWithData <BigInteger>(MatryxCortex.Instance, MatryxToken.balanceOf(NetworkSettings.currentAddress)); yield return(balance); if (balance.result < tournament.entryFee) { ResultsMenu.Instance.SetStatus("Insufficient MTX. Please visit <link=https://app.matryx.ai/><u>our Matryx Dapp</u></link> for MTX Tokens.", true); yield break; } if (allowance.result < tournament.entryFee) { ResultsMenu.Instance.SetStatus("Approving entry fee..."); if (allowance.result != BigInteger.Zero) { var approveZero = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, MatryxToken.approve(MatryxPlatform.address, BigInteger.Zero)); yield return(approveZero); if (!approveZero.result) { Debug.Log("Failed to reset tournament's allowance to zero for this user. Please check the allowance this user has granted the tournament"); ResultsMenu.Instance.PostFailure(this); yield break; } } var approveEntryFee = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, MatryxToken.approve(MatryxPlatform.address, tournament.entryFee)); yield return(approveEntryFee); if (!approveEntryFee.result) { Debug.Log("Failed to set the tournament's allowance from this user to the tournament's entry fee"); ResultsMenu.Instance.PostFailure(this); yield break; } } ResultsMenu.Instance.SetStatus("Entering Tournament..."); var enterTournament = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, tournament.enter()); yield return(enterTournament); if (!enterTournament.result) { Debug.Log("Failed to enter tournament"); ResultsMenu.Instance.PostFailure(this); yield break; } } ResultsMenu.Instance.SetStatus("Claiming Content..."); bool shouldBreak = false; yield return(commit.claim((res) => { }, (nada) => { ResultsMenu.Instance.PostFailure(this, "Could not claim your content on Matryx..."); shouldBreak = true; })); if (shouldBreak) { yield break; } ResultsMenu.Instance.SetStatus("Hashing to Matryx..."); yield return(commit.create()); ResultsMenu.Instance.SetStatus("Uploading submission content..."); yield return(uploadContent()); if (!dto.Content.Contains("Qm")) { Debug.Log("Failed to upload file to IPFS"); ResultsMenu.Instance.PostFailure(this); yield break; } ResultsMenu.Instance.SetStatus("Creating Submission in Matryx..."); var createSubmission = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, tournament.createSubmission(this)); yield return(createSubmission); callback?.Invoke(createSubmission.result); if (!createSubmission.result) { Debug.Log("Failed to create submission"); yield break; } }
public static IEnumerator MTXBalanceCoroutine(Async.EventDelegate onSuccess) { var tokenBalanceCoroutine = new Utils.CoroutineWithData <BigInteger>(MatryxCortex.Instance, MatryxToken.balanceOf(NetworkSettings.currentAddress)); yield return(tokenBalanceCoroutine); var balance = tokenBalanceCoroutine.result / new BigInteger(1e18); onSuccess(balance); }
public static IEnumerator InitializeUser() { bool settingUp = true; while (!NetworkSettings.declinedAccountUnlock.HasValue || settingUp) { yield return(null); settingUp = NetworkSettings.currentAddress == null || NetworkSettings.currentAddress == "" || MatryxPlatform.address == null || MatryxToken.address == null || MatryxCommit.address == null || MatryxTournament.ABI == null; } if (NetworkSettings.declinedAccountUnlock.Value) { yield break; } var tokenBalance = new Utils.CoroutineWithData <BigInteger>(MatryxCortex.Instance, MatryxToken.balanceOf(NetworkSettings.currentAddress)); yield return(tokenBalance); NetworkSettings.MTXBalance = tokenBalance.result; if (MatryxAccountMenu.Instance) { MatryxAccountMenu.Instance.AccountInfoText[1].text = (NetworkSettings.MTXBalance / new BigInteger(1e18)).ToString() + " MTX"; } MatryxCommit.loadLocalClaims(); yield return(GetMyCommits(MatryxCommit.LoadCommits, (obj) => { Tippies.HeadsetModal("Could not load commits"); })); yield break; }
//function createSubmission(string calldata content, bytes32 commitHash) external; public IEnumerator create(Async.EventDelegate callback = null) { StatisticsTracking.StartEvent("Matryx", "Tournament Creation"); ResultsMenu.transactionObject = this; ResultsMenu.Instance.SetStatus("Checking MTX balance and platform allowance..."); var allowance = new Utils.CoroutineWithData <BigInteger>(MatryxCortex.Instance, MatryxToken.allowance(NetworkSettings.currentAddress, MatryxPlatform.address)); yield return(allowance); var balance = new Utils.CoroutineWithData <BigInteger>(MatryxCortex.Instance, MatryxToken.balanceOf(NetworkSettings.currentAddress)); yield return(balance); if (balance.result < bounty) { ResultsMenu.Instance.SetStatus("Insufficient MTX. Please visit <link=https://app.matryx.ai/><u>our Matryx Dapp</u></link> for MTX Tokens.", true); ResultsMenu.Instance.ReturnToCalcflowAfterSeconds(8f); yield break; } if (allowance.result < bounty) { ResultsMenu.Instance.SetStatus("Approving MatryxPlatform for " + Bounty + " MTX..."); if (allowance.result != BigInteger.Zero) { var approveZero = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, MatryxToken.approve(MatryxPlatform.address, BigInteger.Zero)); yield return(approveZero); if (!approveZero.result) { ResultsMenu.Instance.PostFailure(this, "Failed to reset the platform allowance to zero"); yield break; } } var approveBounty = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, MatryxToken.approve(MatryxPlatform.address, bounty)); yield return(approveBounty); if (!approveBounty.result) { ResultsMenu.Instance.PostFailure(this, "Failed to give the platform an MTX allowance"); yield break; } } if (contentHash.Equals("")) { ResultsMenu.Instance.SetStatus("Uploading Tournament Content..."); var uploadToIPFS = new Utils.CoroutineWithData <string[]>(MatryxCortex.Instance, uploadContent()); yield return(uploadToIPFS); if (!uploadToIPFS.result[0].Equals(string.Empty)) { contentHash = uploadToIPFS.result[0]; } if (!uploadToIPFS.result[1].Equals(string.Empty)) { fileHash = uploadToIPFS.result[1]; } } ResultsMenu.Instance.SetStatus("Creating Tournament " + title + "..."); var createTournament = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, MatryxPlatform.createTournament(this)); yield return(createTournament); callback?.Invoke(createTournament.result); }