SC CODE: Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "main.js")
31 STORE("descrHdr", "AS's Playground Live")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "AS's Playground Live")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "2ff934eedacedda8084e1e41b4b4219c2e1c0881e6a738367719434acdd76c37")
37 STORE("fileCheckS", "2eec54abf2f971bfc68367e69bf290c822fbbf61c854e775d87986809fa8c4ff")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*
let socket;
// Provide Engram's Cyberdeck details about this connection request
const applicationData = {
"id": "6631df0da874d1f3e9431b5e81a363d507b1f47ff3703c100de2f9c27ed224c9",
"name": "AS's Playground Live",
"description": "Basic WS connection parts for TELA application",
"url": "http://localhost:" + location.port,
};
// Function to send the DERO.GetInfo request via WebSocket, this is the primary info displayed in N/A
function sendDEROGetInfoRequest() {
const requestData = {
"jsonrpc": "2.0",
"method": "DERO.GetInfo",
"id": "nodeStatusChannel"
};
sendData(requestData);
}
// Function to send data over WebSocket
function sendData(d) {
if (socket && socket.readyState === WebSocket.OPEN) {
try {
socket.send(JSON.stringify(d)); // Send data as a JSON string
console.log("Data sent:", d);
} catch (error) {
console.error("Failed to send data:", error);
}
} else {
console.log("WebSocket is not open. State:", socket ? socket.readyState : "N/A");
}
}
let intervalId = null; // Store the interval ID globally to track it
// Function to connect to the WebSocket
function connectWebSocket() {
const connectButton = document.getElementById("connectButton");
// If the button says "Disconnect", close the connection
if (connectButton.textContent === "Disconnect") {
if (socket && socket.readyState === WebSocket.OPEN) {
socket.close(); // Close the WebSocket connection
clearInterval(intervalId); // Stop the periodic request
intervalId = null; // Reset interval ID
document.getElementById('wsStatus').innerText = "Not connected";
document.getElementById('wsStatus').className = "text-xs text-red-600 dark:text-red-400";
}
return;
}
// Otherwise, initiate a new connection
socket = new WebSocket("ws://localhost:44326/xswd"); // WebSocket connection URL
// When the WebSocket connection is established
socket.addEventListener("open", function(event) {
console.log("WebSocket connection established:", event);
document.getElementById('wsStatus').innerText = "Waiting...";
document.getElementById('wsStatus').className = "text-xs text-gray-600 dark:text-gray-400";
// First, send the required applicationData to the server
sendData(applicationData);
});
// Handle WebSocket errors
socket.addEventListener("error", function(event) {
console.error("WebSocket error:", event);
document.getElementById('wsStatus').innerText = "Check Cyberdeck";
document.getElementById('wsStatus').className = "text-xs text-red-600 dark:text-red-400";
document.getElementById('connectButton').innerText = "Connect";
});
// Handle WebSocket closing
socket.addEventListener("close", function(event) {
console.log("WebSocket connection closed:", event.code, event.reason);
// Clear the interval when the WebSocket is closed
if (intervalId) {
clearInterval(intervalId);
intervalId = null; // Reset the interval ID
}
if (event.code === 1006) { // Handle abnormal closure
document.getElementById('wsStatus').innerText = "Check Cyberdeck";
document.getElementById('wsStatus').className = "text-xs text-red-600 dark:text-red-400";
} else {
document.getElementById('wsStatus').innerText = "Not connected";
document.getElementById('wsStatus').className = "text-xs text-gray-600 dark:text-gray-400";
}
document.getElementById('connectButton').innerText = "Connect";
});
// When a message is received from the WebSocket server
socket.addEventListener("message", function(event) {
const response = JSON.parse(event.data);
console.log("Message received from server:", response);
// Check for the "accepted" field to handle authorization messages specifically
if (response.accepted && response.message) {
console.log("Authorization message received:", response.message);
document.getElementById('wsStatus').innerText = "Authorized";
document.getElementById('wsStatus').className = "text-xs text-green-600 dark:text-green-400";
// Start the interval after authorization
if (!intervalId) {
intervalId = setInterval(function() {
sendDEROGetInfoRequest(); // Get node data periodically
attemptEPOCHfun(); // Send the hash requests periodically
}, 1000);
}
getEPOCHmaxHashes(); // Get max hashes allowed from host application
return; // Skip further processing of authorization messages
}
// Ensure the ID is consistent and check for undefined
const responseId = response.id ? String(response.id).replace(/^"|"$/g, '') : null;
if (responseId === null) {
console.warn("Received a response with no ID field:", response);
return; // Exit if no ID is present
}
switch (responseId) {
case "nodeStatusChannel": // Regular interval call ID
if (response.result) {
updateData(response.result);
}
break;
case "maxEPOCHhashChannel": // Handler for the call with ID "maxEPOCHhashChannel"
handleEPOCHmaxHashesResponse(response.result);
break;
case "AttemptEPOCHchannel": // Handler for the call with ID "AttemptEPOCHchannel"
handleEPOCHresponse(response.result);
break;
default:
console.warn("Unhandled response ID:", responseId);
}
});
}
*/ |
SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "main.js")
31 STORE("descrHdr", "AS's Playground Live")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "AS's Playground Live")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "2ff934eedacedda8084e1e41b4b4219c2e1c0881e6a738367719434acdd76c37")
37 STORE("fileCheckS", "2eec54abf2f971bfc68367e69bf290c822fbbf61c854e775d87986809fa8c4ff")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*
let socket;
// Provide Engram's Cyberdeck details about this connection request
const applicationData = {
"id": "6631df0da874d1f3e9431b5e81a363d507b1f47ff3703c100de2f9c27ed224c9",
"name": "AS's Playground Live",
"description": "Basic WS connection parts for TELA application",
"url": "http://localhost:" + location.port,
};
// Function to send the DERO.GetInfo request via WebSocket, this is the primary info displayed in N/A
function sendDEROGetInfoRequest() {
const requestData = {
"jsonrpc": "2.0",
"method": "DERO.GetInfo",
"id": "nodeStatusChannel"
};
sendData(requestData);
}
// Function to send data over WebSocket
function sendData(d) {
if (socket && socket.readyState === WebSocket.OPEN) {
try {
socket.send(JSON.stringify(d)); // Send data as a JSON string
console.log("Data sent:", d);
} catch (error) {
console.error("Failed to send data:", error);
}
} else {
console.log("WebSocket is not open. State:", socket ? socket.readyState : "N/A");
}
}
let intervalId = null; // Store the interval ID globally to track it
// Function to connect to the WebSocket
function connectWebSocket() {
const connectButton = document.getElementById("connectButton");
// If the button says "Disconnect", close the connection
if (connectButton.textContent === "Disconnect") {
if (socket && socket.readyState === WebSocket.OPEN) {
socket.close(); // Close the WebSocket connection
clearInterval(intervalId); // Stop the periodic request
intervalId = null; // Reset interval ID
document.getElementById('wsStatus').innerText = "Not connected";
document.getElementById('wsStatus').className = "text-xs text-red-600 dark:text-red-400";
}
return;
}
// Otherwise, initiate a new connection
socket = new WebSocket("ws://localhost:44326/xswd"); // WebSocket connection URL
// When the WebSocket connection is established
socket.addEventListener("open", function(event) {
console.log("WebSocket connection established:", event);
document.getElementById('wsStatus').innerText = "Waiting...";
document.getElementById('wsStatus').className = "text-xs text-gray-600 dark:text-gray-400";
// First, send the required applicationData to the server
sendData(applicationData);
});
// Handle WebSocket errors
socket.addEventListener("error", function(event) {
console.error("WebSocket error:", event);
document.getElementById('wsStatus').innerText = "Check Cyberdeck";
document.getElementById('wsStatus').className = "text-xs text-red-600 dark:text-red-400";
document.getElementById('connectButton').innerText = "Connect";
});
// Handle WebSocket closing
socket.addEventListener("close", function(event) {
console.log("WebSocket connection closed:", event.code, event.reason);
// Clear the interval when the WebSocket is closed
if (intervalId) {
clearInterval(intervalId);
intervalId = null; // Reset the interval ID
}
if (event.code === 1006) { // Handle abnormal closure
document.getElementById('wsStatus').innerText = "Check Cyberdeck";
document.getElementById('wsStatus').className = "text-xs text-red-600 dark:text-red-400";
} else {
document.getElementById('wsStatus').innerText = "Not connected";
document.getElementById('wsStatus').className = "text-xs text-gray-600 dark:text-gray-400";
}
document.getElementById('connectButton').innerText = "Connect";
});
// When a message is received from the WebSocket server
socket.addEventListener("message", function(event) {
const response = JSON.parse(event.data);
console.log("Message received from server:", response);
// Check for the "accepted" field to handle authorization messages specifically
if (response.accepted && response.message) {
console.log("Authorization message received:", response.message);
document.getElementById('wsStatus').innerText = "Authorized";
document.getElementById('wsStatus').className = "text-xs text-green-600 dark:text-green-400";
// Start the interval after authorization
if (!intervalId) {
intervalId = setInterval(function() {
sendDEROGetInfoRequest(); // Get node data periodically
attemptEPOCHfun(); // Send the hash requests periodically
}, 1000);
}
getEPOCHmaxHashes(); // Get max hashes allowed from host application
return; // Skip further processing of authorization messages
}
// Ensure the ID is consistent and check for undefined
const responseId = response.id ? String(response.id).replace(/^"|"$/g, '') : null;
if (responseId === null) {
console.warn("Received a response with no ID field:", response);
return; // Exit if no ID is present
}
switch (responseId) {
case "nodeStatusChannel": // Regular interval call ID
if (response.result) {
updateData(response.result);
}
break;
case "maxEPOCHhashChannel": // Handler for the call with ID "maxEPOCHhashChannel"
handleEPOCHmaxHashesResponse(response.result);
break;
case "AttemptEPOCHchannel": // Handler for the call with ID "AttemptEPOCHchannel"
handleEPOCHresponse(response.result);
break;
default:
console.warn("Unhandled response ID:", responseId);
}
});
}
*/'] |