Browse Source

implement withdraw profit crontab task

main
ghost 4 months ago
parent
commit
d913d70ded
  1. 13
      .env
  2. 3
      README.md
  3. 2
      composer.json
  4. 3
      config/services.yaml
  5. 41
      src/Controller/CrontabController.php

13
.env

@ -39,14 +39,23 @@ APP_KEVACOIN_PORT=9992 @@ -39,14 +39,23 @@ APP_KEVACOIN_PORT=9992
APP_KEVACOIN_USERNAME=EDIT_ME
APP_KEVACOIN_PASSWORD=EDIT_ME
# Share with other some mining pool to get coins
# KevaCoin address to withdraw instance profit (empty to disable)
APP_KEVACOIN_WITHDRAW_PROFIT_ADDRESS=
# Keep at least n KVA on balance (for app transactions)
APP_KEVACOIN_WITHDRAW_BALANCE_MIN_KVA=1
# Withdraw funds starting from (do not keep amount greater this value)
APP_KEVACOIN_WITHDRAW_BALANCE_MAX_KVA=10
# 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
# Explorer URL
APP_KEVACOIN_EXPLORER_URL=https://keva.one/explorer/address/
# Address to receive kevacoin powers (make others able to fill node balance)
# Address to receive kevacoin donations (make others able to fill node balance)
APP_KEVACOIN_BOOST_ADDRESS=EDIT_ME
# Pinned room namespaces, separated with |

3
README.md

@ -40,7 +40,8 @@ All messages related to their room `namespace`. @@ -40,7 +40,8 @@ All messages related to their room `namespace`.
* `cd webapp`
* `composer update`
* `php bin/console doctrine:schema:update --force`
* `* * * * * /usr/bin/wget -q --spider http://../crontab/pool > /dev/null 2>&1`
* `* * * * * /usr/bin/wget -q --spider http://../crontab/pool > /dev/null 2>&1` - process transactions pool
* `0 0 * * * /usr/bin/wget -q --spider http://../crontab/withdraw > /dev/null 2>&1` - withdraw node profit
## Update

2
composer.json

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.0",
"jdenticon/jdenticon": "^1.0",
"kevachat/kevacoin": "^1.7",
"kevachat/kevacoin": "dev-main",
"league/commonmark": "^2.4",
"symfony/console": "7.0.*",
"symfony/dotenv": "7.0.*",

3
config/services.yaml

@ -15,6 +15,9 @@ parameters: @@ -15,6 +15,9 @@ parameters:
app.kevacoin.port: '%env(APP_KEVACOIN_PORT)%'
app.kevacoin.username: '%env(APP_KEVACOIN_USERNAME)%'
app.kevacoin.password: '%env(APP_KEVACOIN_PASSWORD)%'
app.kevacoin.withdraw.profit.address: '%env(APP_KEVACOIN_WITHDRAW_PROFIT_ADDRESS)%'
app.kevacoin.withdraw.balance.min.kva: '%env(APP_KEVACOIN_WITHDRAW_BALANCE_MIN_KVA)%'
app.kevacoin.withdraw.balance.max.kva: '%env(APP_KEVACOIN_WITHDRAW_BALANCE_MAX_KVA)%'
app.kevacoin.room.namespaces.pinned: '%env(APP_KEVACOIN_ROOM_NAMESPACES_PINNED)%'
app.kevacoin.room.namespaces.readonly: '%env(APP_KEVACOIN_ROOM_NAMESPACES_READONLY)%'
app.kevacoin.room.namespace.default: '%env(APP_KEVACOIN_ROOM_NAMESPACE_DEFAULT)%'

41
src/Controller/CrontabController.php

@ -138,4 +138,45 @@ class CrontabController extends AbstractController @@ -138,4 +138,45 @@ class CrontabController extends AbstractController
return new Response(); // @TODO
}
#[Route(
'/crontab/withdraw',
name: 'crontab_withdraw',
methods:
[
'GET'
]
)]
public function withdraw(): Response
{
// Connect kevacoin
$client = new \Kevachat\Kevacoin\Client(
$this->getParameter('app.kevacoin.protocol'),
$this->getParameter('app.kevacoin.host'),
$this->getParameter('app.kevacoin.port'),
$this->getParameter('app.kevacoin.username'),
$this->getParameter('app.kevacoin.password')
);
// Withdraw profit
if ($this->getParameter('app.kevacoin.withdraw.profit.address'))
{
if ($balance = $client->getBalance())
{
if ($balance - $this->getParameter('app.kevacoin.withdraw.balance.min.kva') >= $this->getParameter('app.kevacoin.withdraw.balance.max.kva'))
{
$client->sendToAddress(
$this->getParameter('app.kevacoin.withdraw.profit.address'),
round(
$balance - $this->getParameter('app.kevacoin.withdraw.balance.min.kva'),
8
),
'crontab/withdraw'
);
}
}
}
return new Response(); // @TODO
}
}
Loading…
Cancel
Save