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 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); }
/// 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; }
public CryptoWorldWarService() { TransactionSignedUnityRequest = new TransactionSignedUnityRequest(Variables.NodeAddress, Variables.PrivateKey); EthCallUnityRequest = new EthCallUnityRequest(Variables.NodeAddress); TransactionReceiptPollingRequest = new TransactionReceiptPollingRequest(Variables.NodeAddress); CryptoWorldWarContract = new Contract(null, Variables.ABI, Variables.ContractAddress); }
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()); } } }
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 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; }
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); }
private static IEnumerator SimpleCall(EthCallUnityRequest request, CallInput input) { var block = BlockParameter.CreateLatest(); var waiting = request.SendRequest(input, block); return(waiting); }
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); } }
private IEnumerator PlaceBetRequest(JsonData jsonData, BigInteger _input, float _bet, int type) { var transactionInput = CreatPlaceBetInput(jsonData, _input, _bet, type); var request = new EthCallUnityRequest(Wallet._url); string privatekey = AccountManager.Instance.GetPrivateKey(); string address_ = AccountManager.Instance.GetAddress(); var transactionSignedRequest = new TransactionSignedUnityRequest(Wallet._url, privatekey, address_); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); // yield return request.SendRequest(craeteInput, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest()); if (request.Exception == null) { //Commit2RobotRequestCallBack(transactionSignedRequest.Result); // StartCoroutine(Timer(transactionSignedRequest.Result,_bet)); Commit2RobotRequestCallBack(transactionSignedRequest.Result, _bet); } else { ViewManager.ShowMessageBox(request.Exception.ToString()); ViewManager.CloseWaitTip(); UnityEngine.Debug.LogError(">>>>>>>>faild===" + request.Exception); } }
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); } }
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); } }
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)); }
//----------------------------------------------------------------------------------------------------------------- // 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()); } } }
//----------------------------------------------------------------------------------------------------------------- // 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); }
// 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); } }
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); }
void Start() { Keys = new List <int>(); CryptoWorldWarService = new CryptoWorldWarService(); //StartCoroutine(CryptoWorldWarService.RegisterPlayer()); Collectables = new List <Collectable>(); StartCoroutine(GetCollectibles()); Collectables = new List <Collectable>(); TransactionSignedUnityRequest = new TransactionSignedUnityRequest(Variables.NodeAddress, Variables.PrivateKey); EthCallUnityRequest = new EthCallUnityRequest(Variables.NodeAddress); TransactionReceiptPollingRequest = new TransactionReceiptPollingRequest(Variables.NodeAddress); CryptoWorldWarContract = new Contract(null, Variables.ABI, Variables.ContractAddress); }
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"); }
// Start is called before the first frame update private void Start() { decrementBy = .25f; level = 0; health = maxLife; levelIncrementor = 1; TransactionSignedUnityRequest = new TransactionSignedUnityRequest(Variables.NodeAddress, Variables.PrivateKey); EthCallUnityRequest = new EthCallUnityRequest(Variables.NodeAddress); TransactionReceiptPollingRequest = new TransactionReceiptPollingRequest(Variables.NodeAddress); DodgeEMToken = new Contract(null, Variables.ABI, Variables.ContractAddress); player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerMovement>(); StartCoroutine(GetTokenOwnerBalance()); }
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 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()); } } }
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); } }
private static IEnumerator CoroutineListSumbissions(RoutineContext context) { // Prepare var function = platformContract.GetFunction("submissionByIndex"); var submissions = new List <Submission>(); // Parse routine params var param = (object[])context.param; var tournamentAddress = (string)param[0]; var page = (long)param[1]; // Loop over every needed indexes var offset = page * 10; Debug.Log("Loading submissions at: " + offset + " in tournament: " + tournamentAddress); for (var i = 0; i < 10; i++) { // Make input var input = function.CreateCallInput(new BigInteger(Convert.ToInt64(tournamentAddress)), i + offset); // Request the specific submission within tournament address at index var request = new EthCallUnityRequest(mtxNode); yield return(SimpleCall(request, input)); // Read results try { var parsedResults = function.DecodeDTOTypeOutput <SubmissionDTO>(request.Result); // Read results var submission = new Submission(); submission.tournamentAddress = tournamentAddress; submission.address = tournamentAddress + ":" + parsedResults.id.ToString(); submission.title = parsedResults.title; submission.body = parsedResults.body; submission.references = parsedResults.references; submission.contributors = parsedResults.contributors; submission.author = parsedResults.author; // Add to list of submissions submissions.Add(submission); } catch (Exception e) { Debug.Log("Could not read submission at index: " + (offset + i)); //Debug.Log(e); //break; } } Debug.Log("Fetched submissions: " + submissions.Count); // Done context.done(submissions); }
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); } }