static void RunConnector() { var settings = ServerSettings.DefaultSettings(); settings.Port = 7080; var server = new HTTPServer(settings, ConsoleLogger.Write); Console.WriteLine("Starting Phantasma Sample connector at port " + settings.Port); /* * server.Get("/authorize/{dapp}", (request) => * { * return link.Execute(request.url); * }); * * server.Get("/getAccount/{dapp}/{token}", (request) => * { * return link.Execute(request.url); * }); * * server.Get("/invokeScript/{script}/{dapp}/{token}", (request) => * { * return link.Execute(request.url); * });*/ var api = new PhantasmaAPI("http://localhost:7078"); var link = new SampleConnector(api); server.WebSocket("/phantasma", (socket) => { while (socket.IsOpen) { var msg = socket.Receive(); if (msg.CloseStatus == WebSocketCloseStatus.None) { var str = Encoding.UTF8.GetString(msg.Bytes); link.Execute(str, (id, root, success) => { root.AddField("id", id); root.AddField("success", success); var json = JSONWriter.WriteToString(root); socket.Send(json); }); } } }); server.Run(); }
public void Login() { if (string.IsNullOrEmpty(addressInputField.text)) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Private Key cannot be empty."); return; } if (PhantasmaDemo.Instance != null) { if (PhantasmaDemo.Instance.PhantasmaApi != null && !PhantasmaAPI.IsValidPrivateKey(addressInputField.text)) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Error: The entered private key is not valid.\nThe private key must start with an 'L' or a 'K' and have 52 characters."); return; } PhantasmaDemo.Instance.Login(addressInputField.text); } }
public void SendClicked() { if (PhantasmaDemo.Instance == null || PhantasmaDemo.Instance.PhantasmaApi == null) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "It was not possible to process the operation. Please try again."); return; } // Validate private key if (string.IsNullOrEmpty(addressInput.text)) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Public address cannot be empty."); return; } Address address; if (!PhantasmaAPI.IsValidAddress(addressInput.text)) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "The entered address is not valid.\nThe address must start with a 'P' and have 45 characters."); return; } address = Address.FromText(addressInput.text); // Check if the 'from' and 'to' addresses are the same if (PhantasmaDemo.Instance.Key.Address.Equals(address)) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Cannot send tokens to your own address. Destination address must be different from the origin address."); addressInput.text = string.Empty; return; } // Validate amount if (string.IsNullOrEmpty(amountInput.text)) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Amount cannot be empty."); return; } BigInteger amount; if (BigInteger.TryParse(amountInput.text, out amount)) { if (amount < 0) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Amount must be a decimal positive value."); amountInput.text = string.Empty; return; } } else { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "Amount must be a decimal positive value."); amountInput.text = string.Empty; return; } if (tokenDropdown.options[tokenDropdown.value].text.Equals(_SELECT_COIN)) { CanvasManager.Instance.ShowResultPopup(EOPERATION_RESULT.FAIL, "You must select a coin from the dropdown menu."); return; } PhantasmaDemo.Instance.TransferTokens(PhantasmaDemo.Instance.Key.Address, address, tokenDropdown.options[tokenDropdown.value].text, amount); }
private void Start() { PhantasmaApi = new PhantasmaAPI(_SERVER_ADDRESS); Invoke("LoadPhantasmaData", 2f); }