Example #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->comment('Sweeping account');
     $address_sender = app('App\\Blockchain\\Sender\\PaymentAddressSender');
     $payment_address_repo = app('App\\Repositories\\PaymentAddressRepository');
     $payment_address = $payment_address_repo->findByUuid($this->input->getArgument('payment-address-id'));
     if (!$payment_address) {
         throw new Exception("Payment address not found", 1);
     }
     $destination = $this->input->getArgument('destination-address');
     if (!AddressValidator::isValid($destination)) {
         throw new Exception("The destination address was invalid", 1);
     }
     $float_fee = $this->input->getOption('fee');
     $api_call = app('App\\Repositories\\APICallRepository')->create(['user_id' => $this->getConsoleUser()['id'], 'details' => ['command' => 'xchain:sweep-address', 'args' => ['payment_address' => $payment_address['uuid'], 'destination' => $destination, 'fee' => $float_fee]]]);
     // get lock
     $lock_acquired = AccountHandler::acquirePaymentAddressLock($payment_address);
     // do the send
     list($txid, $float_balance_sent) = $address_sender->sweepAllAssets($payment_address, $destination, $float_fee);
     // clear all balances from all accounts
     AccountHandler::zeroAllBalances($payment_address, $api_call);
     // release the account lock
     if ($lock_acquired) {
         AccountHandler::releasePaymentAddressLock($payment_address);
     }
     $this->comment('done');
 }
 public function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->after(function () use($validator) {
         // validate destinations
         $destinations = $this->json('destinations');
         if ($destinations) {
             if (is_array($destinations)) {
                 $offset = 0;
                 foreach ($destinations as $destination) {
                     if (!isset($destination['address']) or !isset($destination['amount'])) {
                         $validator->errors()->add('destinations', 'Missing address or amount for destination ' . ($offset + 1) . '.');
                         continue;
                     }
                     if (!AddressValidator::isValid($destination['address'])) {
                         $validator->errors()->add('destinations', 'The address for destination ' . ($offset + 1) . ' was invalid.');
                     }
                     if (!is_numeric($destination['amount']) or CurrencyUtil::valueToSatoshis($destination['amount']) <= 0) {
                         $validator->errors()->add('destinations', 'The amount for destination ' . ($offset + 1) . ' was invalid.');
                     }
                     ++$offset;
                 }
             } else {
                 $validator->errors()->add('destinations', 'The destinations were invalid.');
             }
         }
     });
     return $validator;
 }
Example #3
0
 public function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->after(function () use($validator) {
         // validate destination
         $destination = $this->json('destination');
         if (!AddressValidator::isValid($destination)) {
             $validator->errors()->add('destination', 'The destination was invalid.');
         }
     });
     return $validator;
 }
Example #4
0
 public function getValidatorInstance()
 {
     $validator = parent::getValidatorInstance();
     $validator->after(function () use($validator) {
         // validate address
         $address = $this->json('address');
         Log::info("\$address={$address} AddressValidator::isValid({$address})=" . AddressValidator::isValid($address));
         if (!AddressValidator::isValid($address)) {
             $validator->errors()->add('address', 'The address was invalid.');
         }
     });
     return $validator;
 }
Example #5
0
 /**
  * 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);
 }
Example #6
0
 public function sampleData_validate($address)
 {
     Log::debug("\$address=" . json_encode($address, 192));
     return ['result' => \LinusU\Bitcoin\AddressValidator::isValid($address), 'is_mine' => false];
 }