Exemple #1
0
    private IEnumerator getWallet()
    {
        string[] molemmat = parseJSON("WalletDB.json");

        // new request
        var req = new EthSendTransactionUnityRequest(_url);

        // new contract from contract address
        var              contract = new Contract(null, molemmat[0], account_hash);
        Function         func     = contract.GetFunction("getWallet");
        TransactionInput ti       = func.CreateTransactionInput(account_hash);

        yield return(req.SendRequest(ti));

        if (req.Exception == null)
        {
            Debug.Log("Wallet found: " + req.Result);
            wallet_hash = req.Result;
            walletFound = true;
            // get assets from wallet
            Debug.Log("Getting assets...");
            StartCoroutine(getAssets());
        }
        else
        {
            throw new InvalidOperationException("Get wallet request failed");
        }
    }
Exemple #2
0
        private static IEnumerator CoroutineUploadSubmission(RoutineContext context)
        {
            // Prepare
            var function = mtxContract.GetFunction("createSubmission");
            // Get accounts
            var requestAccounts = new EthAccountsUnityRequest(mtxNode);

            yield return(requestAccounts.SendRequest());

            var resultsAccounts = requestAccounts.Result;
            var usedAccount     = resultsAccounts[0];
            // Parse routine params
            var param             = (object[])context.param;
            var submission        = (Submission)param[0];
            var tournamentAddress = Convert.ToInt64(submission.tournamentAddress);
            var title             = submission.title;
            var body         = submission.body;
            var references   = submission.references + "\n";
            var contributors = submission.contributors + "\n";
            // Make input
            var transactionInput = function.CreateTransactionInput(usedAccount, tournamentAddress, title, body, references, contributors);

            transactionInput.Gas = new HexBigInteger(3000000);
            // Do request
            var requestTransaction = new EthSendTransactionUnityRequest(mtxNode);

            yield return(requestTransaction.SendRequest(transactionInput));

            // Results
            try
            {
                var resultsTransaction = requestTransaction.Result;
                // Success
                context.done(resultsTransaction);
            }
            catch (Exception e)
            {
                // Error
                Debug.Log("Could not submit submission");
                //Debug.Log(e);
                context.done(null);
            }
        }
Exemple #3
0
    private IEnumerator getAssetInfo()
    {
        string[] molemmat = parseJSON("Asset.json");
        // new request
        var req = new EthSendTransactionUnityRequest(_url);

        // new contract from contract address
        var              contract = new Contract(null, molemmat[0], account_hash);
        Function         func     = contract.GetFunction("getRock");
        TransactionInput ti       = func.CreateTransactionInput(account_hash);

        yield return(req.SendRequest(ti));

        if (req.Exception == null)
        {
            Debug.Log("Info found: " + req.Result);
        }
        else
        {
            throw new InvalidOperationException("Get info request failed");
        }
    }
Exemple #4
0
        IEnumerator InitRoutine()
        {
            // Get accounts
            var requestAccounts = new EthAccountsUnityRequest(mtxNode);

            yield return(requestAccounts.SendRequest());

            var resultsAccounts = requestAccounts.Result;
            var usedAccount     = resultsAccounts[0];

            Debug.Log("Used account:" + usedAccount);
            var function         = mtxContract.GetFunction("prepareBalance");
            var transactionInput = function.CreateTransactionInput(usedAccount, (long)42);

            transactionInput.Gas = new HexBigInteger(3000000);
            // Do request
            var requestTransaction = new EthSendTransactionUnityRequest(mtxNode);

            yield return(requestTransaction.SendRequest(transactionInput));

            var resultsTransaction = requestTransaction.Result;
        }
Exemple #5
0
    public IEnumerator getAssets()
    {
        // read json and get abi and bytecode
        string[] molemmat = parseJSON("GameWallet.json");
        // new request
        var req = new EthSendTransactionUnityRequest(_url);
        // new contract and wanted function from contract address
        var contract        = new Contract(null, molemmat[0], account_hash);
        var func            = contract.GetFunction("getAssets");
        TransactionInput ti = func.CreateTransactionInput(account_hash);

        yield return(req.SendRequest(ti));

        if (req.Exception == null)
        {
            asset_hash = req.Result;
            // assetin tiedot
            StartCoroutine(getAssetInfo());
        }
        else
        {
            throw new InvalidOperationException("Get assets request failed");
        }
    }
