Ejemplo n.º 1
0
 public function createSamplePaymentAddress($user = null, $override_vars = [], $initial_balances = null)
 {
     $new_address = $this->createSamplePaymentAddressWithoutDefaultAccount($user, $override_vars);
     // also create a default account for this address
     AccountHandler::createDefaultAccount($new_address);
     // add initial balances
     if ($initial_balances === null) {
         $initial_balances = ['TOKENLY' => 100, 'BTC' => 1];
     }
     if ($initial_balances) {
         $this->addBalancesToPaymentAddressAccount($initial_balances, $new_address);
     }
     return $new_address;
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(APIControllerHelper $helper, CreatePaymentAddressRequest $request, PaymentAddressRepository $payment_address_respository, Guard $auth)
 {
     $user = $auth->getUser();
     if (!$user) {
         throw new Exception("User not found", 1);
     }
     $attributes = $request->only(array_keys($request->rules()));
     $attributes['user_id'] = $user['id'];
     $address = $payment_address_respository->create($attributes);
     EventLog::log('paymentAddress.created', $address->toArray());
     // create a default account
     AccountHandler::createDefaultAccount($address);
     return $helper->transformResourceForOutput($address);
 }
Ejemplo n.º 3
0
 protected function addPaymentAddresses($addresses)
 {
     if (!$addresses) {
         return;
     }
     foreach ($addresses as $raw_attributes) {
         $attributes = $raw_attributes;
         unset($attributes['accountBalances']);
         unset($attributes['rawAccountBalances']);
         $payment_address = $this->payment_address_repository->createWithUser($this->getSampleUser(), $this->payment_address_helper->sampleVars($attributes));
         // create a default account
         AccountHandler::createDefaultAccount($payment_address);
         // assign balances
         $ledger_entry_repository = app('App\\Repositories\\LedgerEntryRepository');
         $account_repository = app('App\\Repositories\\AccountRepository');
         $default_account = $account_repository->findByName('default', $payment_address['id']);
         $btc_balance = 0;
         if (isset($raw_attributes['accountBalances'])) {
             foreach ($raw_attributes['accountBalances'] as $asset => $balance) {
                 $ledger_entry_repository->addCredit($balance, $asset, $default_account, LedgerEntry::CONFIRMED, LedgerEntry::DIRECTION_OTHER, 'testtxid');
                 if ($asset == 'BTC') {
                     $btc_balance += $balance;
                 }
             }
         }
         if (isset($raw_attributes['rawAccountBalances'])) {
             foreach ($raw_attributes['rawAccountBalances'] as $type_string => $balances) {
                 foreach ($balances as $asset => $balance) {
                     $ledger_entry_repository->addCredit($balance, $asset, $default_account, LedgerEntry::typeStringToInteger($type_string), LedgerEntry::DIRECTION_OTHER, 'testtxid');
                     if ($asset == 'BTC') {
                         $btc_balance += $balance;
                     }
                 }
             }
         }
         // add UTXOs
         if ($btc_balance > 0) {
             $this->payment_address_helper->addUTXOToPaymentAddress($btc_balance, $payment_address);
         }
     }
 }