Пример #1
0
    public IEnumerator SendGetUserTopScoreRequest(string userAddress)
    {
        var unityClientService = new EthCallUnityRequest(_url);

        yield return(unityClientService.SendRequest(_scoreContractService.CreateUserTopScoreCallInput(userAddress), Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest()));

        Exception = unityClientService.Exception;

        if (!String.IsNullOrEmpty(unityClientService.Result))
        {
            Debug.Log(unityClientService.Result);
            Result = _scoreContractService.DecodeUserTopScoreOutput(unityClientService.Result);
        }
    }
Пример #2
0
    //Making a contract call:

    //Check if the user top score has changed on the contract chain every 2 seconds
    public IEnumerator CheckTopScore()
    {
        var wait = 0;

        while (true)
        {
            yield return(new WaitForSeconds(wait));

            wait = 2;

            //Create a unity call request (we have a request for each type of rpc operation)
            var userTopScoreRequest = new EthCallUnityRequest(_url);

            if (_userAddress != null)
            {
                //Use the service to create a call input which includes the encoded
                var userTopScoreCallInput = _scoreContractService.CreateUserTopScoreCallInput(_userAddress);
                //Call request sends and yield for response
                yield return(userTopScoreRequest.SendRequest(userTopScoreCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest()));

                //Each request has a exception and a result. The exception is set when an error occurs.
                //Follows a similar patter to the www and unitywebrequest

                if (userTopScoreRequest.Exception == null)
                {
                    //decode the top score using the service
                    var topScoreUser = _scoreContractService.DecodeUserTopScoreOutput(userTopScoreRequest.Result);
                    //and set it to the text box
                    topScoreText.text = "Your top: " + topScoreUser.ToString();
                    //set the value on the global worl
                    GameControl.instance.TopScoreRecorded = topScoreUser;
                    wait = 3;
                }
                else
                {
                    Debug.Log(userTopScoreRequest.Exception.ToString());
                }
            }
        }
    }