Exemple #6
0
        IEnumerator InitRoutine()
        {
            // instantiate platform contract
            using (WWW www = new WWW(latestPlatformInfoEndpt))
            {
                yield return(www);

                var jsonObj = serializer.Deserialize <object>(www.bytes) as Dictionary <string, object>;

                var platformAbi = Encoding.UTF8.GetString(serializer.Serialize(jsonObj["abi"]));
                platformAddress  = jsonObj["address"] as string;
                platformContract = new Contract(null, platformAbi, platformAddress);
            }

            // instantiate token contract
            using (WWW www2 = new WWW(latestTokenInfoEndpt))
            {
                yield return(www2);

                var tokenJsonObj = serializer.Deserialize <object>(www2.bytes) as Dictionary <string, object>;
                var tokenAddress = tokenJsonObj["address"] as string;

                var tokenAbi = Encoding.UTF8.GetString(serializer.Serialize(tokenJsonObj["abi"]));
                tokenContract = new Contract(null, tokenAbi, tokenAddress);
            }

            // instantiate tournament contract (without address)
            using (WWW www3 = new WWW(latestTournamentAbiEndpt))
            {
                yield return(www3);

                var tournyJsonObj = serializer.Deserialize <object>(www3.bytes) as Dictionary <string, object>;
                tournamentAbi = Encoding.UTF8.GetString(serializer.Serialize(tournyJsonObj["abi"]));
                //var tournamentAbi = Encoding.UTF8.GetString(serializer.Serialize(tournyJsonObj["abi"]));
            }

            // Get accounts
            var requestAccounts = new EthAccountsUnityRequest(mtxNode);

            yield return(requestAccounts.SendRequest());

            var resultsAccounts = requestAccounts.Result;

            if (resultsAccounts != null && resultsAccounts[0] != null)
            {
                StatisticsTracking.InstantEvent("Matryx Init", "Eth Node", new Dictionary <string, object>()
                {
                    { "Node Found", true },
                });

                var usedAccount = resultsAccounts[0];
                Debug.Log("Used account:" + usedAccount);
                var function         = platformContract.GetFunction("prepareBalance");
                var transactionInput = function.CreateTransactionInput(usedAccount, (long)42);
                transactionInput.Gas = new HexBigInteger(3000000);
                // Do request
                var requestTransaction = new EthSendTransactionUnityRequest(customRPCNode);
                yield return(requestTransaction.SendRequest(transactionInput));

                var resultsTransaction = requestTransaction.Result;
            }
            else
            {
                StatisticsTracking.InstantEvent("Matryx Init", "Eth Node", new Dictionary <string, object>()
                {
                    { "Node Found", false },
                });
            }
        }
