From 5d5843cce530dfe6166269a0c104545ec9f840bd Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 18 Feb 2024 02:16:05 +0200 Subject: [PATCH] use profit address only to withdraw funds --- .env | 5 ++++- config/services.yaml | 1 + src/Controller/CrontabController.php | 24 +++++++++++++++++------- src/Controller/RoomController.php | 6 ++++-- src/Controller/UserController.php | 18 ++---------------- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/.env b/.env index 9dcb3e7..3d23a4f 100644 --- a/.env +++ b/.env @@ -39,7 +39,7 @@ APP_KEVACOIN_PORT=9992 APP_KEVACOIN_USERNAME=EDIT_ME APP_KEVACOIN_PASSWORD=EDIT_ME -# Separated profit account (KevaCoin wallet) +# Separated profit account (to withdraw profit funds collected) APP_KEVACOIN_PROFIT_ACCOUNT=PROFIT # Address to receive KevaCoin donations @@ -54,6 +54,9 @@ APP_KEVACOIN_PROFIT_WITHDRAW_BALANCE_MIN_KVA=1 # Withdraw funds starting from (do not keep amount greater this value) APP_KEVACOIN_PROFIT_WITHDRAW_BALANCE_MAX_KVA=10 +# Separated pool account (to generate tmp addresses e.g. guest publications) +APP_KEVACOIN_POOL_ACCOUNT=POOL + # Share with other some mining pool to get free coins APP_KEVACOIN_MINE_POOL_URL=https://miningpoolstats.stream/kevacoin APP_KEVACOIN_MINE_SOLO_URL=https://kevacoin.org/tutorial_solo_mining.html diff --git a/config/services.yaml b/config/services.yaml index c454425..f768d36 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -15,6 +15,7 @@ parameters: app.kevacoin.port: '%env(APP_KEVACOIN_PORT)%' app.kevacoin.username: '%env(APP_KEVACOIN_USERNAME)%' app.kevacoin.password: '%env(APP_KEVACOIN_PASSWORD)%' + app.kevacoin.pool.account: '%env(APP_KEVACOIN_POOL_ACCOUNT)%' app.kevacoin.profit.account: '%env(APP_KEVACOIN_PROFIT_ACCOUNT)%' app.kevacoin.profit.address: '%env(APP_KEVACOIN_PROFIT_ADDRESS)%' app.kevacoin.profit.withdraw.address: '%env(APP_KEVACOIN_PROFIT_WITHDRAW_ADDRESS)%' diff --git a/src/Controller/CrontabController.php b/src/Controller/CrontabController.php index bc39d2b..b62f31b 100644 --- a/src/Controller/CrontabController.php +++ b/src/Controller/CrontabController.php @@ -62,7 +62,7 @@ class CrontabController extends AbstractController if ($client->getReceivedByAddress($pool->getAddress(), $this->getParameter('app.pool.confirmations')) >= $pool->getCost()) { // Check physical wallet balance - if ($client->getBalance() <= $pool->getCost()) + if ($client->getBalance($this->getParameter('app.kevacoin.pool.account')) <= $pool->getCost()) { break; // @TODO exception } @@ -115,6 +115,18 @@ class CrontabController extends AbstractController $entity->flush(); } } + + // Send this amount to profit account + $client->sendToAddress( + $this->getParameter('app.kevacoin.profit.address'), + $pool->getCost(), + sprintf( + '#%d', + $pool->getId() + ), + null, + true // subtract from amount + ); } // Record expired @@ -161,19 +173,17 @@ class CrontabController extends AbstractController // Withdraw profit if ($this->getParameter('app.kevacoin.profit.withdraw.address')) { - if ($balance = $client->getBalance()) + if ($balance = $client->getBalance($this->getParameter('app.kevacoin.profit.account'))) { if ($balance - $this->getParameter('app.kevacoin.profit.withdraw.balance.min.kva') >= $this->getParameter('app.kevacoin.profit.withdraw.balance.max.kva')) { - $client->sendToAddress( + $client->sendFrom( + $this->getParameter('app.kevacoin.profit.account'), $this->getParameter('app.kevacoin.profit.withdraw.address'), round( $balance - $this->getParameter('app.kevacoin.profit.withdraw.balance.min.kva'), 8 - ), - 'crontab/withdraw', - null, - true + ) ); } } diff --git a/src/Controller/RoomController.php b/src/Controller/RoomController.php index f5cfa59..f50adb4 100644 --- a/src/Controller/RoomController.php +++ b/src/Controller/RoomController.php @@ -650,7 +650,9 @@ class RoomController extends AbstractController ); $pool->setAddress( - $address = $client->getNewAddress() + $address = $client->getNewAddress( + $this->getParameter('app.kevacoin.pool.account') + ) ); $pool->setNamespace( @@ -961,7 +963,7 @@ class RoomController extends AbstractController // Room registration has commission cost, send to pending payment pool if ($this->getParameter('app.add.room.cost.kva')) { - if ($address = $client->getNewAddress()) + if ($address = $client->getNewAddress($this->getParameter('app.kevacoin.pool.account'))) { $time = time(); diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 0d33d4b..99ca6fc 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -506,7 +506,7 @@ class UserController extends AbstractController // User registration has commission cost, send message to pending payment pool if ($this->getParameter('app.add.user.cost.kva')) { - if ($address = $client->getNewAddress()) + if ($address = $client->getNewAddress($this->getParameter('app.kevacoin.pool.account'))) { $time = time(); @@ -577,7 +577,7 @@ class UserController extends AbstractController } // Auth success, add user to DB - if (!$this->_add($client, $namespace, $username, $hash)) + if (!$client->kevaPut($namespace, $username, $hash)) { return $this->redirectToRoute( 'user_add', @@ -920,18 +920,4 @@ class UserController extends AbstractController return null; } - - private function _add( - \Kevachat\Kevacoin\Client $client, - string $namespace, - string $username, - string $hash - ): ?string - { - return $client->kevaPut( - $namespace, - $username, - $hash - ); - } } \ No newline at end of file