SC CODE: Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "index.html")
31 STORE("descrHdr", "index.html")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "webguy.tela")
34 STORE("docType", "TELA-HTML-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "29c08c3864fa935d614903d1b1c4125cce451c315870aa17017751fb7c77a333")
37 STORE("fileCheckS", "1a4c2c5aeb347bb15d8927865a14bbab6b2d236eb10b580abdf1cf158281bead")
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
/*
<!DOCTYPE html>
<html lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="WebGuy.tela"/>
<script> //This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
window.addEventListener("load", (event) => {
function storageSupported() {
var testKey = 'test', storage = window.localStorage;
try {
storage.setItem(testKey, '1');
storage.removeItem(testKey);
return true;
} catch (error) {
return false;
}
}
var storage = storageSupported();
function saveConnection(daemon = ''){
if(localStorage && storage){
window.localStorage.setItem("daemon",daemon);
}
}
function getConnection(){
if (localStorage && storage && 'daemon' in localStorage) {
return window.localStorage.getItem('daemon');
}
return '';
}
function selectedConnection(c){
saveConnection(c);
loadInit();
}
function addConn(error="Choose a Node"){
if (typeof socket !== 'undefined') {
socket.close();
}
document.body.innerHTML = daemon_form;
document.getElementById("connection-errors").innerHTML = error;
document.getElementById("daemon-select").addEventListener('change', (event) => {
window.connectionURL = event.target.value;
selectedConnection(window.connectionURL);
document.getElementById("daemon-select-div").remove();
})
document.getElementById("daemon-custom-submit").addEventListener('click', (event) => {
window.connectionURL = document.getElementById("daemon-custom-input").value;
selectedConnection(window.connectionURL);
document.getElementById("daemon-select-div").remove();
})
}
window.addConnection = addConn;
var daemon_form = '<div id="daemon-select-div" style="max-width:500px;border-radius:3px;border:1px solid #888;padding: 5px;margin: auto;">'+
'<h2 id="connection-errors"></h2>'+
'<select id="daemon-select">'+
'<option value="">Select Daemon</option>'+
'<option value="node.derofoundation.org:11012">node.derofoundation.org:11012</option>'+
'<option value="secretnamebasis.site:10102">secretnamebasis.site:10102</option>'+
'<option value="dero-node.mysrv.cloud:10102">dero-node.mysrv.cloud:10102</option>'+
' </select>'+
'<hr>'+
' Or Enter Custom Daemon Connection<br>'+
' <input id ="daemon-custom-input" type="text" placeholder="127.0.0.1:10102"><br>'+
'<button id ="daemon-custom-submit" type="button">Use Custom Connection</button>'+
' </div>';
if(getConnection() ==''){
window.connectionURL = "127.0.0.1:10102";
selectedConnection("127.0.0.1:10102");
}else{
window.connectionURL = getConnection();
loadInit();
}
function hexToUtf8(s)
{
return decodeURIComponent(
s.replace(/\s+/g, '') // remove spaces
.replace(/[0-9a-f]{2}/g, '%$&') // add '%' before each 2 characters
);
}
var socket;
function loadInit(){
socket = new WebSocket("ws://"+window.connectionURL+"/ws");
var preflight1 = true;
socket.onopen = function(e) {
socket.send('{"jsonrpc": "2.0", "id": "1", "method": "DERO.GetBlock", "params": {"height": 420 }}');
};
socket.onerror = function(event) {
addConnection("Error Connecting");
return;
}
var lastObj;
socket.onmessage = function(event) {
lastObj = JSON.parse(event.data);
if(typeof lastObj.result === 'undefined'){
addConnection("Error Retrieving Smart Contract");
return;
}
if(typeof lastObj.result.block_header === 'undefined' && preflight1){
addConnection("Service Temporarily Unavailable");
return;
}else if(preflight1){
preflight1 = false;
//initscript scid
return getSC1("d6685789dce445754b34acb5908e518c39027b650a5ffaf93b318612e49674a9");
}
if(typeof lastObj.result.stringkeys !== 'undefined'){
if(lastObj.result.stringkeys["initscript"] !== 'undefined'){
if(document.querySelectorAll("#initscript").length ==0){
let ele = document.createElement('script');
ele.textContent = hexToUtf8(lastObj.result.stringkeys["initscript"]);
ele.id = 'initscript';
document.head.appendChild(ele);
}
setResources();
}
}else if(!preflight1){
addConnection("Service Temporarily Unavailable");
return;
}
socket.close();
};
}
function getSC1(sc){
let json = {};
json.jsonrpc = "2.0";
json.id = "1";
json.method = "DERO.GetSC";
json.params = {};
json.params.scid = sc;
json.params.code = false;
json.params.variables = true;
json = JSON.stringify(json);
socket.send(json);
}
})
</script>
</head>
<body>
</body>
</html>
*/ |
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", "index.html")
31 STORE("descrHdr", "index.html")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "webguy.tela")
34 STORE("docType", "TELA-HTML-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "29c08c3864fa935d614903d1b1c4125cce451c315870aa17017751fb7c77a333")
37 STORE("fileCheckS", "1a4c2c5aeb347bb15d8927865a14bbab6b2d236eb10b580abdf1cf158281bead")
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
/*
<!DOCTYPE html>
<html lang="en-us" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="WebGuy.tela"/>
<script> //This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
window.addEventListener("load", (event) => {
function storageSupported() {
var testKey = 'test', storage = window.localStorage;
try {
storage.setItem(testKey, '1');
storage.removeItem(testKey);
return true;
} catch (error) {
return false;
}
}
var storage = storageSupported();
function saveConnection(daemon = ''){
if(localStorage && storage){
window.localStorage.setItem("daemon",daemon);
}
}
function getConnection(){
if (localStorage && storage && 'daemon' in localStorage) {
return window.localStorage.getItem('daemon');
}
return '';
}
function selectedConnection(c){
saveConnection(c);
loadInit();
}
function addConn(error="Choose a Node"){
if (typeof socket !== 'undefined') {
socket.close();
}
document.body.innerHTML = daemon_form;
document.getElementById("connection-errors").innerHTML = error;
document.getElementById("daemon-select").addEventListener('change', (event) => {
window.connectionURL = event.target.value;
selectedConnection(window.connectionURL);
document.getElementById("daemon-select-div").remove();
})
document.getElementById("daemon-custom-submit").addEventListener('click', (event) => {
window.connectionURL = document.getElementById("daemon-custom-input").value;
selectedConnection(window.connectionURL);
document.getElementById("daemon-select-div").remove();
})
}
window.addConnection = addConn;
var daemon_form = '<div id="daemon-select-div" style="max-width:500px;border-radius:3px;border:1px solid #888;padding: 5px;margin: auto;">'+
'<h2 id="connection-errors"></h2>'+
'<select id="daemon-select">'+
'<option value="">Select Daemon</option>'+
'<option value="node.derofoundation.org:11012">node.derofoundation.org:11012</option>'+
'<option value="secretnamebasis.site:10102">secretnamebasis.site:10102</option>'+
'<option value="dero-node.mysrv.cloud:10102">dero-node.mysrv.cloud:10102</option>'+
' </select>'+
'<hr>'+
' Or Enter Custom Daemon Connection<br>'+
' <input id ="daemon-custom-input" type="text" placeholder="127.0.0.1:10102"><br>'+
'<button id ="daemon-custom-submit" type="button">Use Custom Connection</button>'+
' </div>';
if(getConnection() ==''){
window.connectionURL = "127.0.0.1:10102";
selectedConnection("127.0.0.1:10102");
}else{
window.connectionURL = getConnection();
loadInit();
}
function hexToUtf8(s)
{
return decodeURIComponent(
s.replace(/\s+/g, '') // remove spaces
.replace(/[0-9a-f]{2}/g, '%$&') // add '%' before each 2 characters
);
}
var socket;
function loadInit(){
socket = new WebSocket("ws://"+window.connectionURL+"/ws");
var preflight1 = true;
socket.onopen = function(e) {
socket.send('{"jsonrpc": "2.0", "id": "1", "method": "DERO.GetBlock", "params": {"height": 420 }}');
};
socket.onerror = function(event) {
addConnection("Error Connecting");
return;
}
var lastObj;
socket.onmessage = function(event) {
lastObj = JSON.parse(event.data);
if(typeof lastObj.result === 'undefined'){
addConnection("Error Retrieving Smart Contract");
return;
}
if(typeof lastObj.result.block_header === 'undefined' && preflight1){
addConnection("Service Temporarily Unavailable");
return;
}else if(preflight1){
preflight1 = false;
//initscript scid
return getSC1("d6685789dce445754b34acb5908e518c39027b650a5ffaf93b318612e49674a9");
}
if(typeof lastObj.result.stringkeys !== 'undefined'){
if(lastObj.result.stringkeys["initscript"] !== 'undefined'){
if(document.querySelectorAll("#initscript").length ==0){
let ele = document.createElement('script');
ele.textContent = hexToUtf8(lastObj.result.stringkeys["initscript"]);
ele.id = 'initscript';
document.head.appendChild(ele);
}
setResources();
}
}else if(!preflight1){
addConnection("Service Temporarily Unavailable");
return;
}
socket.close();
};
}
function getSC1(sc){
let json = {};
json.jsonrpc = "2.0";
json.id = "1";
json.method = "DERO.GetSC";
json.params = {};
json.params.scid = sc;
json.params.code = false;
json.params.variables = true;
json = JSON.stringify(json);
socket.send(json);
}
})
</script>
</head>
<body>
</body>
</html>
*/'] |