SC CODE: Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "nfatool.js")
31 STORE("descrHdr", "nfa tool js")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "webguy.tela")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "213a9e985d25ca9f1cbc8f65f22ad9d3ae2959e53835cd306b5b8572ea0b686e")
37 STORE("fileCheckS", "28fa89b137636ef4d7c05b223b265ab3b5868fb3d426d7f78131e09755f0c39b")
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
/*
function lookup(scid){
let fields = [];
fields.push({"field":"descrHdr","value":""});
fields.push({"field":"typeHdr","value":""});
fields.push({"field":"iconURLHdr","value":""});
fields.push({"field":"tagsHdr","value":""});
fields.push({"field":"fileCheckC","value":""});
fields.push({"field":"fileCheckS","value":""});
fields.push({"field":"fileURL","value":""});
fields.push({"field":"fileSignURL","value":""});
fields.push({"field":"coverURL","value":""});
fields.push({"field":"collection","value":""});
let socket = new WebSocket("ws://"+window.connectionURL+"/ws");
let preflight = true;
socket.onopen = function(e) {
socket.send('{"jsonrpc": "2.0", "id": "1", "method": "DERO.GetBlock", "params": {"height": 420 }}');
};
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' && preflight){
addConnection("Service Temporarily Unavailable");
return;
}else if(preflight){
preflight = false;
return getSC(scid);
}
console.log(lastObj.result);
if(typeof lastObj.result.code !== 'undefined'){
if(lastObj.result.code.includes("Function BuyItNow() Uint64")){
fields.forEach((pair,index) => {
if(lastObj.result.stringkeys[pair.field] !== 'undefined'){
pair.value = hexToUtf8(lastObj.result.stringkeys[pair.field]);
}
});
}
if(fields[0].value !=""){
render(lastObj.result.code);
}
}
socket.close();
};
function hexToUtf8(s)
{
return decodeURIComponent(
s.replace(/\s+/g, '') // remove spaces
.replace(/[0-9a-f]{2}/g, '%$&') // add '%' before each 2 characters
);
}
function getSC(sc){
let json = {};
json.jsonrpc = "2.0";
json.id = "1";
json.method = "DERO.GetSC";
json.params = {};
json.params.scid = sc;
json.params.code = true;
json.params.variables = true;
json = JSON.stringify(json);
socket.send(json);
}
function render(sc_code){
document.getElementById("info").innerHTML = "";
document.getElementById("sccode").innerHTML = "";
let coverField = fields.filter(f => f.field === 'coverURL');
let img_url = (coverField[0].value.indexOf('://') === -1) ? 'https://' + coverField[0].value : coverField[0].value ;
document.getElementById("image").innerHTML = '<img onerror="alert(\'Error Loading Image\')" src="'+img_url+'">';
fields.forEach((pair,index) => {
if(pair.field !== 'coverURL'){
let tr = document.createElement("tr");
let tdf = document.createElement("td");
let tdv = document.createElement("td");
tdf.appendChild(document.createTextNode(pair.field));
tdv.appendChild(document.createTextNode(pair.value));
tr.appendChild(tdf);
tr.appendChild(tdv);
// add the text node to the newly created div
document.getElementById("info").appendChild(tr);
}
});
let pre = document.createElement("pre");
pre.appendChild(document.createTextNode(sc_code));
document.getElementById("sccode").appendChild(pre);
}
}
var form = document.getElementById('lookup');
form.addEventListener('submit', function(event) {
event.preventDefault();
scid = form.elements.scid.value;
lookup(scid);
});
*/ |
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", "nfatool.js")
31 STORE("descrHdr", "nfa tool js")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "webguy.tela")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "213a9e985d25ca9f1cbc8f65f22ad9d3ae2959e53835cd306b5b8572ea0b686e")
37 STORE("fileCheckS", "28fa89b137636ef4d7c05b223b265ab3b5868fb3d426d7f78131e09755f0c39b")
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
/*
function lookup(scid){
let fields = [];
fields.push({"field":"descrHdr","value":""});
fields.push({"field":"typeHdr","value":""});
fields.push({"field":"iconURLHdr","value":""});
fields.push({"field":"tagsHdr","value":""});
fields.push({"field":"fileCheckC","value":""});
fields.push({"field":"fileCheckS","value":""});
fields.push({"field":"fileURL","value":""});
fields.push({"field":"fileSignURL","value":""});
fields.push({"field":"coverURL","value":""});
fields.push({"field":"collection","value":""});
let socket = new WebSocket("ws://"+window.connectionURL+"/ws");
let preflight = true;
socket.onopen = function(e) {
socket.send('{"jsonrpc": "2.0", "id": "1", "method": "DERO.GetBlock", "params": {"height": 420 }}');
};
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' && preflight){
addConnection("Service Temporarily Unavailable");
return;
}else if(preflight){
preflight = false;
return getSC(scid);
}
console.log(lastObj.result);
if(typeof lastObj.result.code !== 'undefined'){
if(lastObj.result.code.includes("Function BuyItNow() Uint64")){
fields.forEach((pair,index) => {
if(lastObj.result.stringkeys[pair.field] !== 'undefined'){
pair.value = hexToUtf8(lastObj.result.stringkeys[pair.field]);
}
});
}
if(fields[0].value !=""){
render(lastObj.result.code);
}
}
socket.close();
};
function hexToUtf8(s)
{
return decodeURIComponent(
s.replace(/\s+/g, '') // remove spaces
.replace(/[0-9a-f]{2}/g, '%$&') // add '%' before each 2 characters
);
}
function getSC(sc){
let json = {};
json.jsonrpc = "2.0";
json.id = "1";
json.method = "DERO.GetSC";
json.params = {};
json.params.scid = sc;
json.params.code = true;
json.params.variables = true;
json = JSON.stringify(json);
socket.send(json);
}
function render(sc_code){
document.getElementById("info").innerHTML = "";
document.getElementById("sccode").innerHTML = "";
let coverField = fields.filter(f => f.field === 'coverURL');
let img_url = (coverField[0].value.indexOf('://') === -1) ? 'https://' + coverField[0].value : coverField[0].value ;
document.getElementById("image").innerHTML = '<img onerror="alert(\'Error Loading Image\')" src="'+img_url+'">';
fields.forEach((pair,index) => {
if(pair.field !== 'coverURL'){
let tr = document.createElement("tr");
let tdf = document.createElement("td");
let tdv = document.createElement("td");
tdf.appendChild(document.createTextNode(pair.field));
tdv.appendChild(document.createTextNode(pair.value));
tr.appendChild(tdf);
tr.appendChild(tdv);
// add the text node to the newly created div
document.getElementById("info").appendChild(tr);
}
});
let pre = document.createElement("pre");
pre.appendChild(document.createTextNode(sc_code));
document.getElementById("sccode").appendChild(pre);
}
}
var form = document.getElementById('lookup');
form.addEventListener('submit', function(event) {
event.preventDefault();
scid = form.elements.scid.value;
lookup(scid);
});
*/'] |