// TODO: Obfusacte private key // Going to store private key // on server and make a web request to retrieve it when needed private IEnumerator SignAndSendTransaction() { yield return(new WaitForSeconds(4)); var addScoreRequest = new TransactionSignedUnityRequest(url, "2a135a7c4a0309f4e77a197d863803f2127ba31119d14fe5e91ae6f24e0ef2bf", 97); Debug.Log(playerNameInput.text); if (playerNameInput.text != null) { yield return(addScoreRequest.SignAndSendTransaction(new AddScoreFunction() { User = playerNameInput.text, Score = Convert.ToInt32(scoreValue.GetComponent <Text>().text) }, contractAddress)); } else { yield return(addScoreRequest.SignAndSendTransaction(new AddScoreFunction() { User = "******", Score = Convert.ToInt32(scoreValue.GetComponent <Text>().text) }, contractAddress)); } if (addScoreRequest.Exception == null) { Debug.Log("High score submitted tx: " + addScoreRequest.Result); } else { Debug.Log("Error submitted tx: " + addScoreRequest.Exception.Message); } SceneManager.LoadScene("MainMenu"); }
public IEnumerator selectWinners(List <byte[]> submissions, List <BigInteger> distribution, BigInteger action, BigInteger start, BigInteger duration, BigInteger review, BigInteger bounty, Async.EventDelegate onComplete = null) { WinnersData wData = new WinnersData() { Submissions = submissions, Distribution = distribution, Action = action }; MatryxRound.RoundDetails rDetails = new MatryxRound.RoundDetails() { Start = start, Duration = duration, Review = review, Bounty = bounty }; var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <SelectWinnersFunction>(new SelectWinnersFunction() { WData = wData, RDetails = rDetails, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }, address)); yield return(Utils.GetTransactionStatus(transactionRequest, "selectWinners", null)); var getTransactionStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "selectWinners", null)); yield return(getTransactionStatus); yield return(getTransactionStatus.result); onComplete?.Invoke(getTransactionStatus.result); }
public static IEnumerator TransferEth(string privateKey, string accountAddress, string toAddress, decimal etherAmount, decimal?gasPriceGwei, BigInteger?gas, System.Action <string, bool, string> callback) { var _transactionSignedUnityRequest = new TransactionSignedUnityRequest(_url, privateKey, accountAddress); var transactionInput = new TransactionInput() { To = toAddress, From = accountAddress, GasPrice = gasPriceGwei == null ? null : new HexBigInteger(UnitConversion.Convert.ToWei(gasPriceGwei.Value, UnitConversion.EthUnit.Gwei)), Value = new HexBigInteger(UnitConversion.Convert.ToWei(etherAmount)), Gas = gas == null ? null : new HexBigInteger(gas.Value) }; yield return(_transactionSignedUnityRequest.SignAndSendTransaction(transactionInput)); if (_transactionSignedUnityRequest.Exception == null) { // If we don't have exceptions we just display the result, congrats! UnityEngine.Debug.Log("transfer submitted: " + _transactionSignedUnityRequest.Result); callback(_transactionSignedUnityRequest.Result, true, toAddress); } else { // if we had an error in the UnityRequest we just display the Exception error UnityEngine.Debug.Log("Error submitting transfer tx: " + _transactionSignedUnityRequest.Exception.Message); callback(_transactionSignedUnityRequest.Exception.Message, false, toAddress); } }
public IEnumerator PlaySlotGo(decimal BetAmount) { var s = Nethereum.Util.UnitConversion.Convert.ToWei(BetAmount, 18).ToString(); Debug.Log("s" + s); var transactionInput = CreateBuyMaterialSlotInput( accountAddress, new HexBigInteger(MineGasAmount), //GasAmount new HexBigInteger(MineGasPrice), //GasPrice / GWEI new HexBigInteger(Nethereum.Util.UnitConversion.Convert.ToWei(BetAmount, 18)) //賭注金額 / TAN ); Debug.Log("你已經開始玩Slot,等待系統確認..."); TransactionText.text = "Play Slot " + BetAmount + "X..."; var transactionSignedRequest = new TransactionSignedUnityRequest(_urlMain, accountPrivateKey, accountAddress); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { Debug.Log("Transfered tx created: " + transactionSignedRequest.Result); checkPlaySlotTx(transactionSignedRequest.Result, (cb) => { Debug.Log("Slot 開啟!"); TransactionText.text = "Slot 開啟!"; LoadingPanel.gameObject.SetActive(false); SpinStart(BetAmount); }); } else { Debug.Log("Error transfering: " + transactionSignedRequest.Exception.Message); } }
public IEnumerator transferEth(string privateKey, string accountAddress, string toAddress, decimal etherAmount, decimal?gasPriceGwei = null, BigInteger?gas = null) { // dll里没有EthTransferUnityRequest这个类, 所以就按照他的实现方式写一遍吧 // var transferEthRequest = new EthTransferUnityRequest(); var _transactionSignedUnityRequest = new TransactionSignedUnityRequest(_url, privateKey, accountAddress); var transactionInput = new TransactionInput() { To = toAddress, From = accountAddress, GasPrice = gasPriceGwei == null ? null : new HexBigInteger(UnitConversion.Convert.ToWei(gasPriceGwei.Value, UnitConversion.EthUnit.Gwei)), Value = new HexBigInteger(UnitConversion.Convert.ToWei(etherAmount)), Gas = gas == null ? null : new HexBigInteger(gas.Value) }; yield return(_transactionSignedUnityRequest.SignAndSendTransaction(transactionInput)); if (_transactionSignedUnityRequest.Exception == null) { // If we don't have exceptions we just display the result, congrats! Debug.Log("transfer submitted: " + _transactionSignedUnityRequest.Result); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting Ping tx: " + _transactionSignedUnityRequest.Exception.Message); } }
public IEnumerator Delegate(string accountAddress, string accountPrivateKey, string toOwner) { var transactionInput = TransactionDelegate( accountAddress, accountPrivateKey, toOwner, new HexBigInteger(50000), new HexBigInteger(0), new HexBigInteger(0) ); var transactionSignedRequest = new TransactionSignedUnityRequest(Inventory.URL, accountPrivateKey, accountAddress); // Then we send it and wait Debug.Log("Sending Delegate transaction..."); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { // If we don't have exceptions we just display the result, congrats! Debug.Log("Delegate transaction submitted: " + transactionSignedRequest.Result); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting Delegate transaction: " + transactionSignedRequest.Exception.Message); } }
public IEnumerator RequestGrantCR(byte score, byte fromTotal) { var transactionTransferRequest = new TransactionSignedUnityRequest(networkUrl, gasWalletAddressPrivate); var transactionMessage = new GrantFunction { FromAddress = gasWalletAddress, Recipient = inputWalletAddress.text, Score = score, FromTotal = fromTotal }; yield return(transactionTransferRequest.SignAndSendTransaction(transactionMessage, contractAddress)); if (transactionTransferRequest.Exception != null) { Debug.LogError(transactionTransferRequest.Exception.Message); } string transactionHash = transactionTransferRequest.Result; Debug.Log(transactionHash); OnRequestGrant?.Invoke(transactionHash); grantTransactionHash = transactionHash; }
public IEnumerator AcceptExchange(string accountAddress, string accountPrivateKey, string fromOwner, string theirItem, string myItem) { var transactionInput = TransactionAcceptExchange( accountAddress, accountPrivateKey, fromOwner, theirItem, myItem, new HexBigInteger(50000), new HexBigInteger(0), new HexBigInteger(0) ); var transactionSignedRequest = new TransactionSignedUnityRequest(Inventory.URL, accountPrivateKey, accountAddress); // Then we send it and wait Debug.Log("Sending AcceptExchange transaction (from = " + fromOwner + " theirItem = " + theirItem + " myItem = " + myItem); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { // If we don't have exceptions we just display the result, congrats! Debug.Log("AcceptExchange transaction submitted: " + transactionSignedRequest.Result); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting AcceptExchange transaction: " + transactionSignedRequest.Exception.Message); } }
public IEnumerator PlayerHitGo() { var transactionInput = CreatePlayerHitInput( accountAddress, new HexBigInteger(MineGasAmount), //GasAmount new HexBigInteger(MineGasPrice), //GasPrice / GWEI new HexBigInteger(0) //TAN ); Debug.Log("玩家補牌,等待系統確認..."); TransactionText.text = "Player Hit..."; var transactionSignedRequest = new TransactionSignedUnityRequest(_urlMain, accountPrivateKey, accountAddress); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { Debug.Log("Transfered tx created: " + transactionSignedRequest.Result); checkPlayerHitTx(transactionSignedRequest.Result, (cb) => { Debug.Log("補牌完成!"); TransactionText.text = "Player hit done."; LoadingPanel.gameObject.SetActive(false); BlockBG.gameObject.SetActive(false); checkPlayerCards(1); }); } else { Debug.Log("Error transfering: " + transactionSignedRequest.Exception.Message); } }
private IEnumerator StartTransfer() { var transferFromFunction = new TransferFromFunction(); transferFromFunction.FromAddress = Variables.tokenOwnerAddress; transferFromFunction.Recipient = addressField.text; transferFromFunction.Amount = manager.emTokens * manager.tokenMultiplier; transferFromFunction.Gas = 8000000; transferFromFunction.GasPrice = 9000000000000; transferFromFunction.Sender = Variables.tokenOwnerAddress; yield return(TransactionSignedUnityRequest.SignAndSendTransaction(transferFromFunction, Variables.ContractAddress)); if (TransactionSignedUnityRequest.Result != null) { StartCoroutine(GetTokenOwnerBalance(addressField.text)); StartCoroutine(manager.GetTokenOwnerBalance()); manager.emTokens = 0; addressField.text = ""; } else { Debug.LogError("Something went wrong"); Debug.LogError(TransactionSignedUnityRequest.Exception); } }
// Send transfer request using TransactionSignedUnityRequest private static IEnumerator TransferCoroutine(string addressTo, decimal amount, UnityAction <string> onSubmitted = null, UnityAction onCompleted = null, UnityAction <System.Exception> onFailed = null) { // Use TransactionSignedUnityRequest from the Nethereum lib to create a transaction request var transactionSignedRequest = new TransactionSignedUnityRequest(WalletSettings.current.networkUrl, CurrentWalletPrivateKey, CurrentWalletAddress); // Create the input, if no gas and gas price are used, it uses the default value var transactionInput = new TransactionInput(null, addressTo, new HexBigInteger(UnitConversion.Convert.ToWei(amount, 18))); // Then we call the method SignAndSendTransaction() from the transactionSignedRequest we created with the transaction input yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); // Now we check if the request has an exception if (transactionSignedRequest.Exception == null) { onSubmitted?.Invoke(transactionSignedRequest.Result); // Keep checking the transaction receipt if an onCompleted used if (onCompleted != null) { GetTransactionReceipt(transactionSignedRequest.Result, 5, (transactionReceipt) => // Retry for every 5 seconds { if (transactionReceipt != null) { onCompleted(); } }); } } else { onFailed?.Invoke(transactionSignedRequest.Exception); } }
public IEnumerator transferRequest(string address, BigInteger value) { var transactionInput = transferContract.CreateTransferInput( accountAddress, address, value, new HexBigInteger(200000), new HexBigInteger(190), new HexBigInteger(0) ); Debug.Log("Transfering tokens: " + address); var transactionSignedRequest = new TransactionSignedUnityRequest(_url, accountPrivateKey, accountAddress); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { Debug.Log("Transfered tx created: " + transactionSignedRequest.Result); // Now we check the transaction until it's mined in the blockchain as we did in // the pingRequest, when the callback is triggered (transaction mined), // we execute the getBalanceRequest for the address we send tokens to checkTx(transactionSignedRequest.Result, (cb) => { //StartCoroutine(getBalanceOfRequest(address)); }); } else { Debug.Log("Error transfering tokens: " + transactionSignedRequest.Exception.Message); } }
private IEnumerator SendSignedTransaction(TransactionInput transac, string password) { string privateKey = GetPrivateKeyFromKeystore(password); if (privateKey != "") { TransactionSignedUnityRequest transactionSignedRequest = new TransactionSignedUnityRequest(url, privateKey, accountAddress); yield return(transactionSignedRequest.SignAndSendTransaction(transac)); if (transactionSignedRequest.Exception == null) { // If we don't have exceptions we just display the result, congrats! Debug.Log("Nexium approve submitted: " + transactionSignedRequest.Result); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting Nexium approve: " + transactionSignedRequest.Exception.Message); } } else { Debug.Log("Can't get private key"); } }
public IEnumerator TransferCollectible(int id, string owner) { TransactionSignedUnityRequest = new TransactionSignedUnityRequest(Variables.NodeAddress, Variables.PrivateKey); Debug.Log("Got here"); var transferCollectibleFunction = new TransferCollectibleFunction(); transferCollectibleFunction.FromAddress = owner; transferCollectibleFunction.Gas = 8000000; transferCollectibleFunction.GasPrice = 999000000000; transferCollectibleFunction.To = Variables.OtherPlayer; transferCollectibleFunction.CollectibleId = id; //Call request sends and yield for response yield return(TransactionSignedUnityRequest.SignAndSendTransaction(transferCollectibleFunction, Variables.ContractAddress)); //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 (TransactionSignedUnityRequest.Exception == null) { //var registered = DecodeRegistrationOutput(TransactionSignedUnityRequest.Result); Debug.Log("Results from transfer: " + TransactionSignedUnityRequest.Result); } else { Debug.Log(TransactionSignedUnityRequest.Exception.ToString()); } }
public IEnumerator deployContract(string abi, string byteCode, string senderAddress, System.Action <string> callback) { // Ammount of gas required to create the contract var gas = new HexBigInteger(900000); // First we build the transaction var transactionInput = contractTransactionBuilder.BuildTransaction(abi, byteCode, senderAddress, gas, null); // Here we create a new signed transaction Unity Request with the url, the private and public key // (this will sign the transaction automatically) var transactionSignedRequest = new TransactionSignedUnityRequest(_url, accountPrivateKey, accountAddress); // Then we send the request and wait for the transaction hash Debug.Log("Sending Deploy contract transaction..."); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { // If we don't have exceptions we just return the result! callback(transactionSignedRequest.Result); } else { // if we had an error in the UnityRequest we just display the Exception error throw new System.InvalidOperationException("Deploy contract tx failed:" + transactionSignedRequest.Exception.Message); } }
public IEnumerator pingRequest() { // since the ping request is a transaction we need to set gas (80000) // gas price (79) and the eth we are going to send (0) // (these are just testing values) var transactionInput = pingTokenContractService.CreatePingInput( accountAddress, new HexBigInteger(80000), new HexBigInteger(79), new HexBigInteger(0) ); var transactionSignedRequest = new TransactionSignedUnityRequest(_url, accountAddress, accountAddress); Debug.Log("Ping transaction being submitted.."); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { Debug.Log("Ping tx created: " + transactionSignedRequest.Result); // Here, after the ping request succeeds, we call checkTx(), and // we send the transaction Hash (the result of the ping request), // and a callback, this will trigger when the tx type == 'mined' checkTx(transactionSignedRequest.Result, (cb) => { // here you can add some more logic to trigger after the tx is mined in the blockchain }); } else { Debug.Log("Error submitting Ping: " + transactionSignedRequest.Exception.Message); } }
public IEnumerator Mint(BigInteger TokenId) { Exception = null; if (defaultAccount == null) { yield return(GetAccounts()); if (Exception != null) { Debug.Log("Got an error: " + Exception.Message); yield break; } } Debug.Log("Minting"); var functionMessage = new MintToFunctionMessage { To = defaultAccount, TokenId = TokenId, }; var transaction = new TransactionSignedUnityRequest(networkName, defaultAccount); yield return(transaction.SignAndSendTransaction(functionMessage, contractAddress)); if (transaction.Exception != null) { this.Exception = transaction.Exception; yield break; } this.mintReceipt = transaction.Result; }
public IEnumerator payForCreation() { string ABI = @"[{'constant':true,'inputs':[],'name':'ceoAddress','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'','type':'address'}],'name':'creationFee','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_newCEO','type':'address'}],'name':'setCEO','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_adminAddress','type':'address'}],'name':'unassignAdmin','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[],'name':'gameserverAddress','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[{'name':'_adminAddress','type':'address'}],'name':'assignAdmin','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[],'name':'unpause','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'','type':'address'}],'name':'adminAddresses','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[],'name':'paused','outputs':[{'name':'','type':'bool'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[],'name':'pause','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':false,'inputs':[{'name':'_newGameserver','type':'address'}],'name':'setGameserver','outputs':[],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[{'name':'','type':'address'}],'name':'ownershipTokenCount','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'','type':'uint256'}],'name':'artifactIndexToApproved','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':true,'inputs':[{'name':'','type':'uint256'}],'name':'artifactIndexToOwner','outputs':[{'name':'','type':'address'}],'payable':false,'stateMutability':'view','type':'function'},{'anonymous':false,'inputs':[{'indexed':true,'name':'from','type':'address'},{'indexed':true,'name':'to','type':'address'},{'indexed':true,'name':'tokenId','type':'uint256'}],'name':'Transfer','type':'event'},{'anonymous':false,'inputs':[{'indexed':false,'name':'payer','type':'address'}],'name':'PayedCreation','type':'event'},{'constant':false,'inputs':[{'name':'_typeId','type':'uint16'},{'name':'_maxAmount','type':'uint32'},{'name':'_isSellable','type':'bool'},{'name':'_owner','type':'address'}],'name':'createArtifact','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'nonpayable','type':'function'},{'constant':true,'inputs':[],'name':'getArtifactsAmount','outputs':[{'name':'','type':'uint256'}],'payable':false,'stateMutability':'view','type':'function'},{'constant':false,'inputs':[],'name':'payForArtifact','outputs':[],'payable':true,'stateMutability':'payable','type':'function'},{'constant':true,'inputs':[{'name':'_id','type':'uint256'}],'name':'getArtifactTypeId','outputs':[{'name':'_typeId','type':'uint16'}],'payable':false,'stateMutability':'view','type':'function'}]"; string contractAddress = "0xaafa19d6f354eee368e0bc6ed0a418cc8bf49763"; Contract contract = new Contract(null, ABI, contractAddress); var func = contract.GetFunction("payForArtifact"); // var sha3 = new Nethereum.Util.Sha3Keccack(); Debug.Log("Owner: " + addressOwner + " , sender: " + address); // var hash = sha3.CalculateHashFromHex(address, addressOwner); // var signer = new MessageSigner(); // var signature = signer.Sign (hash.HexToByteArray(), privateKey); // var ethEcdsa = MessageSigner.ExtractEcdsaSignature(signature); var inp = func.CreateTransactionInput(address, new HexBigInteger(100000), new HexBigInteger(1250000000000000)); Debug.Log("Generated transaction input"); var transactionSignedRequest = new TransactionSignedUnityRequest(url, privateKey, address); Debug.Log("Sent request"); yield return(transactionSignedRequest.SignAndSendTransaction(inp)); if (transactionSignedRequest.Exception == null) { Debug.Log("Payed for artifact!"); } else { Debug.Log("Error :("); } }
IEnumerator NexiumApprove(string spender, BigInteger value) { string accountPrivateKey = GetPrivateKeyFromKeystore(Password.text); if (accountPrivateKey == "") { yield break; } var transactionInput = m_nexiumContract.Create_approve_TransactionInput( accountAddress, spender, value, new HexBigInteger(20000), new HexBigInteger(10), new HexBigInteger(0) ); var transactionSignedRequest = new TransactionSignedUnityRequest(_url, accountPrivateKey, accountAddress); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { // If we don't have exceptions we just display the result, congrats! Debug.Log("Nexium approve submitted: " + transactionSignedRequest.Result); } else { // if we had an error in the UnityRequest we just display the Exception error Debug.Log("Error submitting Nexium approve: " + transactionSignedRequest.Exception.Message); } }
IEnumerator Cancellation(BigInteger duelID, Action act) { string accountPrivateKey = GetPrivateKeyFromKeystore(Password.text); if (accountPrivateKey == "") { yield break; } var transactionInput = m_spaceMMContract.Create_cancellation_TransactionInput( accountAddress, accountPrivateKey, duelID, new HexBigInteger(20000), new HexBigInteger(10), new HexBigInteger(0) ); var transactionSignedRequest = new TransactionSignedUnityRequest(_url, accountPrivateKey, accountAddress); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { if (act != null) { act(); } } else { Debug.Log("Error Validate Duel: " + transactionSignedRequest.Exception.Message); } }
public IEnumerator SendTransaction() { yield return(new WaitForSeconds(2)); //Build transaction TransactionInput transInput = new TransactionInput(); transInput.Value = "0x43"; transInput.To = toAddress; transInput.From = fromAddress; transInput.Gas = "0x76c0"; transInput.GasPrice = "0x9184272a000"; //Create Unity Request with the private key, url and user address var transactionSignedRequest = new TransactionSignedUnityRequest("http://localhost:8545", privateKey, fromAddress); yield return(transactionSignedRequest.SignAndSendTransaction(transInput)); if (transactionSignedRequest.Exception == null) { Debug.Log("Submitted tx: " + transactionSignedRequest.Result); } else { Debug.Log("Error submitted tx: " + transactionSignedRequest.Exception.Message); } }
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 createSubmission(string tournamentAddress, string parentHash, bool isFork, BigInteger value, Async thread = null) { var salt = getClaim(ipfsContentHash).salt; var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); var createSubmissionMsg = new CreateSubmissionFunction() { TournamentAddress = tournamentAddress, SubmissionContentHash = ipfsContentHash, ParentHash = parentHash, IsFork = isFork, Salt = salt, CommitContentHash = ipfsContentHash, Value = value, Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }; yield return(transactionRequest.SignAndSendTransaction <CreateSubmissionFunction>(createSubmissionMsg, MatryxCommit.address)); var txStatus = new Utils.CoroutineWithData <bool>(MatryxCortex.Instance, Utils.GetTransactionStatus(transactionRequest, "createSubmission", thread)); yield return(txStatus); yield return(txStatus.result); }
//Check if the user top score has changed on the contract chain every 2 seconds public IEnumerator RegisterPlayer(string address, string privateKey) { TransactionSignedUnityRequest = new TransactionSignedUnityRequest(Variables.NodeAddress, privateKey); Debug.Log("Got here"); var regFunc = new RegisterPlayerFunction(); regFunc.FromAddress = address; regFunc.Gas = 8000000; regFunc.GasPrice = 9000000000000; //Call request sends and yield for response yield return(TransactionSignedUnityRequest.SignAndSendTransaction(regFunc, Variables.ContractAddress)); //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 (TransactionSignedUnityRequest.Exception == null) { //var registered = DecodeRegistrationOutput(TransactionSignedUnityRequest.Result); Debug.Log("Results from registration: " + DecodeRegistrationOutput(TransactionSignedUnityRequest.Result)); } else { Debug.Log(TransactionSignedUnityRequest.Exception.ToString()); } }
//Making a transaction signed raw request public IEnumerator CheckSubmitScore() { var wait = 4; while (true) { yield return(new WaitForSeconds(wait)); //Game control sets a signal if (// GameControl.instance.SubmitTopScore && !submitting) { if (_userAddress != null) { submitting = true; Debug.Log("Submitting tx"); //Create the transaction input with encoded values for the function var transactionInput = _scoreContractService.CreateSetTopScoreTransactionInput(_userAddress, _addressOwner, _privateKey, 20, // GameControl.instance.TopScore, //new HexBigInteger (21000), //new HexBigInteger (21000)); new HexBigInteger(4712388)); if (ExternalProvider) { Debug.Log("Submitting tx to score using external: " + transactionInput.Data); SendTransaction(transactionInput.To, transactionInput.Data); } else { //Create Unity Request with the private key, url and user address //(the address could be recovered from private key as in normal Nethereum, could put this an overload) // premature optimisation var transactionSignedRequest = new TransactionSignedUnityRequest(_url, _privateKey, // GameControl.instance.Key, _userAddress); //send and wait yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { //get transaction receipt Debug.Log("Top score submitted tx: " + transactionSignedRequest.Result); } else { Debug.Log("Error submitted tx: " + transactionSignedRequest.Exception.Message); } } } // GameControl.instance.SubmitTopScore = false; submitting = false; } } }
/// Sets the DNA based on the input fields /// 1. Estimate Gas parameter /// 2. Send transaction /// 3. Wait for receipt private IEnumerator SetDNA() { string wallet = inputWallet.text; string privateKey = inputPrivateKey.text; var contract = new Contract(null, itemManagerABI, itemManagerContractAddress); var function = contract.GetFunction("setDNA"); EthEstimateGasUnityRequest estimateRequest = new EthEstimateGasUnityRequest(url); // convert string to hex to work the same way as Javascript Example string id = int.Parse(inputSetDNAItemID.text).ToString("x"); string hexString = System.Numerics.BigInteger.Parse(inputSetDNADNA.text).ToString("x"); TransactionInput estimateInput = function.CreateTransactionInput(wallet, id, hexString); yield return(estimateRequest.SendRequest(estimateInput)); if (estimateRequest.Exception != null) { Debug.Log(estimateRequest.Exception); yield break; } Debug.Log("Gas: " + estimateRequest.Result.Value); var req = new TransactionSignedUnityRequest(url, privateKey, wallet); var callInput = function.CreateTransactionInput( wallet, estimateRequest.Result, new HexBigInteger("0x0"), id, hexString); yield return(req.SignAndSendTransaction(callInput)); textSetDNAStatus.text = "waiting"; var receiptRequest = new EthGetTransactionReceiptUnityRequest(url); bool done = false; while (!done) { yield return(receiptRequest.SendRequest(req.Result)); if (receiptRequest.Result != null) { done = true; } yield return(new WaitForSeconds(1.0f)); } textSetDNAStatus.text = "done"; }
IEnumerator SendTransactionCoroutine(TransactionInput requestParameters, System.Action <UnityRequest <string> > requestCallback) { var request = new TransactionSignedUnityRequest(requestNode, privateKey, accountAddress); yield return(request.SignAndSendTransaction(requestParameters)); requestCallback.Invoke(request); transactionHashes.Add(request.Result); }
public IEnumerator PlayBJGo(int BetAmount) { var transactionInput = CreatePlayBJInput( accountAddress, new HexBigInteger(MineGasAmount), //GasAmount new HexBigInteger(MineGasPrice), //GasPrice / GWEI new HexBigInteger(Nethereum.Util.UnitConversion.Convert.ToWei(BetAmount, 18)) //賭注金額 / TAN ); Debug.Log("你已經開始玩BJ,等待系統確認..."); TransactionText.text = "Play Blackjack " + BetAmount + "X..."; var transactionSignedRequest = new TransactionSignedUnityRequest(_urlMain, accountPrivateKey, accountAddress); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (transactionSignedRequest.Exception == null) { Debug.Log("Transfered tx created: " + transactionSignedRequest.Result); checkPlayBJTx(transactionSignedRequest.Result, (cb) => { Debug.Log("Blackjack 開啟!"); TransactionText.text = "Blackjack Start!"; LoadingPanel.gameObject.SetActive(false); if (StartResult == 0) { checkPlayerCards(1); DealPanel.gameObject.SetActive(false); PlayPanel.gameObject.SetActive(true); StandPanel.gameObject.SetActive(true); ShowCardsPanel.gameObject.SetActive(false); HitPanel.gameObject.SetActive(true); RestartGamePanel.gameObject.SetActive(false); } else if (StartResult == 1) { PUSHPanel.gameObject.SetActive(true); checkPlayerCards(1); } else if (StartResult == 2) { P_BlackJackPanel.gameObject.SetActive(true); checkPlayerCards(1); } else if (StartResult == 3) { B_BlackJackPanel.gameObject.SetActive(true); checkPlayerCards(1); } }); } else { Debug.Log("Error transfering: " + transactionSignedRequest.Exception.Message); } }
public IEnumerator recoverBounty(Async thread = null) { var transactionRequest = new TransactionSignedUnityRequest(NetworkSettings.infuraProvider, NetworkSettings.currentPrivateKey); yield return(transactionRequest.SignAndSendTransaction <RecoverBountyFunction>(new RecoverBountyFunction() { Gas = NetworkSettings.txGas, GasPrice = NetworkSettings.txGasPrice }, address)); yield return(Utils.GetTransactionStatus(transactionRequest, "recoverFunds", thread)); }
// write date to contact ,it will use some gas public IEnumerator SignTransaction(TransactionInput transactionInput, System.Action <UnityRequest <string> > result) { var transactionSignedRequest = new TransactionSignedUnityRequest(URL, privateKey); yield return(transactionSignedRequest.SignAndSendTransaction(transactionInput)); if (result != null) { result.Invoke(transactionSignedRequest); } }