private void PrintWallet() { var uc = new UnitConversion(); Console.WriteLine(); Console.WriteLine("Account balances"); Console.WriteLine("===================================="); Console.WriteLine($"Wallet ETH balance: {uc.FromWei(this.WalletETH):N18}"); Console.WriteLine($"MetaDollar ETH balance: {uc.FromWei(this.MetaDollarETH):N18}"); Console.WriteLine($"Wallet token balance: {uc.FromWei(this.WalletToken):N18}"); Console.WriteLine($"MetaDollar token balance: {uc.FromWei(this.MetaDollarToken):N18}"); }
public void ShouldConvertToWeiUsingNumberOfDecimalsEth() { var unitConversion = new UnitConversion(); var val = BigInteger.Parse("1000000000000000000000000001"); var result = unitConversion.FromWei(val, 18); var result2 = unitConversion.FromWei(val); Assert.Equal(result, result2); result2 = unitConversion.FromWei(val, BigInteger.Parse("1000000000000000000")); Assert.Equal(result, result2); Assert.Equal(val, UnitConversion.Convert.ToWei(result, 18)); }
public void ShouldConvertFromWeiAndBackToEth() { var unitConversion = new UnitConversion(); var val = BigInteger.Parse("1000000000000000000000000001"); var result = unitConversion.FromWei(val, 18); var result2 = unitConversion.FromWei(val); Assert.Equal(result, result2); result2 = unitConversion.FromWei(val, BigInteger.Parse("1000000000000000000")); Assert.Equal(result, result2); Assert.Equal(val, UnitConversion.Convert.ToWei(result)); }
private void PrintWallet() { var uc = new UnitConversion(); Console.WriteLine(); Console.WriteLine("Account balances"); Console.WriteLine("===================================="); Console.WriteLine($"Wallet ETH balance: {uc.FromWei(this.WalletETH):N18}"); Console.WriteLine($"EtherDelta ETH balance: {uc.FromWei(this.EtherDeltaETH):N18}"); Console.WriteLine($"Wallet token balance: {uc.FromWei(this.WalletToken):N18}"); Console.WriteLine($"EtherDelta token balance: {uc.FromWei(this.EtherDeltaToken):N18}"); }
public async Task ShouldDeployWithFixedGasPrice(string inputHashValue) { var web3 = ethereumClientIntegrationFixture.GetWeb3(); var estimatedGasConsumed = await web3.Eth.DeployContract.EstimateGasAsync(contractAbi, byteCode, sender, inputHashValue); var avgGasPrice = await web3.Eth.GasPrice.SendRequestAsync(); var unitConversion = new UnitConversion(); var gasPrice = unitConversion.FromWei(avgGasPrice); output.WriteLine("Estimate gas: {0} & Average Gas price: {1}", estimatedGasConsumed.Value.ToString(), gasPrice.ToString()); CancellationTokenSource cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(15)); TransactionReceipt txReceipt = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync( contractAbi, byteCode, sender, gasLimit, avgGasPrice, null, cancellationToken, inputHashValue ); var contract = web3.Eth.GetContract(contractAbi, txReceipt.ContractAddress); var hashFunc = contract.GetFunction("hashValue"); var actualHashValue = await hashFunc.CallAsync <string>(); Assert.Equal(inputHashValue, actualHashValue); }
public void ShouldConvertFromWeiToDecimal(int units, string expected, string weiAmount) { var unitConversion = new UnitConversion(); var result = unitConversion.FromWei(BigInteger.Parse(weiAmount), units); Assert.Equal(expected, result.ToString()); }
public void ShouldFailToConvertUsingNonPowerOf10Units(int value) { var unitConversion = new UnitConversion(); var val = BigInteger.Parse("1000000000000000000000000001"); var result = unitConversion.FromWei(val, 18); Assert.Throws <Exception>(() => UnitConversion.Convert.ToWeiFromUnit(result, new BigInteger(value))); }
public void ShouldNotFailToConvertUsing0DecimalUnits() { var unitConversion = new UnitConversion(); var val = BigInteger.Parse("1000000000000000000000000001"); var result = unitConversion.FromWei(val, 18); Assert.Equal(1000000000, UnitConversion.Convert.ToWei(result, (int)0)); }
/// <summary> /// 获取事件成功返回 /// </summary> /// <param name="jsonData">Json data.</param> /// <param name="txHash">Tx hash.</param> private void GetEventLogsCallBack(JsonData jsonData, string txHash) { if (jsonData != null && jsonData["games"] != null) { var list = jsonData["games"]; //itemList.Add(item); var isSucess = false; UnityEngine.Debug.LogError(">>>>>>>count==" + list.Count); var payment = ""; for (var i = 0; i < list.Count; i++) { if (list[i]["tx_hash"].Equals(txHash)) { payment = list[i]["dice_payment"].ToString(); if (payment == "") { } else if (payment == "0") { isSucess = true; } else { isSucess = true; } break; } } if (isSucess) { ViewManager.CloseWaitTip(); if (payment == "0") { ViewManager.ShowMessageBox("您输了"); } else { var unitConversion = new UnitConversion(); ViewManager.ShowMessageBox("赢:" + unitConversion.FromWei(BigInteger.Parse(payment), 18).ToString("0.0000")); } AccountManager.Instance.UpdateBalance(null); } else { StartGetEventLogs(txHash); } UnityEngine.Debug.LogError(">>>>>>>>>>是否成功---" + isSucess); } else { //重新请求 StartGetEventLogs(txHash); } }
public void ShouldConvertPeriodicTether() { var unitConversion = new UnitConversion(); var ether = (decimal)1 / 3; var wei = UnitConversion.Convert.ToWei(ether, UnitConversion.EthUnit.Gether); var val = BigInteger.Parse("3".PadLeft(27, '3')); var result = unitConversion.FromWei(val, UnitConversion.EthUnit.Gether); Assert.Equal(UnitConversion.Convert.ToWei(result, UnitConversion.EthUnit.Gether), wei); }
public void ShouldConvertNoDecimal() { var unitConversion = new UnitConversion(); var ether = 1m; var wei = UnitConversion.Convert.ToWei(ether, UnitConversion.EthUnit.Ether); var val = BigInteger.Parse("1".PadRight(19, '0')); var result = unitConversion.FromWei(val, 18); Assert.Equal(UnitConversion.Convert.ToWei(result), wei); }
public void ShouldConvertLargeDecimal() { var unitConversion = new UnitConversion(); var ether = 1.243842387924387924897423897423m; var wei = UnitConversion.Convert.ToWei(ether, UnitConversion.EthUnit.Ether); var val = BigInteger.Parse("1243842387924387924"); var result = unitConversion.FromWei(val, 18); Assert.Equal(UnitConversion.Convert.ToWei(result), wei); }
public void ShouldConvertPeriodic() { var unitConversion = new UnitConversion(); var ether = (decimal)1 / 3; var wei = UnitConversion.Convert.ToWei(ether, UnitConversion.EthUnit.Ether); var val = BigInteger.Parse("333333333333333333"); var result = unitConversion.FromWei(val, 18); Assert.Equal(UnitConversion.Convert.ToWei(result), wei); }
async Task <long> GetContractBalance() { var contractAddress = "0x6e4a860420e024d2f269d45f85a24dc6f586376d"; var abi = BondContract.ContractAbi; var web3 = new Nethereum.Web3.Web3("http://52.179.18.34:8545"); var contract = web3.Eth.GetContract(abi, contractAddress); var balance = await contract.Eth.GetBalance.SendRequestAsync(contractAddress); var unitConversion = new UnitConversion(); var exp = unitConversion.FromWei(balance); return(decimal.ToInt64(exp)); }
/// <summary> /// Gets the balance of the provided account - if public address provided get balance by address /// Otherwise get balance by identifier /// </summary> /// <param name="publicAddress">The public address of the account</param> /// <returns>Returns the balance in ether.</returns> public async Task <decimal> GetCurrentBalance(string publicAddress = "", string identifier = "") { if (string.IsNullOrEmpty(publicAddress) && string.IsNullOrEmpty(identifier)) { throw new ArgumentNullException("public address or identifier should be provided"); } if (string.IsNullOrEmpty(publicAddress)) { publicAddress = await GetPublicAddressAsync(identifier); } var unitConverion = new UnitConversion(); return(unitConverion.FromWei(await m_web3.Eth.GetBalance.SendRequestAsync(publicAddress))); }
private async Task NotifyEyEmail(Transaction transactions, NotificationModel user, string to, BigInteger value) { string tokenSymbol = "Ether"; if (TokenSignature.IsTransfer(transactions.Input)) { var contract = _web3.Eth.GetContract(TokenSignature.StandartABI, transactions.To); tokenSymbol = _tokenSignature.GetTokenSymbol(contract).Result; } await _emailSender.SendEmailAsync(user.Email, "Guapcoin Notification Service", "Guapcoin\n\n" + $"You received {_unitConversion.FromWei(value)} {tokenSymbol}, in your address {to}.\n\n" + "For detailed information please open this link: " + $"https://ropsten.etherscan.io/tx/{transactions.TransactionHash}\n\n"); }
/// <summary> /// Gets the balance of the provided account /// </summary> /// <param name="publicAddress">The public address of the account</param> /// <returns>Returns the balance in ether.</returns> public async Task <decimal> GetCurrentBalance(string publicAddress) { var unitConverion = new UnitConversion(); return(unitConverion.FromWei(await m_web3.Eth.GetBalance.SendRequestAsync(publicAddress))); }
public Maker(RyxExConfiguration config, ILogger logger = null) : base(config, logger) { PrintMyOrders(); const int ordersPerSide = 1; var expires = Service.GetBlockNumber().Result + 10; var buyOrdersToPlace = ordersPerSide - Service.MyOrders.Buys.Count(); var sellOrdersToPlace = ordersPerSide - Service.MyOrders.Sells.Count(); var buyVolumeToPlace = RyxExETH; var sellVolumeToPlace = RyxExToken; var bestBuy = Service.GetBestAvailableBuy(); var bestSell = Service.GetBestAvailableSell(); if (bestBuy == null || bestSell == null) { Console.WriteLine("Market is not two-sided, cannot calculate mid-market"); return; } // Make sure we have a reliable mid market if (Math.Abs((bestBuy.Price - bestSell.Price) / (bestBuy.Price + bestSell.Price) / 2) > 0.05m) { Console.WriteLine("Market is too wide, will not place orders"); return; } var uc = new UnitConversion(); var midMarket = (bestBuy.Price + bestSell.Price) / 2; var orders = new List <Order>(); for (var i = 0; i < sellOrdersToPlace; i += 1) { var price = midMarket + ((i + 1) * midMarket * 0.05m); var amount = sellVolumeToPlace / sellOrdersToPlace; Console.WriteLine($"Sell { amount.ToString("N3")} @ { price:N9}"); try { var order = Service.CreateOrder(OrderType.Sell, expires, uc.ToWei(price), amount); orders.Add(order); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); } } for (var i = 0; i < buyOrdersToPlace; i += 1) { var price = midMarket - ((i + 1) * midMarket * 0.05m); var amount = uc.FromWei(buyVolumeToPlace) / price / buyOrdersToPlace; Console.WriteLine($"Buy { amount:N3} @ { price:N9}"); try { var order = Service.CreateOrder(OrderType.Buy, expires, uc.ToWei(price), uc.ToWei(amount)); orders.Add(order); } catch (Exception ex) { Console.WriteLine(ex); } } var orderTasks = new List <Task>(); orders.ForEach(order => { var amount = order.TokenGive == Service.ZeroToken ? order.AmountGet : order.AmountGive; orderTasks.Add(Service.TakeOrder(order, amount)); }); try { Task.WaitAll(orderTasks.ToArray()); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.InnerException != null ? ex.InnerException.Message : ex.Message); Console.ResetColor(); } Console.WriteLine("Done"); }