<!DOCTYPE html>
<html lang="en">
<head>
  <title>TOPISTO</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

  <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Bangers" rel="stylesheet" type="text/css">

  <link href="css/topisto.css" rel="stylesheet" type="text/css">
  <link href="css/fonts.css" rel="stylesheet" type="text/css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <script>
    // Init array
    var liste_blocks = {
      'WHALE201810' : '0000000000000000000f9f2dadfb8f312572183272802cbfcc4ff95b4ee6777d',
      'BLOCK21E800' : '00000000000000000021e800c1e8df51b22c1588e5a624bea17e9faa34b2dc4a',   
      'HURRICANE_1' : '0000000000000000000fe6d521a187a5523d5cef6f6c178923ff82ffe5a0f372',
      'SEGWIT'      : '000000000000000000cbeff0b533f8e1189cf09dfbebf57a8ebe349362811b80',
      'SEGWIT_LOCK' : '0000000000000000012e6060980c6475a9a8e62a1bf44b76c5d51f707d54522c',
      'BCC'         : '00000000000000000019f112ec0a9982926f1258cdcc558dd7c3b7e5dc7fa148',
      'BIP_91_LOCK' : '0000000000000000015411ca4b35f7b48ecab015b14de5627b647e262ba0ec40',
      'HALVING_2'   : '000000000000000002cce816c0ab2c5c269cb081896b7dcb34b8422d6b74ffa1',
      'HALVING_1'   : '000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e',
      'PIZZA'       : '00000000006de085dadb3ec413ef074022fe781121b467e98960280dd246bb00',
      'TOPISTO'     : '000000000a73e64735a2b75c97ea674950a9018da1420d01328a918c9ff9852c',
      'LEET'        : '000000008bf44a528a09d203203a6a97c165cf53a92ecc27aed0b49b86a19564',
      'LUCIFER'     : '00000000fc5b3c76f27f810ee775e480ae7fd604fd196b2d8da4257fcd39f4f9',
      'THE_ANSWER'  : '00000000314e90489514c787d615cea50003af2023796ccdd085b6bcc1fa28f5',
      'GENESIS'     : '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', 
    };

    var flag_nav   = true;
    var classes    = ['bg-grey-even','bg-grey-odd'];
    var cur_class  = 0;
    var cur_height = [];

    function precisionRound(number) {
      var precision = 4;
      var factor = Math.pow(10, precision);
      return Math.round((number/100000000) * factor) / factor;
    }

    function addInfoForBlock(block)
    {
      var height = '300px';
      var contenu = '';
      var downloadingImage = new Image();

      cur_height.push(block.height);
      
      cur_class  = 1 - cur_class;
      
      contenu += '      <h2> <span style="font-size:12px">block</span> '+block.height+'</h2>';
      contenu += '      <table width="100%">';
      //contenu += '       <tr><td>hash</td><td align="right"><b>'+block.hash+'</b></td></tr>';
      //contenu += '       <tr><td>index</td><td align="right"><b>'+block.block_index+'</b></td></tr>';
      contenu += '        <tr><td>timestamp</td><td align="right"><b>'+block.time+'</b></td></tr>';
      contenu += '        <tr><td>nonce</td><td align="right"><b>'+block.nonce+'</b></td></tr>';
      contenu += '        <tr><td>nb tx</td><td align="right"><b>'+block.n_tx+'</b></td></tr>';
      contenu += '        <tr><td>outputs</td><td align="right"><b>'+precisionRound(block.topisto_outputs).toFixed(4)+'</b></td></tr>';
      contenu += '        <tr><td>inputs</td><td align="right"><b>'+precisionRound(block.topisto_inputs).toFixed(4)+'</b></td></tr>';
      contenu += '        <tr><td>fees</td><td align="right"><b>'+precisionRound(block.topisto_fees).toFixed(4)+'</b></td></tr>';
      contenu += '        <tr><td>reward</td><td align="right"><b>'+precisionRound(block.topisto_reward).toFixed(4)+'</b></td></tr>';
      contenu += '      </table>';

      $('#info_'+block.height).html(contenu);

      downloadingImage.onload = function(){
        $('#img_'+block.height).attr('src', this.src);   
        //$('#img_'+block.height).attr('height', height);
        //$('#img_'+block.height).attr('width','auto');
        flag_nav = true;
      };
      downloadingImage.src = 'images/block_image.php?methode=hasard&hash='+block.hash;

      return true;
    }

    function addDivForBlock(block_height)
    {
      var contenu = '';

      contenu += '<div id="block_'+block_height+'" class="container-fluid '+classes[cur_class]+'">';
      contenu += '  <div class="row">';
      contenu += '    <div class="col-sm-8" id="info_'+block_height+'">';
      contenu += '      <h2>COMPUTING ...</h2>';
      contenu += '    </div>';
      contenu += '    <div class="col-sm-4 text-right">';
      contenu += '      <div width="100%" class="text-center">';
      contenu += '        <img id="img_'+block_height+'" src="images/loading.gif" class="img-responsive"></img>';
      contenu += '      </div>';
      contenu += '    </div>';
      contenu += '  </div>';
      contenu += '</div>';

      $('#blockchain').append(contenu);

      return true;
    }

    function addDivForVoid()
    {
      var contenu = '';

      contenu += '<div id="the_void" class="container-fluid '+classes[cur_class]+'">';
      contenu += '  <div class="row">';
      contenu += '    <div class="col-sm-8">';
      contenu += '      <h2>the VOID ... </h2>';
      contenu += '    </div>';
      contenu += '    <div class="col-sm-4 text-right">';
      contenu += '      <div width="100%" class="text-center">';
      contenu += '        <img src="images/loading.gif" class="img-responsive"></img>';
      contenu += '      </div>';
      contenu += '    </div>';
      contenu += '  </div>';
      contenu += '</div>';

      $('#blockchain').append(contenu);

      return true;
    }

    function toggleForwardBtn()
    {
      if (cur_height.length < 3)
      {
        $('#btn-forward').removeClass('btn-info');
        $('#btn-forward').addClass('btn-danger');
      } else {
        $('#btn-forward').removeClass('btn-danger');
        $('#btn-forward').addClass('btn-info');
      }
      return true;      
    }


    function gotoBlock(block_name)
    {
      $(document).scrollTop( $("#navigation").offset().top );

      // Bloquer la navigation pendant le calcul
      if (!flag_nav)
      {
        window.alert('A block image is currently computed, please wait ...');
        return false;
      }
      flag_nav   = false;

      if (block_name == 'NEXT')
      {
        flag_nav   = true;

        // Supprimer un block
        if (cur_height.length < 3)
        {
          window.alert('No Next Block, you are at '+$('#blockSelector').val()+' block !');
          return false;
        }

        liste_blocks['PREVIOUS'] = liste_blocks['BLOCK_'+cur_height[cur_height.length-1]];
        cur_height.pop();
        
        toggleForwardBtn();

        $('#block_'+cur_height[cur_height.length-2]).slideDown(400, function() {
          // Animation complete.
          $('#blockchain').children('div:last').remove();
          cur_class = 1 - cur_class;
        });

      } else {
        // Ajouter un block
        addDivForBlock(cur_height[cur_height.length-1] - 1);

        // Décaler d'un block vers le haut
        if (cur_height.length > 1) $('#block_'+cur_height[cur_height.length-2]).slideUp();

        block_hash = '';
        if (block_name != 'LAST') block_hash = '?block_hash='+liste_blocks[block_name];
        $.getJSON('data/getBlockInfo.php'+block_hash, function( data ) {
          liste_blocks['PREVIOUS'] = data.prev;
          liste_blocks['BLOCK_'+data.height] = data.hash;
          addInfoForBlock(data);

          toggleForwardBtn();
        });
      }

      return true;
    }

    function initBlockchain(block_name)
    {
      $(document).scrollTop( $("#navigation").offset().top );

      $('#blockchain').html('');
      cur_height = [];
      cur_class  = 0;
      flag_nav   = true;

      block_hash = '';
      if (block_name != 'LAST') block_hash = '?block_hash='+liste_blocks[block_name];
      $.getJSON('data/getBlockInfo.php'+block_hash, function( data ) {
        addDivForBlock(data.height);        
        addInfoForBlock(data);

        liste_blocks['PREVIOUS'] = data.prev;
        if (data.prev != '0000000000000000000000000000000000000000000000000000000000000000')
          gotoBlock('PREVIOUS');
        else 
          addDivForVoid();
      });
      return true;
    }

    function blockSelectorChange()
    {
      initBlockchain($('#blockSelector').val());
      $('#fast_forward_btn').attr('data-original-title', $('#blockSelector').val());
    }

    $(document).ready(function(){
      // Init the selector
      var select = $('#blockSelector');
      $.each(liste_blocks, function (key, text) {
        select.append(new Option(key, key));
      });

      // tooltips activation
      $('[data-toggle="tooltip"]').tooltip();

      // init de la Blockchain
      initBlockchain('LAST');

      // Add smooth scrolling to all links in navbar + footer link
      $(".navbar a, footer a[href='#myPage']").on('click', function(event) {
        // Make sure this.hash has a value before overriding default behavior
        if (this.hash !== "") {
          // Prevent default anchor click behavior
          event.preventDefault();

          // Store hash
          var hash = this.hash;

          // Using jQuery's animate() method to add smooth page scroll
          // The optional number (900) specifies the number of milliseconds it takes to scroll to the specified area
          $('html, body').animate({
            scrollTop: $(hash).offset().top
          }, 900, function(){
            // Add hash (#) to URL when done scrolling (default click behavior)
            window.location.hash = hash;
          });
        } // End if
      });
  
      $(window).scroll(function() {
        $(".slideanim").each(function(){
          var pos = $(this).offset().top;
          var winTop = $(window).scrollTop();
          if (pos < winTop + 600) {
            $(this).addClass("slide");
          }
          if (winTop < 400) $('#logo_topisto').css('visibility', 'hidden');
          else $('#logo_topisto').css('visibility', 'visible');
        });
      });
    });

  </script>

