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; }
private static IEnumerator GetCommit(string commitHash, bool getContent, Async.EventDelegate onSuccess, Async.EventDelegate onError = null) { var url = commitURL + commitHash; using (var www = new WWW(url)) { yield return(www); MatryxCommit commit = new MatryxCommit(); try { Debug.Log(www.text); var res = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; var data = res["data"] as Dictionary <string, object>; var commitData = data["commit"] as Dictionary <string, object>; commit.hash = commitData["hash"] as string; commit.owner = commitData["owner"] as string; commit.parentHash = commitData["parentHash"] as string; commit.ipfsContentHash = commitData["ipfsContent"] as string; commit.height = BigInteger.Parse(commitData["height"].ToString()); commit.value = BigInteger.Parse(commitData["value"].ToString()); commit.ownerTotalValue = BigInteger.Parse(commitData["ownerTotalValue"].ToString()); commit.totalValue = BigInteger.Parse(commitData["totalValue"].ToString()); commit.timestamp = BigInteger.Parse(commitData["timestamp"].ToString()); if (getContent) { RunGetJSONContent(commit.ipfsContentHash, (cont) => { commit.content = Utils.Substring(cont as string, '{', '}'); if (commit.content == "") { onError(cont); } else { onSuccess?.Invoke(commit); } }, onError); } else { onSuccess?.Invoke(commit); } } catch (Exception e) { Debug.Log("Could not fetch details of commit with content: " + commitHash); Debug.Log(e); onError?.Invoke(null); } yield return(commit); } }
public static IEnumerator InitializeContracts(Async.EventDelegate onError = null) { using (WWW www = new WWW(artifactsURL)) { yield return(www); if (www.error != null) { Debug.Log("Error making request. Either your internet is down...or Cortex is down. Fingers crossed its the internet :)"); onError?.Invoke(www.error); yield break; } var response = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; var data = response["data"] as Dictionary <string, object>; var token = data["token"] as Dictionary <string, object>; var tokenAbi = serializer.SerializeString(token["abi"]); var tokenAddress = token["address"].ToString(); if (MatryxToken.contract == null) { MatryxToken.setContract(tokenAbi, tokenAddress); } var platform = data["platform"] as Dictionary <string, object>; var platformAbi = serializer.SerializeString(platform["abi"]); var platformAddress = platform["address"] as string; if (MatryxPlatform.contract == null) { MatryxPlatform.setContract(platformAbi, platformAddress); } var commit = data["commit"] as Dictionary <string, object>; var commitAbi = serializer.SerializeString(commit["abi"]); var commitAddress = commit["address"] as string; if (MatryxCommit.contract == null) { MatryxCommit.setContract(commitAbi, commitAddress); } var tournament = data["tournament"] as Dictionary <string, object>; var tournamentAbi = serializer.SerializeString(tournament["abi"]); if (MatryxTournament.ABI == null) { MatryxTournament.ABI = tournamentAbi; } } }
private static IEnumerator GetMyCommits(Async.EventDelegate onSuccess = null, Async.EventDelegate onError = null) { var url = myCommitsURL + NetworkSettings.currentAddress; using (var www = new WWW(url)) { yield return(www); if (www.error != null) { Debug.Log("Error getting commits: " + www.error); onError?.Invoke(www.error); yield break; } var commits = new List <MatryxCommit>(); try { Debug.Log(www.text); var res = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>; var data = res["data"] as Dictionary <string, object>; var jsonCommits = data["commits"] as List <object>; foreach (Dictionary <string, object> jsonCommit in jsonCommits) { MatryxCommit commit = new MatryxCommit(); commit.hash = jsonCommit["hash"] as string; commit.owner = jsonCommit["owner"] as string; commit.parentHash = jsonCommit["parentHash"] as string; commit.ipfsContentHash = jsonCommit["ipfsContent"] as string; commit.height = BigInteger.Parse(jsonCommit["height"].ToString()); commit.value = BigInteger.Parse(jsonCommit["value"].ToString()); commit.ownerTotalValue = BigInteger.Parse(jsonCommit["ownerTotalValue"].ToString()); commit.totalValue = BigInteger.Parse(jsonCommit["totalValue"].ToString()); commit.timestamp = BigInteger.Parse(jsonCommit["timestamp"].ToString()); commit.mine = true; commits.Add(commit); } } catch (Exception e) { Debug.Log(e); onError?.Invoke(commits); } onSuccess?.Invoke(commits); } }
// This constructor is used specifically for Submissions // owned by an account loaded into Calcflow public MatryxSubmission ( MatryxTournament tournament, string title, string hash = "", string description = null, string commitContent = null, int value = 1 ) : this(title, hash) { this.tournament = tournament; dto.TournamentAddress = tournament.address; this.description = description; this.dto.Content = ""; // "QmTDNWPTf6nM5sAwqKN1unTqvRDhr5sDxDEkLRMxbwAokz"; commit = new MatryxCommit(commitContent, value); }