public function testCurrentUtilsConversions()
 {
     // float value to satoshis
     PHPUnit::assertEquals(12300000000, CurrencyUtil::valueToSatoshis(123));
     PHPUnit::assertEquals(2100000000000000, CurrencyUtil::valueToSatoshis(21000000));
     PHPUnit::assertEquals(12311111119, CurrencyUtil::valueToSatoshis(123.111111189));
     // satoshis to float value
     PHPUnit::assertEquals(123, CurrencyUtil::satoshisToValue(12300000000));
     PHPUnit::assertEquals(21000000, CurrencyUtil::satoshisToValue(2100000000000000));
     PHPUnit::assertEquals(123.11111119, CurrencyUtil::satoshisToValue(12311111119));
     // satoshisToFormattedString
     PHPUnit::assertEquals('123', CurrencyUtil::satoshisToFormattedString(12300000000));
     PHPUnit::assertEquals('123.4', CurrencyUtil::satoshisToFormattedString(12340000000));
     PHPUnit::assertEquals('1,235.6', CurrencyUtil::satoshisToFormattedString(123560000000));
     // valueToFormattedString
     PHPUnit::assertEquals('1,234.5', CurrencyUtil::valueToFormattedString(1234.5));
 }
Пример #2
0
 protected function buildDifferences($xchain_map, $daemon_map)
 {
     // $items_to_add = [];
     // $items_to_delete = [];
     $differences = [];
     $any_differences = false;
     foreach ($daemon_map as $daemon_map_key => $dum) {
         if (!isset($xchain_map[$daemon_map_key]) and $daemon_map[$daemon_map_key] != 0) {
             // $items_to_add[] = [$daemon_map_key => $daemon_map[$daemon_map_key]];
             $differences[$daemon_map_key] = ['xchain' => '[NULL]', 'daemon' => $daemon_map[$daemon_map_key]];
             $any_differences = true;
         }
     }
     foreach ($xchain_map as $xchain_map_key => $dum) {
         if (!isset($daemon_map[$xchain_map_key])) {
             // $items_to_delete[] = $xchain_map_key;
             $differences[$xchain_map_key] = ['xchain' => $xchain_map[$xchain_map_key], 'daemon' => '[NULL]'];
             $any_differences = true;
         } else {
             if (CurrencyUtil::valueToFormattedString($daemon_map[$xchain_map_key]) != CurrencyUtil::valueToFormattedString($xchain_map[$xchain_map_key])) {
                 $differences[$xchain_map_key] = ['xchain' => $xchain_map[$xchain_map_key], 'daemon' => $daemon_map[$xchain_map_key]];
                 $any_differences = true;
             }
         }
     }
     // return ['any' => $any_differences, 'add' => $items_to_add, 'updates' => $differences, 'delete' => $items_to_delete];
     return ['any' => $any_differences, 'differences' => $differences];
 }
Пример #3
0
 protected function showAccount(Account $account, $show_ledger = false)
 {
     $ledger = app('App\\Repositories\\LedgerEntryRepository');
     $all_account_balances = $ledger->accountBalancesByAsset($account, null);
     $sep = str_repeat('-', 60) . "\n";
     $out = '';
     $out .= "{$sep}{$account['name']} ({$account['id']}, {$account['uuid']})\n{$sep}";
     if ($show_ledger) {
         $out .= "\n";
         $rows = [];
         $all_entries = $ledger->findByAccount($account);
         foreach ($all_entries as $entry) {
             $row = [];
             $row['date'] = $entry['created_at']->setTimezone('America/Chicago')->format('Y-m-d H:i:s T');
             $row['amount'] = CurrencyUtil::satoshisToFormattedString($entry['amount']);
             $row['asset'] = $entry['asset'];
             $row['type'] = LedgerEntry::typeIntegerToString($entry['type']);
             $row['txid'] = $entry['txid'];
             $rows[] = $row;
         }
         $renderer = new ArrayToTextTable($rows);
         $renderer->showHeaders(true);
         $out .= $renderer->render(true) . "\n";
     }
     // $out .= "BALANCES\n";
     $out .= "\n";
     foreach (LedgerEntry::allTypeStrings() as $type_string) {
         $out .= "{$type_string}:\n";
         if (isset($all_account_balances[$type_string]) and $all_account_balances[$type_string]) {
             foreach ($all_account_balances[$type_string] as $asset => $balance) {
                 $out .= "  {$asset}: " . CurrencyUtil::valueToFormattedString($balance) . "\n";
             }
         } else {
             $out .= "  [empty]\n";
         }
     }
     $out .= "\n{$sep}\n";
     return $out;
 }