</head>
<body id="myPage" data-spy="scroll" data-target=".navbar" data-offset="60">

<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="..">
        <img id="logo_topisto" src="images/topisto_vert.png" style="border-radius:6px;display:inline-block;visibility:hidden;height:72px;;box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)">
        <span style="vertical-align:text-bottom;display:inline-block;color:black;font-family: Bangers, sans-serif;font-size: 70px;">TOPISTO</span>
      </a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#about">About</a></li>
        <li><a href="#contact">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>

<div id="about" class="container-fluid">
  <div class="row">
    <div class="col-sm-4">
      <img src="images/topisto_vert.png" alt="avatar dragon gargoyle" width="100%; height: auto"></img>
    </div>
    <div class="col-sm-8">
      <br><br><br>
      <h4>This site is a hobby.<br>It's also a testing place where i can do <a href="blog.php">things</a> that are impossible at work.</h4>
      <p class="text-justify">I like <b>surfing</b> and sailing on the ocean. But during longs winter nights, computing is fun. I'm interesting into <b>cryptocurrencies</b>, computationnal art, datavisualisation. I know that <b>42</b> is the answer to the Life, Universe and Everything Else. As <b>Eto Demerzel</b> said to me, the <b>Seldon's Plan</b> will save the Galaxy. My favorites books are the <b>House of leaves</b>, the <b>Necronomicron</b> and the <b>DarkHold</b>. I also know that great power comes with great responsibility. I'm still in <b>the search of Captain Zero</b>, because <b>the truth is out there</b>.</p>
    </div>
  </div>
