implement withdraw profit crontab task

This commit is contained in:
ghost 2024-02-17 22:58:25 +02:00
parent be100a1420
commit d913d70ded
5 changed files with 58 additions and 4 deletions

13
.env
View File

@ -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 |

View File

@ -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

View File

@ -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.*",

View File

@ -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)%'

View File

@ -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
}
}