SC Arguments: [Name:SC_ACTION Type:uint64 Value:'0' Name:SC_ID Type:hash Value:'bfe785f81c25be362b03863a6a18cb261b7dfc5f7d3c3ff0e82730f0e9cd41bb' Name:content Type:string Value:'var doctypeselect=document.getElementById("doc_type"),docNameHdr=document.getElementById("docNameHdr"),docDescrHdr=document.getElementById("docDescrHdr"),docIconURLHdr=document.getElementById("docIconURLHdr"),docDURL=document.getElementById("docDURL"),docSubDir=document.getElementById("docSubDir"),docinputs=[docNameHdr,docDescrHdr,docIconURLHdr,docDURL,docSubDir];function docEdit(e){smartcontract.value=getDocSCCode();let n=checkDocInputs();if(n.ok?deployDocButton.removeAttribute("disabled"):deployDocButton.setAttribute("disabled",!0),0!=n.errors.length){let e="";for(const t of n.errors)e=t+e+"\n";alert(e)}}function checkDocInputs(){let e=!0,n=[];if(blob=new Blob([docText.value]),blob.size>18e3&&(n.push("Doc too large."),e=!1),""!=doctypeselect.value&&""!=docNameHdr.value&&""!=docDescrHdr.value&&""!=docDURL.value&&""!=fileCheckC&&""!=fileCheckS&&""!=docText.value&&""!=filename&&""!=signed_filename||(e=!1),""!=signed_filename&&""!=filename){let t="",d="";if(d=signed_filename.substring(0,signed_filename.lastIndexOf("."))||signed_filename,d=d.split(".").pop(),t=filename.split(".").pop(),"TELA-"+t.toUpperCase()+"-1"==doctypeselect.value&&"TELA-"+d.toUpperCase()+"-1"==doctypeselect.value||(n.push("File Extension doesn't match selected document type."),e=!1),installed_docs.length>0){let t=docSubDir.value+docNameHdr.value;for(let d in installed_docs)t==installed_docs[d].subdir+installed_docs[d].filename&&(n.push("Doc already installed!"),e=!1)}}return{ok:e,errors:n}}function getDocSCCode(){return'// Copyright 2024. Civilware. All rights reserved.\n// TELA Decentralized Web Document (TELA-DOC-1)\nFunction InitializePrivate() Uint64\n10 IF init() == 0 THEN GOTO 30\n20 RETURN 1\n30 STORE("nameHdr", "'+docNameHdr.value+'")\n31 STORE("descrHdr", "'+docDescrHdr.value+'")\n32 STORE("iconURLHdr", "'+docIconURLHdr.value+'")\n33 STORE("dURL", "'+docDURL.value+'")\n34 STORE("docType", "'+doctypeselect.value+'")\n35 STORE("subDir", "'+docSubDir.value.replace(/^\/|\/|\/$/g,"")+'")\n36 STORE("fileCheckC", "'+fileCheckC+'")\n37 STORE("fileCheckS", "'+fileCheckS+'")\n100 RETURN 0\nEnd Function\n\n'+'Function 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 < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30\n20 RETURN 1\n30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())\n40 IF r < 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'+("/*"+docText.value+"*/")}docinputs.forEach((e=>{e.addEventListener("keyup",docEdit),e.addEventListener("change",docEdit),e.addEventListener("blur",docEdit)})),doctypeselect.addEventListener("change",docEdit);let fileCheckC="",fileCheckS="";var filename="",signed_filename="",installed_docs=[];let fileContents=document.querySelector('input#open_file[type="file"]');function parseSignedFile(e){let n=e.split("C: ",2)[1],t=n.split("S: ",2)[1];return n=n.split(/\r?\n/,2)[0],t=t.split(/\r?\n/,2)[0],{C:n,S:t}}fileContents.addEventListener("change",(()=>{if(1!==fileContents.files.length)return docText.value="",filename="",docNameHdr.value="",void docEdit();let e=fileContents.files[0],n=new FileReader;n.onload=()=>{docText.value=n.result,filename=e.name,docNameHdr.value=filename,docEdit()},n.readAsText(e)}));let fileCheck=document.querySelector('input#open_signed_file[type="file"]');fileCheck.addEventListener("change",(()=>{if(1!==fileCheck.files.length)return fileCheck.value="",fileCheckC="",fileCheckS="",void docEdit();let e=fileCheck.files[0],n=new FileReader;n.onload=()=>{if("signed"!==e.name.split(".").pop())return fileCheck.value="",fileCheckC="",fileCheckS="",alert("Not a .signed file."),void docEdit();let t=parseSignedFile(n.result);fileCheckC=t.C,fileCheckS=t.S;let d="";d=(signed_filename=e.name).substring(0,signed_filename.lastIndexOf("."))||signed_filename,d!=filename&&(""!=filename?alert("Filename Mismatch"):alert("No document file selected yet.")),docEdit()},n.readAsText(e)}));var installType="doc";function listener(e){let n=JSON.parse(e.data).result;if(n.txid)if("doc"==installType){installed_docs.push({subdir:docSubDir.value.replace(/^\/|\/|\/$/g,""),filename:filename,scid:n.txid}),docNameHdr.value="",filename="",signed_filename="",fileContents.value="",fileCheck.value="";let e="";for(let n in installed_docs)e+=(""!=installed_docs[n].subdir?installed_docs[n].subdir+"/":"")+installed_docs[n].filename+":"+installed_docs[n].scid+"<br>";document.getElementById("output").innerHTML=e,docEdit(),alert(n.txid)}else"index"==installType&&(document.getElementById("indexscid").innerHTML="Tela Site Index SCID:"+n.txid,alert("Congrats, you're all done! This is your Tela Site SCID:"+n.txid));socket.removeEventListener("message",listener)}function socketSend(e){socket.addEventListener("message",listener),sendData(e)}var smartcontract=document.getElementById("smartcontract"),docText=document.getElementById("document"),deployDocButton=document.getElementById("deployDoc");function getQuoteJSON(e){let n={jsonrpc:"2.0",id:"1",method:"DERO.GetGasEstimate",params:{}};return n.params.transfers=[{destination:"dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270",amount:0,Burn:0,payload_rpc:[]}],n.params.sc=e,n.params.sc_value=0,n.params.sc_rpc=[],n.params.ringsize=2,n.params.signer="dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270",n}function getInstallJSON(e){let n={jsonrpc:"2.0",id:"1",method:"transfer",params:{}};return n.params.fees=0,n.params.transfers=[{destination:"dero1qykyta6ntpd27nl0yq4xtzaf4ls6p5e9pqu0k2x4x3pqq5xavjsdxqgny8270",amount:0,Burn:0,payload_rpc:[]}],n.params.sc=e,n.params.sc_value=0,n.params.sc_rpc=[],n.params.ringsize=2,n}function installDoc(){socketSend(getInstallJSON(smartcontract.value))}function installIndex(){socketSend(getInstallJSON(indexSCCode.value))}deployDocButton.addEventListener("click",(function(e){installType="doc";let n=getQuoteJSON(smartcontract.value);confirm("Estimated Cost: "+niceRound(2*n.params.sc.length*1e-5)+" DERO, Install Doc?")?installDoc():alert("Action canceled.")}));var indexNameHdr=document.getElementById("indexNameHdr"),indexDescrHdr=document.getElementById("indexDescrHdr"),indexIconURLHdr=document.getElementById("indexIconURLHdr"),indexDURL=document.getElementById("indexDURL"),deployIndexButton=document.getElementById("deployIndex"),generateIndexButton=document.getElementById("generateIndex"),indexinputs=[indexNameHdr,indexDescrHdr,indexIconURLHdr,indexDURL];function indexEdit(e){let n="",t=40;for(let e in installed_docs)n+=t+++' STORE("DOC'+(parseFloat(e)+1)+'", "'+installed_docs[e].scid+'")\n';indexSCCode.value=getIndexSC(n);let d=checkIndexInputs();if(d.ok?deployIndexButton.removeAttribute("disabled"):deployIndexButton.setAttribute("disabled",!0),0!=d.errors.length){let e="";for(const n of d.errors)e=n+e+"\n";alert(e)}}function checkIndexInputs(){let e=!0,n=[];return blob=new Blob([indexSCCode.value]),blob.size>18e3&&(n.push("Doc too large."),e=!1),""!=indexNameHdr.value&&""!=indexDescrHdr.value&&""!=indexDURL.value&&""!=indexSCCode.value&&0!=installed_docs.length||(e=!1),{ok:e,errors:n}}indexinputs.forEach((e=>{e.addEventListener("keyup",indexEdit),e.addEventListener("change",indexEdit),e.addEventListener("blur",indexEdit)})),deployIndexButton.addEventListener("click",(function(e){installType="index";let n=getQuoteJSON(indexSCCode.value);confirm("Estimated Cost: "+niceRound(2*n.params.sc.length*1e-5)+" DERO, Install Tela-Index?")?installIndex(indexSCCode.value):console.log("Action canceled.")}));var indexSCCode=document.getElementById("indexSCCode");function getIndexSC(e){return'// Copyright 2024. Civilware. All rights reserved.\n// TELA Decentralized Web Standard (TELA-INDEX-1)\nFunction InitializePrivate() Uint64\n10 IF init() == 0 THEN GOTO 30\n20 RETURN 1\n30 STORE("nameHdr", "'+indexNameHdr.value+'")\n31 STORE("descrHdr", "'+indexDescrHdr.value+'")\n32 STORE("iconURLHdr", "'+indexIconURLHdr.value+'")\n33 STORE("dURL", "'+indexDURL.value+'")\n'+e+"\n1000 RETURN 0\nEnd Function\n\n"+'Function init() Uint64\n10 IF EXISTS("owner") == 0 THEN GOTO 30\n20 RETURN 1\n30 STORE("owner", address())\n50 STORE("telaVersion", "1.0.0") // TELA SC version\n60 STORE("commit", 0) // The initial commit\n70 STORE(0, HEX(TXID())) // SCID commit hash\n80 STORE("hash", HEX(TXID()))\n85 STORE("likes", 0)\n90 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 < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30\n20 RETURN 1\n30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())\n40 IF r < 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\nFunction UpdateCode(code String) Uint64\n10 IF LOAD("owner") == "anon" THEN GOTO 20\n15 IF code == "" THEN GOTO 20\n16 IF LOAD("owner") == address() THEN GOTO 30\n20 RETURN 1\n30 UPDATE_SC_CODE(code)\n40 STORE("commit", LOAD("commit")+1) // New commit\n50 STORE(LOAD("commit"), HEX(TXID())) // New hash\n60 STORE("hash", HEX(TXID()))\n100 RETURN 0\nEnd Function\n'}function niceRound(e){return Math.round(1e8*e)/1e8}' Name:entrypoint Type:string Value:'StoreItem' Name:name Type:string Value:'siteinstaller.js'] |