pageTitle = $coin->name." block explorer"; $txid = getparam('txid'); $q = getparam('q'); if (!empty($q) && ctype_xdigit($q)) $txid = $q; elseif (empty($txid)) $txid = 'txid not set'; // prevent highlight echo << function toggleRaw(el) { $(el).parents('tr').next('tr.raw').toggle(); } $(function() { $('#favicon').remove(); $('head').append(''); $('span.txid').bind('click', function(el) { toggleRaw(el.target); }); $('span.txid:contains("{$txid}")').css('color','darkred'); }); END; ////////////////////////////////////////////////////////////////////////////////////// function colorizeJson($json) { $json = str_replace('"', '"', $json); // strings $res = preg_match_all("# "([^&]+)"([,\s])#", $json, $matches); if ($res) foreach($matches[1] as $n=>$m) { $sfx = $matches[2][$n]; $class = ''; if (strlen($m) == 64 && ctype_xdigit($m)) $class = 'hash'; if (strlen($m) == 34 && ctype_alnum($m)) $class = 'addr'; if (strlen($m) == 35 && ctype_alnum($m)) $class = 'addr'; if (strlen($m) > 160 && ctype_alnum($m)) $class = 'data'; if ($class == '' && strlen($m) < 64 && ctype_xdigit($m)) $class = 'hexa'; $json = str_replace(' "'.$m.""".$sfx, ' "'.$m.'"'.$sfx, $json); } // keys $res = preg_match_all("#"([^&]+)":#", $json, $matches); if ($res) foreach($matches[1] as $n=>$m) { $json = str_replace('"'.$m.""", '"'.$m.'"', $json); } // humanize timestamps like "blocktime": 1462359961, $res = preg_match_all("#: ([0-9]{10})([,\s])#", $json, $matches); if ($res) foreach($matches[1] as $n=>$m) { $ts = intval($m); if ($ts > 1400000000 && $ts < 1600000000) { $sfx = $matches[2][$n]; $date = strftime("%Y-%m-%d %T %z", $ts); $json = str_replace(' '.$m.$sfx, ' "'.$date.'"'.$sfx, $json); } } // numeric $res = preg_match_all("#: ([e\-\.0-9]+)([,\s])#", $json, $matches); if ($res) foreach($matches[1] as $n=>$m) { $sfx = $matches[2][$n]; $json = str_replace(' '.$m.$sfx, ' '.$m.''.$sfx, $json); } $json = preg_replace('#\[\s+\]#', '[]', $json); $json = str_replace('[', '[', $json); $json = str_replace(']', ']', $json); $json = str_replace('{', '{', $json); $json = str_replace('}', '}', $json); return $json; } function simplifyscript($script) { $script = preg_replace("/[0-9a-f]+ OP_DROP ?/","", $script); $script = preg_replace("/OP_NOP ?/","", $script); return trim($script); } /////////////////////////////////////////////////////////////////////////////////////////////// $remote = new WalletRPC($coin); $block = $remote->getblock($hash); if(!$block) return; //debuglog($block); $d = date('Y-m-d H:i:s', $block['time']); $confirms = isset($block['confirmations'])? $block['confirmations']: ''; $txcount = count($block['tx']); $version = dechex($block['version']); $nonce = $block['nonce']; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if(isset($block['flags'])) echo ''; if(isset($block['previousblockhash']) && $coin->algo == 'x16r') { echo ''; } if(isset($block['previousblockhash'])) echo ''; if(isset($block['nextblockhash'])) echo ''; echo ''; echo ''; echo "
Coin:'.$coin->createExplorerLink($coin->name).'
Blockhash:'.$hash.'
Confirmations:'.$confirms.'
Height:'.$block['height'].'
Time:'.$d.' ('.$block['time'].')'.'
Difficulty:'.$block['difficulty'].'
Bits:'.$block['bits'].'
Nonce:'.$nonce.'
Version:'.$version.'
Size:'.$block['size'].' bytes
Flags:'.$block['flags'].'
Hash order:'. substr($block['previousblockhash'], -16). '
Previous Hash:'. $coin->createExplorerLink($block['previousblockhash'], array('hash'=>$block['previousblockhash'])). '
Next Hash:'. $coin->createExplorerLink($block['nextblockhash'], array('hash'=>$block['nextblockhash'])). '
Merkle Root:'.$block['merkleroot'].'
Transactions:'.$txcount.'

