public function testSendRequest() { if (!$this->CONNECTION_IS_SET) { $this->markTestIncomplete("Authorization credentials must be defined as environment vars."); } $xcpd_client = new Client($this->CONNECTION_STRING, $this->RPC_USER, $this->RPC_PASSWORD); $response_data = $xcpd_client->get_block_info(['block_index' => 312600]); // echo json_encode($response_data, 192)."\n"; PHPUnit::assertNotEmpty($response_data); PHPUnit::assertEquals('312600', $response_data['block_index']); }
/** * Get all balances for an address * * @param int $id * @return Response */ public function show(Client $xcpd_client, BitcoinPayer $bitcoin_payer, Cache $asset_info_cache, $address) { if (!AddressValidator::isValid($address)) { $message = "The address {$address} was not valid"; EventLog::logError('error.getBalance', ['address' => $address, 'message' => $message]); return new JsonResponse(['message' => $message], 500); } $balances = $xcpd_client->get_balances(['filters' => ['field' => 'address', 'op' => '==', 'value' => $address]]); // and get BTC balance too $btc_float_balance = $bitcoin_payer->getBalance($address); $balances = array_merge([['asset' => 'BTC', 'quantity' => $btc_float_balance]], $balances); $out = ['balances' => [], 'balancesSat' => []]; foreach ($balances as $balance) { $asset_name = $balance['asset']; if ($asset_name == 'BTC') { // BTC quantity is a float $quantity_float = floatval($balance['quantity']); $quantity_sat = CurrencyUtil::valueToSatoshis($balance['quantity']); } else { // determine quantity based on asset info $is_divisible = $asset_info_cache->isDivisible($asset_name); if ($is_divisible) { $quantity_float = CurrencyUtil::satoshisToValue($balance['quantity']); $quantity_sat = intval($balance['quantity']); } else { // non-divisible assets don't use satoshis $quantity_float = floatval($balance['quantity']); $quantity_sat = CurrencyUtil::valueToSatoshis($balance['quantity']); } } $out['balances'][$asset_name] = $quantity_float; $out['balancesSat'][$asset_name] = $quantity_sat; } ksort($out['balances']); ksort($out['balancesSat']); return json_encode($out); }