</div>

<div id="navigation" class="container-fluid bg-grey" style="padding-top:10px">
  <div class="row">
    <div class="col-sm-12">&nbsp;</div>
  </div>
</div>
<div class="container-fluid bg-grey" style="padding-top:0px;padding-bottom:10px">
  <div class="row">
    <div class="col-sm-4">
      <br><br><xsmall>A kind of Blockchain Explorer</xsmall>
    </div>
    <div class="col-sm-2">
      <a href="#navigation" onclick="javascript:initBlockchain('GENESIS');" class="btn btn-success btn-lg" data-toggle="tooltip" title="GENESIS">
        <span class="glyphicon glyphicon-fast-backward"></span>
      </a>
      <a href="#navigation" onclick="javascript:gotoBlock('PREVIOUS');" class="btn btn-info btn-lg" data-toggle="tooltip" title="PREVIOUS">
        <span class="glyphicon glyphicon-backward"></span>
      </a>
    </div>
    <div class="col-sm-4">
      <select id="blockSelector" style="width:100%" onchange="javascript:blockSelectorChange()" data-width="100%">
        <option value="LAST">LAST</option>
      </select>
    </div>
    <div class="col-sm-2 text-right">
      <a id="btn-forward" href="#navigation" onclick="javascript:gotoBlock('NEXT');" class="btn btn-danger btn-lg" data-toggle="tooltip" title="NEXT">
        <span class="glyphicon glyphicon-forward"></span>
      </a>
      <a href="#navigation" id="fast_forward_btn" onclick="javascript:blockSelectorChange()" class="btn btn-success btn-lg" data-toggle="tooltip" title="LAST">
        <span class="glyphicon glyphicon-fast-forward"></span>
      </a>
    </div>
  </div>
