Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //mysql connection settings start
- $mysql_username="root";
- $mysql_password="";
- $mysql_database="burstdb";
- $mysql_server="localhost";
- //mysql connect settings end
- //database connection start
- $con = mysql_connect($mysql_server,$mysql_username,$mysql_password);
- mysql_select_db($mysql_database,$con);
- //database connection end
- //get blockheight start
- $mininginfo=file_get_contents("http://127.0.0.1:8125/burst?requestType=getMiningInfo");
- $mininginfo=json_decode($mininginfo);
- //var_dump($mininginfo);
- $height=(int)$mininginfo->{"height"};
- echo "wallet blockchain height: ".$height."\n";
- //get blockheight end
- //get last block in db start
- // $sql = "SELECT * FROM $mysql_database.dbstate where iddbstate=0";
- $sql = "SELECT height FROM $mysql_database.blocks order by height desc limit 1";
- $startblock_tmp = mysql_query($sql);
- $row = mysql_fetch_assoc($startblock_tmp);
- // $startblock = $row['last_block'];
- $startblock = $row['height'];
- echo "we start at block: ".$startblock."\n";
- //get last block in db end
- //blockdata start
- $i=1;
- for ($i=$startblock+1;$i<$height;$i=$i+1){
- $blockdata=file_get_contents("http://127.0.0.1:8125/burst?requestType=getBlock&height=$i");
- $blockdata=json_decode($blockdata);
- // var_dump($blockdata);
- // echo "block: ".$i." scoop: ".$blockdata->{"scoopNum"}." target: ".$blockdata->{"baseTarget"}." reward: ".$blockdata->{"blockReward"}." miner: ".$blockdata->{"generatorRS"}." time: ".$blockdata->{"timestamp"}."\n";
- $block=$i;
- $scoop=$blockdata->{"scoopNum"};
- $target=$blockdata->{"baseTarget"};
- $reward=$blockdata->{"blockReward"};
- $miner=$blockdata->{"generatorRS"};
- $time=$blockdata->{"timestamp"};
- $txids=count($blockdata->{"transactions"});
- echo "tx ids: ".$txids." ";
- //put data into mysql start
- $sql = "INSERT INTO $mysql_database.blocks (height, scoop, target, reward, miner, time, txids) VALUES ($block, $scoop, $target, $reward, '$miner', $time, $txids);";
- //echo $sql;
- mysql_query($sql, $con);
- //put data into mysql end
- //fill txids start
- if ($txids > 0){
- for ($k=0;$k<$txids;$k=$k+1){
- //var_dump($blockdata);
- $txid=$blockdata->{"transactions"}[$k];
- $txdata=file_get_contents("http://127.0.0.1:8125/burst?requestType=getTransaction&transaction=$txid");
- $txdata=json_decode($txdata);
- $transaction=$txdata->{"transaction"};
- $amountNQT=$txdata->{"amountNQT"};
- $txheight=$txdata->{"height"};
- $recipientRS=$txdata->{"recipientRS"};
- $type=$txdata->{"type"};
- $feeNQT=$txdata->{"feeNQT"};
- $recipient=$txdata->{"recipient"};
- $sender=$txdata->{"sender"};
- $subtype=$txdata->{"subtype"};
- $deadline=$txdata->{"deadline"};
- $senderRS=$txdata->{"senderRS"};
- //echo "transaction: ".$transaction." height: ".$txheight." recipientRS: ".$recipientRS."\n";
- $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');";
- //echo $sql;
- mysql_query($sql, $con);
- }
- }
- //fill txids end
- //update db state start
- $sql="UPDATE $mysql_database.dbstate last_block SET last_block=$i where iddbstate=0;";
- mysql_query($sql, $con);
- //update db state end
- echo "block: ".$i." scoop: ".$blockdata->{"scoopNum"}." target: ".$blockdata->{"baseTarget"}." reward: ".$blockdata->{"blockReward"}." miner: ".$blockdata->{"generatorRS"}." time: ".$blockdata->{"timestamp"}."\n";
- }
- //close the mysql connection start
- mysql_close();
- //close mysql connection end
- //blockdata end
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement