Browse Source

use profit address only to withdraw funds

main
ghost 10 months ago
parent
commit
5d5843cce5
  1. 5
      .env
  2. 1
      config/services.yaml
  3. 24
      src/Controller/CrontabController.php
  4. 6
      src/Controller/RoomController.php
  5. 18
      src/Controller/UserController.php

5
.env

@ -39,7 +39,7 @@ APP_KEVACOIN_PORT=9992 @@ -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 @@ -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

1
config/services.yaml

@ -15,6 +15,7 @@ parameters: @@ -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)%'

24
src/Controller/CrontabController.php

@ -62,7 +62,7 @@ class CrontabController extends AbstractController @@ -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 @@ -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 @@ -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
)
);
}
}

6
src/Controller/RoomController.php

@ -650,7 +650,9 @@ class RoomController extends AbstractController @@ -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 @@ -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();

18
src/Controller/UserController.php

@ -506,7 +506,7 @@ class UserController extends AbstractController @@ -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 @@ -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 @@ -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
);
}
}
Loading…
Cancel
Save