Smart Contract Details

Open on Dero Explorer
Internal ID:
49778
Block:
Timestamp:
2025-05-16 20:09:51 UTC (2 months ago)
Creator:
goodwallet (1770683)
Raw Data:
[{"name":"SC_ACTION","datatype":"U","value":1},{"name":"SC_CODE","datatype":"S","value":"Function InitializePrivate() Uint64\n10 IF init() == 0 THEN GOTO 30\n20 RETURN 1\n30 STORE(\"nameHdr\", \"main.js\")\n31 STORE(\"descrHdr\", \"AS's Playground Live\")\n32 STORE(\"iconURLHdr\", \"\")\n33 STORE(\"dURL\", \"AS's Playground Live\")\n34 STORE(\"docType\", \"TELA-JS-1\")\n35 STORE(\"subDir\", \"\")\n36 STORE(\"fileCheckC\", \"2ff934eedacedda8084e1e41b4b4219c2e1c0881e6a738367719434acdd76c37\")\n37 STORE(\"fileCheckS\", \"2eec54abf2f971bfc68367e69bf290c822fbbf61c854e775d87986809fa8c4ff\")\n100 RETURN 0\nEnd Function\n\nFunction init() Uint64\n10 IF EXISTS(\"owner\") == 0 THEN GOTO 30\n20 RETURN 1\n30 STORE(\"owner\", address())\n50 STORE(\"docVersion\", \"1.0.0\")\n60 STORE(\"hash\", HEX(TXID()))\n70 STORE(\"likes\", 0)\n80 STORE(\"dislikes\", 0)\n100 RETURN 0\nEnd Function\n\nFunction address() String\n10 DIM s as String\n20 LET s = SIGNER()\n30 IF IS_ADDRESS_VALID(s) THEN GOTO 50\n40 RETURN \"anon\"\n50 RETURN ADDRESS_STRING(s)\nEnd Function\n\nFunction Rate(r Uint64) Uint64\n10 DIM addr as String\n15 LET addr = address()\n16 IF r \u003c 100 \u0026\u0026 EXISTS(addr) == 0 \u0026\u0026 addr != \"anon\" THEN GOTO 30\n20 RETURN 1\n30 STORE(addr, \"\"+r+\"_\"+BLOCK_HEIGHT())\n40 IF r \u003c 50 THEN GOTO 70\n50 STORE(\"likes\", LOAD(\"likes\")+1)\n60 RETURN 0\n70 STORE(\"dislikes\", LOAD(\"dislikes\")+1)\n100 RETURN 0\nEnd Function\n\n/*\nlet socket;\r\n\r\n// Provide Engram's Cyberdeck details about this connection request\r\nconst applicationData = {\r\n    \"id\": \"6631df0da874d1f3e9431b5e81a363d507b1f47ff3703c100de2f9c27ed224c9\",\r\n    \"name\": \"AS's Playground Live\",\r\n    \"description\": \"Basic WS connection parts for TELA application\",\r\n    \"url\": \"http://localhost:\" + location.port,\r\n};\r\n\r\n// Function to send the DERO.GetInfo request via WebSocket, this is the primary info displayed in N/A\r\nfunction sendDEROGetInfoRequest() {\r\n    const requestData = {\r\n        \"jsonrpc\": \"2.0\",\r\n        \"method\": \"DERO.GetInfo\",\r\n        \"id\": \"nodeStatusChannel\"\r\n    };\r\n    sendData(requestData);\r\n}\r\n\r\n// Function to send data over WebSocket\r\nfunction sendData(d) {\r\n    if (socket \u0026\u0026 socket.readyState === WebSocket.OPEN) {\r\n        try {\r\n            socket.send(JSON.stringify(d)); // Send data as a JSON string\r\n            console.log(\"Data sent:\", d);\r\n        } catch (error) {\r\n            console.error(\"Failed to send data:\", error);\r\n        }\r\n    } else {\r\n        console.log(\"WebSocket is not open. State:\", socket ? socket.readyState : \"N/A\");\r\n    }\r\n}\r\n\r\nlet intervalId = null; // Store the interval ID globally to track it\r\n\r\n// Function to connect to the WebSocket\r\nfunction connectWebSocket() {\r\n    const connectButton = document.getElementById(\"connectButton\");\r\n\r\n    // If the button says \"Disconnect\", close the connection\r\n    if (connectButton.textContent === \"Disconnect\") {\r\n        if (socket \u0026\u0026 socket.readyState === WebSocket.OPEN) {\r\n            socket.close(); // Close the WebSocket connection\r\n            clearInterval(intervalId); // Stop the periodic request\r\n            intervalId = null; // Reset interval ID\r\n            document.getElementById('wsStatus').innerText = \"Not connected\";\r\n            document.getElementById('wsStatus').className = \"text-xs text-red-600 dark:text-red-400\";\r\n        }\r\n        return;\r\n    }\r\n\r\n    // Otherwise, initiate a new connection\r\n    socket = new WebSocket(\"ws://localhost:44326/xswd\"); // WebSocket connection URL\r\n\r\n    // When the WebSocket connection is established\r\n    socket.addEventListener(\"open\", function(event) {\r\n        console.log(\"WebSocket connection established:\", event);\r\n        document.getElementById('wsStatus').innerText = \"Waiting...\";\r\n        document.getElementById('wsStatus').className = \"text-xs text-gray-600 dark:text-gray-400\";\r\n\r\n        // First, send the required applicationData to the server\r\n        sendData(applicationData);\r\n    });\r\n\r\n    // Handle WebSocket errors\r\n    socket.addEventListener(\"error\", function(event) {\r\n        console.error(\"WebSocket error:\", event);\r\n        document.getElementById('wsStatus').innerText = \"Check Cyberdeck\";\r\n        document.getElementById('wsStatus').className = \"text-xs text-red-600 dark:text-red-400\";\r\n        document.getElementById('connectButton').innerText = \"Connect\";\r\n    });\r\n\r\n    // Handle WebSocket closing\r\n    socket.addEventListener(\"close\", function(event) {\r\n        console.log(\"WebSocket connection closed:\", event.code, event.reason);\r\n\r\n        // Clear the interval when the WebSocket is closed\r\n        if (intervalId) {\r\n            clearInterval(intervalId);\r\n            intervalId = null; // Reset the interval ID\r\n        }\r\n\r\n        if (event.code === 1006) { // Handle abnormal closure\r\n            document.getElementById('wsStatus').innerText = \"Check Cyberdeck\";\r\n            document.getElementById('wsStatus').className = \"text-xs text-red-600 dark:text-red-400\";\r\n        } else {\r\n            document.getElementById('wsStatus').innerText = \"Not connected\";\r\n            document.getElementById('wsStatus').className = \"text-xs text-gray-600 dark:text-gray-400\";\r\n        }\r\n\r\n        document.getElementById('connectButton').innerText = \"Connect\";\r\n    });\r\n\r\n    // When a message is received from the WebSocket server\r\n    socket.addEventListener(\"message\", function(event) {\r\n        const response = JSON.parse(event.data);\r\n        console.log(\"Message received from server:\", response);\r\n\r\n        // Check for the \"accepted\" field to handle authorization messages specifically\r\n        if (response.accepted \u0026\u0026 response.message) {\r\n            console.log(\"Authorization message received:\", response.message);\r\n            document.getElementById('wsStatus').innerText = \"Authorized\";\r\n            document.getElementById('wsStatus').className = \"text-xs text-green-600 dark:text-green-400\";\r\n\r\n            // Start the interval after authorization\r\n            if (!intervalId) {\r\n                intervalId = setInterval(function() {\r\n                    sendDEROGetInfoRequest(); // Get node data periodically\r\n                    attemptEPOCHfun(); // Send the hash requests periodically\r\n                }, 1000);\r\n            }\r\n            getEPOCHmaxHashes(); // Get max hashes allowed from host application\r\n            return; // Skip further processing of authorization messages\r\n        }\r\n\r\n        // Ensure the ID is consistent and check for undefined\r\n        const responseId = response.id ? String(response.id).replace(/^\"|\"$/g, '') : null;\r\n\r\n        if (responseId === null) {\r\n            console.warn(\"Received a response with no ID field:\", response);\r\n            return; // Exit if no ID is present\r\n        }\r\n\r\n        switch (responseId) {\r\n            case \"nodeStatusChannel\": // Regular interval call ID\r\n                if (response.result) {\r\n                    updateData(response.result);\r\n                }\r\n                break;\r\n            case \"maxEPOCHhashChannel\": // Handler for the call with ID \"maxEPOCHhashChannel\"\r\n                handleEPOCHmaxHashesResponse(response.result);\r\n                break;\r\n            case \"AttemptEPOCHchannel\": // Handler for the call with ID \"AttemptEPOCHchannel\"\r\n                handleEPOCHresponse(response.result);\r\n                break;\r\n            default:\r\n                console.warn(\"Unhandled response ID:\", responseId);\r\n        }\r\n\r\n    });\r\n}\r\n\r\n\r\n\r\n\r\n\n*/"}]
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);
        }

    });
}





*/