public void ParseUTXO(MyJson.JsonNode_Array jsonarray) { Dictionary <string, CoinType> cointype = new Dictionary <string, CoinType>(); foreach (var item in jsonarray) { var asset = item.AsDict()["asset"].AsString(); if (cointype.ContainsKey(asset) == false) { var ctype = new CoinType(asset); cointype[asset] = ctype; allcoins.Add(ctype); } var coins = cointype[asset]; var coin = new UTXOCoin(); coin.assetID = asset; coin.fromID = item.AsDict()["txid"].AsString(); coin.fromN = item.AsDict()["n"].AsInt(); var value = decimal.Parse(item.AsDict()["value"].AsString()); coin.value = value; coins.coins.Add(coin); } }
private void Button_Click_5(object sender, RoutedEventArgs e) { if (lastCoinHeight == apiHeight)//高度一样就别刷了 { return; } try { if (initCoins == false) { var json = api_getAllAssets(); Tools.CoinTool.Load(); Tools.CoinTool.ParseUtxoAsset(json.AsList()); initCoins = true; } } catch (Exception err) { MessageBox.Show("InitCoins:" + err.Message); } try { var json = api_getUTXO().AsList(); myasset = new Tools.Asset(); myasset.ParseUTXO(json); foreach (var nep5 in Tools.CoinTool.assetNep5) { var dec = rpc_getNep5Balance(nep5.Key); if (dec > 0) { var nep5coin = new Tools.CoinType(nep5.Key, true); nep5coin.Value = dec; myasset.allcoins.Add(nep5coin); } } lastCoinHeight = apiHeight; infoAssetHeight.Text = "Refresh:" + lastCoinHeight; //fill item treeCoins.Items.Clear(); foreach (var cointype in myasset.allcoins) { TreeViewItem item = new TreeViewItem(); item.Tag = cointype; if (cointype.NEP5) { item.Header = "(NEP5)" + Tools.CoinTool.GetName(cointype.AssetID) + ":" + cointype.Value; } else { item.Header = "(UTXO)" + Tools.CoinTool.GetName(cointype.AssetID) + ":" + cointype.Value; foreach (var coin in cointype.coins) { TreeViewItem itemUtxo = new TreeViewItem(); itemUtxo.Tag = coin; itemUtxo.Header = coin.value + " <== " + coin.fromID + "[" + coin.fromN + "]"; item.Items.Add(itemUtxo); } } treeCoins.Items.Add(item); } } catch (Exception err) { MessageBox.Show("GetBalance:" + err.Message); } }