public function addressBalance() { $address = $this->context->takeNextPathComponent(); $fiveSecs = Time\readInterval('5 seconds'); try { return $this->textResponse(Bitcoin\getBalance($address, 'BTC', $maxCacheAge = $fiveSecs)); } catch (Bitcoin\InvalidAddress $_) { return $this->textResponse('Invalid Bitcoin address', $code = 400); } }
function testGetBalanceUsesLocallyCachedValueWhenAppropriate() { $address = '1K7dyLY6arFRXBidQhrtnyqksqJZdj2F37'; $actualBalance = BlockchainDotInfo\getBalanceInSatoshis($address); $cachedBalance = $actualBalance + 1000; DB\delete('bitcoin_addresses', 'address = ?', array($address)); DB\insertOne('bitcoin_addresses', array('address' => $address, 'satoshis' => $cachedBalance, 'updated_at' => new DateTime('now'))); $balance = Bitcoin\getBalance($address, null); assertEqual($cachedBalance, $balance->numSatoshis); assertEqual($cachedBalance / Bitcoin\satoshisPerBTC(), $balance->numBTC); }
function progress(RequestContext $c) { try { $w = $this->takeWidgetFromURI($c); $fiveSecs = Time\readInterval('5 seconds'); $w->updateBalance(Bitcoin\getBalance($w->bitcoinAddress, $maxCacheAge = $fiveSecs)); return $this->textResponse($w->progressPercent); } catch (\SpareParts\WebClient\NetworkError $e) { Log\notice("Caught " . get_class($e) . " when attempting to check Bitcoin-address balance: " . $e->getMessage()); return $this->textResponse("Network error occurred when trying to check address balance", 503); } }
public function populateFromArray(array $a) { foreach ($a as $key => $val) { if (is_string($key)) { $this->{$key} = $val; } } $this->ending = new \DateTime($a['ending']); $this->bitcoinAddress = $a['address']; $this->id = (int) $a['id']; $this->uriID = $a['uri_id']; $this->ownerID = (int) $a['owner_id']; $this->countryCode = $a['country']; $this->color = in_array($a['color'], allowedColors()) ? $a['color'] : 'white'; //$this->satoshisRaised = $a['satoshis']; $this->goalAmnt = new Amount($this->currency, $a['goal']); $this->updateBalance(Bitcoin\getBalance($this->bitcoinAddress)); return $this; }