Esempio n. 1
0
 public static void RunGetRound(MatryxTournament tournament, int roundIndex, Async.EventDelegate onSuccess, Async.EventDelegate onError = null)
 {
     Async main = Async.runInCoroutine(delegate(Async thread, object param)
     {
         return(GetRound(tournament, roundIndex, onSuccess, onError));
     });
 }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
 // 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);
 }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public static void RunGetMySubmissions(MatryxTournament tournament, float waitTime = 0, Async.EventDelegate onSuccess = null, Async.EventDelegate onError = null)
 {
     queue(GetMySubmissions(tournament, waitTime, onSuccess, onError));
 }
Esempio n. 7
0
        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);
                }
            }
        }
Esempio n. 8
0
        private static IEnumerator GetTournaments(long page, float waitTime, bool onlyMine, Async.EventDelegate onSuccess, Async.EventDelegate onError = null)
        {
            if (waitTime > 0)
            {
                yield return(new WaitForSeconds(waitTime));
            }

            var tournaments = new List <MatryxTournament>();
            var offset      = page * 10;
            var url         = onlyMine ? myTournamentsURL + NetworkSettings.currentAddress : tournamentsURL;

            using (WWW www = new WWW(url))
            {
                yield return(www);

                if (www.error != null)
                {
                    Debug.Log("Error making request. Matryx Cortex down!!");
                    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 tournamentList = data["tournaments"] as List <object>;
                for (int i = 0; i < tournamentList.Count; i++)
                {
                    var jsonTournament = tournamentList[i] as Dictionary <string, object>;
                    var jsonRound      = jsonTournament["round"] as Dictionary <string, object>;

                    string category = jsonTournament["category"] as string;
                    if (!supportedCalcflowCategories.Contains(category))
                    {
                        continue;
                    }

                    var owner = jsonTournament["owner"] as string;
                    if (onlyMine && !owner.Equals(NetworkSettings.currentAddress, StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }
                    else if (!onlyMine)
                    {
                        var status = jsonRound["status"] as string;
                        if (!status.Equals("open", StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                    }

                    var tournamentTitle = jsonTournament["title"] as string;
                    var bounty          = new BigInteger((long)Convert.ToDouble(jsonTournament["bounty"])) * new BigInteger(1e18);
                    var entryFee        = new BigInteger((long)Convert.ToDouble(jsonTournament["entryFee"])) * new BigInteger(1e18);
                    var tournament      = new MatryxTournament(jsonTournament["address"] as string, tournamentTitle, bounty, entryFee);
                    tournament.description = jsonTournament["description"] as string;
                    tournament.owner       = owner;

                    var idx               = Convert.ToInt32(jsonRound["index"] as string);
                    var roundStart        = DateTime.Parse(jsonRound["startDate"] as string);
                    var roundEnd          = DateTime.Parse(jsonRound["endDate"] as string);
                    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,
                        startDate         = roundStart,
                        endDate           = roundEnd,
                        reviewEndDate     = roundReviewEnd,
                        Bounty            = roundBounty,
                        totalParticipants = roundParticipants,
                        totalSubmissions  = roundSubmissions
                    };

                    tournaments.Add(tournament);
                }

                onSuccess?.Invoke(tournaments);
            }
        }