コード例 #1
0
 //$currency = Main::getCurrency($currencyName);
 $db = new MariaInterface(["host" => $config->dbhost, "user" => $config->dbuser, "pass" => $config->dbpass, "port" => $config->dbport, "name" => $config->dbname]);
 $bitcoind = RpcFactory::bitcoind($config->rpchost, $config->rpcport, $config->rpcuser, $config->rpcpass);
 $network = NetworkFactory::create($config->magic_byte, $config->magic_p2sh_byte, $config->private_key_byte)->setHDPubByte($config->hd_pub_byte)->setHDPrivByte($config->hd_priv_byte)->setNetMagicBytes($config->net_magic_bytes);
 Bitcoin::setNetwork($network);
 $nextBlockHash = $bitcoind->getblockhash($x);
 do {
     echo "Block {$x}\n";
     $blockhash = $nextBlockHash;
     $block = $bitcoind->getblock($blockhash);
     $blockHeader = $block->getHeader();
     $blockBits = $blockHeader->getBits();
     $blockTime = $blockHeader->getTimestamp();
     $nextBlockHash = $blockHeader->getNextBlock();
     $bvals = ['isiidsisdss', $blockHeader->getTimestamp(), $blockHeader->getBlockHash(), $block->getBuffer()->getSize(), $x, $blockHeader->getVersion(), $blockHeader->getMerkleRoot(), $blockHeader->getNonce(), $math->getCompact($blockBits), $difficulty->getDifficulty($blockBits), $blockHeader->getPrevBlock(), $nextBlockHash];
     $block_id = $db->value('select block_id from blocks where hash = ?', ['s', $blockhash]);
     if (!$block_id) {
         $bsql = "insert into blocks " . "(time, " . "hash, " . "size, " . "height, " . "version, " . "merkleroot, " . "nonce, " . "bits, " . "difficulty, " . "previousblockhash, " . "nextblockhash, " . "last_updated " . ") values (from_unixtime(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, now())";
         $block_id = $db->insert($bsql, $bvals);
     } else {
         $bsql = "update blocks set " . "time = ?, hash = ?, size = ?, height = ?, version = ?, " . "merkleroot = ?, nonce = ?, bits = ?, difficulty = ?, " . "previousblockhash = ?, nextblockhash = ?, last_updated = now() " . "where block_id = ?";
         $bvals[0] = $bvals[0] . 'i';
         $bvals[] = $block_id;
         $db->update($bsql, $bvals);
     }
     $txs = $block->getTransactions();
     for ($t = 0; $t < $txs->count(); $t++) {
         $tx = $txs->getTransaction($t);
         $txid = $tx->getTransactionId();
         //echo "\n","TXID: ",$txid,"\n";
         $txFlds = ['sisiiii', $blockhash, $block_id, $txid, $tx->getVersion(), $blockTime, $blockTime, $tx->getLockTime()];