Esempio n. 1
0
 public function testMoveAccounts()
 {
     // receiving a transaction adds TXOs
     $txo_repository = $this->app->make('App\\Repositories\\TXORepository');
     // setup monitors
     $payment_address_helper = app('PaymentAddressHelper');
     $receiving_address_one = $payment_address_helper->createSamplePaymentAddressWithoutInitialBalances(null, ['address' => '1JztLWos5K7LsqW5E78EASgiVBaCe6f7cD']);
     // create a second account
     $default_account = AccountHandler::getAccount($receiving_address_one);
     $account_1 = AccountHandler::createAccount($receiving_address_one, 'account1');
     // receive unconfirmed transactions
     $parsed_txs = $this->receiveUnconfirmedTransactions(1);
     $loaded_txos = $txo_repository->findAll();
     // check that it is in the default account
     $all_txos = $txo_repository->findAll();
     $loaded_txo = $all_txos[0];
     PHPUnit::assertEquals($default_account['id'], $loaded_txo['account_id']);
     // move the utxo to account 1
     TXOHandler::moveAccounts([$loaded_txo], $default_account, $account_1);
     $all_txos = $txo_repository->findAll();
     PHPUnit::assertCount(1, $all_txos);
     $loaded_txo = $all_txos[0];
     PHPUnit::assertEquals($account_1['id'], $loaded_txo['account_id']);
     // check findByAccount
     $loaded_txos = $txo_repository->findByAccount($default_account, true);
     PHPUnit::assertCount(0, $loaded_txos);
     $loaded_txos = $txo_repository->findByAccount($account_1, true);
     PHPUnit::assertCount(1, $loaded_txos);
     $loaded_txos = $txo_repository->findByAccount($account_1, false);
     PHPUnit::assertCount(0, $loaded_txos);
 }
 public function updateUTXOs($found_addresses, $parsed_tx, $confirmations, $block_seq, Block $block = null)
 {
     $sources = $parsed_tx['sources'] ? $parsed_tx['sources'] : [];
     // get all destinations, including change addresses
     $destinations = TXOHandler::extractAllDestinationsFromVouts($parsed_tx);
     // determine matched payment addresses
     foreach ($found_addresses['payment_addresses'] as $payment_address) {
         // Log::debug("upating account balances for payment address {$payment_address['address']}.  txid is {$parsed_tx['txid']}");
         if (in_array($payment_address['address'], $sources)) {
             // this address sent some UTXOs
             try {
                 TXOHandler::send($payment_address, $parsed_tx, $confirmations);
             } catch (Exception $e) {
                 EventLog::logError('utxo.send.error', $e, ['txid' => $parsed_tx['txid'], 'confirmations' => $confirmations]);
                 throw $e;
             }
         }
         if (in_array($payment_address['address'], $destinations)) {
             // this address received some UTXOs
             try {
                 TXOHandler::receive($payment_address, $parsed_tx, $confirmations);
             } catch (Exception $e) {
                 EventLog::logError('utxo.send.error', $e, ['txid' => $parsed_tx['txid'], 'confirmations' => $confirmations]);
                 throw $e;
             }
         }
     }
 }