Example #1
0
        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;
                }
            }
        }
Example #2
0
        //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);
        }