use profit address only to withdraw funds

This commit is contained in:
ghost 2024-02-18 02:16:05 +02:00
parent 1c4930be38
commit 5d5843cce5
5 changed files with 28 additions and 26 deletions

5
.env
View File

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

View File

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

View File

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

View File

@ -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();

View File

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