SC CODE: Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("var_header_name", "connectivity.js")
31 STORE("var_header_description", "")
32 STORE("var_header_icon", "")
33 STORE("dURL", "")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "/")
36 STORE("fileCheckC", "225a85f115c78eead422ebb15e1aeb05623fbad2538b0f0a2675a221df5dedad")
37 STORE("fileCheckS", "103832d733f024da11745b42ea2a64ca8ba76bfc0a1b29fd5f8e043549d6cdd0")
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
/*
// DERO Explorer v2.0 - Connectivity Module
const module = (function() {
'use strict';
const { state, ui, utils } = window.DeroExplorer;
// App info for XSWD handshake
const APP_NAME = 'DERO Explorer';
const APP_DESC = 'Read-only blockchain explorer - no wallet permissions required';
// Module state
const S = {
conn: null,
mode: null,
connected: false,
pending: new Map(),
reqId: 0,
reconnects: 0,
maxReconnects: 3,
reconnectDelay: 2000,
appId: null
};
// Generate SHA-256 hash for App ID
async function genAppId(name) {
const enc = new TextEncoder();
const data = enc.encode(name);
const hash = await crypto.subtle.digest('SHA-256', data);
return Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, '0')).join('');
}
// Initialize connectivity
async function initialize() {
ui.updateStatus('node', 'connecting', 'Connecting...');
// Generate app ID once
if (!S.appId) {
S.appId = await genAppId(APP_NAME + ' TELA Edition v2.0');
}
// Check for telaHost first (HOLOGRAM environment)
if (typeof telaHost !== 'undefined' && telaHost) {
return initTelaHost();
}
// Fallback to XSWD WebSocket
return initXSWD();
}
// Initialize telaHost connection
async function initTelaHost() {
try {
S.conn = telaHost;
S.mode = 'telaHost';
S.connected = true;
state.connection = telaHost;
state.connectionMode = 'telaHost';
state.isConnected = true;
ui.updateStatus('node', 'connected', 'telaHost');
updateFooter('HOLOGRAM (telaHost)');
const info = await call('DERO.GetInfo');
return info ? true : false;
} catch (e) {
return false;
}
}
// Initialize XSWD WebSocket connection
async function initXSWD() {
return new Promise((resolve) => {
try {
const ws = new WebSocket('ws://127.0.0.1:44326/xswd');
let done = false, timer;
ws.onopen = () => {
// Send XSWD handshake with proper SHA-256 App ID
const handshake = {
id: S.appId,
name: APP_NAME,
description: APP_DESC,
url: window.location.origin || window.location.href.split('?')[0]
};
ws.send(JSON.stringify(handshake));
timer = setTimeout(() => { if (!done) { ws.close(); resolve(false); } }, 10000);
};
ws.onmessage = (e) => {
try {
const data = JSON.parse(e.data);
if (!done && data.accepted !== undefined) {
done = true;
clearTimeout(timer);
if (data.accepted) {
S.conn = ws;
S.mode = 'xswd';
S.connected = true;
S.reconnects = 0;
state.connection = ws;
state.connectionMode = 'xswd';
state.isConnected = true;
ui.updateStatus('node', 'connected', 'XSWD');
ui.updateStatus('wallet', 'connected', 'Connected');
updateFooter('XSWD WebSocket');
resolve(true);
} else {
ui.updateStatus('node', 'disconnected', 'Rejected');
ui.updateStatus('wallet', 'disconnected', 'Rejected');
resolve(false);
}
return;
}
handleMsg(data);
} catch (err) {}
};
ws.onclose = () => {
S.connected = false;
state.isConnected = false;
if (done) {
ui.updateStatus('node', 'disconnected', 'Disconnected');
ui.updateStatus('wallet', 'disconnected', 'No Wallet');
if (S.reconnects < S.maxReconnects) {
S.reconnects++;
setTimeout(() => {
initXSWD().then(ok => { if (ok) window.dispatchEvent(new CustomEvent('explorer:reconnected')); });
}, S.reconnectDelay);
}
} else {
clearTimeout(timer);
resolve(false);
}
};
ws.onerror = () => {
clearTimeout(timer);
if (!done) { ui.updateStatus('node', 'disconnected', 'Offline'); resolve(false); }
};
} catch (err) {
ui.updateStatus('node', 'disconnected', 'Error');
resolve(false);
}
});
}
// Handle XSWD WebSocket message
function handleMsg(data) {
if (data.jsonrpc && data.id) {
const p = S.pending.get(data.id);
if (p) {
S.pending.delete(data.id);
data.error ? p.reject(new Error(data.error.message || 'RPC Error')) : p.resolve(data.result);
}
}
if (data.method === 'new_topoheight') {
window.dispatchEvent(new CustomEvent('explorer:newBlock', { detail: { topoheight: data.params?.topoheight } }));
}
}
// Make RPC call
async function call(method, params = {}) {
if (!S.connected) throw new Error('Not connected');
if (S.mode === 'telaHost') return await S.conn.call(method, params);
return new Promise((resolve, reject) => {
const id = Date.now() + '-' + (++S.reqId);
const req = { jsonrpc: '2.0', method: method, id: id };
if (params && Object.keys(params).length > 0) req.params = params;
S.pending.set(id, { resolve, reject });
try { S.conn.send(JSON.stringify(req)); }
catch (e) { S.pending.delete(id); reject(e); return; }
const t = method.includes('SC') ? 30000 : 15000;
setTimeout(() => { if (S.pending.has(id)) { S.pending.delete(id); reject(new Error('Timeout: ' + method)); } }, t);
});
}
// Convenience methods
async function getNetworkInfo() {
const r = await call('DERO.GetInfo');
return {
height: r?.height || 0,
topoheight: r?.topoheight || 0,
stableheight: r?.stableheight || 0,
difficulty: r?.difficulty || 0,
hashrate: utils.difficultyToHashrate(r?.difficulty || 0),
version: r?.version || 'Unknown',
network: r?.testnet ? 'Testnet' : 'Mainnet',
testnet: r?.testnet || false,
averageBlockTime: r?.averageblocktime50 || 18,
peerCount: (r?.incoming_connections_count || 0) + (r?.outgoing_connections_count || 0),
txPoolSize: r?.tx_pool_size || 0,
totalSupply: r?.total_supply || 0,
medianBlockSize: r?.median_block_size || 0
};
}
async function getBlock(h) {
return call('DERO.GetBlock', typeof h === 'number' ? { height: h } : { hash: h });
}
async function getBlockHeader(h) {
const r = await call('DERO.GetBlockHeaderByHeight', { height: h });
return r?.block_header || null;
}
async function getTransaction(txid) {
const r = await call('DERO.GetTransaction', { txs_hashes: [txid] });
return r?.txs?.[0] || null;
}
async function getTransactionWithRings(txid) {
if (S.mode === 'telaHost') {
try {
const r = await call('GetTransactionWithRings', { txid });
if (r?.success) return r.transaction;
} catch {}
}
return getTransaction(txid);
}
async function getSmartContract(scid, code = true, vars = true) {
return call('DERO.GetSC', { scid: scid, code: code, variables: vars });
}
async function getTxPool() { return call('DERO.GetTxPool'); }
async function validateProof(proof, txid) {
if (S.mode !== 'telaHost') throw new Error('Proof validation requires a backend that supports ValidateProofFull (e.g., HOLOGRAM or local explorer with proof validation)');
return call('ValidateProofFull', { proof, txid });
}
async function getBlockDetails(h) {
if (S.mode === 'telaHost') {
try {
const r = await call('GetBlockDetails', { height: h });
if (r?.success) return r.block;
} catch {}
}
return getBlock(h);
}
async function subscribe(event) {
if (S.mode !== 'xswd') return false;
try { await call('Subscribe', { event }); return true; } catch { return false; }
}
function updateFooter(mode) {
const el = document.getElementById('connection-mode');
if (el) el.textContent = 'Mode: ' + mode;
}
function hasEnhancedFeatures() { return S.mode === 'telaHost'; }
function getStatus() {
return { connected: S.connected, mode: S.mode, enhanced: hasEnhancedFeatures() };
}
return {
initialize, call,
getNetworkInfo, getBlock, getBlockHeader, getTransaction, getTransactionWithRings,
getSmartContract, getTxPool, getBlockDetails, validateProof, subscribe,
getStatus, hasEnhancedFeatures
};
})();
*/ |
| 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("var_header_name", "connectivity.js")
31 STORE("var_header_description", "")
32 STORE("var_header_icon", "")
33 STORE("dURL", "")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "/")
36 STORE("fileCheckC", "225a85f115c78eead422ebb15e1aeb05623fbad2538b0f0a2675a221df5dedad")
37 STORE("fileCheckS", "103832d733f024da11745b42ea2a64ca8ba76bfc0a1b29fd5f8e043549d6cdd0")
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
/*
// DERO Explorer v2.0 - Connectivity Module
const module = (function() {
'use strict';
const { state, ui, utils } = window.DeroExplorer;
// App info for XSWD handshake
const APP_NAME = 'DERO Explorer';
const APP_DESC = 'Read-only blockchain explorer - no wallet permissions required';
// Module state
const S = {
conn: null,
mode: null,
connected: false,
pending: new Map(),
reqId: 0,
reconnects: 0,
maxReconnects: 3,
reconnectDelay: 2000,
appId: null
};
// Generate SHA-256 hash for App ID
async function genAppId(name) {
const enc = new TextEncoder();
const data = enc.encode(name);
const hash = await crypto.subtle.digest('SHA-256', data);
return Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, '0')).join('');
}
// Initialize connectivity
async function initialize() {
ui.updateStatus('node', 'connecting', 'Connecting...');
// Generate app ID once
if (!S.appId) {
S.appId = await genAppId(APP_NAME + ' TELA Edition v2.0');
}
// Check for telaHost first (HOLOGRAM environment)
if (typeof telaHost !== 'undefined' && telaHost) {
return initTelaHost();
}
// Fallback to XSWD WebSocket
return initXSWD();
}
// Initialize telaHost connection
async function initTelaHost() {
try {
S.conn = telaHost;
S.mode = 'telaHost';
S.connected = true;
state.connection = telaHost;
state.connectionMode = 'telaHost';
state.isConnected = true;
ui.updateStatus('node', 'connected', 'telaHost');
updateFooter('HOLOGRAM (telaHost)');
const info = await call('DERO.GetInfo');
return info ? true : false;
} catch (e) {
return false;
}
}
// Initialize XSWD WebSocket connection
async function initXSWD() {
return new Promise((resolve) => {
try {
const ws = new WebSocket('ws://127.0.0.1:44326/xswd');
let done = false, timer;
ws.onopen = () => {
// Send XSWD handshake with proper SHA-256 App ID
const handshake = {
id: S.appId,
name: APP_NAME,
description: APP_DESC,
url: window.location.origin || window.location.href.split('?')[0]
};
ws.send(JSON.stringify(handshake));
timer = setTimeout(() => { if (!done) { ws.close(); resolve(false); } }, 10000);
};
ws.onmessage = (e) => {
try {
const data = JSON.parse(e.data);
if (!done && data.accepted !== undefined) {
done = true;
clearTimeout(timer);
if (data.accepted) {
S.conn = ws;
S.mode = 'xswd';
S.connected = true;
S.reconnects = 0;
state.connection = ws;
state.connectionMode = 'xswd';
state.isConnected = true;
ui.updateStatus('node', 'connected', 'XSWD');
ui.updateStatus('wallet', 'connected', 'Connected');
updateFooter('XSWD WebSocket');
resolve(true);
} else {
ui.updateStatus('node', 'disconnected', 'Rejected');
ui.updateStatus('wallet', 'disconnected', 'Rejected');
resolve(false);
}
return;
}
handleMsg(data);
} catch (err) {}
};
ws.onclose = () => {
S.connected = false;
state.isConnected = false;
if (done) {
ui.updateStatus('node', 'disconnected', 'Disconnected');
ui.updateStatus('wallet', 'disconnected', 'No Wallet');
if (S.reconnects < S.maxReconnects) {
S.reconnects++;
setTimeout(() => {
initXSWD().then(ok => { if (ok) window.dispatchEvent(new CustomEvent('explorer:reconnected')); });
}, S.reconnectDelay);
}
} else {
clearTimeout(timer);
resolve(false);
}
};
ws.onerror = () => {
clearTimeout(timer);
if (!done) { ui.updateStatus('node', 'disconnected', 'Offline'); resolve(false); }
};
} catch (err) {
ui.updateStatus('node', 'disconnected', 'Error');
resolve(false);
}
});
}
// Handle XSWD WebSocket message
function handleMsg(data) {
if (data.jsonrpc && data.id) {
const p = S.pending.get(data.id);
if (p) {
S.pending.delete(data.id);
data.error ? p.reject(new Error(data.error.message || 'RPC Error')) : p.resolve(data.result);
}
}
if (data.method === 'new_topoheight') {
window.dispatchEvent(new CustomEvent('explorer:newBlock', { detail: { topoheight: data.params?.topoheight } }));
}
}
// Make RPC call
async function call(method, params = {}) {
if (!S.connected) throw new Error('Not connected');
if (S.mode === 'telaHost') return await S.conn.call(method, params);
return new Promise((resolve, reject) => {
const id = Date.now() + '-' + (++S.reqId);
const req = { jsonrpc: '2.0', method: method, id: id };
if (params && Object.keys(params).length > 0) req.params = params;
S.pending.set(id, { resolve, reject });
try { S.conn.send(JSON.stringify(req)); }
catch (e) { S.pending.delete(id); reject(e); return; }
const t = method.includes('SC') ? 30000 : 15000;
setTimeout(() => { if (S.pending.has(id)) { S.pending.delete(id); reject(new Error('Timeout: ' + method)); } }, t);
});
}
// Convenience methods
async function getNetworkInfo() {
const r = await call('DERO.GetInfo');
return {
height: r?.height || 0,
topoheight: r?.topoheight || 0,
stableheight: r?.stableheight || 0,
difficulty: r?.difficulty || 0,
hashrate: utils.difficultyToHashrate(r?.difficulty || 0),
version: r?.version || 'Unknown',
network: r?.testnet ? 'Testnet' : 'Mainnet',
testnet: r?.testnet || false,
averageBlockTime: r?.averageblocktime50 || 18,
peerCount: (r?.incoming_connections_count || 0) + (r?.outgoing_connections_count || 0),
txPoolSize: r?.tx_pool_size || 0,
totalSupply: r?.total_supply || 0,
medianBlockSize: r?.median_block_size || 0
};
}
async function getBlock(h) {
return call('DERO.GetBlock', typeof h === 'number' ? { height: h } : { hash: h });
}
async function getBlockHeader(h) {
const r = await call('DERO.GetBlockHeaderByHeight', { height: h });
return r?.block_header || null;
}
async function getTransaction(txid) {
const r = await call('DERO.GetTransaction', { txs_hashes: [txid] });
return r?.txs?.[0] || null;
}
async function getTransactionWithRings(txid) {
if (S.mode === 'telaHost') {
try {
const r = await call('GetTransactionWithRings', { txid });
if (r?.success) return r.transaction;
} catch {}
}
return getTransaction(txid);
}
async function getSmartContract(scid, code = true, vars = true) {
return call('DERO.GetSC', { scid: scid, code: code, variables: vars });
}
async function getTxPool() { return call('DERO.GetTxPool'); }
async function validateProof(proof, txid) {
if (S.mode !== 'telaHost') throw new Error('Proof validation requires a backend that supports ValidateProofFull (e.g., HOLOGRAM or local explorer with proof validation)');
return call('ValidateProofFull', { proof, txid });
}
async function getBlockDetails(h) {
if (S.mode === 'telaHost') {
try {
const r = await call('GetBlockDetails', { height: h });
if (r?.success) return r.block;
} catch {}
}
return getBlock(h);
}
async function subscribe(event) {
if (S.mode !== 'xswd') return false;
try { await call('Subscribe', { event }); return true; } catch { return false; }
}
function updateFooter(mode) {
const el = document.getElementById('connection-mode');
if (el) el.textContent = 'Mode: ' + mode;
}
function hasEnhancedFeatures() { return S.mode === 'telaHost'; }
function getStatus() {
return { connected: S.connected, mode: S.mode, enhanced: hasEnhancedFeatures() };
}
return {
initialize, call,
getNetworkInfo, getBlock, getBlockHeader, getTransaction, getTransactionWithRings,
getSmartContract, getTxPool, getBlockDetails, validateProof, subscribe,
getStatus, hasEnhancedFeatures
};
})();
*/'] |