From c56904b02c69df86424665d9eae7da8d7fe4795e Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Mon, 4 Mar 2019 11:39:36 +0100 Subject: [PATCH] Adding resync to EOM --- Logic/Financial/HotBitcoinAddresses.cs | 10 ++++++++++ Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs | 25 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Logic/Financial/HotBitcoinAddresses.cs b/Logic/Financial/HotBitcoinAddresses.cs index 565d3fd2..3fb463a4 100644 --- a/Logic/Financial/HotBitcoinAddresses.cs +++ b/Logic/Financial/HotBitcoinAddresses.cs @@ -26,6 +26,16 @@ namespace Swarmops.Logic.Financial return FromArray(SwarmDb.GetDatabaseForReading().GetHotBitcoinAddresses(chain, organization)); } + public static Dictionary GetSatoshisInHotwallet(Organization organization) + { + Dictionary result = new Dictionary(); + + result[BitcoinChain.Cash] = ForOrganization(organization, BitcoinChain.Cash).BalanceSatoshisTotal; + result[BitcoinChain.Core] = ForOrganization(organization, BitcoinChain.Core).BalanceSatoshisTotal; + + return result; + } + public HotBitcoinAddresses InMainWallet { get diff --git a/Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs b/Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs index a6d1009a..3c832f76 100644 --- a/Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs +++ b/Site/Pages/v5/Ledgers/EndOfMonth.aspx.cs @@ -8,6 +8,7 @@ using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; using Swarmops.Basic.Types.Common; +using Swarmops.Common; using Swarmops.Common.Enums; using Swarmops.Logic.Financial; using Swarmops.Logic.Security; @@ -109,6 +110,30 @@ namespace Swarmops.Frontend.Pages.Ledgers dataUploadItem.Skippable = false; group1.Items.Add(dataUploadItem); + + // Check if we need to add a resync of the hotwallet's native ledger + + Int64 cashSatoshisInLedger = + CurrentOrganization.FinancialAccounts.AssetsBitcoinHot.GetForeignCurrencyBalanceDeltaCents( + Constants.DateTimeLow, Constants.DateTimeHigh).Cents; + + Int64 cashSatoshisInHotwallet = + HotBitcoinAddresses.GetSatoshisInHotwallet(CurrentOrganization)[BitcoinChain.Cash]; + + if (cashSatoshisInHotwallet != cashSatoshisInLedger) + { + // Resync required + + EomItem resyncSatoshiCountItem = new EomItem(); + resyncSatoshiCountItem.Id = "ResyncSatoshisLedger"; + resyncSatoshiCountItem.Icon = "wrench"; + resyncSatoshiCountItem.Completed = false; + resyncSatoshiCountItem.Skippable = false; + resyncSatoshiCountItem.Callback = "ResyncSatoshisLedger"; + resyncSatoshiCountItem.Name = String.Format("Ledger cash microcoin {0:N2}; hotwallet {1:N2}", + cashSatoshisInLedger/100.0, cashSatoshisInHotwallet/100.0); + group1.Items.Add(resyncSatoshiCountItem); + } } }