public IEnumerator GetTokenInfo() { //Create a unity call request (we have a request for each type of rpc operation) var currencyInfoRequest = new EthCallUnityRequest(_url); // get token symbol (string) yield return(currencyInfoRequest.SendRequest(CreateCallInput("symbol"), BlockParameter.CreateLatest())); TokenInfo.symbol = DecodeVariable <string>("symbol", currencyInfoRequest.Result); // get token decimal places (uint 8) yield return(currencyInfoRequest.SendRequest(CreateCallInput("decimals"), BlockParameter.CreateLatest())); TokenInfo.decimals = DecodeVariable <int>("decimals", currencyInfoRequest.Result); // get token name (string) yield return(currencyInfoRequest.SendRequest(CreateCallInput("name"), BlockParameter.CreateLatest())); TokenInfo.name = DecodeVariable <string>("name", currencyInfoRequest.Result); // get token totalSupply (uint 256) yield return(currencyInfoRequest.SendRequest(CreateCallInput("totalSupply"), BlockParameter.CreateLatest())); TokenInfo.totalSupply = DecodeVariable <BigInteger>("totalSupply", currencyInfoRequest.Result); WalletManager.Instance.AddInfoText("Token Address: \n" + TokenContractAddress, true); WalletManager.Instance.AddInfoText("Name: " + TokenInfo.name + " (" + TokenInfo.symbol + ")"); WalletManager.Instance.AddInfoText("Decimals: " + TokenInfo.decimals); WalletManager.Instance.AddInfoText("Total Supply: " + UnitConversion.Convert.FromWei(TokenInfo.totalSupply, TokenInfo.decimals) + " " + TokenInfo.symbol); WalletManager.Instance.LoadingIndicator.SetActive(false); }
public IEnumerator GetTokenInfo() { //Create a unity call request (we have a request for each type of rpc operation) var currencyInfoRequest = new EthCallUnityRequest(_url); // get token symbol (string) yield return(currencyInfoRequest.SendRequest(CreateCallInput("symbol"), BlockParameter.CreateLatest())); TokenInfo.symbol = DecodeVariable <string>("symbol", currencyInfoRequest.Result); // get token decimal places (uint 8) yield return(currencyInfoRequest.SendRequest(CreateCallInput("decimals"), BlockParameter.CreateLatest())); TokenInfo.decimals = DecodeVariable <int>("decimals", currencyInfoRequest.Result); // get token name (string) yield return(currencyInfoRequest.SendRequest(CreateCallInput("name"), BlockParameter.CreateLatest())); TokenInfo.name = DecodeVariable <string>("name", currencyInfoRequest.Result); // get token totalSupply (uint 256) yield return(currencyInfoRequest.SendRequest(CreateCallInput("totalSupply"), BlockParameter.CreateLatest())); TokenInfo.totalSupply = DecodeVariable <BigInteger>("totalSupply", currencyInfoRequest.Result); //WalletManager.Instance.LoadingIndicator.SetActive(false); }
public IEnumerator openRooms() { var wait = 0; yield return(new WaitForSeconds(wait)); wait = 2; WalletData wd = WalletManager.Instance.GetSelectedWalletData(); var getOpenRequest = new EthCallUnityRequest(WalletManager.Instance.networkUrl); if (wd.address != null) { var getOpenInput = contract.createGetOpenCallInput(); yield return(getOpenRequest.SendRequest(getOpenInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (getOpenRequest.Exception == null) { var topScoreUser = contract.decodeGetOpen(getOpenRequest.Result); Debug.Log("No error"); bool x = true; foreach (int index in topScoreUser) { var getRoom = contract.createGetRoomCallInput(index); yield return(getOpenRequest.SendRequest(getRoom, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (getOpenRequest.Exception == null) { var roomsData = contract.decodeGetOpenRoom(getOpenRequest.Result); AddLobbys(roomsData.maxPlayers, roomsData.Players, roomsData.timeCreated, roomsData.timeLeft, index, roomsData.Price, x); x = false; wait = 3; } else { Debug.Log("error"); Debug.Log(getOpenRequest.Exception.ToString()); } } wait = 3; } else { Debug.Log("error"); Debug.Log(getOpenRequest.Exception.ToString()); } } }
public IEnumerator GetItems(int index) { var request = new EthCallUnityRequest(Inventory.URL); var callInput = CallGetItems(index); Debug.Log("Getting all items..."); yield return(request.SendRequest(callInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (request.Exception == null) { // If we don't have exceptions we just display the raw result and the // result decode it with our function (decodePings) from the service, congrats! var function = ContractGetItems(); itemAdresses.Add(ResultToString(function, request.Result)); // allItemsInOneString = Debug.Log("items (HEX): " + request.Result); Debug.Log("items (string):" + itemAdresses[itemAdresses.Count - 1]); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting item list length tx: " + request.Exception.Message); } }
public IEnumerator getMyRoom() { var wait = 0; yield return(new WaitForSeconds(wait)); wait = 2; WalletData wd = WalletManager.Instance.GetSelectedWalletData(); var getOpenRequest = new EthCallUnityRequest(WalletManager.Instance.networkUrl); if (wd.address != null) { var getOpenInput = contract.createGetMyRoomCallInput(); yield return(getOpenRequest.SendRequest(getOpenInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (getOpenRequest.Exception == null) { var topScoreUser = contract.decodeGetOpen(getOpenRequest.Result); Debug.Log("No error"); foreach (int i in topScoreUser) { } wait = 3; } else { Debug.Log("error"); Debug.Log(getOpenRequest.Exception.ToString()); } } }
/// Gets the items based on the input fields private IEnumerator GetItems() { var req = new EthCallUnityRequest(url); var contract = new Contract(null, ownershipABI, ownershipContractAddress); var function = contract.GetFunction("itemsOf"); var callInput = function.CreateCallInput(inputGetDNAAddress.text); var blockParameter = Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest(); yield return(req.SendRequest(callInput, blockParameter)); string resultLog = "TokenIDs: [ "; var result = function.DecodeDTOTypeOutput <ItemsOfResult>(req.Result); foreach (var value in result.TokenIDs) { resultLog += value + " "; } resultLog += "]\nItemTypeIDs: [ "; foreach (var value in result.ItemTypeIDs) { resultLog += value + " "; } resultLog += "]"; inputGetItemsResult.text = resultLog; }
private static IEnumerator SimpleCall(EthCallUnityRequest request, CallInput input) { var block = BlockParameter.CreateLatest(); var waiting = request.SendRequest(input, block); return(waiting); }
public IEnumerator CheckAccountBalanceCoroutine(string address) { EtherBalanceText.text = "Loading Balance..."; CustomTokenBalanceText.text = ""; yield return(0); // allow UI to update var getBalanceRequest = new EthGetBalanceUnityRequest(networkUrl); string etherBalance; string customTokenBalance; yield return(getBalanceRequest.SendRequest(address, BlockParameter.CreateLatest())); if (getBalanceRequest.Exception == null) { etherBalance = UnitConversion.Convert.FromWei(getBalanceRequest.Result.Value).ToString(); } else { throw new System.InvalidOperationException("Get balance request failed"); } var tokenBalanceRequest = new EthCallUnityRequest(networkUrl); // get custom token balance (uint 256) yield return(tokenBalanceRequest.SendRequest(TokenContractService.Instance.CreateCallInput("balanceOf", address), BlockParameter.CreateLatest())); customTokenBalance = UnitConversion.Convert.FromWei( TokenContractService.Instance.DecodeVariable <BigInteger>("balanceOf", tokenBalanceRequest.Result), TokenContractService.Instance.TokenInfo.decimals).ToString(); EtherBalanceText.text = "ETH: " + etherBalance; CustomTokenBalanceText.text = TokenContractService.Instance.TokenInfo.symbol + ": " + customTokenBalance; }
private IEnumerator TestPlaceBetRequest(JsonData jsonData) { var craeteInput = TestCreatPlaceBetInput(jsonData); var request = new EthCallUnityRequest(Wallet._url); yield return(request.SendRequest(craeteInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (request.Exception == null) { var unitConversion = new UnitConversion(); var result = request.Result; //BigInteger num = System.Convert.ToInt64(result, 16); ////var _num = unitConversion.FromWei(num, 18); //var arrayType = ArrayType.CreateABIType("uint[20]"); //var list = arrayType.Decode<List<BigInteger>>(result); //for (var i = 0; i < list.Count; i++){ UnityEngine.Debug.LogError(">>>>>>>>success=======" + result); //} UnityEngine.Debug.LogError(">>>>>>>>>>>>success"); } else { UnityEngine.Debug.LogError(">>>>>>>>faild===" + request.Exception); } }
public IEnumerator getPings() { // We create a new pingsRequest as a new Eth Call Unity Request var pingsRequest = new EthCallUnityRequest(_url); var pingsCallInput = pingContractService.CreatePingsCallInput(); Debug.Log("Getting pings..."); // Then we send the request with the pingsCallInput and the most recent block mined to check. // And we wait for the response... yield return(pingsRequest.SendRequest(pingsCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (pingsRequest.Exception == null) { // If we don't have exceptions we just display the raw result and the // result decode it with our function (decodePings) from the service, congrats! Debug.Log("Pings (HEX): " + pingsRequest.Result); Debug.Log("Pings (INT):" + pingContractService.DecodePings(pingsRequest.Result)); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting getPings tx: " + pingsRequest.Exception.Message); } }
public IEnumerator GetItemsListLength() { var request = new EthCallUnityRequest(Inventory.URL); var callInput = CallItemsListLength(); Debug.Log("Getting item list length..."); yield return(request.SendRequest(callInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (request.Exception == null) { var function = ContractItemsListLength(); // itemListLength = System.Int32.Parse( request.Result, NumberStyles.AllowHexSpecifier ); Debug.Log("string of result = " + ResultToInt(function, request.Result)); itemListLength = ResultToInt(function, request.Result); Debug.Log("item list length (HEX): " + request.Result); Debug.Log("item list length (int):" + itemListLength); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting item list length tx: " + request.Exception.Message); } }
public IEnumerator GetIcon() { var request = new EthCallUnityRequest(Inventory.URL); var callInput = CallGetIcon(); Debug.Log("Getting item(" + adress + ") icon..."); yield return(request.SendRequest(callInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (request.Exception == null) { var function = ContractGetIcon(); iconName = itemGenerator.ResultToString(function, request.Result); sprite = spriteMap.GetPictureSpriteByName(iconName); pictureSprite = spriteMap.GetPictureSpriteByName(iconName); // itemListLength = System.Int32.Parse( request.Result, NumberStyles.AllowHexSpecifier ); // Debug.Log ("item icon (HEX): " + request.Result); // Debug.Log ("item icon (string):" + iconName); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting item icon length tx: " + request.Exception.Message); } }
IEnumerator SendRequestCoroutine(CallInput requestParameters, System.Action <UnityRequest <string> > requestCallback) { var request = new EthCallUnityRequest(requestNode); yield return(request.SendRequest(requestParameters, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); requestCallback.Invoke(request); }
//----------------------------------------------------------------------------------------------------------------- // GET ONE COLORED BALANCE //----------------------------------------------------------------------------------------------------------------- IEnumerator GetOneColoredBalance(uint i, BigInteger uid) { var playContractRequest = new EthCallUnityRequest(_url); var playGetColoredTokensCallInput = _playContractReader.CreateGetColoredTokenBalanceCallInput(uid, i); yield return(playContractRequest.SendRequest(playGetColoredTokensCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); tokenManager.SetColorBalance(i, _playContractReader.DecodeGetColoredTokenBalance(playContractRequest.Result)); }
public IEnumerator Exec3(double gas, double value_wei, params object[] args) { yield return(req_.SendRequest( Function.CreateCallInput(RPCMgr.instance.Account.address_, new HexBigInteger(new BigInteger(gas)), new HexBigInteger(new BigInteger(value_wei)), args), Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); }
// execute contact function with view keyword or contact field, it doesn't need gas public IEnumerator CallTransaction(CallInput callInput, System.Action <UnityRequest <string> > result) { var callRequest = new EthCallUnityRequest(URL); yield return(callRequest.SendRequest(callInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (result != null) { result.Invoke(callRequest); } }
//----------------------------------------------------------------------------------------------------------------- // GET EXTERNAL TOKEN BALANCE //----------------------------------------------------------------------------------------------------------------- public IEnumerator GetExternalToken(BigInteger uid, string address) { var toyContractRequest = new EthCallUnityRequest(_url); var getExternalTokenCallInput = _toyContractReader.CreateGetExternalTokenBalanceCallInput(uid, address); yield return(toyContractRequest.SendRequest(getExternalTokenCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); var balance = _toyContractReader.DecodeGetExternalTokenBalance(toyContractRequest.Result); tokenManager.SetExternalTokenBalance(address, balance); }
//----------------------------------------------------------------------------------------------------------------- // GET COLORED TOKEN BALANCE //----------------------------------------------------------------------------------------------------------------- IEnumerator GetColoredTokenName(uint i) { var playContractRequest = new EthCallUnityRequest(_url); var getColoredTokenNamesCallInput = _playContractReader.CreateGetColoredTokenCallInput(i); yield return(playContractRequest.SendRequest(getColoredTokenNamesCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); var coloredToken = _playContractReader.DecodeGetColoredToken(playContractRequest.Result); tokenManager.SetColorName(i, coloredToken.Name); }
//----------------------------------------------------------------------------------------------------------------- // GET ERC-20 BALANCE //----------------------------------------------------------------------------------------------------------------- IEnumerator GetErc20Balance(int index, string tokenOwner) { var erc20ContractRequest = new EthCallUnityRequest(_url); var balanceOfCallInput = _erc20Readers[index].CreateBalanceOfCallInput(tokenOwner); yield return(erc20ContractRequest.SendRequest(balanceOfCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); var balance = _erc20Readers[index].DecodeBalanceOf(erc20ContractRequest.Result); tokenManager.SetAccountTokenBalance(tokenManager.fungibleTokens[index].address, balance); }
public IEnumerator GetName(int id, BigInteger bet, int prn, string selection = "JoinRoom") { var wait = 0; wait = 2; WalletData wd = WalletManager.Instance.GetSelectedWalletData(); var getOpenRequest = new EthCallUnityRequest(WalletManager.Instance.networkUrl); if (wd.address != null) { var getNameInput = contract.createGetNameCallInput(wd.address); yield return(getOpenRequest.SendRequest(getNameInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (getOpenRequest.Exception == null) { var topScoreUser = contract.decodeGetName(getOpenRequest.Result); Debug.Log("No error"); if (topScoreUser == "") { Debug.Log(topScoreUser); yield return(transictionScripts.Instance.createUsers(wd.name)); switch (selection) { case "JoinRoom": transictionScripts.Instance._JoinRoom(id, bet, prn); break; case "CreateRoom": transictionScripts.Instance._CreateRoom(); break; } } else { switch (selection) { case "JoinRoom": transictionScripts.Instance._JoinRoom(id, bet, prn); break; case "CreateRoom": transictionScripts.Instance._CreateRoom(); break; } } } else { Debug.Log("error"); Debug.Log(getOpenRequest.Exception.ToString()); } } }
IEnumerator CallAdd(int num1, int num2) { var _AddRequest = new EthCallUnityRequest(m_Url); yield return(_AddRequest.SendRequest(GetSumCallInput(num1, num2), BlockParameter.CreateLatest())); var _AddResult = _AddRequest.Result; Debug.Log("_AddResult: " + _AddResult); m_Result = _AddResult.ToString(); m_Btn.interactable = true; }
public IEnumerator EthCall() { EthCallUnityRequest req = new EthCallUnityRequest(m_endpoint); CallInput input = new CallInput("", m_addrTo, m_addr, new HexBigInteger(new BigInteger(21000)), new HexBigInteger(new BigInteger(20L * m_gwei)), //gwei new HexBigInteger(new BigInteger(0.01f * m_ether))); //ether yield return(req.SendRequest(input, BlockParameter.CreateLatest())); Debug.Log("EthCall " + req.Result); }
private IEnumerator GetCharacterDetails(int index) { Debug.Log("Fetching character " + index); requestedCharacter = null; var function = contract.GetFunction("getCharacterDetails"); var input = function.CreateCallInput(index); var request = new EthCallUnityRequest(_url); yield return(request.SendRequest(input, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); requestedCharacter = function.DecodeDTOTypeOutput <CharacterDetailsDTO>(request.Result); Debug.Log("Character fetched"); }
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); } }
public IEnumerator getNews() { var getNewsRequest = new EthCallUnityRequest(ETH_ENDPOINT); var getNewsCallInput = this._quantCardContract.createGetNewsCallInput(0); yield return(getNewsRequest.SendRequest(getNewsCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); var value = this._quantCardContract.DecodeGetNewsDTO(getNewsRequest.Result); this.message += value.Description + "\n\n"; getNewsCallInput = this._quantCardContract.createGetNewsCallInput(1); yield return(getNewsRequest.SendRequest(getNewsCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); value = this._quantCardContract.DecodeGetNewsDTO(getNewsRequest.Result); if (null != value && null != value.Description) { this.message += value.Description + "\n\n"; } getNewsCallInput = this._quantCardContract.createGetNewsCallInput(2); yield return(getNewsRequest.SendRequest(getNewsCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); value = this._quantCardContract.DecodeGetNewsDTO(getNewsRequest.Result); if (null != value && null != value.Description) { this.message += value.Description + "\n\n"; } this.newsTextMesh.text = this.message; }
protected IEnumerator CallCoroutine(CallInput functionInput, UnityAction <string> onSuccess = null, UnityAction <System.Exception> onFailed = null) { var request = new EthCallUnityRequest(WalletSettings.current.networkUrl); yield return(request.SendRequest(functionInput, BlockParameter.CreateLatest())); if (request.Exception == null) { onSuccess?.Invoke(request.Result); } else { onFailed?.Invoke(request.Exception); } }
public IEnumerator GetTokenOwnerBalance(string address) { yield return(EthCallUnityRequest.SendRequest(GetBalanceOfCallInput(address), BlockParameter.CreateLatest())); if (EthCallUnityRequest.Result != null) { BigInteger balance = GetBalanceOfFunction().DecodeSimpleTypeOutput <BigInteger>(EthCallUnityRequest.Result); Debug.LogError("User Balance: " + balance); } else { Debug.LogError(EthCallUnityRequest.Exception); Debug.LogError(EthCallUnityRequest.Result); Debug.LogError(EthCallUnityRequest); } }
public IEnumerator getPingsRequest() { var getPingsRequest = new EthCallUnityRequest(_url); var getPingsInput = pingTokenContractService.CreatePingsInput(); Debug.Log("Getting pings..."); yield return(getPingsRequest.SendRequest(getPingsInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (getPingsRequest.Exception == null) { Debug.Log("Pings: " + pingTokenContractService.DecodePings(getPingsRequest.Result)); } else { Debug.Log("Error getting pings: " + getPingsRequest.Exception.Message); } }
private IEnumerator GetAddrRequest(JsonData jsonData) { var craeteInput = CreatGetAddrInput(jsonData); var request = new EthCallUnityRequest(Wallet._url); yield return(request.SendRequest(craeteInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (request.Exception == null) { UnityEngine.Debug.LogError(">>>>>GetAddrRequest>>>>>>>success===" + request.Result); } else { UnityEngine.Debug.LogError(">>>>>>>>faild===" + request.Exception); } }
//----------------------------------------------------------------------------------------------------------------- // GET OWNED TOYS //----------------------------------------------------------------------------------------------------------------- public IEnumerator GetOwnedToys(string address) { GameObject.Find("ScanButton").GetComponent <Image>().color = Color.green; // get list of owned Toy Token UIDs var toyContractRequest = new EthCallUnityRequest(_url); var tokensOfOwnerCallInput = _toyContractReader.CreateTokensOfOwnerCallInput(address); yield return(toyContractRequest.SendRequest(tokensOfOwnerCallInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); List <long> uids = _toyContractReader.DecodeTokensOfOwner(toyContractRequest.Result); inventory.ownedToyUids = uids; inventory.InitializeOwnedToys(uids.Count); // notify inventory to finish initialization inventory.OnFinishedLoading(); }