Sockified donations. Major changes.
This commit is contained in:
@@ -63,6 +63,10 @@
|
||||
<HintPath>..\packages\Mono.Posix-4.5.4.5.0\lib\net45\Mono.Posix.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NBitcoin, Version=3.0.0.84, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NBitcoin.3.0.0.84\lib\net45\NBitcoin.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
||||
+255
-88
@@ -19,7 +19,9 @@ using Swarmops.Utility;
|
||||
using Swarmops.Utility.BotCode;
|
||||
using Swarmops.Utility.Communications;
|
||||
using Swarmops.Utility.Mail;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
using Satoshis=NBitcoin.Money;
|
||||
|
||||
namespace Swarmops.Backend
|
||||
{
|
||||
@@ -204,112 +206,128 @@ namespace Swarmops.Backend
|
||||
_socketServer.AddWebSocketService<BackendServices>("/Backend");
|
||||
_socketServer.Start();
|
||||
|
||||
// Begin maintenance loop
|
||||
// Initialize socket client to Blockchain.Info (pending our own services)
|
||||
|
||||
DateTime cycleStartTime = DateTime.UtcNow;
|
||||
DateTime cycleEndTime;
|
||||
|
||||
int lastSecond = cycleStartTime.Second;
|
||||
int lastMinute = cycleStartTime.Minute;
|
||||
int lastHour = cycleStartTime.Hour;
|
||||
|
||||
bool exitFlag = false;
|
||||
|
||||
while (!exitFlag) // exit is handled by signals handling at end of loop
|
||||
using (
|
||||
_blockChainInfoSocket =
|
||||
new WebSocket("wss://ws.blockchain.info/inv?api_code=" + SystemSettings.BlockchainSwarmopsApiKey))
|
||||
{
|
||||
BotLog.Write (0, "MainCycle", "Cycle Start");
|
||||
|
||||
cycleStartTime = DateTime.UtcNow;
|
||||
cycleEndTime = cycleStartTime.AddSeconds(10);
|
||||
// Begin maintenance loop
|
||||
|
||||
try
|
||||
DateTime cycleStartTime = DateTime.UtcNow;
|
||||
DateTime cycleEndTime;
|
||||
|
||||
int lastSecond = cycleStartTime.Second;
|
||||
int lastMinute = cycleStartTime.Minute;
|
||||
int lastHour = cycleStartTime.Hour;
|
||||
|
||||
bool exitFlag = false;
|
||||
|
||||
_blockChainInfoSocket.OnOpen += new EventHandler(OnBlockchainOpen);
|
||||
_blockChainInfoSocket.OnError += new EventHandler<ErrorEventArgs>(OnBlockchainError);
|
||||
_blockChainInfoSocket.OnClose += new EventHandler<CloseEventArgs>(OnBlockchainClose);
|
||||
_blockChainInfoSocket.OnMessage += new EventHandler<MessageEventArgs>(OnBlockchainMessage);
|
||||
|
||||
_blockChainInfoSocket.Connect();
|
||||
|
||||
while (!exitFlag) // exit is handled by signals handling at end of loop
|
||||
{
|
||||
OnEveryTenSeconds();
|
||||
BotLog.Write(0, "MainCycle", "Cycle Start");
|
||||
|
||||
if (cycleStartTime.Second < lastSecond)
|
||||
cycleStartTime = DateTime.UtcNow;
|
||||
cycleEndTime = cycleStartTime.AddSeconds(10);
|
||||
|
||||
try
|
||||
{
|
||||
OnEveryMinute();
|
||||
OnEveryTenSeconds();
|
||||
|
||||
if (cycleStartTime.Minute%5 == 0)
|
||||
if (cycleStartTime.Second < lastSecond)
|
||||
{
|
||||
OnEveryFiveMinutes();
|
||||
OnEveryMinute();
|
||||
|
||||
if (cycleStartTime.Minute%5 == 0)
|
||||
{
|
||||
OnEveryFiveMinutes();
|
||||
}
|
||||
}
|
||||
|
||||
if (cycleStartTime.Minute < lastMinute)
|
||||
{
|
||||
OnEveryHour();
|
||||
|
||||
if (DateTime.Now.Hour == 10 && DateTime.Today.DayOfWeek == DayOfWeek.Tuesday)
|
||||
{
|
||||
OnTuesdayMorning();
|
||||
}
|
||||
|
||||
if (DateTime.Now.Hour == 7 && DateTime.Today.DayOfWeek == DayOfWeek.Monday)
|
||||
{
|
||||
OnMondayMorning();
|
||||
}
|
||||
}
|
||||
|
||||
if (cycleStartTime.Hour >= 12 && lastHour < 12)
|
||||
{
|
||||
OnNoon();
|
||||
}
|
||||
|
||||
if (cycleStartTime.Hour < lastHour)
|
||||
{
|
||||
OnMidnight();
|
||||
}
|
||||
}
|
||||
|
||||
if (cycleStartTime.Minute < lastMinute)
|
||||
catch (Exception e)
|
||||
{
|
||||
OnEveryHour();
|
||||
// Note each "OnEvery..." catches its own errors and sends Exception mails,
|
||||
// so that failure in one should not stop the others from running. This particular
|
||||
// code should never run.
|
||||
|
||||
if (DateTime.Now.Hour == 10 && DateTime.Today.DayOfWeek == DayOfWeek.Tuesday)
|
||||
ExceptionMail.Send(new Exception("Failed in swarmops-backend main loop", e), true);
|
||||
}
|
||||
|
||||
lastSecond = cycleStartTime.Second;
|
||||
lastMinute = cycleStartTime.Minute;
|
||||
lastHour = cycleStartTime.Hour;
|
||||
|
||||
// Wait for a maximum of ten seconds (the difference between cycleStartTime and cycleEndTime)
|
||||
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
while (utcNow < cycleEndTime && !exitFlag)
|
||||
{
|
||||
int signalIndex = 250;
|
||||
|
||||
// Block until a SIGINT or SIGTERM signal is generated, or 1/4 second has passed.
|
||||
// However, we can't do that in a development environment - it won't have the
|
||||
// Mono.Posix assembly, and won't understand UnixSignals. So people running this in
|
||||
// a dev environment will need to stop it manually.
|
||||
|
||||
if (!Debugger.IsAttached)
|
||||
{
|
||||
OnTuesdayMorning();
|
||||
signalIndex = UnixSignal.WaitAny(killSignals, 250);
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeSpan timeLeft = (cycleEndTime - utcNow);
|
||||
|
||||
BotLog.Write(0, "MainCycle Debug",
|
||||
string.Format(CultureInfo.InvariantCulture,
|
||||
"Waiting for {0:F2} more seconds for cycle end",
|
||||
timeLeft.TotalMilliseconds/1000.0));
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
|
||||
if (DateTime.Now.Hour == 7 && DateTime.Today.DayOfWeek == DayOfWeek.Monday)
|
||||
if (signalIndex < 250)
|
||||
{
|
||||
OnMondayMorning();
|
||||
exitFlag = true;
|
||||
Console.WriteLine("Caught signal " + killSignals[signalIndex].Signum + ", exiting");
|
||||
BotLog.Write(0, "MainCycle",
|
||||
"EXIT SIGNAL (" + killSignals[signalIndex].Signum + "), terminating backend");
|
||||
}
|
||||
|
||||
utcNow = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
if (cycleStartTime.Hour >= 12 && lastHour < 12)
|
||||
{
|
||||
OnNoon();
|
||||
}
|
||||
|
||||
if (cycleStartTime.Hour < lastHour)
|
||||
{
|
||||
OnMidnight();
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
// Note each "OnEvery..." catches its own errors and sends Exception mails,
|
||||
// so that failure in one should not stop the others from running. This particular
|
||||
// code should never run.
|
||||
|
||||
ExceptionMail.Send (new Exception ("Failed in swarmops-backend main loop", e), true);
|
||||
}
|
||||
|
||||
lastSecond = cycleStartTime.Second;
|
||||
lastMinute = cycleStartTime.Minute;
|
||||
lastHour = cycleStartTime.Hour;
|
||||
|
||||
// Wait for a maximum of ten seconds (the difference between cycleStartTime and cycleEndTime)
|
||||
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
while (utcNow < cycleEndTime && !exitFlag)
|
||||
{
|
||||
int signalIndex = 250;
|
||||
|
||||
// Block until a SIGINT or SIGTERM signal is generated, or 1/4 second has passed.
|
||||
// However, we can't do that in a development environment - it won't have the
|
||||
// Mono.Posix assembly, and won't understand UnixSignals. So people running this in
|
||||
// a dev environment will need to stop it manually.
|
||||
|
||||
if (!Debugger.IsAttached)
|
||||
{
|
||||
signalIndex = UnixSignal.WaitAny(killSignals, 250);
|
||||
}
|
||||
else
|
||||
{
|
||||
TimeSpan timeLeft = (cycleEndTime - utcNow);
|
||||
|
||||
BotLog.Write(0, "MainCycle Debug",
|
||||
string.Format(CultureInfo.InvariantCulture, "Waiting for {0:F2} more seconds for cycle end",
|
||||
timeLeft.TotalMilliseconds / 1000.0));
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
|
||||
if (signalIndex < 250)
|
||||
{
|
||||
exitFlag = true;
|
||||
Console.WriteLine ("Caught signal " + killSignals[signalIndex].Signum + ", exiting");
|
||||
BotLog.Write (0, "MainCycle",
|
||||
"EXIT SIGNAL (" + killSignals[signalIndex].Signum + "), terminating backend");
|
||||
}
|
||||
|
||||
utcNow = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -612,7 +630,7 @@ namespace Swarmops.Backend
|
||||
{
|
||||
TraceAndReport (e);
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
BotLog.DeleteOld (14); // delete logs older than 14 days
|
||||
@@ -825,13 +843,162 @@ namespace Swarmops.Backend
|
||||
private static void BroadcastTimestamp()
|
||||
{
|
||||
JObject json = new JObject();
|
||||
json["messageType"] = "Heartbeat";
|
||||
json["MessageType"] = "Heartbeat";
|
||||
json["Timestamp"] = DateTime.UtcNow.ToUnix();
|
||||
|
||||
_socketServer.WebSocketServices.Broadcast(json.ToString());
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------- BLOCKCHAIN.INFO WEB SOCKET INTERFACE CODE -------------------------
|
||||
|
||||
public static void OnBlockchainOpen(object sender, EventArgs args)
|
||||
{
|
||||
Console.WriteLine(" - Socket to Blockchain open and active");
|
||||
// TODO: Subscribe to all active addresses
|
||||
}
|
||||
|
||||
public static void OnBlockchainError(object sender, ErrorEventArgs args)
|
||||
{
|
||||
Console.WriteLine(" - ERROR on Blockchain socket: " + args.Message);
|
||||
}
|
||||
|
||||
public static void OnBlockchainClose(object sender, CloseEventArgs args)
|
||||
{
|
||||
Console.WriteLine(" - Socket to Blockchain CLOSED");
|
||||
}
|
||||
|
||||
public static void OnBlockchainMessage(object sender, MessageEventArgs args)
|
||||
{
|
||||
Console.WriteLine(" - Blockchain says: " + args.Data);
|
||||
|
||||
JObject json = JObject.Parse(args.Data);
|
||||
string op = (string) json["op"];
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case "utx":
|
||||
// transaction received on an address we sub to
|
||||
ProcessBitcoinTransaction(json);
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine(" -- unknown/unhandled op: '{0}'", op);
|
||||
break;
|
||||
}
|
||||
|
||||
// A LOT OF TODO HERE
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal static void ProcessBitcoinTransaction(JObject blockchainTransaction)
|
||||
{
|
||||
/* Format:
|
||||
|
||||
{
|
||||
"op": "utx",
|
||||
"x": {
|
||||
"lock_time": 0,
|
||||
"ver": 1,
|
||||
"size": 192,
|
||||
"inputs": [
|
||||
{
|
||||
"sequence": 4294967295,
|
||||
"prev_out": {
|
||||
"spent": true,
|
||||
"tx_index": 99005468,
|
||||
"type": 0,
|
||||
"addr": "1BwGf3z7n2fHk6NoVJNkV32qwyAYsMhkWf",
|
||||
"value": 65574000,
|
||||
"n": 0,
|
||||
"script": "76a91477f4c9ee75e449a74c21a4decfb50519cbc245b388ac"
|
||||
},
|
||||
"script": "483045022100e4ff962c292705f051c2c2fc519fa775a4d8955bce1a3e29884b2785277999ed02200b537ebd22a9f25fbbbcc9113c69c1389400703ef2017d80959ef0f1d685756c012102618e08e0c8fd4c5fe539184a30fe35a2f5fccf7ad62054cad29360d871f8187d"
|
||||
}
|
||||
],
|
||||
"time": 1440086763,
|
||||
"tx_index": 99006637,
|
||||
"vin_sz": 1,
|
||||
"hash": "0857b9de1884eec314ecf67c040a2657b8e083e1f95e31d0b5ba3d328841fc7f",
|
||||
"vout_sz": 1,
|
||||
"relayed_by": "127.0.0.1",
|
||||
"out": [
|
||||
{
|
||||
"spent": false,
|
||||
"tx_index": 99006637,
|
||||
"type": 0,
|
||||
"addr": "1A828tTnkVFJfSvLCqF42ohZ51ksS3jJgX",
|
||||
"value": 65564000,
|
||||
"n": 0,
|
||||
"script": "76a914640cfdf7b79d94d1c980133e3587bd6053f091f388ac"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Console.WriteLine(" - block received");
|
||||
|
||||
if (_transactionCache == null)
|
||||
{
|
||||
_transactionCache = new SerializableDictionary<string, JObject>();
|
||||
}
|
||||
|
||||
_transactionCache[(string) (blockchainTransaction["x"]["hash"])] = (JObject) blockchainTransaction["x"];
|
||||
|
||||
foreach (JObject outpoint in blockchainTransaction["x"]["out"])
|
||||
{
|
||||
Satoshis satoshis = Int64.Parse((string) outpoint["value"]);
|
||||
string addressString = (string) outpoint["addr"];
|
||||
|
||||
HotBitcoinAddress hotAddress = null;
|
||||
|
||||
try
|
||||
{
|
||||
hotAddress = HotBitcoinAddress.FromAddress(addressString);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Ignore this - it means the addressString isn't ours
|
||||
throw;
|
||||
}
|
||||
|
||||
if (hotAddress != null)
|
||||
{
|
||||
JObject json = new JObject();
|
||||
json["MessageType"] = "BitcoinReceived";
|
||||
json["Address"] = addressString;
|
||||
|
||||
Currency currency = hotAddress.Organization.Currency;
|
||||
json["OrganizationId"] = hotAddress.OrganizationId.ToString();
|
||||
json["Currency"] = currency.Code;
|
||||
Swarmops.Logic.Financial.Money organizationCents = new Money(satoshis, Currency.Bitcoin).ToCurrency(currency);
|
||||
json["Satoshis"] = satoshis.ToString();
|
||||
json["Cents"] = organizationCents.Cents.ToString();
|
||||
json["CentsFormatted"] = String.Format("N2", organizationCents.Cents/100.0);
|
||||
|
||||
_socketServer.WebSocketServices.Broadcast(json.ToString());
|
||||
|
||||
// TODO: Examine what address this is, handle accordingly
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void AddBitcoinAddress(string address)
|
||||
{
|
||||
JObject json = new JObject();
|
||||
json["op"] = "addr_sub";
|
||||
json["addr"] = address;
|
||||
|
||||
_blockChainInfoSocket.Send(json.ToString());
|
||||
}
|
||||
|
||||
|
||||
private static WebSocket _blockChainInfoSocket;
|
||||
private static WebSocketServer _socketServer;
|
||||
private static SerializableDictionary<string, JObject> _transactionCache; // Need mechanism to clear this over time
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace Swarmops.Backend.SocketServices
|
||||
// Basically just echo whatever's sent here
|
||||
|
||||
JObject json = JObject.Parse(e.Data);
|
||||
string serverRequest = (string)json["serverRequest"];
|
||||
string serverRequest = (string)json["BackendRequest"];
|
||||
|
||||
if (string.IsNullOrEmpty(serverRequest))
|
||||
{
|
||||
@@ -35,6 +35,9 @@ namespace Swarmops.Backend.SocketServices
|
||||
case "UpdateQueueCounts":
|
||||
//Sessions.Broadcast(Program.GetQueueInfoJson());
|
||||
break;
|
||||
case "AddBitcoinAddress":
|
||||
BackendLoop.AddBitcoinAddress((string) json["Address"]);
|
||||
break;
|
||||
default:
|
||||
// do nothing;
|
||||
break;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Mono.Posix-4.5" version="4.5.0" targetFramework="net45" />
|
||||
<package id="NBitcoin" version="3.0.0.84" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
|
||||
<package id="WebSocketSharp" version="1.0.3-rc11" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -38,6 +38,10 @@
|
||||
<HintPath>..\packages\Mono.Posix-4.5.4.5.0\lib\net45\Mono.Posix.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NBitcoin, Version=3.0.0.84, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NBitcoin.3.0.0.84\lib\net45\NBitcoin.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
||||
@@ -86,13 +86,13 @@ namespace Swarmops.Frontend.Socket
|
||||
|
||||
Console.WriteLine("Connecting backend socket " + backendSocketUri);
|
||||
|
||||
using (var socketClient = new WebSocket(backendSocketUri))
|
||||
using (_backendSocket = new WebSocket(backendSocketUri))
|
||||
{
|
||||
socketClient.OnMessage += new EventHandler<MessageEventArgs>(OnBackendMessage);
|
||||
socketClient.OnOpen += new EventHandler(OnBackendOpen);
|
||||
socketClient.OnClose += new EventHandler<CloseEventArgs>(OnBackendClose);
|
||||
socketClient.OnError += new EventHandler<ErrorEventArgs>(OnBackendError);
|
||||
socketClient.Connect();
|
||||
_backendSocket.OnMessage += new EventHandler<MessageEventArgs>(OnBackendMessage);
|
||||
_backendSocket.OnOpen += new EventHandler(OnBackendOpen);
|
||||
_backendSocket.OnClose += new EventHandler<CloseEventArgs>(OnBackendClose);
|
||||
_backendSocket.OnError += new EventHandler<ErrorEventArgs>(OnBackendError);
|
||||
_backendSocket.Connect();
|
||||
|
||||
while (!exitFlag) // exit is handled by signals handling at end of loop
|
||||
{
|
||||
@@ -197,6 +197,8 @@ namespace Swarmops.Frontend.Socket
|
||||
|
||||
|
||||
private static WebSocketServer _socketServer;
|
||||
private static WebSocket _backendSocket;
|
||||
|
||||
private static bool _isSandbox = false;
|
||||
private static int _sandboxDummy1 = 500;
|
||||
private static int _sandboxDummy2 = 50000;
|
||||
@@ -211,9 +213,9 @@ namespace Swarmops.Frontend.Socket
|
||||
_sandboxDummy2 += new Random().Next(1000) - 200;
|
||||
|
||||
JObject data = new JObject();
|
||||
data["messageType"] = "SandboxUpdate";
|
||||
data["local"] = _sandboxDummy1.ToString(CultureInfo.InvariantCulture);
|
||||
data["profit"] = _sandboxDummy2.ToString(CultureInfo.InvariantCulture);
|
||||
data["MessageType"] = "SandboxUpdate";
|
||||
data["Local"] = _sandboxDummy1.ToString(CultureInfo.InvariantCulture);
|
||||
data["Profit"] = _sandboxDummy2.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
_socketServer.WebSocketServices.Broadcast(data.ToString());
|
||||
}
|
||||
@@ -273,6 +275,18 @@ namespace Swarmops.Frontend.Socket
|
||||
|
||||
|
||||
|
||||
public static void AddBitcoinAddress(string address)
|
||||
{
|
||||
JObject json = new JObject();
|
||||
json["BackendRequest"] = "AddBitcoinAddress";
|
||||
json["Address"] = address;
|
||||
|
||||
_backendSocket.Send(json.ToString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// --------------------------------- LEGACY CODE BELOW THIS MARK -------------------------------
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Swarmops.Frontend.Socket
|
||||
// Basically just echo whatever's sent here
|
||||
|
||||
JObject json = JObject.Parse (e.Data);
|
||||
string serverRequest = (string) json["serverRequest"];
|
||||
string serverRequest = (string) json["ServerRequest"];
|
||||
|
||||
if (string.IsNullOrEmpty (serverRequest))
|
||||
{
|
||||
@@ -33,8 +33,8 @@ namespace Swarmops.Frontend.Socket
|
||||
|
||||
switch (serverRequest)
|
||||
{
|
||||
case "UpdateQueueCounts":
|
||||
// Sessions.Broadcast (FrontendLoop.GetQueueInfoJson());
|
||||
case "AddBitcoinAddress":
|
||||
FrontendLoop.AddBitcoinAddress((string) json["Address"]);
|
||||
break;
|
||||
case "Ping":
|
||||
// TODO: Request heartbeat from backend
|
||||
@@ -67,7 +67,7 @@ namespace Swarmops.Frontend.Socket
|
||||
{
|
||||
base.OnClose (e);
|
||||
|
||||
Sessions.Broadcast("{\"messageType\":\"EditorCount\"," + String.Format("\"editorCount\":\"{0}\"", Sessions.ActiveIDs.ToArray().Length) + '}');
|
||||
// Sessions.Broadcast("{\"messageType\":\"EditorCount\"," + String.Format("\"editorCount\":\"{0}\"", Sessions.ActiveIDs.ToArray().Length) + '}');
|
||||
}
|
||||
|
||||
private Authority _authority = null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Mono.Posix-4.5" version="4.5.0" targetFramework="net452" />
|
||||
<package id="NBitcoin" version="3.0.0.84" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
|
||||
<package id="WebSocketSharp" version="1.0.3-rc11" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -1 +1 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-PositionsTree.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_PositionsTree" %>
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-PositionsTree.aspx.cs" CodeBehind="Json-PositionsTree.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_PositionsTree" %>
|
||||
|
||||
+11
-8
@@ -1,18 +1,17 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" Inherits="Swarmops.Frontend.Default" CodeFile="Default.aspx.cs" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
<!-- Odometer -->
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/odometer.js" ></script>
|
||||
<link href="/Style/odometer-theme-car.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
<div class="box" style="background-image: url(/Images/Other/member-background-istockphoto.jpg); background-size: 700px"><div class="content">
|
||||
<div class="odometer-wrapper"><div class="elementFloatFar odometer odometer-integer nocents" id="odoGlobalParticipation">12342500</div><div class="odometer-label">Current Participants (Testing new code)</div>
|
||||
<div class="odometer-wrapper">
|
||||
<div class="elementFloatFar odometer odometer-integer nocents" id="odoGlobalParticipation">12342500</div><div class="odometer-label">Current Participants (Testing new code)</div>
|
||||
</div>
|
||||
|
||||
<div class="odometer-wrapper"><div class="elementFloatFar odometer odometer-integer nocents" id="odoActiveParticipation">125498</div><div class="odometer-label">Active Participants Last 30 Days (Testing new code)</div>
|
||||
<div class="odometer-wrapper">
|
||||
<div class="elementFloatFar odometer odometer-integer nocents" id="odoActiveParticipation">125498</div><div class="odometer-label">Active Participants Last 30 Days (Testing new code)</div>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
@@ -23,9 +22,13 @@
|
||||
|
||||
</div></div>
|
||||
|
||||
<div class="box" style="background-image: url(/Images/Other/coins-background-istockphoto.jpg); background-size: 700px"><div class="content">
|
||||
<div class="odometer-wrapper"><div class="elementFloatFar odometer odometer-currency" id="odoProfitLossToDate">0.001</div><div class="odometer-label">Annual Profit To Date (Testing new code)</div>
|
||||
</div></div></div>
|
||||
<div class="box" style="background-image: url(/Images/Other/coins-background-istockphoto.jpg); background-size: 700px">
|
||||
<div class="content">
|
||||
<div class="odometer-wrapper">
|
||||
<div class="elementFloatFar odometer odometer-currency" id="odoProfitLossToDate">0.001</div><div class="odometer-label">Annual Profit To Date (Testing new code)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box"><div class="content">
|
||||
<h2><asp:Label ID="LabelHeaderLocal" runat="server" /></h2>
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/jquery.json.min.js" ></script>
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/qrcode.min.js"></script>
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/jquery.qrcode.min.js"></script>
|
||||
|
||||
<script language="javascript" type="text/javascript" src="/Scripts/odometer.js" ></script>
|
||||
|
||||
<!-- fonts -->
|
||||
<link href='https://fonts.googleapis.com/css?family=Permanent+Marker' rel='stylesheet' type='text/css' />
|
||||
<link href='https://fonts.googleapis.com/css?family=Ubuntu:light,regular,500,bold' rel='stylesheet' type='text/css' />
|
||||
@@ -45,6 +46,7 @@
|
||||
<link href="/Style/alertify.default.css" rel="stylesheet" type="text/css" />
|
||||
<link href="/Style/superfish.css" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
|
||||
<link href="/Style/odometer-theme-car.css" rel="stylesheet" type="text/css" />
|
||||
|
||||
<!-- external packages that are commonly used (on practically all pages) -->
|
||||
<Swarmops5:ExternalScripts ID="ExternalScriptEasyUI" Package="easyui" runat="server" />
|
||||
|
||||
@@ -5,80 +5,55 @@
|
||||
<script type="text/javascript" language="javascript">
|
||||
$(document).ready(function() {
|
||||
|
||||
// Initialize socket to wait for transaction
|
||||
|
||||
if (enable) {
|
||||
initializeSocket();
|
||||
if (pageBitcoinReceived != undefined) {
|
||||
alertify.log("Undefined check works");
|
||||
}
|
||||
|
||||
// TODO: Also poll regularly in case socket fails
|
||||
});
|
||||
|
||||
function initializeSocket() {
|
||||
if (socket != null) {
|
||||
socket.close();
|
||||
socket = null;
|
||||
function pageBitcoinReceived (address, hash, satoshis, cents, currencycode) {
|
||||
if (address == addressUsed) {
|
||||
// We have received a donation at this address
|
||||
|
||||
donatedFunds += (cents / 100.0);
|
||||
$('#odoDonatedCents').innerHTML = donatedFunds;
|
||||
|
||||
SwarmopsJS.ajaxCall('/Pages/v5/Financial/Donate.aspx/ProcessTransactionReceived',
|
||||
{ guid: guid, txHash: hash },
|
||||
function (data) {
|
||||
if (data.Success) {
|
||||
$('#paraStatus').text(data.DisplayMessage);
|
||||
$('#paraIntro').fadeOut().slideUp();
|
||||
$('#divQr').fadeOut().slideUp();
|
||||
completed = true;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
socket = new WebSocket("wss://ws.blockchain.info/inv?api_code=<%= SystemSettings.BlockchainSwarmopsApiKey %>");
|
||||
|
||||
socket.onopen = function(data) {
|
||||
console.log("socket opened");
|
||||
socket.send('{"op":"addr_sub","addr":"' + addressUsed + '"}');
|
||||
};
|
||||
socket.onclose = function (data) {
|
||||
if (!completed) {
|
||||
console.log("socket lost");
|
||||
initializeSocket();
|
||||
}
|
||||
};
|
||||
socket.onerror = function(data) { console.log("socket error"); };
|
||||
socket.onmessage = function(data) {
|
||||
|
||||
console.log(data.data);
|
||||
|
||||
var message = $.parseJSON(data.data);
|
||||
|
||||
if (message.op == "utx") {
|
||||
// transaction received at address
|
||||
// call page to check if funds received server side
|
||||
|
||||
alertify.log(decodeURIComponent('<asp:Literal ID="LiteralTxDetected" runat="server" />'));
|
||||
checkTransactionReceived(message.x.hash);
|
||||
}
|
||||
};
|
||||
return false; // not handled
|
||||
}
|
||||
|
||||
function checkTransactionReceived(hash) {
|
||||
|
||||
if (hash == null) {
|
||||
hash = "";
|
||||
}
|
||||
|
||||
SwarmopsJS.ajaxCall('/Pages/v5/Financial/Donate.aspx/CheckTransactionReceived',
|
||||
{ guid: guid, txHash: hash },
|
||||
function (data) {
|
||||
if (data.Success) {
|
||||
$('#paraStatus').text(data.DisplayMessage);
|
||||
$('#paraIntro').fadeOut().slideUp();
|
||||
$('#divQr').fadeOut().slideUp();
|
||||
completed = true;
|
||||
socket.close();
|
||||
socket = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
var donatedFunds = 0.001; // the 0.1 cents are necessary for an odometer workaround
|
||||
|
||||
var addressUsed = '<asp:Literal runat="server" ID="LiteralBitcoinAddress" />';
|
||||
var guid = '<asp:Literal runat="server" ID="LiteralGuid" />';
|
||||
var socket = null;
|
||||
var completed = false;
|
||||
var enable = <asp:Literal ID="LiteralEnable" runat="server">true</asp:Literal>;
|
||||
|
||||
</script>
|
||||
</asp:Content>
|
||||
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
<div class="box" style="background-image: url(/Images/Other/coins-background-istockphoto.jpg); background-size: 700px">
|
||||
<div class="content">
|
||||
<div class="odometer-wrapper">
|
||||
<div class="elementFloatFar odometer odometer-currency" id="odoDonatedCents">0.001</div><div class="odometer-label">Annual Profit To Date (Testing new code)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box"><div class="content">
|
||||
<asp:Panel runat="server" ID="PanelEnabled">
|
||||
<h2><asp:Label runat="server" ID="BoxTitle" /></h2>
|
||||
<p id="paraIntro"><asp:Label runat="server" ID="LabelExplainBitcoinDonation" /></p>
|
||||
@@ -92,6 +67,7 @@
|
||||
<p>Contact the administrator for <%=this.CurrentOrganization.Name %> and ask them to enable the bitcoin hotwallet.</p>
|
||||
<div style="clear:both"></div>
|
||||
</asp:Panel>
|
||||
</div></div>
|
||||
|
||||
</asp:Content>
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
protected void Page_Load (object sender, EventArgs e)
|
||||
{
|
||||
this.PageAccessRequired = new Access (this.CurrentOrganization, AccessAspect.Participant);
|
||||
this.IsDashboard = true; // prevents encaps and enables odometer
|
||||
|
||||
/* TEMP TEMP TEMP - REMOVE THIS CODE */
|
||||
/*
|
||||
@@ -38,13 +39,11 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
this.PageTitle = Resources.Pages.Financial.Donate_PageTitle;
|
||||
this.InfoBoxLiteral = Resources.Pages.Financial.Donate_Info;
|
||||
this.LabelStatus.Text = Resources.Pages.Financial.Donate_StatusInitial;
|
||||
this.LiteralTxDetected.Text = JavascriptEscape (Resources.Pages.Financial.Donate_TransactionDetected);
|
||||
|
||||
if (this.CurrentOrganization.FinancialAccounts.AssetsBitcoinHot == null)
|
||||
{
|
||||
this.PanelDisabled.Visible = true;
|
||||
this.PanelEnabled.Visible = false;
|
||||
this.LiteralEnable.Text = @"false";
|
||||
}
|
||||
|
||||
HotBitcoinAddress address = HotBitcoinAddress.Create (this.CurrentOrganization,
|
||||
@@ -88,7 +87,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
}
|
||||
|
||||
[WebMethod]
|
||||
static public AjaxCallResult CheckTransactionReceived (string guid, string txHash)
|
||||
static public AjaxCallResult ProcessTransactionReceived (string guid, string txHash)
|
||||
{
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture(); // just to make sure we're called properly
|
||||
|
||||
|
||||
-18
@@ -12,15 +12,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
|
||||
|
||||
public partial class Donate {
|
||||
|
||||
/// <summary>
|
||||
/// LiteralTxDetected control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Literal LiteralTxDetected;
|
||||
|
||||
/// <summary>
|
||||
/// LiteralBitcoinAddress control.
|
||||
/// </summary>
|
||||
@@ -39,15 +30,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial {
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Literal LiteralGuid;
|
||||
|
||||
/// <summary>
|
||||
/// LiteralEnable control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Literal LiteralEnable;
|
||||
|
||||
/// <summary>
|
||||
/// PanelEnabled control.
|
||||
/// </summary>
|
||||
|
||||
@@ -31,15 +31,26 @@ function _masterInitializeSocket(authenticationTicket) {
|
||||
|
||||
var message = $.parseJSON(data.data);
|
||||
|
||||
if (message.messageType == "Heartbeat") {
|
||||
if (message.MessageType == "Heartbeat") {
|
||||
alertify.log("Master socket heartbeat: " + message.Timestamp);
|
||||
}
|
||||
else if (message.messageType == "SandboxUpdate") {
|
||||
}
|
||||
else if (message.MessageType == "BitcoinReceived") {
|
||||
var handled = false;
|
||||
|
||||
if (pageBitcoinReceived != undefined) {
|
||||
handled = pageBitcoinReceived(message.Address, message.Hash, message.Satoshis, message.Cents, message.Currency);
|
||||
}
|
||||
|
||||
if (!handled) {
|
||||
alertify.log("Bitcoin received: " + message.Currecy + " " + message.CentsFormatted);
|
||||
}
|
||||
}
|
||||
else if (message.MessageType == "SandboxUpdate") {
|
||||
if (odoLocalParticipation != undefined) { // Real ugly accessing specific page elements here, but it's temporary
|
||||
odoLocalParticipation.innerHTML = message.local;
|
||||
odoGlobalParticipation.innerHTML = 12345678 + message.local * 5;
|
||||
odoActiveParticipation.innerHTML = 123412 + message.local * 5;
|
||||
odoProfitLossToDate.innerHTML = (message.profit / 100.0) + 0.001;
|
||||
odoLocalParticipation.innerHTML = message.Local;
|
||||
odoGlobalParticipation.innerHTML = 12345678 + message.Local * 5;
|
||||
odoActiveParticipation.innerHTML = 123412 + message.Local * 5;
|
||||
odoProfitLossToDate.innerHTML = (message.Profit / 100.0) + 0.001;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user