private void btnLogOut_Click(object sender, RoutedEventArgs e) { WelcomeWindow WelcomeWnd = new WelcomeWindow(); WelcomeWnd.Show(); isLogOut = true; AddressAssetsImp.getInstance().Reset(); AssetsManager.GetInstance().Reset(); this.Close(); }
private void LoadMaxAmount() { string FromAddr = cmb_from.Text; Global.AssetDescriptor asset = cmb_assets.SelectedItem as Global.AssetDescriptor; if (asset == null) { return; } UInt256 AssetID = new UInt256(asset.AssetId.ToArray()); if (AddressAssetsImp.getInstance().GetList().ContainsKey(FromAddr)) { if (AddressAssetsImp.getInstance().GetList()[FromAddr].Assets.ContainsKey(AssetID)) { txb_max_amount.Text = AddressAssetsImp.getInstance().GetList()[FromAddr].Assets[AssetID] + " " + cmb_assets.SelectedItem; return; } } txb_max_amount.Text = "0 " + cmb_assets.SelectedItem; }
private void dispatcherTimer_Tick(object sender, EventArgs e) { if (Constant.CurrentWallet.WalletHeight == 0) { TxbHeight.Text = $"{StringTable.GetInstance().GetString("STR_MW_HEIGHT", iLang)} : {Constant.CurrentWallet.WalletHeight}/{Blockchain.Default.Height}/{Blockchain.Default.HeaderHeight}"; } else { TxbHeight.Text = $"{StringTable.GetInstance().GetString("STR_MW_HEIGHT", iLang)} : {Constant.CurrentWallet.WalletHeight - 1}/{Blockchain.Default.Height}/{Blockchain.Default.HeaderHeight}"; } TxbConnected.Text = $"{StringTable.GetInstance().GetString("STR_MW_CONNECTED", iLang)} : " + Constant.LocalNode.RemoteNodeCount.ToString(); if (Constant.LocalNode.RemoteNodeCount > 0) { TxbConnected.Foreground = new SolidColorBrush(Colors.YellowGreen); } else { TxbConnected.Foreground = new SolidColorBrush(Colors.Orange); } if (Constant.CurrentWallet.WalletHeight - 1 < Blockchain.Default.HeaderHeight - 1 || Blockchain.Default.Height < Blockchain.Default.HeaderHeight - 1) { TxbHeight.Foreground = new SolidColorBrush(Colors.Orange); } else { TxbHeight.Foreground = new SolidColorBrush(Colors.YellowGreen); } if (Constant.CurrentWallet != null) { if (Constant.CurrentWallet.WalletHeight <= Blockchain.Default.Height + 1) { if (balance_changed) { IEnumerable <Coin> coins = Constant.CurrentWallet?.GetCoins().Where(p => !p.State.HasFlag(CoinState.Spent)) ?? Enumerable.Empty <Coin>(); IEnumerable <JSCoin> jscoins = Constant.CurrentWallet?.GetJSCoins().Where(p => !p.State.HasFlag(CoinState.Spent)) ?? Enumerable.Empty <JSCoin>(); IEnumerable <RCTCoin> rctcoins = Constant.CurrentWallet?.GetRCTCoins().Where(p => !p.State.HasFlag(CoinState.Spent)) ?? Enumerable.Empty <RCTCoin>(); Fixed8 bonus_available = Blockchain.CalculateBonus(Constant.CurrentWallet.GetUnclaimedCoins().Select(p => p.Reference)); Fixed8 bonus_unavailable = Blockchain.CalculateBonus(coins.Where(p => p.State.HasFlag(CoinState.Confirmed) && p.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)).Select(p => p.Reference), Blockchain.Default.Height + 1); Fixed8 bonus = bonus_available + bonus_unavailable; var assets = coins.GroupBy(p => p.Output.AssetId, (k, g) => new { Asset = Blockchain.Default.GetAssetState(k), Value = g.Sum(p => p.Output.Value), Claim = k.Equals(Blockchain.UtilityToken.Hash) ? bonus : Fixed8.Zero }).ToDictionary(p => p.Asset.AssetId); var jsAssets = jscoins.GroupBy(p => p.Output.AssetId, (k, g) => new { Asset = Blockchain.Default.GetAssetState(k), Value = g.Sum(p => p.Output.Value) }).ToDictionary(p => p.Asset.AssetId); var rctAssets = rctcoins.GroupBy(p => p.Output.AssetId, (k, g) => new { Asset = Blockchain.Default.GetAssetState(k), Value = g.Sum(p => p.Output.Value) }).ToDictionary(p => p.Asset.AssetId); if (bonus != Fixed8.Zero && !assets.ContainsKey(Blockchain.UtilityToken.Hash)) { assets[Blockchain.UtilityToken.Hash] = new { Asset = Blockchain.Default.GetAssetState(Blockchain.UtilityToken.Hash), Value = Fixed8.Zero, Claim = bonus }; } if (assets.Count + jsAssets.Count + rctAssets.Count < assetItems.Count) { ResetAssetInfoPan(); AssetsManager.GetInstance().Reset(); sendPage.Reset(); } foreach (var asset in assets.Values) { AddAssets(asset.Asset, asset.Value, asset.Claim); } foreach (var jsAsset in jsAssets.Values) { AddAssets(jsAsset.Asset, jsAsset.Value, Fixed8.Zero); } foreach (var rctAsset in rctAssets.Values) { AddAssets(rctAsset.Asset, rctAsset.Value, Fixed8.Zero); } var balance_qrs = coins.Where(p => p.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); var balance_rct_qrs = rctcoins.Where(p => p.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); var balance_js_qrs = jscoins.Where(p => p.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); var balance_qrg = coins.Where(p => p.Output.AssetId.Equals(Blockchain.UtilityToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); var balance_rct_qrg = rctcoins.Where(p => p.Output.AssetId.Equals(Blockchain.UtilityToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); var balance_js_qrg = jscoins.Where(p => p.Output.AssetId.Equals(Blockchain.UtilityToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); Fixed8 qrs_total = Fixed8.Zero; Fixed8 qrg_total = Fixed8.Zero; foreach (UInt160 scriptHash in Constant.CurrentWallet.GetAddresses().ToArray()) { VerificationContract contract = Constant.CurrentWallet.GetContract(scriptHash); Fixed8 qrs = balance_qrs.ContainsKey(scriptHash) ? balance_qrs[scriptHash] : Fixed8.Zero; Fixed8 js_qrs = balance_js_qrs.ContainsKey(scriptHash) ? balance_js_qrs[scriptHash] : Fixed8.Zero; Fixed8 rct_qrs = balance_rct_qrs.ContainsKey(scriptHash) ? balance_rct_qrs[scriptHash] : Fixed8.Zero; Fixed8 qrg = balance_qrg.ContainsKey(scriptHash) ? balance_qrg[scriptHash] : Fixed8.Zero; Fixed8 js_qrg = balance_js_qrg.ContainsKey(scriptHash) ? balance_js_qrg[scriptHash] : Fixed8.Zero; Fixed8 rct_qrg = balance_rct_qrg.ContainsKey(scriptHash) ? balance_rct_qrg[scriptHash] : Fixed8.Zero; AddressAssetsImp.getInstance().RefrshAssets(contract.Address, Blockchain.GoverningToken.Hash, (qrs + js_qrs).ToString()); AddressAssetsImp.getInstance().RefrshAssets(contract.Address, Blockchain.UtilityToken.Hash, (qrg + js_qrg).ToString()); qrs_total += qrs; qrs_total += js_qrs; qrs_total += rct_qrs; qrg_total += qrg; qrg_total += js_qrg; qrg_total += rct_qrg; } TxbQRSBalance.Text = Helper.FormatNumber(qrs_total.ToString()); TxbQRGBalance.Text = Helper.FormatNumber(qrg_total.ToString()); TxbQrsUsdBalance.Text = $"${Helper.FormatNumber((qrs_total * Fixed8.Satoshi * 8000000).ToString())}"; TxbQrgUsdBalance.Text = $"${Helper.FormatNumber((qrg_total * Fixed8.Satoshi * 2000000).ToString())}"; balance_changed = false; } } } }
public string GetErrorMessage() { string ret = ""; if (cmb_from.Text.Length == 0) { ret = StringTable.DATA[iLang, 58]; return(ret); } try { Pure.Wallets.Wallet.GetAddressVersion(cmb_from.Text); } catch { ret = StringTable.DATA[iLang, 59]; return(ret); } if (txb_recieve_addr.Text.Length == 0) { ret = StringTable.DATA[iLang, 60]; return(ret); } if (txb_recieve_addr.Text == cmb_from.Text) { ret = StringTable.DATA[iLang, 61]; return(ret); } try { Pure.Wallets.Wallet.GetAddressVersion(txb_recieve_addr.Text); } catch { ret = StringTable.DATA[iLang, 62]; return(ret); } if (cmb_assets.SelectedItem == null) { ret = StringTable.DATA[iLang, 63]; return(ret); } if (txb_amount.Text.Length == 0) { ret = StringTable.DATA[iLang, 64]; return(ret); } if (!Fixed8.TryParse(txb_amount.Text, out Fixed8 amount)) { ret = StringTable.DATA[iLang, 65]; return(ret); } if (amount == Fixed8.Zero) { ret = StringTable.DATA[iLang, 66]; return(ret); } Fixed8 max_balance = Fixed8.Zero; string FromAddr = cmb_from.Text; string MaxAmount = "0"; Global.AssetDescriptor asset = cmb_assets.SelectedItem as Global.AssetDescriptor; if (asset == null) { ret = StringTable.DATA[iLang, 67]; return(ret); } UInt256 AssetID = new UInt256(asset.AssetId.ToArray()); if (AddressAssetsImp.getInstance().GetList().ContainsKey(FromAddr)) { if (AddressAssetsImp.getInstance().GetList()[FromAddr].Assets.ContainsKey(AssetID)) { MaxAmount = AddressAssetsImp.getInstance().GetList()[FromAddr].Assets[AssetID]; } } max_balance = Fixed8.One * Fixed8.Parse(MaxAmount); if (amount > max_balance) { ret = StringTable.DATA[iLang, 68]; return(ret); } if (Wallet.GetAddressVersion(cmb_from.Text) == Wallet.AnonymouseAddressVersion || Wallet.GetAddressVersion(txb_recieve_addr.Text) == Wallet.AnonymouseAddressVersion) { if (Constant.bSnarksParamLoaded == false) { ret = StringTable.DATA[iLang, 69]; return(ret); } } return(ret); }
private void timer1_Tick(object sender, EventArgs e) { lbl_height.Text = $"{StringTable.DATA[iLang, 33]} : {Constant.CurrentWallet.WalletHeight - 1}/{Blockchain.Default.Height}/{Blockchain.Default.HeaderHeight}"; lbl_connected.Text = $"{StringTable.DATA[iLang, 34]} : " + Constant.LocalNode.RemoteNodeCount.ToString(); if (Constant.CurrentWallet != null) { if (Constant.CurrentWallet.WalletHeight <= Blockchain.Default.Height + 1) { if (balance_changed) { IEnumerable <Coin> coins = Constant.CurrentWallet?.GetCoins().Where(p => !p.State.HasFlag(CoinState.Spent)) ?? Enumerable.Empty <Coin>(); IEnumerable <JSCoin> jscoins = Constant.CurrentWallet?.GetJSCoins().Where(p => !p.State.HasFlag(CoinState.Spent)) ?? Enumerable.Empty <JSCoin>(); Fixed8 bonus_available = Blockchain.CalculateBonus(Constant.CurrentWallet.GetUnclaimedCoins().Select(p => p.Reference)); Fixed8 bonus_unavailable = Blockchain.CalculateBonus(coins.Where(p => p.State.HasFlag(CoinState.Confirmed) && p.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)).Select(p => p.Reference), Blockchain.Default.Height + 1); Fixed8 bonus = bonus_available + bonus_unavailable; var assets = coins.GroupBy(p => p.Output.AssetId, (k, g) => new { Asset = Blockchain.Default.GetAssetState(k), Value = g.Sum(p => p.Output.Value), Claim = k.Equals(Blockchain.UtilityToken.Hash) ? bonus : Fixed8.Zero }).ToDictionary(p => p.Asset.AssetId); if (bonus != Fixed8.Zero && !assets.ContainsKey(Blockchain.UtilityToken.Hash)) { assets[Blockchain.UtilityToken.Hash] = new { Asset = Blockchain.Default.GetAssetState(Blockchain.UtilityToken.Hash), Value = Fixed8.Zero, Claim = bonus }; } var balance_qrs = coins.Where(p => p.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); var balance_js_qrs = jscoins.Where(p => p.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); var balance_qrg = coins.Where(p => p.Output.AssetId.Equals(Blockchain.UtilityToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); var balance_js_qrg = jscoins.Where(p => p.Output.AssetId.Equals(Blockchain.UtilityToken.Hash)).GroupBy(p => p.Output.ScriptHash).ToDictionary(p => p.Key, p => p.Sum(i => i.Output.Value)); Fixed8 qrs_total = Fixed8.Zero; Fixed8 qrg_total = Fixed8.Zero; foreach (UInt160 scriptHash in Constant.CurrentWallet.GetAddresses().ToArray()) { VerificationContract contract = Constant.CurrentWallet.GetContract(scriptHash); Fixed8 qrs = balance_qrs.ContainsKey(scriptHash) ? balance_qrs[scriptHash] : Fixed8.Zero; Fixed8 js_qrs = balance_js_qrs.ContainsKey(scriptHash) ? balance_js_qrs[scriptHash] : Fixed8.Zero; Fixed8 qrg = balance_qrg.ContainsKey(scriptHash) ? balance_qrg[scriptHash] : Fixed8.Zero; Fixed8 js_qrg = balance_js_qrg.ContainsKey(scriptHash) ? balance_js_qrg[scriptHash] : Fixed8.Zero; AddressAssetsImp.getInstance().RefrshAssets(contract.Address, Blockchain.GoverningToken.Hash, (qrs + js_qrs).ToString()); AddressAssetsImp.getInstance().RefrshAssets(contract.Address, Blockchain.UtilityToken.Hash, (qrg + js_qrg).ToString()); qrs_total += qrs; qrs_total += js_qrs; qrg_total += qrg; qrg_total += js_qrg; } dashboardPan1.SetQRSTotalBalance(Helper.FormatNumber(qrs_total.ToString())); dashboardPan1.SetQRGTotalBalance(Helper.FormatNumber(qrg_total.ToString())); balance_changed = false; } } } }