SC Arguments: [Name:SC_ACTION Type:uint64 Value:'0' Name:SC_ID Type:hash Value:'83ad91a2f9375db6baedddca79e303a00f6c9a13dabd222c9f2cd7fae44644d1' Name:content Type:string Value:'var installed_docs = [];
var line_no = 40;
var fileContents = document.querySelector('input#open_file[type="file"]');
fileContents.addEventListener('change', () => {
var file = fileContents.files[0];
var reader = new FileReader();
reader.onload = () => {
doc.value = reader.result;
};
reader.readAsText(file);
});
function listener(event) {
let lastObj = JSON.parse(event.data);
let res = lastObj.result;
if (res.txid) {
installed_docs.push({"scid":res.txid});
fileContents.value = "";
fileContents.value = "";
let installedText ="";
for (let x in installed_docs) {
installedText += (line_no++) + ` STORE("DOC`+(parseFloat(x) + 1) + `", "` +installed_docs[x].scid + `")`+"<br>";
}
document.getElementById("output").innerHTML = installedText;
alert(res.txid);
}
socket.removeEventListener("message", listener);
};
function socketSend(data){
socket.addEventListener("message", listener);
sendData(data);
}
var doctypeselect = document.getElementById('doc_type');
var smartcontract = document.getElementById('smartcontract');
var doc = document.getElementById('document');
var deployButton = document.getElementById('deploy');
function getQuoteJSON(){
let quoteJSON = {};
quoteJSON.jsonrpc = "2.0";
quoteJSON.id = "1";
quoteJSON.method = "DERO.GetGasEstimate";
quoteJSON.params = {};
quoteJSON.params.transfers = [{
destination: "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270",
amount:0,
Burn:0,
payload_rpc:[]
}];
quoteJSON.params.sc = smartcontract.value + "/*"+doc.value+"*/"
quoteJSON.params.sc_value = 0;
quoteJSON.params.sc_rpc = [];
quoteJSON.params.ringsize = 2;
quoteJSON.params.signer = "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270";
return quoteJSON;
}
deployButton.addEventListener('click', function(event) {
let quoteJSON = getQuoteJSON();
let result = confirm("Estimated Cost: "+(quoteJSON.params.sc.length * 2) +", Install Doc?");
if (result) {
installDoc();
} else {
console.log("Action canceled.");
}
});
//Install JSON
function getInstallJSON(){
let installJSON = {};
installJSON.jsonrpc = "2.0";
installJSON.id = "1";
installJSON.method = "transfer";
installJSON.params = {};
installJSON.params.fees = 0;
installJSON.params.transfers = [{
destination: "dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270",
amount:0,
Burn:0,
payload_rpc:[]
}];
installJSON.params.sc = smartcontract.value + "/*"+doc.value+"*/";
installJSON.params.sc_value = 0;
installJSON.params.sc_rpc = [];
installJSON.params.ringsize = 2;
return installJSON;
}
//Install function
function installDoc(){
socketSend(getInstallJSON());
}
doctypeselect.addEventListener('change', function (e) {
switch(e.target.value) {
case "css":
smartcontract.value = css;
break;
case "js":
smartcontract.value = js;
break;
default:
smartcontract.value = html;
}
});
var html = `Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "index.html")
31 STORE("descrHdr", "WebGuy Alpha")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "webguy.alpha.tela")
34 STORE("docType", "TELA-HTML-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "REQUIRED")
37 STORE("fileCheckS", "REQUIRED")
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
`;
var css = `Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "general.css")
31 STORE("descrHdr", "Style for...")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "webguy.alpha.tela")
34 STORE("docType", "TELA-CSS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "REQUIRED")
37 STORE("fileCheckS", "REQUIRED")
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
`;
var js = `Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "general.js")
31 STORE("descrHdr", "Script for...")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "webguy.alpha.tela")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "REQUIRED")
37 STORE("fileCheckS", "REQUIRED")
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
`;
//default is html
smartcontract.value = html;
' Name:entrypoint Type:string Value:'StoreItem' Name:name Type:string Value:'docinstaller.js'] |