Exemple #7
0
        private static IEnumerator CoroutineUploadSubmission(RoutineContext context)
        {
            // Get accounts
            var requestAccounts = new EthAccountsUnityRequest(mtxNode);

            yield return(requestAccounts.SendRequest());

            var resultsAccounts = requestAccounts.Result;
            var usedAccount     = resultsAccounts[0];

            // Try to create a peer.
            var createPeerFunction = platformContract.GetFunction("createPeer");

            object[] createPeerParams = { };
            var      createPeerInput  = createPeerFunction.CreateTransactionInput(usedAccount, createPeerParams);

            createPeerInput.Gas = new HexBigInteger(3000000);
            var createPeerCall = new EthSendTransactionUnityRequest(mtxNode);

            yield return(createPeerCall.SendRequest(createPeerInput));

            try
            {
                var resultsTransaction = createPeerCall.Result;
            }
            catch (Exception e)
            {
                // Error
                Debug.Log("Could not check peer status");
            }

            // tournament.entryFee();
            var submission = (Submission)((object[])context.param)[0];

            tournamentContract = new Contract(null, tournamentAbi, submission.tournamentAddress);
            var entryFeeFunction = tournamentContract.GetFunction("entryFee");
            var entryFeeInput    = entryFeeFunction.CreateCallInput(new object[0]);

            entryFeeInput.Gas = new HexBigInteger(300000);
            var entryFeeCall = new EthCallUnityRequest(mtxNode);

            yield return(entryFeeCall.SendRequest(entryFeeInput, BlockParameter.CreateLatest()));

            EntryFeeDTO entryFee = new EntryFeeDTO();

            try
            {
                entryFee = entryFeeFunction.DecodeDTOTypeOutput <EntryFeeDTO>(entryFeeCall.Result);
            }
            catch (Exception e)
            {
                Debug.Log("Could not get tournament entry fee.");
            }

            // token.approve(tournament.address, tournament.entryFee)
            if (entryFee.entryFee > 0)
            {
                var      tokenApproveFunction    = tokenContract.GetFunction("approve");
                object[] tokenClearApproveParams = { submission.tournamentAddress, 0 };
                object[] tokenApproveParams      = { submission.tournamentAddress, entryFee.entryFee };
                var      tokenClearApproveInput  = tokenApproveFunction.CreateTransactionInput(usedAccount, tokenClearApproveParams);
                var      tokenApproveInput       = tokenApproveFunction.CreateTransactionInput(usedAccount, tokenApproveParams);
                tokenClearApproveInput.Gas = new HexBigInteger(3000000);
                tokenApproveInput.Gas      = new HexBigInteger(3000000);
                var tokenClearApproveTransaction = new EthSendTransactionUnityRequest(mtxNode);
                var tokenApproveTransaction      = new EthSendTransactionUnityRequest(mtxNode);
                yield return(tokenClearApproveTransaction.SendRequest(tokenClearApproveInput));

                try
                {
                    var tokenClearApprovalResult = tokenClearApproveTransaction.Result;
                }
                catch (Exception e)
                {
                    Debug.Log("Could not approve tournament to withdraw entry fee.");
                }

                yield return(tokenApproveTransaction.SendRequest(tokenApproveInput));

                try
                {
                    var tokenApprovalTransactionResult = tokenApproveTransaction.Result;
                }
                catch (Exception e)
                {
                    Debug.Log("Could not approve tournament to withdraw entry fee.");
                }
            }

            //platform.enterTournament(tournament.address)
            var enterTournamentFunction = platformContract.GetFunction("enterTournament");

            object[] enterTournamentParams = { submission.tournamentAddress };
            var      enterTournamentInput  = enterTournamentFunction.CreateTransactionInput(usedAccount, enterTournamentParams);

            enterTournamentInput.Gas = new HexBigInteger(3300000);
            var enterTournamentTransaction = new EthSendTransactionUnityRequest(mtxNode);

            yield return(enterTournamentTransaction.SendRequest(enterTournamentInput));

            try
            {
                var enterTournamentTransactionResult = enterTournamentTransaction.Result;
            }
            catch (Exception e)
            {
                Debug.Log("Could not enter tournament.");
            }

            // Fix the below code
            // Prepare create submission
            var createSubmissionFunction = tournamentContract.GetFunction("createSubmission");
            // Parse routine params
            var tournamentAddress = (submission.tournamentAddress);
            var title             = submission.title;

            WWWForm form = new WWWForm();

            form.AddBinaryData("description", Encoding.ASCII.GetBytes(((Submission)((object[])(context.param))[0]).title), "description.txt", "text/plain");
            form.AddBinaryData("jsonContent", Encoding.ASCII.GetBytes(((Submission)((object[])(context.param))[0]).body), "jsonContent.json", "application/json");
            UnityWebRequest ipfsRequest = UnityWebRequest.Post(submissionUploadEndpt, form);

            yield return(ipfsRequest.Send());

            print("request completed with code: " + ipfsRequest.responseCode);
            if (ipfsRequest.isError)
            {
                print("Error: " + ipfsRequest.error);
            }
            else
            {
                print("Request Response: " + ipfsRequest.downloadHandler.text);
            }

            var response   = serializer.Deserialize <object>(ipfsRequest.downloadHandler.data) as Dictionary <string, object>;
            var folderHash = Encoding.UTF8.GetBytes((string)response["folderHash"]);

            string[] contributors            = { };
            int[]    contributorDistribution = { };
            string[] references = { };

            if (submission.references != string.Empty)
            {
                references = submission.references.Split(',');
            }
            if (submission.contributors != string.Empty)
            {
                contributors            = submission.contributors.Split(',');
                contributorDistribution = Enumerable.Range(0, contributors.Length).Select(x => 1).ToArray();
            }

            // Make input
            object[] inputParams      = { title, usedAccount, folderHash, contributors, contributorDistribution, references };
            var      transactionInput = createSubmissionFunction.CreateTransactionInput(usedAccount, inputParams);

            transactionInput.Gas      = new HexBigInteger(3000000);
            transactionInput.GasPrice = new HexBigInteger(20);
            // Do request
            var requestTransaction = new EthSendTransactionUnityRequest(mtxNode);

            yield return(requestTransaction.SendRequest(transactionInput));

            // Results
            try
            {
                var resultsTransaction = requestTransaction.Result;
                // Success
                context.done(resultsTransaction);
            }
            catch (Exception e)
            {
                // Error
                Debug.Log("Could not submit submission");
                //Debug.Log(e);
                context.done(null);
            }
        }