From 61cb1b9de8923ace8529c80eca13900dd3fc64e7 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sun, 19 Feb 2017 21:42:24 +0100 Subject: [PATCH] Forgot to sub the donation address --- Backend/BackendLoop.cs | 19 +++++++++++---- Logic/Logic.csproj | 4 ++++ Logic/packages.config | 1 + Site/Pages/v5/Financial/Donate.aspx | 2 +- Site/Pages/v5/Financial/Donate.aspx.cs | 33 +++++++++++++------------- Site/Site.csproj | 4 ++++ Site/packages.config | 1 + 7 files changed, 42 insertions(+), 22 deletions(-) diff --git a/Backend/BackendLoop.cs b/Backend/BackendLoop.cs index c4e2887f..62cb21e6 100644 --- a/Backend/BackendLoop.cs +++ b/Backend/BackendLoop.cs @@ -989,16 +989,27 @@ namespace Swarmops.Backend public static void AddBitcoinAddress(string address) { - JObject json = new JObject(); - json["op"] = "addr_sub"; - json["addr"] = address; + if (_addressLookup == null) + { + _addressLookup = new SerializableDictionary(); + } + + if (!_addressLookup.ContainsKey(address)) + { + JObject json = new JObject(); + json["op"] = "addr_sub"; + json["addr"] = address; + _blockChainInfoSocket.Send(json.ToString()); + + _addressLookup[address] = true; // dupe prevention + } - _blockChainInfoSocket.Send(json.ToString()); } private static WebSocket _blockChainInfoSocket; private static WebSocketServer _socketServer; private static SerializableDictionary _transactionCache; // Need mechanism to clear this over time + private static SerializableDictionary _addressLookup; } } \ No newline at end of file diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 40858213..5ee14ce2 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -110,6 +110,10 @@ + + ..\packages\WebSocketSharp.1.0.3-rc11\lib\websocket-sharp.dll + True + diff --git a/Logic/packages.config b/Logic/packages.config index 72e6e460..cbe54756 100644 --- a/Logic/packages.config +++ b/Logic/packages.config @@ -12,4 +12,5 @@ + \ No newline at end of file diff --git a/Site/Pages/v5/Financial/Donate.aspx b/Site/Pages/v5/Financial/Donate.aspx index cd5f8952..5bd460c9 100644 --- a/Site/Pages/v5/Financial/Donate.aspx +++ b/Site/Pages/v5/Financial/Donate.aspx @@ -48,7 +48,7 @@
-
0.001
Annual Profit To Date (Testing new code)
+
0.001
Received funds (CUR)
diff --git a/Site/Pages/v5/Financial/Donate.aspx.cs b/Site/Pages/v5/Financial/Donate.aspx.cs index b5efd6a3..9b48edd1 100644 --- a/Site/Pages/v5/Financial/Donate.aspx.cs +++ b/Site/Pages/v5/Financial/Donate.aspx.cs @@ -8,11 +8,14 @@ using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; using NBitcoin; +using Newtonsoft.Json.Linq; using Swarmops.Logic.Cache; using Swarmops.Logic.Financial; using Swarmops.Logic.Security; using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; using Satoshis = NBitcoin.Money; // Sets it apart from Swarmops' Money class +using WebSocketSharp; namespace Swarmops.Frontend.Pages.v5.Financial { @@ -54,26 +57,22 @@ namespace Swarmops.Frontend.Pages.v5.Financial GuidCache.Set (guid, address.Address); this.LiteralGuid.Text = guid; - // TEST TEST TEST - /* - BitcoinSecret secretKey = address.PrivateKey; - Coin[] spendableCoin = BitcoinUtility.GetSpendableCoin (secretKey); + // Add subscription to address - TransactionBuilder txBuild = new TransactionBuilder(); - Transaction tx = txBuild.AddCoins (spendableCoin) - .AddKeys (secretKey) - .Send (new BitcoinAddress (BitcoinUtility.BitcoinTestAddress), new Satoshis (address.UnspentSatoshis - BitcoinUtility.FeeSatoshisPerThousandBytes)) - .SendFees (new Satoshis(BitcoinUtility.FeeSatoshisPerThousandBytes)) - .SetChange (secretKey.GetAddress()) - .BuildTransaction (true); - - bool test = txBuild.Verify (tx); - if (!test) + using ( + WebSocket socket = + new WebSocket("ws:/localhost:" + SystemSettings.WebsocketPortFrontend + "?Auth=" + + Uri.EscapeDataString(this.CurrentAuthority.ToEncryptedXml()))) { - throw new InvalidOperationException("Tx is not properly signed"); - } + socket.Connect(); - BitcoinUtility.BroadcastTransaction (tx);*/ + JObject data = new JObject(); + data ["ServerRequest"] = "AddBitcoinAddress"; + data["Address"] = address.Address; + + socket.Send(data.ToString()); + socket.Close(); + } this.BoxTitle.Text = Resources.Pages.Financial.Donate_PageTitle; this.LabelExplainBitcoinDonation.Text = String.Format (Resources.Pages.Financial.Donate_Explain, diff --git a/Site/Site.csproj b/Site/Site.csproj index bdc1ceed..a7db1c4f 100644 --- a/Site/Site.csproj +++ b/Site/Site.csproj @@ -83,6 +83,10 @@ + + ..\packages\WebSocketSharp.1.0.3-rc11\lib\websocket-sharp.dll + True +
diff --git a/Site/packages.config b/Site/packages.config index 36c9b014..e50285a5 100644 --- a/Site/packages.config +++ b/Site/packages.config @@ -6,4 +6,5 @@ + \ No newline at end of file