Пример #1
0
        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;
            }
        }
Пример #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);
        }