$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()]; $transaction_id = $db->value("select transaction_id " . "from transactions where txid = ?", ['s', $txid]); if (!$transaction_id) { $txSql = 'insert into transactions ' . '(blockhash, ' . 'block_id, ' . 'txid, ' . 'version, ' . 'time, ' . 'blocktime, ' . 'locktime ' . ') values (?, ?, ?, ?, from_unixtime(?), from_unixtime(?), ?)'; $transaction_id = $db->insert($txSql, $txFlds); } else { $txSql = 'update transactions set ' . 'blockhash = ?, ' . 'block_id = ?, ' . 'txid = ?, ' . 'version = ?, ' . 'time = ?, ' . 'blocktime = ?, ' . 'locktime = ? ' . 'where transaction_id = ?'; $txFlds[0] = $txFlds[0] . 'i'; $txFlds[] = $transaction_id;