SC CODE: Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "search.js")
31 STORE("descrHdr", "Blockchain search functionality")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "explorer.tela")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "4686016e2db77977941b891797b7e9c8a3960ab68f44b73149b382747fa9b57")
37 STORE("fileCheckS", "2938602a6681ddb512310f3bd5b34e7b3fae171350d5dd600e207d9f9cdf0edb")
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
/*
({
name: 'search',
version: '1.0.0',
// Render search bar HTML
renderSearchBar: function() {
return '<div class="card"><div class="section-header"><h2>Blockchain Search</h2><div class="section-info">Search blocks, transactions, and addresses on the DERO blockchain</div></div><div class="search-bar" style="margin-top:0;margin-bottom:1rem"><input type="text" id="dashboard-search-input" placeholder="Block height, hash, transaction hash, or SCID..." onkeypress="if(event.key===\'Enter\')window.searchModule.performSearch()"><button onclick="window.searchModule.performSearch()">Search</button></div><div class="search-hint"><strong>Examples:</strong><a href="#" onclick="window.searchModule.quickSearch(\'0\')" style="color:var(--primary-color);margin:0 8px">Block 0</a> • <a href="#" onclick="window.searchModule.quickSearch(\'543210\')" style="color:var(--primary-color);margin:0 8px">Block 543210</a> • <a href="#" onclick="window.searchModule.quickSearch(\'latest\')" style="color:var(--primary-color);margin:0 8px">Latest</a> • <a href="#" onclick="window.searchModule.quickSearch(\'pool\')" style="color:var(--primary-color);margin:0 8px">Mempool</a><br><strong>Also supports:</strong> Transaction hashes, Block hashes, Smart Contract IDs (SCIDs)</div></div>';
},
// Quick search with predefined query
quickSearch: function(query) {
const input = document.getElementById('dashboard-search-input') || document.getElementById('search-input');
if (input) {
input.value = query;
this.performSearch();
}
},
// Detect search query type
detectType: function(query) {
query = query.trim();
console.log('Detecting type for query:', query, 'length:', query.length);
// Check for 64-character hex strings FIRST (before checking for numbers)
// This prevents TXIDs like "000000..." from being misidentified as block heights
if (/^[0-9a-fA-F]{64}$/i.test(query)) {
console.log('Detected as 64-char hash (TXID/Block Hash/SCID)');
return 'hash';
}
// Disabled: 66-character hex strings cause browser freezes
// if (/^[0-9a-fA-F]{66}$/i.test(query)) {
// console.log('Detected as 66-char hex data (SC variable/encoded data)');
// return 'sc_data';
// }
// Check for block height (numbers only) - but only if not 64 chars
if (/^\d+$/.test(query) && query.length < 20) {
console.log('Detected as block height');
return 'height';
}
// Special keywords
if (query.toLowerCase() === 'latest') {
console.log('Detected as latest');
return 'latest';
}
if (query.toLowerCase() === 'pool') {
console.log('Detected as pool');
return 'pool';
}
// Partial hash (less than 64 chars but hex)
if (/^[0-9a-fA-F]{8,}$/i.test(query) && query.length < 64 && query.length >= 8) {
console.log('Detected as partial hash');
return 'partial';
}
console.log('Detected as unknown');
return 'unknown';
},
// Perform search based on query
performSearch: async function() {
const input = document.getElementById('dashboard-search-input') || document.getElementById('search-input');
const query = input ? input.value.trim() : '';
if (!query) {
this.showError('Please enter a search query');
return;
}
this.showProgress('Searching...');
try {
const type = this.detectType(query);
switch (type) {
case 'height':
this.clearSearch();
window.location.hash = 'block/' + query;
break;
case 'latest':
if (window.stats && window.stats.height) {
this.clearSearch();
window.location.hash = 'block/' + window.stats.height;
} else {
const info = await window.xswdCore.getNetworkInfo();
if (info && info.height) {
this.clearSearch();
window.location.hash = 'block/' + info.height;
} else {
this.showError('Unable to get latest block height');
}
}
break;
case 'pool':
this.clearSearch();
window.location.hash = 'pool';
break;
case 'hash':
await this.searchHash(query);
break;
case 'sc_data':
this.showSCDataInfo(query);
break;
case 'partial':
this.showError('Hash appears incomplete. Please provide the full 64-character hash.');
break;
default:
this.showError('Invalid search query. Use block height, block hash, transaction hash, SCID, "latest", or "pool".');
}
} catch (error) {
this.showError('Search failed: ' + error.message);
}
},
// Search for hash (could be block or transaction)
searchHash: async function(hash) {
if (!window.xswdCore || !window.xswdCore.isConnected) {
this.showError('XSWD connection required');
return;
}
console.log('Searching hash:', hash);
// Try as TRANSACTION HASH FIRST since that's what users usually search for
try {
// Try as transaction hash - use multiple API approaches for better compatibility
console.log('Trying as transaction hash...');
// Try with decode_as_json first (same as transaction module)
let txResult = await window.xswdCore.call('DERO.GetTransaction', {
txs_hashes: [hash],
decode_as_json: 1
});
console.log('Transaction API response (with decode_as_json):', txResult);
// Check if transaction exists in primary format
if (txResult && txResult.txs && txResult.txs.length > 0) {
console.log('Found as transaction hash (primary format)');
this.clearSearch();
window.location.hash = 'tx/' + hash;
return;
}
// Try without decode_as_json for TestNet compatibility
console.log('Trying transaction search without decode_as_json...');
txResult = await window.xswdCore.call('DERO.GetTransaction', {
txs_hashes: [hash]
});
console.log('Transaction API response (without decode):', txResult);
// Check multiple possible response formats
if (txResult && (
(txResult.txs && txResult.txs.length > 0) ||
(txResult.txs_as_hex && txResult.txs_as_hex.length > 0) ||
(txResult.result && txResult.result.txs && txResult.result.txs.length > 0)
)) {
console.log('Found as transaction hash (alternative format)');
this.clearSearch();
window.location.hash = 'tx/' + hash;
return;
} else {
console.log('Transaction not found in any response format');
}
} catch (error) {
console.log('Transaction search API error:', error.message);
}
// Try as block hash ONLY if transaction search fails
try {
console.log('Trying as block hash...');
const blockResult = await window.xswdCore.call('DERO.GetBlockHeaderByHash', { hash: hash });
if (blockResult && blockResult.block_header) {
console.log('Found as block hash, height:', blockResult.block_header.height);
// Special case: if this looks like a TXID but is being found as Block 0,
// show a helpful message
if (blockResult.block_header.height === 0 && hash.length === 64) {
console.log('TXID-like hash found as Block 0 - might be TestNet behavior');
}
this.clearSearch();
window.location.hash = 'block/' + blockResult.block_header.height;
return;
}
} catch (error) {
console.log('Not a block hash:', error.message);
}
// Final fallback: try as SCID
try {
console.log('Trying as smart contract ID...');
const normalizedSCID = hash.toLowerCase();
const scInfo = await window.xswdCore.call('DERO.GetSC', {
scid: normalizedSCID,
code: false,
variables: true
});
if (scInfo && (scInfo.status === 'OK' || scInfo.balance !== undefined)) {
console.log('Found as smart contract ID');
this.clearSearch();
window.location.hash = 'smartcontracts/' + normalizedSCID;
return;
} else {
console.log('Not a valid smart contract ID');
}
} catch (error) {
console.log('Smart contract search error:', error.message);
}
console.log('Hash not found in any category:', hash);
// CRITICAL: Prevent navigation to Block 0 by ensuring we don't change the hash
// when the search fails
this.showError('Hash not found in blockchain. Please verify it is a valid block hash, transaction hash, or smart contract ID (SCID).');
// Ensure we stay on the current page and don't navigate anywhere
return false;
},
// Search for SCID (Smart Contract ID)
searchSCID: async function(scid) {
if (!window.xswdCore || !window.xswdCore.isConnected) {
this.showError('XSWD connection required');
return;
}
try {
// Normalize SCID to lowercase
const normalizedSCID = scid.toLowerCase();
// Try to get smart contract information
const scInfo = await window.xswdCore.call('DERO.GetSC', {
scid: normalizedSCID,
code: false,
variables: true
});
if (scInfo && (scInfo.status === 'OK' || scInfo.balance !== undefined)) {
// SCID exists - navigate to smart contracts page with this SCID
this.clearSearch();
window.location.hash = 'smartcontracts/' + normalizedSCID;
return;
}
} catch (error) {
}
// If SCID lookup failed, try as a regular hash (could be misidentified)
try {
await this.searchHash(scid);
return;
} catch (error) {
// Final fallback error
this.showError('SCID "' + scid + '" not found. Please verify it is a valid smart contract ID, block hash, or transaction hash.');
}
},
// Clear search input
clearSearch: function() {
const input = document.getElementById('dashboard-search-input') || document.getElementById('search-input');
if (input) {
input.value = '';
}
},
// Show search progress
showProgress: function(message) {
const searchResult = document.getElementById('search-result');
if (searchResult) {
searchResult.innerHTML = '<div class="loading-indicator">' + message + '</div>';
}
},
// Show search error
showError: function(message) {
console.log('Search Error:', message);
const searchResult = document.getElementById('search-result');
if (searchResult) {
searchResult.innerHTML = '<div class="enhanced-card"><div class="error-card"><h3>Search Error</h3><p>' + message + '</p></div></div>';
} else {
// If no search result container, show error in main content or alert
const mainContent = document.getElementById('main-content');
if (mainContent && !mainContent.innerHTML.includes('Loading')) {
// Show error overlay
const errorDiv = document.createElement('div');
errorDiv.style.cssText = 'position:fixed;top:20px;right:20px;background:rgba(239,68,68,0.9);color:white;padding:1rem;border-radius:8px;z-index:1000;max-width:300px;';
errorDiv.innerHTML = '<strong>Search Error:</strong><br/>' + message + '<br/><button onclick="this.parentElement.remove()" style="margin-top:0.5rem;padding:0.25rem 0.5rem;background:rgba(255,255,255,0.2);border:none;color:white;border-radius:4px;cursor:pointer;">Close</button>';
document.body.appendChild(errorDiv);
// Auto-remove after 8 seconds
setTimeout(() => {
if (errorDiv.parentElement) {
errorDiv.remove();
}
}, 8000);
} else {
alert(message);
}
}
},
// Show search success
showSuccess: function(message) {
const searchResult = document.getElementById('search-result');
if (searchResult) {
searchResult.innerHTML = '<div class="enhanced-card"><div class="success-card"><h3>Search Complete</h3><p>' + message + '</p></div></div>';
}
},
// Debug function for testing transaction searches
testTxSearch: async function(txHash) {
console.log('🧪 Testing transaction search for:', txHash);
if (!window.xswdCore || !window.xswdCore.isConnected) {
console.log('❌ XSWD not connected');
return false;
}
try {
// Test the exact same call as the search function
const txResult1 = await window.xswdCore.call('DERO.GetTransaction', {
txs_hashes: [txHash],
decode_as_json: 1
});
console.log('🧪 Test result 1 (with decode):', txResult1);
const txResult2 = await window.xswdCore.call('DERO.GetTransaction', {
txs_hashes: [txHash]
});
console.log('🧪 Test result 2 (without decode):', txResult2);
return { result1: txResult1, result2: txResult2 };
} catch (error) {
console.log('🧪 Test error:', error);
return { error: error.message };
}
},
showSCDataInfo: function(hexData) {
console.log('Showing SC data info for:', hexData);
this.clearSearch();
// Quick and safe hex decoding with limits
let decodedText = 'Hex data analysis disabled for performance';
// For now, just show the hex data without heavy processing
// The CPU freeze was likely caused by the hex decoding loop
const searchResult = document.getElementById('search-result');
if (searchResult) {
searchResult.innerHTML = `
<div class="enhanced-card">
<div class="card-header">
<h2 style="color: #b959b6; font-size: 1.6rem; font-weight: 700; margin: 0;">Smart Contract Variable Data</h2>
</div>
<div class="card-content">
<div style="margin-bottom: 1rem;">
<div style="color: #b3b3b3; font-size: 0.9rem; margin-bottom: 0.5rem;">Hex Data (${hexData.length} characters):</div>
<div style="font-family: monospace; color: #4ade80; font-size: 0.8rem; word-break: break-all; background: rgba(0,0,0,0.3); padding: 1rem; border-radius: 6px; cursor: pointer;" onclick="navigator.clipboard.writeText('${hexData}')" title="Click to copy">${hexData}</div>
</div>
<div style="margin-bottom: 1rem;">
<div style="color: #b3b3b3; font-size: 0.9rem; margin-bottom: 0.5rem;">Decoded Text (if readable):</div>
<div style="font-family: monospace; color: #fbbf24; font-size: 0.8rem; background: rgba(0,0,0,0.3); padding: 1rem; border-radius: 6px;">${decodedText}</div>
</div>
<div style="color: #888; font-size: 0.8rem; line-height: 1.4;">
This appears to be smart contract variable data. It's not a standard TXID/SCID/Block hash, but may contain encoded information or references.
</div>
</div>
</div>
`;
}
}
});
*/ |
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", "search.js")
31 STORE("descrHdr", "Blockchain search functionality")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "explorer.tela")
34 STORE("docType", "TELA-JS-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "4686016e2db77977941b891797b7e9c8a3960ab68f44b73149b382747fa9b57")
37 STORE("fileCheckS", "2938602a6681ddb512310f3bd5b34e7b3fae171350d5dd600e207d9f9cdf0edb")
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
/*
({
name: 'search',
version: '1.0.0',
// Render search bar HTML
renderSearchBar: function() {
return '<div class="card"><div class="section-header"><h2>Blockchain Search</h2><div class="section-info">Search blocks, transactions, and addresses on the DERO blockchain</div></div><div class="search-bar" style="margin-top:0;margin-bottom:1rem"><input type="text" id="dashboard-search-input" placeholder="Block height, hash, transaction hash, or SCID..." onkeypress="if(event.key===\'Enter\')window.searchModule.performSearch()"><button onclick="window.searchModule.performSearch()">Search</button></div><div class="search-hint"><strong>Examples:</strong><a href="#" onclick="window.searchModule.quickSearch(\'0\')" style="color:var(--primary-color);margin:0 8px">Block 0</a> • <a href="#" onclick="window.searchModule.quickSearch(\'543210\')" style="color:var(--primary-color);margin:0 8px">Block 543210</a> • <a href="#" onclick="window.searchModule.quickSearch(\'latest\')" style="color:var(--primary-color);margin:0 8px">Latest</a> • <a href="#" onclick="window.searchModule.quickSearch(\'pool\')" style="color:var(--primary-color);margin:0 8px">Mempool</a><br><strong>Also supports:</strong> Transaction hashes, Block hashes, Smart Contract IDs (SCIDs)</div></div>';
},
// Quick search with predefined query
quickSearch: function(query) {
const input = document.getElementById('dashboard-search-input') || document.getElementById('search-input');
if (input) {
input.value = query;
this.performSearch();
}
},
// Detect search query type
detectType: function(query) {
query = query.trim();
console.log('Detecting type for query:', query, 'length:', query.length);
// Check for 64-character hex strings FIRST (before checking for numbers)
// This prevents TXIDs like "000000..." from being misidentified as block heights
if (/^[0-9a-fA-F]{64}$/i.test(query)) {
console.log('Detected as 64-char hash (TXID/Block Hash/SCID)');
return 'hash';
}
// Disabled: 66-character hex strings cause browser freezes
// if (/^[0-9a-fA-F]{66}$/i.test(query)) {
// console.log('Detected as 66-char hex data (SC variable/encoded data)');
// return 'sc_data';
// }
// Check for block height (numbers only) - but only if not 64 chars
if (/^\d+$/.test(query) && query.length < 20) {
console.log('Detected as block height');
return 'height';
}
// Special keywords
if (query.toLowerCase() === 'latest') {
console.log('Detected as latest');
return 'latest';
}
if (query.toLowerCase() === 'pool') {
console.log('Detected as pool');
return 'pool';
}
// Partial hash (less than 64 chars but hex)
if (/^[0-9a-fA-F]{8,}$/i.test(query) && query.length < 64 && query.length >= 8) {
console.log('Detected as partial hash');
return 'partial';
}
console.log('Detected as unknown');
return 'unknown';
},
// Perform search based on query
performSearch: async function() {
const input = document.getElementById('dashboard-search-input') || document.getElementById('search-input');
const query = input ? input.value.trim() : '';
if (!query) {
this.showError('Please enter a search query');
return;
}
this.showProgress('Searching...');
try {
const type = this.detectType(query);
switch (type) {
case 'height':
this.clearSearch();
window.location.hash = 'block/' + query;
break;
case 'latest':
if (window.stats && window.stats.height) {
this.clearSearch();
window.location.hash = 'block/' + window.stats.height;
} else {
const info = await window.xswdCore.getNetworkInfo();
if (info && info.height) {
this.clearSearch();
window.location.hash = 'block/' + info.height;
} else {
this.showError('Unable to get latest block height');
}
}
break;
case 'pool':
this.clearSearch();
window.location.hash = 'pool';
break;
case 'hash':
await this.searchHash(query);
break;
case 'sc_data':
this.showSCDataInfo(query);
break;
case 'partial':
this.showError('Hash appears incomplete. Please provide the full 64-character hash.');
break;
default:
this.showError('Invalid search query. Use block height, block hash, transaction hash, SCID, "latest", or "pool".');
}
} catch (error) {
this.showError('Search failed: ' + error.message);
}
},
// Search for hash (could be block or transaction)
searchHash: async function(hash) {
if (!window.xswdCore || !window.xswdCore.isConnected) {
this.showError('XSWD connection required');
return;
}
console.log('Searching hash:', hash);
// Try as TRANSACTION HASH FIRST since that's what users usually search for
try {
// Try as transaction hash - use multiple API approaches for better compatibility
console.log('Trying as transaction hash...');
// Try with decode_as_json first (same as transaction module)
let txResult = await window.xswdCore.call('DERO.GetTransaction', {
txs_hashes: [hash],
decode_as_json: 1
});
console.log('Transaction API response (with decode_as_json):', txResult);
// Check if transaction exists in primary format
if (txResult && txResult.txs && txResult.txs.length > 0) {
console.log('Found as transaction hash (primary format)');
this.clearSearch();
window.location.hash = 'tx/' + hash;
return;
}
// Try without decode_as_json for TestNet compatibility
console.log('Trying transaction search without decode_as_json...');
txResult = await window.xswdCore.call('DERO.GetTransaction', {
txs_hashes: [hash]
});
console.log('Transaction API response (without decode):', txResult);
// Check multiple possible response formats
if (txResult && (
(txResult.txs && txResult.txs.length > 0) ||
(txResult.txs_as_hex && txResult.txs_as_hex.length > 0) ||
(txResult.result && txResult.result.txs && txResult.result.txs.length > 0)
)) {
console.log('Found as transaction hash (alternative format)');
this.clearSearch();
window.location.hash = 'tx/' + hash;
return;
} else {
console.log('Transaction not found in any response format');
}
} catch (error) {
console.log('Transaction search API error:', error.message);
}
// Try as block hash ONLY if transaction search fails
try {
console.log('Trying as block hash...');
const blockResult = await window.xswdCore.call('DERO.GetBlockHeaderByHash', { hash: hash });
if (blockResult && blockResult.block_header) {
console.log('Found as block hash, height:', blockResult.block_header.height);
// Special case: if this looks like a TXID but is being found as Block 0,
// show a helpful message
if (blockResult.block_header.height === 0 && hash.length === 64) {
console.log('TXID-like hash found as Block 0 - might be TestNet behavior');
}
this.clearSearch();
window.location.hash = 'block/' + blockResult.block_header.height;
return;
}
} catch (error) {
console.log('Not a block hash:', error.message);
}
// Final fallback: try as SCID
try {
console.log('Trying as smart contract ID...');
const normalizedSCID = hash.toLowerCase();
const scInfo = await window.xswdCore.call('DERO.GetSC', {
scid: normalizedSCID,
code: false,
variables: true
});
if (scInfo && (scInfo.status === 'OK' || scInfo.balance !== undefined)) {
console.log('Found as smart contract ID');
this.clearSearch();
window.location.hash = 'smartcontracts/' + normalizedSCID;
return;
} else {
console.log('Not a valid smart contract ID');
}
} catch (error) {
console.log('Smart contract search error:', error.message);
}
console.log('Hash not found in any category:', hash);
// CRITICAL: Prevent navigation to Block 0 by ensuring we don't change the hash
// when the search fails
this.showError('Hash not found in blockchain. Please verify it is a valid block hash, transaction hash, or smart contract ID (SCID).');
// Ensure we stay on the current page and don't navigate anywhere
return false;
},
// Search for SCID (Smart Contract ID)
searchSCID: async function(scid) {
if (!window.xswdCore || !window.xswdCore.isConnected) {
this.showError('XSWD connection required');
return;
}
try {
// Normalize SCID to lowercase
const normalizedSCID = scid.toLowerCase();
// Try to get smart contract information
const scInfo = await window.xswdCore.call('DERO.GetSC', {
scid: normalizedSCID,
code: false,
variables: true
});
if (scInfo && (scInfo.status === 'OK' || scInfo.balance !== undefined)) {
// SCID exists - navigate to smart contracts page with this SCID
this.clearSearch();
window.location.hash = 'smartcontracts/' + normalizedSCID;
return;
}
} catch (error) {
}
// If SCID lookup failed, try as a regular hash (could be misidentified)
try {
await this.searchHash(scid);
return;
} catch (error) {
// Final fallback error
this.showError('SCID "' + scid + '" not found. Please verify it is a valid smart contract ID, block hash, or transaction hash.');
}
},
// Clear search input
clearSearch: function() {
const input = document.getElementById('dashboard-search-input') || document.getElementById('search-input');
if (input) {
input.value = '';
}
},
// Show search progress
showProgress: function(message) {
const searchResult = document.getElementById('search-result');
if (searchResult) {
searchResult.innerHTML = '<div class="loading-indicator">' + message + '</div>';
}
},
// Show search error
showError: function(message) {
console.log('Search Error:', message);
const searchResult = document.getElementById('search-result');
if (searchResult) {
searchResult.innerHTML = '<div class="enhanced-card"><div class="error-card"><h3>Search Error</h3><p>' + message + '</p></div></div>';
} else {
// If no search result container, show error in main content or alert
const mainContent = document.getElementById('main-content');
if (mainContent && !mainContent.innerHTML.includes('Loading')) {
// Show error overlay
const errorDiv = document.createElement('div');
errorDiv.style.cssText = 'position:fixed;top:20px;right:20px;background:rgba(239,68,68,0.9);color:white;padding:1rem;border-radius:8px;z-index:1000;max-width:300px;';
errorDiv.innerHTML = '<strong>Search Error:</strong><br/>' + message + '<br/><button onclick="this.parentElement.remove()" style="margin-top:0.5rem;padding:0.25rem 0.5rem;background:rgba(255,255,255,0.2);border:none;color:white;border-radius:4px;cursor:pointer;">Close</button>';
document.body.appendChild(errorDiv);
// Auto-remove after 8 seconds
setTimeout(() => {
if (errorDiv.parentElement) {
errorDiv.remove();
}
}, 8000);
} else {
alert(message);
}
}
},
// Show search success
showSuccess: function(message) {
const searchResult = document.getElementById('search-result');
if (searchResult) {
searchResult.innerHTML = '<div class="enhanced-card"><div class="success-card"><h3>Search Complete</h3><p>' + message + '</p></div></div>';
}
},
// Debug function for testing transaction searches
testTxSearch: async function(txHash) {
console.log('🧪 Testing transaction search for:', txHash);
if (!window.xswdCore || !window.xswdCore.isConnected) {
console.log('❌ XSWD not connected');
return false;
}
try {
// Test the exact same call as the search function
const txResult1 = await window.xswdCore.call('DERO.GetTransaction', {
txs_hashes: [txHash],
decode_as_json: 1
});
console.log('🧪 Test result 1 (with decode):', txResult1);
const txResult2 = await window.xswdCore.call('DERO.GetTransaction', {
txs_hashes: [txHash]
});
console.log('🧪 Test result 2 (without decode):', txResult2);
return { result1: txResult1, result2: txResult2 };
} catch (error) {
console.log('🧪 Test error:', error);
return { error: error.message };
}
},
showSCDataInfo: function(hexData) {
console.log('Showing SC data info for:', hexData);
this.clearSearch();
// Quick and safe hex decoding with limits
let decodedText = 'Hex data analysis disabled for performance';
// For now, just show the hex data without heavy processing
// The CPU freeze was likely caused by the hex decoding loop
const searchResult = document.getElementById('search-result');
if (searchResult) {
searchResult.innerHTML = `
<div class="enhanced-card">
<div class="card-header">
<h2 style="color: #b959b6; font-size: 1.6rem; font-weight: 700; margin: 0;">Smart Contract Variable Data</h2>
</div>
<div class="card-content">
<div style="margin-bottom: 1rem;">
<div style="color: #b3b3b3; font-size: 0.9rem; margin-bottom: 0.5rem;">Hex Data (${hexData.length} characters):</div>
<div style="font-family: monospace; color: #4ade80; font-size: 0.8rem; word-break: break-all; background: rgba(0,0,0,0.3); padding: 1rem; border-radius: 6px; cursor: pointer;" onclick="navigator.clipboard.writeText('${hexData}')" title="Click to copy">${hexData}</div>
</div>
<div style="margin-bottom: 1rem;">
<div style="color: #b3b3b3; font-size: 0.9rem; margin-bottom: 0.5rem;">Decoded Text (if readable):</div>
<div style="font-family: monospace; color: #fbbf24; font-size: 0.8rem; background: rgba(0,0,0,0.3); padding: 1rem; border-radius: 6px;">${decodedText}</div>
</div>
<div style="color: #888; font-size: 0.8rem; line-height: 1.4;">
This appears to be smart contract variable data. It's not a standard TXID/SCID/Block hash, but may contain encoded information or references.
</div>
</div>
</div>
`;
}
}
});
*/'] |