SC CODE: Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "ethcalls.js")
31 STORE("descrHdr", "Eth calls")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "ethcalls.js")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "8a5b35ea51d7460ff9289cda4d0ef354cddf24a8409654fbf7573bcbea6e8c6")
37 STORE("fileCheckS", "2e8a711be0358c46889083e7518c3ef2d8f47e0f0e541d23e1f1679233e2126e")
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
/*
//Install
async function installPLSHTL(days,pls_receiver_address) {
if(! await connectionOK()){return false;}
let HTLContract = new web3.eth.Contract(HTLContractABI);
HTLContract.handleRevert = true;
let contractDeployer = HTLContract.deploy({
data: '0x' + getInstallByteCode(days),
arguments: [pls_receiver_address],
});
let gas = await contractDeployer.estimateGas({
from: connected_evm_account,
});
let gasPrice = await web3.eth.getGasPrice();
let totalCostInETH = web3.utils.fromWei(gas * gasPrice, 'ether');
let result = await confirmModal("Storage cost: " + totalCostInETH + " , continue?");
if (result) {
darken_layer.classList.remove("hidden");
let tx_hash ="";
let confirmed =false;
//create contract deployer
const deployer = HTLContract.deploy({
data: '0x' + getInstallByteCode(days), //bytecode must start with 0x
arguments: [pls_receiver_address], //receiver_address for the constructor in the contract
});
//send transaction to the network
await deployer.send({
from: connected_evm_account
}, function(error, transactionHash){})
.on('error', function(error){
messages.innerHTML = error.message;
alertModal(error.message)
return false;})
.on('transactionHash', function(transactionHash){tx_hash=transactionHash})
.on('receipt', function(receipt){})
.on('confirmation', function(confirmationNumber, receipt){confirmed=true})
.then(tx => {})
.catch(error => {
alertModal(error.message)
return false;
});
if(tx_hash != "" && confirmed){
return tx_hash;
}
return false;
}
return false;
}
//Fund htl scid. Used for both stages.
async function fundPLSHTL(id,pls_htl_scid,pls_amt,hash){
if(! await connectionOK()){return false;}
let HTLContract = new web3.eth.Contract(HTLContractABI, pls_htl_scid);
//send transaction to the network
const txReceipt = await HTLContract.methods
.startSwap("0x"+hash) //name of the function you are calling in the contract
.send({ from: connected_evm_account, value: toPLSAtomicUnits(pls_amt)})
.catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
return false;
}
});
if(typeof txReceipt.transactionHash !== 'undefined'){
//show tx hash
alertModal("Funds Deposited and locked with provided hash." + "<br> TXID" + txReceipt.transactionHash);
return txReceipt.transactionHash;
}
return false;
}
//Withdraw PLS
async function plsWithdrawal(key,pls_txid="",pls_scid="") {
if(! await connectionOK()){return false;}
if(key == ""){
await alertModal("key is null");
}
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
let HTLContract = new web3.eth.Contract(HTLContractABI, pls_scid);
//send transaction to the network
const txReceipt = await HTLContract.methods
.withdraw(key) //name of the function you are calling in the contract
.send({ from: connected_evm_account })
.catch(async (err) => {
if(typeof err.message !== 'undefined'){
await alertModal(err.message);
return "";
}
});
if(typeof txReceipt.transactionHash !== 'undefined'){
//show tx hash
await alertModal(txReceipt.transactionHash);
return txReceipt.transactionHash;
}
}
//Withdraw PLS
async function refundPLS(pls_txid="",pls_scid="") {
if(! await connectionOK()){return false;}
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
let HTLContract = new web3.eth.Contract(HTLContractABI, pls_scid);
//send transaction to the network
const txReceipt = await HTLContract.methods
.refund() //name of the function you are calling in the contract
.send({ from: connected_evm_account })
.catch(async (err) => {
if(typeof err.message !== 'undefined'){
await alertModal(err.message);
}
});
if(typeof txReceipt.transactionHash !== 'undefined'){
//show tx hash
await alertModal(txReceipt.transactionHash);
return txReceipt.transactionHash;
}
}
async function getPLSBalance(HTLContract,pls_txid="",pls_scid="") {
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
const functionSelector = HTLContract.methods.getBalance().encodeABI();
// Make the eth_call
const result = await web3.eth.call({
to: pls_scid,
data: functionSelector,
}).catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
if(typeof result !== 'undefined'){
//show tx hash
return web3.utils.hexToNumberString(result);
}else{
return 0;
}
}
let web3contracts = [];
async function getPLSHTLDetails(pls_htl_scid_tx,_pls_amount){
let plsHTL = {};
let pls_htl_scid = await getContractAddressFromTxId(pls_htl_scid_tx);
if(!pls_htl_scid){
plsHTL.hash_ok = false;
plsHTL.balance_ok = false;
plsHTL.deadline_ok = false;
plsHTL.key_ok = false;
return plsHTL;
}
if(!web3contracts.hasOwnProperty(pls_htl_scid)){
web3contracts[pls_htl_scid] = new web3.eth.Contract(HTLContractABI, pls_htl_scid);
}
plsHTL.scid = pls_htl_scid;
plsHTL.scid_tx = pls_htl_scid_tx;
plsHTL.hash_ok = true;
plsHTL.balance_ok = true;
plsHTL.deadline_ok = true;
plsHTL.key_ok = true;
plsHTL.hash = await web3contracts[pls_htl_scid].methods.hash().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
plsHTL.deposited = await web3contracts[pls_htl_scid].methods.deposited().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
plsHTL.deposited = fromPLSAtomicUnits(plsHTL.deposited);
plsHTL.deadline = await web3contracts[pls_htl_scid].methods.deadline().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
plsHTL.key = await web3contracts[pls_htl_scid].methods.key().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
plsHTL.balance = await getPLSBalance(web3contracts[pls_htl_scid],"",plsHTL.scid);
plsHTL.balance = fromPLSAtomicUnits(plsHTL.balance);
plsHTL.receiver = await web3contracts[pls_htl_scid].methods.receiver().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
if(plsHTL.hash !="" && plsHTL.hash !== "0x0000000000000000000000000000000000000000000000000000000000000000"){
plsHTL.hash = plsHTL.hash;
}else{
plsHTL.hash_ok = false;
}
if(typeof plsHTL.key !== "undefined"){
if(plsHTL.key == ""){
plsHTL.key_ok = false;
}
}else{
plsHTL.key_ok = false;
}
if(parseInt(plsHTL.deposited) < 1 ||
_pls_amount != plsHTL.deposited ||
_pls_amount != plsHTL.balance
){
plsHTL.balance_ok = false;
}
plsHTL.deadline = parseInt(plsHTL.deadline);
if(plsHTL.deadline < nowInSeconds()){
plsHTL.deadline_ok = false;
}
return(plsHTL);
}
async function getKeyPLS(pls_txid="",pls_scid="") {
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
let HTLContract = new web3.eth.Contract(HTLContractABI, pls_scid);
let key = await HTLContract.methods.key().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
return key;
}
async function getInstalledByteCode(pls_txid="",pls_scid="") {
let solSCCode = ""
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
solSCCode = await web3.eth.getCode(pls_scid).catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
solSCCode = ""
}
});
return solSCCode;
}
async function getContractAddressFromTxId(txid){
let tx = await web3.eth.getTransactionReceipt(txid).catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
return false;
}
});
return tx.contractAddress;
}
async function checkInstalledByteCode(days,plsHTL) {
if(!plsHTL.scid_tx){
return;
}
let txRecord = await web3.eth.getTransaction(plsHTL.scid_tx).catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
let source_code = "0x" + getInstallByteCode(days);
plsHTL.code = txRecord.data.substring(0, source_code.length);
plsHTL.code_valid = false;
if(source_code === plsHTL.code){
plsHTL.code_valid = true;
return true;
}
return false;
}
*/ |
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", "ethcalls.js")
31 STORE("descrHdr", "Eth calls")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "ethcalls.js")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "8a5b35ea51d7460ff9289cda4d0ef354cddf24a8409654fbf7573bcbea6e8c6")
37 STORE("fileCheckS", "2e8a711be0358c46889083e7518c3ef2d8f47e0f0e541d23e1f1679233e2126e")
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
/*
//Install
async function installPLSHTL(days,pls_receiver_address) {
if(! await connectionOK()){return false;}
let HTLContract = new web3.eth.Contract(HTLContractABI);
HTLContract.handleRevert = true;
let contractDeployer = HTLContract.deploy({
data: '0x' + getInstallByteCode(days),
arguments: [pls_receiver_address],
});
let gas = await contractDeployer.estimateGas({
from: connected_evm_account,
});
let gasPrice = await web3.eth.getGasPrice();
let totalCostInETH = web3.utils.fromWei(gas * gasPrice, 'ether');
let result = await confirmModal("Storage cost: " + totalCostInETH + " , continue?");
if (result) {
darken_layer.classList.remove("hidden");
let tx_hash ="";
let confirmed =false;
//create contract deployer
const deployer = HTLContract.deploy({
data: '0x' + getInstallByteCode(days), //bytecode must start with 0x
arguments: [pls_receiver_address], //receiver_address for the constructor in the contract
});
//send transaction to the network
await deployer.send({
from: connected_evm_account
}, function(error, transactionHash){})
.on('error', function(error){
messages.innerHTML = error.message;
alertModal(error.message)
return false;})
.on('transactionHash', function(transactionHash){tx_hash=transactionHash})
.on('receipt', function(receipt){})
.on('confirmation', function(confirmationNumber, receipt){confirmed=true})
.then(tx => {})
.catch(error => {
alertModal(error.message)
return false;
});
if(tx_hash != "" && confirmed){
return tx_hash;
}
return false;
}
return false;
}
//Fund htl scid. Used for both stages.
async function fundPLSHTL(id,pls_htl_scid,pls_amt,hash){
if(! await connectionOK()){return false;}
let HTLContract = new web3.eth.Contract(HTLContractABI, pls_htl_scid);
//send transaction to the network
const txReceipt = await HTLContract.methods
.startSwap("0x"+hash) //name of the function you are calling in the contract
.send({ from: connected_evm_account, value: toPLSAtomicUnits(pls_amt)})
.catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
return false;
}
});
if(typeof txReceipt.transactionHash !== 'undefined'){
//show tx hash
alertModal("Funds Deposited and locked with provided hash." + "<br> TXID" + txReceipt.transactionHash);
return txReceipt.transactionHash;
}
return false;
}
//Withdraw PLS
async function plsWithdrawal(key,pls_txid="",pls_scid="") {
if(! await connectionOK()){return false;}
if(key == ""){
await alertModal("key is null");
}
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
let HTLContract = new web3.eth.Contract(HTLContractABI, pls_scid);
//send transaction to the network
const txReceipt = await HTLContract.methods
.withdraw(key) //name of the function you are calling in the contract
.send({ from: connected_evm_account })
.catch(async (err) => {
if(typeof err.message !== 'undefined'){
await alertModal(err.message);
return "";
}
});
if(typeof txReceipt.transactionHash !== 'undefined'){
//show tx hash
await alertModal(txReceipt.transactionHash);
return txReceipt.transactionHash;
}
}
//Withdraw PLS
async function refundPLS(pls_txid="",pls_scid="") {
if(! await connectionOK()){return false;}
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
let HTLContract = new web3.eth.Contract(HTLContractABI, pls_scid);
//send transaction to the network
const txReceipt = await HTLContract.methods
.refund() //name of the function you are calling in the contract
.send({ from: connected_evm_account })
.catch(async (err) => {
if(typeof err.message !== 'undefined'){
await alertModal(err.message);
}
});
if(typeof txReceipt.transactionHash !== 'undefined'){
//show tx hash
await alertModal(txReceipt.transactionHash);
return txReceipt.transactionHash;
}
}
async function getPLSBalance(HTLContract,pls_txid="",pls_scid="") {
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
const functionSelector = HTLContract.methods.getBalance().encodeABI();
// Make the eth_call
const result = await web3.eth.call({
to: pls_scid,
data: functionSelector,
}).catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
if(typeof result !== 'undefined'){
//show tx hash
return web3.utils.hexToNumberString(result);
}else{
return 0;
}
}
let web3contracts = [];
async function getPLSHTLDetails(pls_htl_scid_tx,_pls_amount){
let plsHTL = {};
let pls_htl_scid = await getContractAddressFromTxId(pls_htl_scid_tx);
if(!pls_htl_scid){
plsHTL.hash_ok = false;
plsHTL.balance_ok = false;
plsHTL.deadline_ok = false;
plsHTL.key_ok = false;
return plsHTL;
}
if(!web3contracts.hasOwnProperty(pls_htl_scid)){
web3contracts[pls_htl_scid] = new web3.eth.Contract(HTLContractABI, pls_htl_scid);
}
plsHTL.scid = pls_htl_scid;
plsHTL.scid_tx = pls_htl_scid_tx;
plsHTL.hash_ok = true;
plsHTL.balance_ok = true;
plsHTL.deadline_ok = true;
plsHTL.key_ok = true;
plsHTL.hash = await web3contracts[pls_htl_scid].methods.hash().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
plsHTL.deposited = await web3contracts[pls_htl_scid].methods.deposited().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
plsHTL.deposited = fromPLSAtomicUnits(plsHTL.deposited);
plsHTL.deadline = await web3contracts[pls_htl_scid].methods.deadline().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
plsHTL.key = await web3contracts[pls_htl_scid].methods.key().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
plsHTL.balance = await getPLSBalance(web3contracts[pls_htl_scid],"",plsHTL.scid);
plsHTL.balance = fromPLSAtomicUnits(plsHTL.balance);
plsHTL.receiver = await web3contracts[pls_htl_scid].methods.receiver().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
if(plsHTL.hash !="" && plsHTL.hash !== "0x0000000000000000000000000000000000000000000000000000000000000000"){
plsHTL.hash = plsHTL.hash;
}else{
plsHTL.hash_ok = false;
}
if(typeof plsHTL.key !== "undefined"){
if(plsHTL.key == ""){
plsHTL.key_ok = false;
}
}else{
plsHTL.key_ok = false;
}
if(parseInt(plsHTL.deposited) < 1 ||
_pls_amount != plsHTL.deposited ||
_pls_amount != plsHTL.balance
){
plsHTL.balance_ok = false;
}
plsHTL.deadline = parseInt(plsHTL.deadline);
if(plsHTL.deadline < nowInSeconds()){
plsHTL.deadline_ok = false;
}
return(plsHTL);
}
async function getKeyPLS(pls_txid="",pls_scid="") {
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
let HTLContract = new web3.eth.Contract(HTLContractABI, pls_scid);
let key = await HTLContract.methods.key().call().catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
return key;
}
async function getInstalledByteCode(pls_txid="",pls_scid="") {
let solSCCode = ""
if(pls_txid != ""){
pls_scid = await getContractAddressFromTxId(pls_txid);
}
solSCCode = await web3.eth.getCode(pls_scid).catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
solSCCode = ""
}
});
return solSCCode;
}
async function getContractAddressFromTxId(txid){
let tx = await web3.eth.getTransactionReceipt(txid).catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
return false;
}
});
return tx.contractAddress;
}
async function checkInstalledByteCode(days,plsHTL) {
if(!plsHTL.scid_tx){
return;
}
let txRecord = await web3.eth.getTransaction(plsHTL.scid_tx).catch((err) => {
if(typeof err.message !== 'undefined'){
messages.innerHTML = err.message;
}
});
let source_code = "0x" + getInstallByteCode(days);
plsHTL.code = txRecord.data.substring(0, source_code.length);
plsHTL.code_valid = false;
if(source_code === plsHTL.code){
plsHTL.code_valid = true;
return true;
}
return false;
}
*/'] |