private function getContent($url) { if (beginsWith(URL\takeDomain($url), 'blockchain.info') && beginsWith(URL\takePath($url), '/q/addressbalance/')) { return $this->addressBalanceRequest(withoutPrefix(URL\takePath($url), '/q/addressbalance/')); } else { if ($url == 'http://blockchain.info/q/addressbalance/peanuts') { return 'Checksum does not validate'; } else { if (beginsWith($url, 'http://blockchain.info/tobtc?currency=USD')) { return '0.00778083'; } else { if ($url == 'http://api.easyjquery.com/ips/?ip=99.99.99.99') { return '{"Country": "US"}'; } else { if ($url == 'https://freegeoip.net/json/99.99.99.99') { return '{"ip":"99.99.99.99","country_code":"US","country_name":"United States",' . '"region_code":"","region_name":"","city":"","zipcode":"","latitude":38,' . '"longitude":-97,"metro_code":"","areacode":""}'; } else { if ($url == 'https://freegeoip.net/json/175.156.249.231') { return "404 page not found"; } else { throw new Exception("Mock 'get' function couldn't handle following URL: {$url}"); } } } } } } }
function getBalanceInSatoshis($address) { $client = new HttpClient(); $response = $client->get(balanceLookupURL($address)); if ($response->statusCode == 200 && isInteger($response->content)) { return intval($response->content); } else { $e = strtolower($response->content); preg_match('@<title>(.*)</title>@', $response->content, $matches); $title = at($matches, 1); if ($e == 'checksum does not validate' || beginsWith($e, 'illegal character') || in_array($e, array('input to short', 'input too short'))) { throw new InvalidAddress("{$address} appears to be an invalid Bitcoin address"); } else { if (contains($e, 'cloudflare') && !empty($title)) { throw new NetworkError("CloudFlare-reported problem at blockchain.info: " . withoutPrefix($title, "blockchain.info | ")); } else { if (contains(strtolower($title), 'under maintenance')) { throw new NetworkError("Blockchain.info appears to be under maintenance"); } else { if (contains($e, "maximum concurrent requests reached")) { throw new NetworkError("Maximum concurrent requests to Blockchain.info reached"); } else { if (!empty($title)) { throw new NetworkError("Unknown error when attempting to check address-balance " . "for ({$address}) via blockchain.info: {$title}"); } else { if (trim($e) == '') { throw new NetworkError("Blockchain.info returned empty/content-less response"); } else { if ($e == 'lock wait timeout exceeded; try restarting transaction') { throw new NetworkError("Blockchain.info responded with error message about lock timeout"); } else { throw new \Exception("Unexpected result received from blockchain.info when " . "attempting to get balance of address {$address}: {$response->content}"); } } } } } } } } }
function isValid($password, $hash) { $unprefixedHash = withoutPrefix($hash, 'bcrypt'); return password_verify($password, $unprefixedHash); }