From a6529001357b45a022dcf4ed4c9986dde103e31e Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 26 Apr 2016 14:16:21 +0200 Subject: [PATCH 1/2] Fix for hotwallet balance calculation --- Site5/App_GlobalResources/Pages.Ledgers.resx | 4 +++ .../Ledgers/Json-BitcoinHotwalletData.aspx.cs | 36 ++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Site5/App_GlobalResources/Pages.Ledgers.resx b/Site5/App_GlobalResources/Pages.Ledgers.resx index da50e635..0a74c064 100644 --- a/Site5/App_GlobalResources/Pages.Ledgers.resx +++ b/Site5/App_GlobalResources/Pages.Ledgers.resx @@ -775,4 +775,8 @@ Bitcoin Hotwallet + + Unspent TxOut + The local translation of a bitcoin UTXO (Unspent Transaction Output). + \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs b/Site5/Pages/v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs index ac8d2bdd..881e6395 100644 --- a/Site5/Pages/v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs +++ b/Site5/Pages/v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs @@ -43,21 +43,49 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers foreach (HotBitcoinAddress address in addresses) { + HotBitcoinAddressUnspents unspents = HotBitcoinAddressUnspents.ForAddress (address); + Int64 satoshisUnspentAddress = 0; + + StringBuilder childResult = new StringBuilder(16384); + foreach (HotBitcoinAddressUnspent unspent in unspents) + { + childResult.Append ("{"); + childResult.AppendFormat( + "\"id\":\"UTXO{0}\"," + + "\"derivePath\":\"{1}\"," + + "\"address\":\"{2}\"," + + "\"balanceMicrocoins\":\"{3}\"," + + "\"balanceFiat\":\"{4}\"", + unspent.Identity, + Resources.Pages.Ledgers.BitcoinHotWallet_UnspentTransaction, + unspent.TransactionHash, + (unspent.AmountSatoshis / 100.0).ToString("N2"), + (unspent.AmountSatoshis / 100.0 * conversionRate).ToString("N2") + ); + satoshisUnspentAddress += unspent.AmountSatoshis; + childResult.Append("},"); + } + if (unspents.Count > 0) + { + childResult.Remove (childResult.Length - 1, 1); // remove last comma + } + result.Append("{"); result.AppendFormat ( "\"id\":\"{0}\"," + "\"derivePath\":\"{1}\"," + "\"address\":\"{2}\"," + "\"balanceMicrocoins\":\"{3}\"," + - "\"balanceFiat\":\"{4}\"", + "\"balanceFiat\":\"{4}\",", address.Identity, address.DerivationPath, address.Address, - (address.BalanceSatoshis/100.0).ToString ("N2"), - (address.BalanceSatoshis/100.0*conversionRate).ToString ("N2") + (satoshisUnspentAddress/100.0).ToString ("N2"), + (satoshisUnspentAddress/100.0*conversionRate).ToString ("N2") ); + result.Append ("\"state\":\"closed\",\"children\":[" + childResult.ToString() + "]"); result.Append("},"); - satoshisTotal += address.BalanceSatoshis; + satoshisTotal += satoshisUnspentAddress; } if (addresses.Count > 0) From 99c66b6f6235d345a5e3b15ef5a28f141dfbb873 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 26 Apr 2016 14:32:28 +0200 Subject: [PATCH 2/2] Added more bitcoin hotwallet drilldown --- Site5/App_GlobalResources/Global.resx | 4 ++++ Site5/App_GlobalResources/Pages.Ledgers.resx | 3 +++ Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx | 10 +++++----- Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx.cs | 2 +- .../v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs | 13 ++++++++++--- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx index f15dbf89..c6876106 100644 --- a/Site5/App_GlobalResources/Global.resx +++ b/Site5/App_GlobalResources/Global.resx @@ -725,4 +725,8 @@ Flags As in a table column header + + Total + Used as footer in tables, summarizing something + \ No newline at end of file diff --git a/Site5/App_GlobalResources/Pages.Ledgers.resx b/Site5/App_GlobalResources/Pages.Ledgers.resx index 0a74c064..51165fd6 100644 --- a/Site5/App_GlobalResources/Pages.Ledgers.resx +++ b/Site5/App_GlobalResources/Pages.Ledgers.resx @@ -775,6 +775,9 @@ Bitcoin Hotwallet + + Transaction Hash + Unspent TxOut The local translation of a bitcoin UTXO (Unspent Transaction Output). diff --git a/Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx b/Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx index 21736c9d..bbe77da5 100644 --- a/Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx +++ b/Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx @@ -8,14 +8,14 @@ $('#tableHotwallet').treegrid( { onBeforeExpand: function (foo) { - $('span.profitlossdata-collapsed-' + foo.id).fadeOut('fast', function () { - $('span.profitlossdata-expanded-' + foo.id).fadeIn('slow'); + $('span.bitcoinhotwalletdata-collapsed-' + foo.id).fadeOut('fast', function () { + $('span.bitcoinhotwalletdata-expanded-' + foo.id).fadeIn('slow'); }); }, onBeforeCollapse: function (foo) { - $('span.profitlossdata-expanded-' + foo.id).fadeOut('fast', function () { - $('span.profitlossdata-collapsed-' + foo.id).fadeIn('slow'); + $('span.bitcoinhotwalletdata-expanded-' + foo.id).fadeOut('fast', function () { + $('span.bitcoinhotwalletdata-collapsed-' + foo.id).fadeIn('slow'); }); }, @@ -51,7 +51,7 @@ animate="true" fitColumns="true" showFooter="true" - idField="id" treeField="name"> + idField="id" treeField="derivePath"> diff --git a/Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx.cs b/Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx.cs index a2f1a4c7..a96eff2b 100644 --- a/Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx.cs +++ b/Site5/Pages/v5/Ledgers/BitcoinHotwallet.aspx.cs @@ -36,7 +36,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers { this.LabelContentHeader.Text = Resources.Pages.Ledgers.BitcoinHotwallet_Header; this.LiteralHeaderDerivationPath.Text = Resources.Pages.Ledgers.BitcoinHotwallet_DerivationPath; - this.LiteralHeaderAddress.Text = Resources.Pages.Ledgers.BitcoinHotwallet_Address; + this.LiteralHeaderAddress.Text = Resources.Pages.Ledgers.BitcoinHotwallet_Address + @" / " + Resources.Pages.Ledgers.BitcoinHotWallet_TransactionHash; this.LiteralHeaderMicrocoins.Text = Resources.Pages.Ledgers.BitcoinHotwallet_BalanceMicrocoins; this.LiteralHeaderFiatValue.Text = String.Format(Resources.Pages.Ledgers.BitcoinHotwallet_ValueFiat, CurrentOrganization.Currency.DisplayCode); } diff --git a/Site5/Pages/v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs b/Site5/Pages/v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs index 881e6395..d5e13acd 100644 --- a/Site5/Pages/v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs +++ b/Site5/Pages/v5/Ledgers/Json-BitcoinHotwalletData.aspx.cs @@ -80,8 +80,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers address.Identity, address.DerivationPath, address.Address, - (satoshisUnspentAddress/100.0).ToString ("N2"), - (satoshisUnspentAddress/100.0*conversionRate).ToString ("N2") + JsonExpandingString (address.Identity, satoshisUnspentAddress), + JsonExpandingString (address.Identity, (Int64) (satoshisUnspentAddress * conversionRate)) ); result.Append ("\"state\":\"closed\",\"children\":[" + childResult.ToString() + "]"); result.Append("},"); @@ -97,7 +97,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers result.Append("{"); - result.AppendFormat("\"derivePath\":\"TOTAL\",\"balanceMicrocoins\":\"{0}\",\"balanceFiat\":\"{1:N2}\"", + result.AppendFormat("\"derivePath\":\"" + Resources.Global.Global_Total + "\",\"balanceMicrocoins\":\"{0}\",\"balanceFiat\":\"{1}\"", (satoshisTotal / 100.0).ToString("N2"), (satoshisTotal / 100.0 * conversionRate).ToString("N2")); result.Append("}]}"); // on separate line to suppress warning @@ -106,6 +106,13 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers } + private string JsonExpandingString(int addressId, Int64 currencyValue) + { + return string.Format(CultureInfo.CurrentCulture, + "Σ {1:N2} ", + addressId, currencyValue / 100.00); + } + } } \ No newline at end of file