Skip to content

Commit

Permalink
Merge pull request #1 from nodeless-io/dev-disableSettings
Browse files Browse the repository at this point in the history
Disable Registration, Fee Collection and Withdrawals by .env Setting
  • Loading branch information
utxo-one authored Jan 24, 2024
2 parents b8c7b2a + e8a56c9 commit b1daada
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

CHARGE_FEES=false
DISABLE_WITHDRAWALS=true
DISABLE_REGISTRATION=true

LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
Expand Down
23 changes: 16 additions & 7 deletions app/Console/Commands/BatchOnchainWithdrawals.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class BatchOnchainWithdrawals extends Command
*/
public function handle()
{

if (env('DISABLE_WITHDRAWALS') == true) {
$this->info('Withdrawals are disabled, exiting');
return Command::SUCCESS;
}

$onchainUsers = User::where('default_withdrawal_type', WithdrawalType::ONCHAIN)->where('onchain_address', '!=', null)->get();

$withdrawalUsers = $onchainUsers
Expand Down Expand Up @@ -139,13 +145,16 @@ public function handle()
'user_id' => $user->id,
]);

$withdrawal->transaction()->create([
'amount' => $fee,
'user_id' => $user->id,
'type' => TransactionType::DEBIT,
'status' => TransactionStatus::SETTLED,
'is_fee' => true,
]);
if (env('CHARGE_FEES') == true) {
$withdrawal->transaction()->create([
'amount' => $fee,
'user_id' => $user->id,
'type' => TransactionType::DEBIT,
'status' => TransactionStatus::SETTLED,
'is_fee' => true,
]);
}


if ($user->notification_setting !== null && $user->notification_setting->withdrawal_success == true) {
Notification::send($user, new WithdrawalSuccessNotification($withdrawal));
Expand Down
6 changes: 6 additions & 0 deletions app/Console/Commands/WithdrawBalanceToLightning.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class WithdrawBalanceToLightning extends Command
*/
public function handle()
{

if (env('DISABLE_WITHDRAWALS') == true) {
$this->info('Withdrawals are disabled, exiting');
return Command::SUCCESS;
}

$users = User::where('default_withdrawal_type', WithdrawalType::LIGHTNING->value)
->where('auto_withdraw', true)
->get();
Expand Down
7 changes: 7 additions & 0 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class RegisteredUserController extends Controller
*/
public function store(Request $request)
{

if (env('DISABLE_REGISTRATION') == true) {
return response()->json([
'message' => 'Registration is disabled',
], 422);
}

$request->validate([
'email' => ['required', 'string', 'email', 'max:255', 'unique:' . User::class],
'password' => ['required', 'max:100', 'confirmed', Rules\Password::defaults()],
Expand Down
10 changes: 10 additions & 0 deletions app/Jobs/RecordTransactionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ private function recordLightningTransaction($event)
}
}

if (env('CHARGE_FEES') == false) {
return;
}

$debit = $event->bitcoinable->transaction()->create([
'user_id' => $event->bitcoinable->user()->first()->id,
'amount' => $this->getFee($amountPaid),
Expand Down Expand Up @@ -161,6 +165,12 @@ private function recordOnchainTransaction($event)
'type' => TransactionType::CREDIT,
]);

Log::info('Created credit transaction ' . $credit->uuid . ' for ' . $event->bitcoinable->uuid);

if (env('CHARGE_FEES') == false) {
return;
}

$debit = $event->bitcoinable->transaction()->create([
'user_id' => $event->bitcoinable->user()->first()->id,
'amount' => $fee,
Expand Down
5 changes: 5 additions & 0 deletions app/Jobs/Withdrawal/DispatchLightningWithdrawalsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public function __construct(Collection $users)
*/
public function handle()
{
if (env('DISABLE_WITHDRAWALS') == true) {
Log::info('Withdrawals are disabled, exiting');
return;
}

foreach ($this->users as $user) {
if (
$user->lightning_address &&
Expand Down

0 comments on commit b1daada

Please sign in to comment.