"; //////////////////////////////////////////////////////////////////////////////// echo << # Transaction Hash Size Value From To (amount) end; $ntx = 0; foreach($block['tx'] as $txhash) { $ntx++; $tx = $remote->getrawtransaction($txhash, 1); if(!$tx && ($ntx == 1 || $txid == $txhash)) { // some transactions are not found directly with getrawtransaction $tx = $remote->gettransaction($txhash); if ($tx && isset($tx['hex'])) { $hex = $tx['hex']; $tx = $remote->decoderawtransaction($hex); $tx['hex'] = $hex; } else { continue; } } if(!$tx) continue; $valuetx = 0; foreach($tx['vout'] as $vout) $valuetx += $vout['value']; echo ''; echo ''.$ntx.''; echo ''.$tx['txid'].''; $size = (strlen($tx['hex'])/2); echo "$size"; echo "$valuetx"; echo ""; $segwit = false; foreach($tx['vin'] as $vin) { if(isset($vin['coinbase'])) echo "Generation"; if(isset($vin['txinwitness'])) $segwit = true; } if($segwit) echo ' '; echo ""; echo ""; $nvout = count($tx['vout']);; if ($nvout > 500) echo "Too much addresses to display ($nvout)"; else foreach($tx['vout'] as $vout) { $value = $vout['value']; if ($value == 0) continue; if(isset($vout['scriptPubKey']['addresses'][0])) echo ''.$vout['scriptPubKey']['addresses'][0]." ($value)"; else echo "($value)"; echo '
'; } echo ""; echo '
'; unset($tx['hex']); echo ($nvout > 500) ? 'truncated' : colorizeJson(json_encode($tx, 128)); echo '
'; echo ""; if ($ntx > 100) { echo 'Too much transations to display...'; break; } } if ($coin->rpcencoding == 'DCR' && isset($block['stx'])) { echo ''; echo 'Stake'; echo ''; $ntx = 0; foreach($block['stx'] as $txhash) { $ntx++; $stx = $remote->getrawtransaction($txhash, 1); if(!$stx) continue; $valuetx = 0; foreach($stx['vout'] as $vout) $valuetx += $vout['value']; echo ''; echo ''.$ntx.''; echo ''.$stx['txid'].''; $size = (strlen($stx['hex'])/2); echo "$size"; echo "$valuetx"; echo ""; if(isset($stx['vout'][0]['scriptPubKey']) && arraySafeVal($stx['vout'][0]['scriptPubKey'],'type') == 'stakesubmission') echo "Ticket"; else foreach($stx['vin'] as $vin) { if (arraySafeVal($vin,'blockheight') > 0) { echo $coin->createExplorerLink($vin['blockheight'], array('height'=>$vin['blockheight'])); echo '
'; } } echo ""; echo ""; foreach($stx['vout'] as $vout) { $value = $vout['value']; if ($value == 0) continue; if(isset($vout['scriptPubKey']['addresses'][0])) echo ''.$vout['scriptPubKey']['addresses'][0]." ($value)"; else echo "($value)"; echo '
'; } echo ""; echo '
'; unset($stx['hex']); echo colorizeJson(json_encode($stx, 128)); echo '
'; echo ''; } } echo ''; $actionUrl = $coin->visible ? '/explorer/'.$coin->symbol : '/explorer/search?id='.$coin->id; echo << end; echo '









'; echo '









'; echo '









';