SC Arguments: [Name:SC_ACTION Type:uint64 Value:'0' Name:SC_ID Type:hash Value:'f66747b4fcb0423e889added204ca5c0fac89eb4a775ad035881ea7d42bc9beb' Name:content Type:string Value:'//Install Doc function
function installDoc(){
socketSend(getInstallJSON(smartcontract.value));
}
//Install Index function
function installIndex(){
socketSend(getInstallJSON(indexSCCode.value));
}
var indexNameHdr = gbid('indexNameHdr');
var indexDescrHdr = gbid('indexDescrHdr');
var indexIconURLHdr = gbid('indexIconURLHdr');
var indexDURL = gbid('indexDURL');
var deployIndexButton = gbid('deployIndex');
var generateIndexButton = gbid('generateIndex');
var indexinputs = [indexNameHdr,indexDescrHdr,indexIconURLHdr,indexDURL];
indexinputs.forEach((input) => {
input.addEventListener("keyup", indexEdit);
input.addEventListener("change", indexEdit);
input.addEventListener("blur", indexEdit);
});
function indexEdit(event) {
let docs ="";
let line_no = 40;
for (let x in installed_docs) {
docs += (line_no++) + ` STORE("DOC`+(parseFloat(x) + 1) + `", "` +installed_docs[x].scid + `")`+"\n";
}
indexSCCode.value = getIndexSC(docs);
let ok = checkIndexInputs();
if(ok.ok){
deployIndexButton.removeAttribute("disabled");
}else{
deployIndexButton.setAttribute("disabled", true);
}
if(ok.errors.length != 0){
let errorsText = "";
for (const error of ok.errors) {
errorsText = error + errorsText + "\n";
}
alert(errorsText);
}
}
deployIndexButton.addEventListener('click', function(event) {
installType ="index";
let quoteJSON = getQuoteJSON(indexSCCode.value);
let result = confirm("Estimated Cost: "+(niceRound(quoteJSON.params.sc.length * 2 * .00001)) +" DERO, Install Tela-Index?");
if (result) {
installIndex(indexSCCode.value);
} else {
console.log("Action canceled.");
}
});
function checkIndexInputs(){
let ok = true;
let ierrors = [];
blob = new Blob([indexSCCode.value]);
if(blob.size > 20000){
ierrors.push("Doc too large.");
ok = false;
}
if(
indexNameHdr.value==""||
indexDescrHdr.value==""||
indexDURL.value==""||
indexSCCode.value==""||
installed_docs.length == 0
){
ok = false;
}
return {"ok":ok,"errors":ierrors};
}
//Index
var indexSCCode = gbid('indexSCCode');
function getIndexSC(docs){
let indexInit = `// Copyright 2024. Civilware. All rights reserved.
// TELA Decentralized Web Standard (TELA-INDEX-1)
Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "`+indexNameHdr.value+`")
31 STORE("descrHdr", "`+indexDescrHdr.value+`")
32 STORE("iconURLHdr", "`+indexIconURLHdr.value+`")
33 STORE("dURL", "`+indexDURL.value+`")
` + docs + `
1000 RETURN 0
End Function
`;
//Maybe Trim the "\n" off of docs here...
let indexTheRest = `Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("telaVersion", "1.0.0") // TELA SC version
60 STORE("commit", 0) // The initial commit
70 STORE(0, HEX(TXID())) // SCID commit hash
80 STORE("hash", HEX(TXID()))
85 STORE("likes", 0)
90 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 UpdateCode(code String) Uint64
10 IF LOAD("owner") == "anon" THEN GOTO 20
15 IF code == "" THEN GOTO 20
16 IF LOAD("owner") == address() THEN GOTO 30
20 RETURN 1
30 UPDATE_SC_CODE(code)
40 STORE("commit", LOAD("commit")+1) // New commit
50 STORE(LOAD("commit"), HEX(TXID())) // New hash
60 STORE("hash", HEX(TXID()))
100 RETURN 0
End Function
`;
return indexInit + indexTheRest;
}
function niceRound(number){
return Math.round(number*100000000)/100000000;
}
' Name:entrypoint Type:string Value:'StoreItem' Name:name Type:string Value:'siteinstaller2.js'] |