// UPLOAD SUBMISSION public static void RunUploadSubmission(MatryxSubmission submission, Async.EventDelegate onSuccess = null, Async.EventDelegate onError = null) { // Schedule query Async submit = Async.runInCoroutine(delegate(Async thread, object param) { return(submission.submit()); }); submit.onEvent("submit", onSuccess); }
public static IEnumerator GetRound(MatryxTournament tournament, int roundIndex, Async.EventDelegate onSuccess, Async.EventDelegate onError = null) { var round = new MatryxRound(roundIndex); round.tournament = tournament; var winningSubmissions = new List <MatryxSubmission>(); using (WWW www = new WWW(tournamentURL + tournament.address + "/round/" + roundIndex)) { yield return(www); if (www.error != null) { Debug.Log("Error making request. Matryx Cortex down!!"); onError?.Invoke(www.error); yield break; } try { var jsonObj = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; if (jsonObj.ContainsKey("error")) { onError?.Invoke(null); } else if (jsonObj.ContainsKey("success")) { var data = jsonObj["data"] as Dictionary <string, object>; var jsonRound = data["round"] as Dictionary <string, object>; round.Details.Bounty = new BigInteger(Convert.ToDecimal(jsonRound["bounty"])) * new BigInteger(1e18); var startDate = DateTime.Parse(jsonRound["startDate"] as string); var endDate = DateTime.Parse(jsonRound["endDate"] as string); round.Details.Start = new BigInteger(Utils.Time.ToUnixTime(startDate)); round.Details.Duration = new BigInteger((endDate - startDate).TotalSeconds); var roundWinners = jsonRound["winners"] as List <object>; for (int i = 0; i < roundWinners.Count; i++) { var submission = new MatryxSubmission(roundWinners[i] as string); winningSubmissions.Add(submission); } round.winningSubmissions = winningSubmissions; onSuccess(round); } } catch (System.Exception e) { Debug.Log(e); onError?.Invoke(null); } } }
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 static IEnumerator GetMySubmissions(MatryxTournament tournament, float waitTime, Async.EventDelegate onSuccess = null, Async.EventDelegate onError = null) { if (waitTime > 0) { yield return(new WaitForSeconds(waitTime)); } var url = mySubmissionsURL + NetworkSettings.currentAddress; using (var www = new WWW(url)) { yield return(www); var submissions = new List <MatryxSubmission>(); try { var res = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; var data = res["data"] as Dictionary <string, object>; var submissionData = data["submissions"] as List <object>; foreach (Dictionary <string, object> submissionDictionary in submissionData) { if (submissionDictionary["tournament"] as string != tournament.address) { continue; } var title = submissionDictionary["title"] as string; var description = submissionDictionary["description"] as string; var hash = submissionDictionary["hash"] as string; MatryxSubmission submission = new MatryxSubmission(tournament, title, hash, description); submissions.Add(submission); } } catch (Exception e) { Debug.Log(e); onError?.Invoke(submissions); } onSuccess?.Invoke(submissions); } }
public static void GetSubmission(MatryxSubmission submission, Async.EventDelegate onSuccess = null, Async.EventDelegate onError = null) { queue(submission.get(onSuccess, onError)); }
private static IEnumerator GetTournament(string tournamentAddress, bool getDescription, Async.EventDelegate onSuccess, Async.EventDelegate onError = null) { var tournament = new MatryxTournament(tournamentAddress); var winningSubmissions = new List <MatryxSubmission>(); using (WWW www = new WWW(tournamentURL + tournamentAddress)) { yield return(www); if (www.error != null) { Debug.Log("Error making request. Matryx Cortex down!!"); onError?.Invoke(www.error); yield break; } try { var jsonObj = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; if (jsonObj.ContainsKey("error")) { onError?.Invoke(null); } else if (jsonObj.ContainsKey("success")) { var data = jsonObj["data"] as Dictionary <string, object>; var jsonTournament = data["tournament"] as Dictionary <string, object>; tournament.owner = jsonTournament["owner"] as string; tournament.contentHash = jsonTournament["ipfsContent"] as string; tournament.title = jsonTournament["title"] as string; tournament.Bounty = new BigInteger(Convert.ToDecimal(jsonTournament["bounty"])); tournament.description = jsonTournament["description"] as string; var jsonRound = jsonTournament["round"] as Dictionary <string, object>; tournament.currentRound = new MatryxRound(Convert.ToInt32(jsonRound["index"])); var idx = Convert.ToInt32(jsonRound["index"] as string); var roundClosed = (jsonRound["status"] as string).Equals("closed"); var roundStart = DateTime.Parse(jsonRound["startDate"] as string); var roundEnd = DateTime.Parse(jsonRound["endDate"] as string); BigInteger duration = new BigInteger((roundEnd - roundStart).TotalSeconds); var roundReviewEnd = DateTime.Parse(jsonRound["reviewEndDate"] as string); var roundBounty = Convert.ToDecimal(jsonRound["bounty"]); var roundParticipants = Convert.ToInt32(jsonRound["totalParticipants"]); var roundSubmissions = Convert.ToInt32(jsonRound["totalSubmissions"]); tournament.currentRound = new MatryxRound() { tournament = tournament, index = idx, closed = roundClosed, startDate = roundStart, endDate = roundEnd, reviewEndDate = roundReviewEnd, Bounty = roundBounty, totalParticipants = roundParticipants, totalSubmissions = roundSubmissions }; tournament.currentRound.Details.Start = new BigInteger(Utils.Time.ToUnixTime(roundStart)); tournament.currentRound.Details.Duration = duration; Dictionary <string, MatryxSubmission> submissionDictionary = new Dictionary <string, MatryxSubmission>(); if (roundEnd < DateTime.Now) { var tournamentSubmissions = jsonRound["submissions"] as List <object>; for (int i = 0; i < tournamentSubmissions.Count; i++) { var jsonSubmission = tournamentSubmissions[i] as Dictionary <string, object>; var subHash = jsonSubmission["hash"] as string; var subOwner = jsonSubmission["owner"] as string; var subTitle = jsonSubmission["title"] as string; var subDesc = jsonSubmission["description"] as string; var subReward = Convert.ToInt32(jsonSubmission["reward"] as string); var subTimestamp = Convert.ToDecimal(jsonSubmission["timestamp"] as string); var submission = new MatryxSubmission(tournament, subTitle, subHash, subDesc) { owner = subOwner, Reward = subReward, Timestamp = subTimestamp }; tournament.currentRound.allSubmissions.Add(submission); submissionDictionary.Add(submission.hash, submission); } } var roundWinners = jsonRound["winners"] as List <object>; for (int i = 0; i < roundWinners.Count; i++) { var winningSubmission = submissionDictionary[roundWinners[i] as string]; winningSubmissions.Add(winningSubmission); } tournament.currentRound.winningSubmissions = winningSubmissions; onSuccess(tournament); } } catch (Exception e) { Debug.Log(e); onError?.Invoke(null); } } }