public IEnumerator selectWinners(List <byte[]> submissions, List <BigInteger> distribution, BigInteger action, BigInteger start, BigInteger duration, BigInteger review, BigInteger bounty, Async.EventDelegate onComplete = null) { WinnersData wData = new WinnersData() { Submissions = submissions, Distribution = distribution, Action = action }; MatryxRound.RoundDetails rDetails = new MatryxRound.RoundDetails() { Start = start, Duration = duration, Review = review, Bounty = bounty }; var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <SelectWinnersFunction>(new SelectWinnersFunction() { WData = wData, RDetails = rDetails, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }, address)); yield return(Utils.GetTransactionStatus(transactionRequest, "selectWinners", null)); var getTransactionStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "selectWinners", null)); yield return(getTransactionStatus); yield return(getTransactionStatus.result); onComplete?.Invoke(getTransactionStatus.result); }
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; }
public IEnumerator uploadContent() { if (!content.Equals("")) { List <string> fileNames = new List <string>() { "jsonContent.json" }; List <byte[]> contents = new List <byte[]>() { MatryxCortex.serializer.Serialize(content) }; List <string> fileTypes = new List <string>() { "application/json" }; var uploadToIPFS = new Utils.CoroutineWithData <string>(MatryxCortex.Instance, MatryxCortex.uploadFiles(fileNames, contents, fileTypes)); yield return(uploadToIPFS); ipfsContentHash = uploadToIPFS.result; yield return(true); } yield return(false); }
public IEnumerator createSubmission(string tournamentAddress, string parentHash, bool isFork, BigInteger value, Async thread = null) { var salt = getClaim(ipfsContentHash).salt; var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); var createSubmissionMsg = new CreateSubmissionFunction() { TournamentAddress = tournamentAddress, SubmissionContentHash = ipfsContentHash, ParentHash = parentHash, IsFork = isFork, Salt = salt, CommitContentHash = ipfsContentHash, Value = value, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; yield return(transactionRequest.SignAndSendTransaction <CreateSubmissionFunction>(createSubmissionMsg, MatryxCommit.address)); var txStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "createSubmission", thread)); yield return(txStatus); yield return(txStatus.result); }
/// <summary> /// Uploads a Tournament's description and files to IPFS. /// </summary> /// <param name="tournament"> The tournament whose description and files are to be uploaded. </param> /// <returns> The description hash and files hash of the tournament in that order. </returns> public IEnumerator uploadContent() { string contentHash = ""; string filesHash = ""; // TODO: Allow for file uploading for tournaments (FileBrowser) //if (tournament.fileHash == null || tournament.fileHash.Equals(string.Empty)) //{ // if (tournament.file != null && !tournament.file.Equals(string.Empty)) // { // var uploadToIPFS = new Utils.CoroutineWithData<string>(MatryxCortex.Instance, Utils.uploadFiles("filesContent", "", tournament.file, "text/plain")); // yield return uploadToIPFS; // filesHash = uploadToIPFS.result; // } //} if (contentHash == string.Empty) { if (description != null && !description.Equals(string.Empty)) { var uploadToIPFS = new Utils.CoroutineWithData <string>(MatryxCortex.Instance, MatryxCortex.uploadJson(title, description, "", "math")); yield return(uploadToIPFS); contentHash = uploadToIPFS.result; } } yield return(new string[2] { contentHash, filesHash }); }
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 IEnumerator transferToRound(BigInteger amount, Async thread = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <TransferToRoundFunction>(new TransferToRoundFunction() { Amount = amount, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }, address)); var getTransactionStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "transferToRound", thread)); yield return(getTransactionStatus); yield return(getTransactionStatus.result); }
public IEnumerator updateDetails(TournamentDetails newDetails, Async thread = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <UpdateDetailsFunction>(new UpdateDetailsFunction() { TDetails = newDetails, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }, address)); var getTransactionStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "createSubmission", thread)); yield return(getTransactionStatus); yield return(getTransactionStatus.result); }
public IEnumerator enter(Async thread = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <EnterFunction>(new EnterFunction() { Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }, address)); var txStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "enter", thread)); yield return(txStatus); yield return(txStatus.result); }
public static IEnumerator withdrawAvailableReward(string commitHash, Async thread = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); var withdrawRewardMsg = new WithdrawAvailableRewardFunction() { CommitHash = commitHash, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; yield return(transactionRequest.SignAndSendTransaction <WithdrawAvailableRewardFunction>(withdrawRewardMsg, MatryxCommit.address)); var txStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "withdrawAvailableReward", thread)); yield return(txStatus); yield return(txStatus.result); }
public IEnumerator uploadContent() { if (dto.Content == null || dto.Content.Equals(string.Empty)) { if (description != null && !description.Equals(string.Empty)) { if (commit.ipfsContentHash != null && commit.ipfsContentHash.Substring(0, 2) == "Qm") { var uploadToIPFS = new Utils.CoroutineWithData <string>(MatryxCortex.Instance, MatryxCortex.uploadJson(title, description, commit.ipfsContentHash)); yield return(uploadToIPFS); dto.Content = uploadToIPFS.result; } } } }
public static IEnumerator approve(string spender, BigInteger amount, Async thread = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); var approveFnMsg = new ApproveFunction() { Spender = spender, Amount = amount, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; yield return(transactionRequest.SignAndSendTransaction <ApproveFunction>(approveFnMsg, address)); var txStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "approve", thread)); yield return(txStatus); yield return(txStatus.result); }
public static IEnumerator addGroupMembers(string commitHash, List <string> members, Async thread = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); var addGroupMembersMsg = new AddGroupMembersFunction() { CommitHash = commitHash, Members = members, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; yield return(transactionRequest.SignAndSendTransaction <AddGroupMembersFunction>(addGroupMembersMsg, MatryxCommit.address)); var txStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "addGroupMembers", thread)); yield return(txStatus); yield return(txStatus.result); }
public IEnumerator updateNextRound(MatryxRound.RoundDetails newDetails, Async.EventDelegate onComplete = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <UpdateNextRoundFunction>(new UpdateNextRoundFunction() { RDetails = newDetails, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }, address)); var getTransactionStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "updateNextRound", null)); yield return(getTransactionStatus); yield return(getTransactionStatus.result); onComplete?.Invoke(getTransactionStatus.result); }
public IEnumerator closeTournament(Async.EventDelegate onComplete = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <CloseTournamentFunction>(new CloseTournamentFunction() { Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }, address)); var getTransactionStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "closeTournament", null)); yield return(getTransactionStatus); yield return(getTransactionStatus.result); onComplete?.Invoke(getTransactionStatus.result); }
public IEnumerator claim(Async.EventDelegate onSuccess = null, Async.EventDelegate onError = null, Async thread = null) { ResultsMenu.Instance?.SetStatus("Uploading Content..."); var contentUploader = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, uploadContent()); yield return(contentUploader); if (claims.ContainsKey(ipfsContentHash)) { onError?.Invoke(null); yield return(false); yield break; } ResultsMenu.Instance?.SetStatus("Hashing Content to Matryx..."); Claim claim = new Claim(ipfsContentHash, content); var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); var claimCommitMsg = new ClaimCommitFunction() { ClaimHash = claim.claimHash, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; yield return(transactionRequest.SignAndSendTransaction(claimCommitMsg, address)); var txStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "claimCommit", thread)); yield return(txStatus); if (txStatus.result) { claims.Add(ipfsContentHash, claim); // Save screenshot and claimed content locally ExpressionSaveLoad.Instance.SaveClaim(this); storeClaimLocally(claim); onSuccess?.Invoke(claim); } else { onError?.Invoke(claim); } yield return(txStatus.result); }
public IEnumerator createSubmission(MatryxSubmission submission, Async thread = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); var createSubmissionMessage = new CreateSubmissionFunction() { Content = submission.dto.Content, CommitHash = Utils.HexStringToByteArray(submission.commit.hash), Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; yield return(transactionRequest.SignAndSendTransaction <CreateSubmissionFunction>(createSubmissionMessage, address)); var getTransactionStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "createSubmission", thread)); yield return(getTransactionStatus); yield return(getTransactionStatus.result); }
public IEnumerator create(Async.EventDelegate onSuccess = null, Async.EventDelegate onFailure = null) { ResultsMenu.Instance?.SetStatus("Committing Content to Matryx..."); Claim claim = getClaim(ipfsContentHash); var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); var createCommitMsg = new CreateCommitFunction() { ParentHash = parentHash, IsFork = fork, Salt = claim.salt, ContentHash = ipfsContentHash, Value = value, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; yield return(transactionRequest.SignAndSendTransaction <CreateCommitFunction>(createCommitMsg, address)); var txStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "createCommit", null)); yield return(txStatus); if (!txStatus.result) { onFailure?.Invoke(null); yield break; } // Get commit hash and assign to this commit var getCommit = new Utils.CoroutineWithData <CommitOutputDTO>(MatryxCortex.Instance, getCommitByContent(ipfsContentHash)); yield return(getCommit); hash = getCommit.result.outCommit.CommitHash.ToHex(true); yield return(txStatus.result); onSuccess?.Invoke(hash); }
public static IEnumerator createTournament(MatryxTournament tournament, Async thread = null) { TournamentDetails tDetails = new TournamentDetails() { ContentHash = tournament.contentHash, Bounty = tournament.bounty, EntryFee = tournament.entryFee, }; var createTournamentFnMsg = new CreateTournamentFunction() { TDetails = tDetails, RDetails = tournament.rounds[0].Details, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <CreateTournamentFunction>(createTournamentFnMsg, address)); var getTransactionStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "createTournament", thread)); yield return(getTransactionStatus); yield return(getTransactionStatus.result); }
//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); }
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; } }