</div>

<div id="blockchain"></div>

<div id="contact" class="container-fluid bg-grey">
  <h4 class="text-center">CONTACT</h4>
  <div class="row slideanim">
    <div class="col-sm-5">
      <p>Contact me</p>
      <p><span class="glyphicon glyphicon-map-marker"></span> Shambala</p>
      <p><span class="glyphicon glyphicon-globe"></span> Employer : Mutiny</p>
      <p><span class="glyphicon glyphicon-phone"></span> +33 4 8 15 16 23 42</p>
      <p>
        <span class="glyphicon glyphicon-envelope"></span>
<!--Place the code below where you want the link to be displayed-->
<span id="obf"><script>document.getElementById("obf").innerHTML="<n uers=\"znvygb:nyoreg.frnaquvyf@gbcvfgb.arg?fhowrpg=pbagnpg\" gnetrg=\"_oynax\">nyoreg.frnaquvyf@gbcvfgb.arg</n>".replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});</script>
<noscript><span style="unicode-bidi:bidi-override;direction:rtl;">ten.otsipot@slihdnaes.trebla</span></noscript></span>
      </p>
    </div>
    <div class="col-sm-5">
      bookmarks : <br>
      <a href="http://inconvergent.net/" target="_blank">Inconvergent</a><br>
      <a href="http://www.datasketch.es/" target="_blank">Data Sketches</a><br>
      <a href="https://bit101.github.io/lab/dailies/170310.html" target="_blank">bit101-github</a><br>
      <a href="http://www.imdb.com/title/tt1508021/" target="_blank">being captain zero</a><br>
    </div>
    <div class="col-sm-2">
      PGP : <br>
      <a href="page.php?id=00000000"><img src="articles/00000000/public_key_qrcode.png" width="100%; height: auto"></img></a>
    </div>
  </div>
</div>

<footer class="container-fluid bg-grey text-center">
  <a href="#myPage" title="To Top">
    <span class="glyphicon glyphicon-chevron-up"></span>
  </a>
  <p>Bootstrap Theme Made By <a href="https://www.w3schools.com" title="Visit w3schools">www.w3schools.com</a></p>
</footer>
</body>
</html>
