-
-
Save mably/a9397eae0585d75e446b to your computer and use it in GitHub Desktop.
Ppcd WebSocket Test on testnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Ppcd WebSocket Test</title> | |
<script language="javascript" type="text/javascript"> | |
var wsUri = 'wss://127.0.0.1:9902/ws'; | |
var rpcUser = "rpcuser"; | |
var rpcPass = "rpcpass"; | |
var websocket; | |
var output, connectButton, disconnectButton; | |
var sendButton, rescanButton; | |
var authenticated = false; | |
var messageID = 0; | |
function init() | |
{ | |
var wsUriInput = document.getElementById("wsUri"); | |
var wsUriLink = document.getElementById("wsUriLink"); | |
wsUriInput.value = wsUri; | |
wsUriLink.href = wsUri.replace('wss:', 'https:'); | |
output = document.getElementById("output"); | |
connectButton = document.getElementById("connect"); | |
disconnectButton = document.getElementById("disconnect"); | |
sendButton = document.getElementById("send"); | |
blocksButton = document.getElementById("blocks"); | |
rescanButton = document.getElementById("rescan"); | |
} | |
function connect() { | |
output.innerHTML = ''; | |
websocket = new WebSocket(wsUri); | |
websocket.onopen = function(evt) { onOpen(evt) }; | |
websocket.onclose = function(evt) { onClose(evt) }; | |
websocket.onmessage = function(evt) { onMessage(evt) }; | |
websocket.onerror = function(evt) { onError(evt) }; | |
} | |
function disconnect() { | |
websocket.close(); | |
} | |
function requestTransactions() { | |
authenticate(); | |
doSend('notifynewtransactions', '[]'); | |
} | |
function notifyBlocks() { | |
authenticate(); | |
doSend('notifyblocks', '[]'); | |
} | |
function rescan() { | |
authenticate(); | |
var beginBlock = "fbc7e12a5b807e2514697a93ac95e9193bcf9da9fd04f3b60a08cef7ec6aa580"; | |
var endBlock = "000000000000000aa67e1ee3dc8dfd9ee98b9f9f9b2b6f4cbd36e13a072025d6"; | |
doSend('rescan', '["'+beginBlock+'", ["PAbC9Wndy1PutBB3aG6NBhQegY38Gd5vEm"], [], '+'"'+endBlock+'"]'); | |
} | |
function onOpen(evt) | |
{ | |
connectButton.setAttribute('disabled', 'disabled'); | |
disconnectButton.removeAttribute('disabled'); | |
sendButton.removeAttribute('disabled'); | |
blocksButton.removeAttribute('disabled'); | |
rescanButton.removeAttribute('disabled'); | |
writeToScreen("CONNECTED"); | |
} | |
function onClose(evt) | |
{ | |
authenticated = false; | |
writeToScreen("DISCONNECTED"); | |
sendButton.setAttribute('disabled', 'disabled'); | |
blocksButton.setAttribute('disabled', 'disabled'); | |
rescanButton.setAttribute('disabled', 'disabled'); | |
disconnectButton.setAttribute('disabled', 'disabled'); | |
connectButton.removeAttribute('disabled'); | |
} | |
function onMessage(evt) | |
{ | |
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>'); | |
} | |
function onError(evt) | |
{ | |
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data); | |
} | |
function authenticate() { | |
if (!authenticated) { | |
doSend('authenticate', '["'+rpcUser+'", "'+rpcPass+'"]') | |
authenticated = true; | |
} | |
} | |
function doSend(method, params) { | |
message = '{"jsonrpc":"1.0","id":"'+messageID+'","method":"'+method+'","params":'+params+'}'; | |
if (method == 'authenticate') { | |
writeToScreen("SENT: " + message.replace(/\"params\":\[.+\]/, '"params":[***]')); | |
} else { | |
writeToScreen("SENT: " + message); | |
} | |
websocket.send(message); | |
messageID++; | |
} | |
function writeToScreen(message) | |
{ | |
var pre = document.createElement("p"); | |
pre.style.wordWrap = "break-word"; | |
pre.innerHTML = message; | |
output.appendChild(pre); | |
} | |
window.addEventListener("load", init, false); | |
</script> | |
</head> | |
<body> | |
<div style="display:block;"> | |
<h2>Cert Acceptance</h2> | |
<p>NOTE: Before you connect for the first time, you will need to | |
go <a id="wsUriLink" href="https://127.0.0.1:9902/ws">here</a> to accept | |
the self-signed certificate unless you've already whitelisted | |
it. Then hit the back button and you should be able to connect. | |
</div> | |
<h2>Ppcd WebSocket Test</h2> | |
<strong>Location:</strong> | |
<input id="wsUri" size="35" /> | |
<input id="connect" type="button" value="Connect" onClick="connect();" /> | |
<input id="disconnect" type="button" value="Disconnect" onClick="disconnect();" disabled="disabled"/> | |
<input id="send" type="button" value="Request Transactions" onClick="requestTransactions();" disabled="disabled"/> | |
<input id="blocks" type="button" value="Notify Blocks" onClick="notifyBlocks();" disabled="disabled"/> | |
<input id="rescan" type="button" value="Rescan" onClick="rescan();" disabled="disabled"/> | |
<div id="output"></div> | |
<h2>Documentation</h2> | |
<ul> | |
<li><a href="https://github.com/ppcsuite/ppcd/blob/master/docs/json_rpc_api.md#ExampleNodeJsCode">https://github.com/ppcsuite/ppcd/blob/master/docs/json_rpc_api.md#ExampleNodeJsCode</a></li> | |
</ul> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment