public static function normalizeTXID($txid) { return trim(SimpleHTTP::get('https://blockchain.info/q/hashtontxid/' . $txid)); }
private function calculateBalance($confirmations = false) { $addr = $this->addr->get(); $blockHeight = 0; if ($confirmations !== false) { $blockHeight = intval(HTTP::get('https://blockchain.info/q/getblockcount')); } Debug::log('Block height: ' . $blockHeight); $balance = 0; foreach ($this->txs as $tx) { if ($tx['double_spend']) { Debug::log('Double spend: ' . $tx['tx_index']); continue; } foreach ($tx['inputs'] as $in) { if (isset($in['prev_out']['addr'])) { if ($confirmations !== false) { if (!isset($tx['block_height'])) { if ($confirmations !== 0) { continue 2; } } $blockReq = $tx['block_height'] + $confirmations; if ($blockReq > $blockHeight) { continue 2; } } } } foreach ($tx['out'] as $out) { if ($out['addr'] !== $addr) { continue; } $balance += $out['value']; } } return Amount::fromSatoshis($balance); }