public JsonResponse onTestAdd(Dictionary <string, object> parameters) { if (!parameters.ContainsKey("wallet")) { JsonError error = new JsonError { code = (int)RPCErrorCode.RPC_INVALID_PARAMETER, message = "Parameter 'wallet' is missing" }; return(new JsonResponse { result = null, error = error }); } byte[] wallet = Base58Check.Base58CheckEncoding.DecodePlain((string)parameters["wallet"]); string responseString = JsonConvert.SerializeObject("Friend added successfully"); if (TestClientNode.addFriend(wallet) == false) { responseString = JsonConvert.SerializeObject("Could not find wallet id or add friend"); } return(new JsonResponse() { result = responseString, error = null }); }
private bool parseRequest(HttpListenerContext context, string methodName) { HttpListenerRequest request = context.Request; // Set the content type to plain to prevent xml parsing errors in various browsers context.Response.ContentType = "application/json"; if (methodName.Equals("shutdown", StringComparison.OrdinalIgnoreCase)) { string responseString = JsonConvert.SerializeObject("Node shutdown"); sendResponse(context.Response, responseString); Node.forceShutdown = true; return(true); } if (methodName.Equals("servers", StringComparison.OrdinalIgnoreCase)) { String[] res = NetworkClientManager.getConnectedClients(); string responseString = JsonConvert.SerializeObject(res); sendResponse(context.Response, responseString); return(true); } if (methodName.Equals("status", StringComparison.OrdinalIgnoreCase)) { Dictionary <string, Object> networkArray = new Dictionary <string, Object>(); networkArray.Add("S2 Node Version", Config.version); string netType = "mainnet"; if (Config.isTestNet) { netType = "testnet"; } networkArray.Add("Network type", netType); networkArray.Add("My time", Clock.getTimestamp()); networkArray.Add("Network time difference", Core.networkTimeDifference); networkArray.Add("My External IP", Config.publicServerIP); /* networkArray.Add("Queues", "Rcv: " + NetworkQueue.getQueuedMessageCount() + ", RcvTx: " + NetworkQueue.getTxQueuedMessageCount() + ", SendClients: " + NetworkServer.getQueuedMessageCount() + ", SendServers: " + NetworkClientManager.getQueuedMessageCount() + ", Storage: " + Storage.getQueuedQueryCount() + ", Logging: " + Logging.getRemainingStatementsCount()); + networkArray.Add("Node Deprecation Block Limit", Config.compileTimeBlockNumber + Config.deprecationBlockOffset); + */ networkArray.Add("Wallets", Node.walletState.numWallets); networkArray.Add("Presences", PresenceList.getTotalPresences()); networkArray.Add("Supply", Node.walletState.calculateTotalSupply().ToString()); networkArray.Add("WS Checksum", Crypto.hashToString(Node.walletState.calculateWalletStateChecksum())); networkArray.Add("WS Delta Checksum", Crypto.hashToString(Node.walletState.calculateWalletStateChecksum(0, true))); // networkArray.Add("Network Clients", NetworkServer.getConnectedClients()); networkArray.Add("Network Servers", NetworkClientManager.getConnectedClients()); string responseString = JsonConvert.SerializeObject(networkArray); sendResponse(context.Response, responseString); return(true); } if (methodName.Equals("pl", StringComparison.OrdinalIgnoreCase)) { string responseString = "None"; // Show a list of presences lock (PresenceList.presences) { var json = PresenceList.presences; responseString = JsonConvert.SerializeObject(json, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented }); } sendResponse(context.Response, responseString); return(true); } if (methodName.Equals("testadd", StringComparison.OrdinalIgnoreCase)) { byte[] wallet = Base58Check.Base58CheckEncoding.DecodePlain(request.QueryString["wallet"]); string responseString = JsonConvert.SerializeObject("Friend added successfully"); if (TestClientNode.addFriend(wallet) == false) { responseString = JsonConvert.SerializeObject("Could not find wallet id or add friend"); } sendResponse(context.Response, responseString); return(true); } return(false); }