From b7d17644be6c571847bcaefbbcf359f948bce338 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Fri, 18 May 2018 18:02:12 +0200 Subject: [PATCH] Adding DebugConsole; testing CashAddr --- Backend/BackendLoop.cs | 2 + Database/Configuration.cs | 4 +- DebugConsole/App.config | 6 ++ DebugConsole/DebugConsole.csproj | 78 +++++++++++++++++++ DebugConsole/Program.cs | 86 +++++++++++++++++++++ DebugConsole/Properties/AssemblyInfo.cs | 36 +++++++++ Logic/Financial/BitcoinUtility.cs | 30 +++++++ Site/Pages/v5/Admin/BitcoinEchoTest.aspx | 5 +- Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs | 6 +- Swarmops.sln | 20 +++++ 10 files changed, 267 insertions(+), 6 deletions(-) create mode 100644 DebugConsole/App.config create mode 100644 DebugConsole/DebugConsole.csproj create mode 100644 DebugConsole/Program.cs create mode 100644 DebugConsole/Properties/AssemblyInfo.cs diff --git a/Backend/BackendLoop.cs b/Backend/BackendLoop.cs index 630663c2..d9e508da 100644 --- a/Backend/BackendLoop.cs +++ b/Backend/BackendLoop.cs @@ -97,6 +97,8 @@ namespace Swarmops.Backend OnNoon(); Console.WriteLine("\r\nMidnight:"); OnMidnight(); + Console.WriteLine("\r\nMonday Morning:"); + OnMondayMorning(); Console.WriteLine ("\r\nTesting database access..."); diff --git a/Database/Configuration.cs b/Database/Configuration.cs index 734f755e..5ba3f22b 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -138,9 +138,9 @@ namespace Swarmops.Database } else { - // Dev console process. + // Dev's debug console process. - string configLocation = "../Site5/database.config"; + string configLocation = "../Site/database.config"; // however, we don't know exactly how deep in the directory structure we are, so keep adding ../ until we // correct level. We may hit the root if the config doesn't exist and that'll throw us out. diff --git a/DebugConsole/App.config b/DebugConsole/App.config new file mode 100644 index 00000000..88fa4027 --- /dev/null +++ b/DebugConsole/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DebugConsole/DebugConsole.csproj b/DebugConsole/DebugConsole.csproj new file mode 100644 index 00000000..64fedb08 --- /dev/null +++ b/DebugConsole/DebugConsole.csproj @@ -0,0 +1,78 @@ + + + + + Debug + AnyCPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0} + Exe + Properties + DebugConsole + DebugConsole + v4.5.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {6608c2e6-f841-4cd1-8ab2-28dc3b1dddd1} + Basic + + + {bbf83512-8486-469e-9d7b-c3c1b78c3f4d} + Common + + + {3a5b5f19-51a5-48ce-a82e-97d5c189e5cb} + Database + + + {13e59551-34ac-43dc-9a03-ef5e4721dc61} + Logic + + + + + \ No newline at end of file diff --git a/DebugConsole/Program.cs b/DebugConsole/Program.cs new file mode 100644 index 00000000..27f39555 --- /dev/null +++ b/DebugConsole/Program.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Swarmops.Common.Enums; +using Swarmops.Logic.Financial; +using Swarmops.Logic.Swarm; +using Swarmops.Logic.Structure; + + +// This is a console environment for debugging the logic and database layers. +// Nothing in this project is deployed to production environments. + + +namespace Swarmops.DebugConsole +{ + class Program + { + static void Main(/*string[] args*/) + { + // Establish that we have a database connection + + Person testPerson = Person.FromIdentity(1); + testPerson.GetSecureAvatarLink(64); // suppress "is never used" warning + + Organization organization = Organization.FromIdentity(7); + + // TODO: + + // 0) Check ForeignCurrency of hotwallet account + + FinancialAccount hotWallet = organization.FinancialAccounts.AssetsBitcoinHot; + + if (hotWallet != null) + { + Console.WriteLine("Organization has Hotwallet"); + + if (hotWallet.ForeignCurrency != null) + { + if (!hotWallet.ForeignCurrency.IsBitcoinCash) + { + Console.WriteLine(" - Foreign Currency was incorrect; setting to BCH"); + + hotWallet.ForeignCurrency = Currency.BitcoinCash; + } + } + else + { + // ForeignCurrency of hotwallet was Null + hotWallet.ForeignCurrency = Currency.BitcoinCash; + + Console.WriteLine(" - Foreign Currency was not set; setting to BCH"); + } + } + + // 1) Check unspents on hotwallet addresses + + HotBitcoinAddresses addresses = HotBitcoinAddresses.ForOrganization(organization); + + foreach (HotBitcoinAddress address in addresses) + { + HotBitcoinAddressUnspents unspents1 = HotBitcoinAddressUnspents.ForAddress(address); + int beforeCheckCount = unspents1.Count(); + + BitcoinUtility.TestUnspents(BitcoinChain.Core, address.ProtocolLevelAddress); + BitcoinUtility.TestUnspents(BitcoinChain.Cash, address.ProtocolLevelAddress); + + HotBitcoinAddressUnspents unspents2 = HotBitcoinAddressUnspents.ForAddress(address); + int correctedCount = unspents2.Count(); + + if (beforeCheckCount != correctedCount) + { + Console.WriteLine(" - Unspent count was corrected: "); + } + } + + // 2) Shapeshift all Core into Cash + + // 3) Adjust balances of foreign cents on hotwallet + + // 4) Adjust value of hotwallet + + } + } +} diff --git a/DebugConsole/Properties/AssemblyInfo.cs b/DebugConsole/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..500abc2b --- /dev/null +++ b/DebugConsole/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("DebugConsole")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DebugConsole")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("22abe11a-416c-4859-83a1-b3e32b4725c0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Logic/Financial/BitcoinUtility.cs b/Logic/Financial/BitcoinUtility.cs index a489ecd7..3a08c2bb 100644 --- a/Logic/Financial/BitcoinUtility.cs +++ b/Logic/Financial/BitcoinUtility.cs @@ -139,6 +139,36 @@ namespace Swarmops.Logic.Financial } + public static void CheckHotwalletAccountBalance(FinancialAccount hotWallet) + { + if (hotWallet == null) + { + return; + } + + Dictionary satoshisPerChain = GetHotwalletSatoshisPerChain(hotWallet.Organization); + + Int64 satoshisCash = 0; + + if (satoshisPerChain.ContainsKey(BitcoinChain.Core)) + { + // There should not be any. Use Shapeshift to convert to Cash. + + // TODO + + return; // do not repeat not process at this time + } + else + { + if (satoshisPerChain.ContainsKey(BitcoinChain.Cash)) + { + satoshisCash = satoshisPerChain[BitcoinChain.Cash]; + } + } + + } + + public static void CheckHotwalletForexProfitLoss(FinancialAccount hotWallet) { if (hotWallet != null) diff --git a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx index d58e21e7..47263e6f 100644 --- a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx +++ b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx @@ -29,7 +29,7 @@ { for (var outAddress in data.vout[index]) { - if (outAddress == addressUsed) { + if (outAddress == addressUsedLegacy || outAddress == addressUsedCash) { var donatedSatoshis = data.vout[index][outAddress]; @@ -80,7 +80,8 @@ var minerFees = -0.001; // negative, or the .1 cents will go wrong var returnedFunds = 0.001; // as above - var addressUsed = SwarmopsJS.unescape('<%=this.BitcoinCashAddressUsed %>'); + var addressUsedLegacy = SwarmopsJS.unescape('<%=this.BitcoinCashAddressLegacy %>'); + var addressUsedCash = SwarmopsJS.unescape('<%=this.BitcoinCashAddressCash %>'); var verifyingText = SwarmopsJS.unescape('<%=this.Localized_Verifying%>'); var guid = SwarmopsJS.unescape('<%=this.TransactionGuid%>'); var conversionRateSatoshisToCents = <%= this.ConversionRateSatoshisToCents %>; diff --git a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs index d0fd3820..4cb0d3f9 100644 --- a/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs +++ b/Site/Pages/v5/Admin/BitcoinEchoTest.aspx.cs @@ -46,7 +46,8 @@ namespace Swarmops.Frontend.Pages.v5.Admin HotBitcoinAddress address = HotBitcoinAddress.CreateUnique(this.CurrentOrganization, BitcoinChain.Cash, BitcoinUtility.BitcoinEchoTestIndex, this.CurrentUser.Identity, utcNow.Year, utcNow.Month, utcNow.Day); - this.BitcoinCashAddressUsed = address.ProtocolLevelAddress; + this.BitcoinCashAddressLegacy = address.ProtocolLevelAddress; + this.BitcoinCashAddressCash = address.HumanAddress; string guid = Guid.NewGuid().ToString("N"); GuidCache.Set(guid, address.ProtocolLevelAddress); this.TransactionGuid = guid; @@ -76,7 +77,8 @@ namespace Swarmops.Frontend.Pages.v5.Admin get { return BitcoinUtility.EchoFeeSatoshis; } } - public string BitcoinCashAddressUsed { get; private set; } + public string BitcoinCashAddressLegacy { get; private set; } + public string BitcoinCashAddressCash { get; private set; } public string TransactionGuid { get; private set; } public double ConversionRateSatoshisToCents { get; private set; } diff --git a/Swarmops.sln b/Swarmops.sln index 9063365e..921e1db6 100644 --- a/Swarmops.sln +++ b/Swarmops.sln @@ -42,6 +42,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Interface", "Interface\Inte EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend-Socket", "FrontSocket\Frontend-Socket.csproj", "{8424E871-028B-4BFA-B956-E575A8F413E2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DebugConsole", "DebugConsole\DebugConsole.csproj", "{22ABE11A-416C-4859-83A1-B3E32B4725C0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Autobuild|.NET = Autobuild|.NET @@ -208,6 +210,24 @@ Global {8424E871-028B-4BFA-B956-E575A8F413E2}.Release|Any CPU.Build.0 = Release|Any CPU {8424E871-028B-4BFA-B956-E575A8F413E2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {8424E871-028B-4BFA-B956-E575A8F413E2}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Autobuild|.NET.ActiveCfg = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Autobuild|.NET.Build.0 = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Autobuild|Any CPU.ActiveCfg = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Autobuild|Any CPU.Build.0 = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Autobuild|Mixed Platforms.ActiveCfg = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Autobuild|Mixed Platforms.Build.0 = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Debug|.NET.ActiveCfg = Debug|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Debug|.NET.Build.0 = Debug|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Release|.NET.ActiveCfg = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Release|.NET.Build.0 = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Release|Any CPU.Build.0 = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {22ABE11A-416C-4859-83A1-B3E32B4725C0}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE