public function transfer($address_uuid, Guard $auth, AccountTransferRequest $request, APIControllerHelper $helper, PaymentAddressRepository $payment_address_repository, APICallRepository $api_call_repository) { $user = $auth->getUser(); if (!$user) { throw new Exception("User not found", 1); } $payment_address = $helper->requireResourceOwnedByUser($address_uuid, $user, $payment_address_repository); $params = $helper->getAttributesFromRequest($request); $api_call = $api_call_repository->create(['user_id' => $user['id'], 'details' => ['method' => 'api/v1/accounts/transfer/' . $address_uuid, 'args' => $params]]); try { if (isset($params['close']) and $params['close']) { AccountHandler::close($payment_address, $params['from'], $params['to'], $api_call); } else { if (isset($params['quantity']) and isset($params['asset'])) { AccountHandler::transfer($payment_address, $params['from'], $params['to'], $params['quantity'], $params['asset'], isset($params['txid']) ? $params['txid'] : null, $api_call); } else { // transfer all AccountHandler::transferAllByTIXD($payment_address, $params['from'], $params['to'], $params['txid'], $api_call); } } // done return $helper->buildJSONResponse([], 204); } catch (AccountException $e) { return $helper->buildJSONResponse(['message' => $e->getMessage(), 'errorName' => $e->getErrorName()], $e->getStatusCode()); } catch (HttpException $e) { return $helper->buildJSONResponse(['message' => $e->getMessage()], $e->getStatusCode()); } }
/** * Execute the console command. * * @return mixed */ public function fire() { DB::transaction(function () { $payment_address_repo = app('App\\Repositories\\PaymentAddressRepository'); $account_repository = app('App\\Repositories\\AccountRepository'); $payment_address_uuid = $this->input->getArgument('payment-address-uuid'); $payment_address = $payment_address_repo->findByUuid($payment_address_uuid); if (!$payment_address) { throw new Exception("Payment address not found", 1); } $account_name = $this->input->getArgument('account-name'); $api_call = app('App\\Repositories\\APICallRepository')->create(['user_id' => $this->getConsoleUser()['id'], 'details' => ['command' => 'xchain:close-account', 'args' => ['payment_address' => $payment_address['uuid']]]]); $from_account = $account_repository->findByName($account_name, $payment_address['id']); if (!$from_account) { $this->error("Account {$from_account} not found."); return; } $this->comment('closing account ' . $account_name); AccountHandler::close($payment_address, $account_name, 'default', $api_call); }); $this->info('done'); }
protected function processTransferEvent($event) { // type: transfer // from: default // to: account1 // quantity: 300 // asset: LTBCOIN // transferType: unconfirmed // txid: cf9d9f4d53d36d9d34f656a6d40bc9dc739178e6ace01bcc42b4b9ea2cbf6741 // get the account (first one) // $account_repository = app('App\Repositories\AccountRepository'); $account = app('App\\Repositories\\AccountRepository')->findAll()->first(); $payment_address = app('App\\Repositories\\PaymentAddressRepository')->findById($account['payment_address_id']); $user = app('App\\Repositories\\UserRepository')->findById($account['user_id']); $txid = isset($event['txid']) ? $event['txid'] : null; $api_call = app('APICallHelper')->newSampleAPICall($user); if (isset($event['close']) and $event['close']) { AccountHandler::close($payment_address, $event['from'], $event['to'], $api_call); } else { AccountHandler::transfer($payment_address, $event['from'], $event['to'], $event['quantity'], $event['asset'], $txid, $api_call); } }