Advertisement
Guest User

mysql php fill script for burstdb schema v01

a guest
May 17th, 2015
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. <?php
  2.  
  3. //mysql connection settings start
  4. $mysql_username="root";
  5. $mysql_password="";
  6. $mysql_database="burstdb";
  7. $mysql_server="localhost";
  8. //mysql connect settings end
  9.  
  10.  
  11. //database connection start
  12. $con = mysql_connect($mysql_server,$mysql_username,$mysql_password);
  13. mysql_select_db($mysql_database,$con);
  14. //database connection end
  15.  
  16.  
  17.  
  18. //get blockheight start
  19. $mininginfo=file_get_contents("http://127.0.0.1:8125/burst?requestType=getMiningInfo");
  20. $mininginfo=json_decode($mininginfo);
  21. //var_dump($mininginfo);
  22. $height=(int)$mininginfo->{"height"};
  23. echo "wallet blockchain height: ".$height."\n";
  24. //get blockheight end
  25.  
  26. //get last block in db start
  27. // $sql = "SELECT * FROM $mysql_database.dbstate where iddbstate=0";
  28. $sql = "SELECT height FROM $mysql_database.blocks order by height desc limit 1";
  29. $startblock_tmp = mysql_query($sql);
  30. $row = mysql_fetch_assoc($startblock_tmp);
  31. // $startblock = $row['last_block'];
  32. $startblock = $row['height'];
  33. echo "we start at block: ".$startblock."\n";
  34. //get last block in db end
  35.  
  36.  
  37.  
  38.  
  39. //blockdata start
  40.  
  41. $i=1;
  42. for ($i=$startblock+1;$i<$height;$i=$i+1){
  43. $blockdata=file_get_contents("http://127.0.0.1:8125/burst?requestType=getBlock&height=$i");
  44. $blockdata=json_decode($blockdata);
  45. // var_dump($blockdata);
  46. // echo "block: ".$i." scoop: ".$blockdata->{"scoopNum"}." target: ".$blockdata->{"baseTarget"}." reward: ".$blockdata->{"blockReward"}." miner: ".$blockdata->{"generatorRS"}." time: ".$blockdata->{"timestamp"}."\n";
  47. $block=$i;
  48. $scoop=$blockdata->{"scoopNum"};
  49. $target=$blockdata->{"baseTarget"};
  50. $reward=$blockdata->{"blockReward"};
  51. $miner=$blockdata->{"generatorRS"};
  52. $time=$blockdata->{"timestamp"};
  53. $txids=count($blockdata->{"transactions"});
  54. echo "tx ids: ".$txids." ";
  55. //put data into mysql start
  56. $sql = "INSERT INTO $mysql_database.blocks (height, scoop, target, reward, miner, time, txids) VALUES ($block, $scoop, $target, $reward, '$miner', $time, $txids);";
  57. //echo $sql;
  58. mysql_query($sql, $con);
  59. //put data into mysql end
  60. //fill txids start
  61. if ($txids > 0){
  62. for ($k=0;$k<$txids;$k=$k+1){
  63. //var_dump($blockdata);
  64. $txid=$blockdata->{"transactions"}[$k];
  65. $txdata=file_get_contents("http://127.0.0.1:8125/burst?requestType=getTransaction&transaction=$txid");
  66. $txdata=json_decode($txdata);
  67. $transaction=$txdata->{"transaction"};
  68. $amountNQT=$txdata->{"amountNQT"};
  69. $txheight=$txdata->{"height"};
  70. $recipientRS=$txdata->{"recipientRS"};
  71. $type=$txdata->{"type"};
  72. $feeNQT=$txdata->{"feeNQT"};
  73. $recipient=$txdata->{"recipient"};
  74. $sender=$txdata->{"sender"};
  75. $subtype=$txdata->{"subtype"};
  76. $deadline=$txdata->{"deadline"};
  77. $senderRS=$txdata->{"senderRS"};
  78. //echo "transaction: ".$transaction." height: ".$txheight." recipientRS: ".$recipientRS."\n";
  79. $sql = "INSERT INTO $mysql_database.tx (transaction, amountNQT, height, recipientRS, type, feeNQT, recipient, sender, subtype, deadline, senderRS) VALUES ($transaction, $amountNQT, $txheight, '$recipientRS', $type, $feeNQT, $recipient, $sender, $subtype, $deadline, '$senderRS');";
  80. //echo $sql;
  81. mysql_query($sql, $con);
  82. }
  83. }
  84. //fill txids end
  85. //update db state start
  86. $sql="UPDATE $mysql_database.dbstate last_block SET last_block=$i where iddbstate=0;";
  87. mysql_query($sql, $con);
  88. //update db state end
  89. echo "block: ".$i." scoop: ".$blockdata->{"scoopNum"}." target: ".$blockdata->{"baseTarget"}." reward: ".$blockdata->{"blockReward"}." miner: ".$blockdata->{"generatorRS"}." time: ".$blockdata->{"timestamp"}."\n";
  90.  
  91. }
  92.  
  93. //close the mysql connection start
  94. mysql_close();
  95. //close mysql connection end
  96.  
  97.  
  98.  
  99. //blockdata end
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement