Browse Source

apply account balance on available

main
ghost 10 months ago
parent
commit
250c1dc137
  1. 184
      src/Controller/RoomController.php

184
src/Controller/RoomController.php

@ -626,85 +626,141 @@ class RoomController extends AbstractController @@ -626,85 +626,141 @@ class RoomController extends AbstractController
);
}
// Post has commission cost, send message to pending payment pool
// Post has commission cost
if ($this->getParameter('app.add.post.cost.kva'))
{
$time = time();
// Send message by account balance on available
if (
$username != 'anon'
&&
$client->getBalance(
$username,
$this->getParameter('app.pool.confirmations')
) >= $this->getParameter('app.add.post.cost.kva')
) {
if (
$txid = $client->kevaPut(
$request->get('namespace'),
sprintf(
'%s@%s',
time(), // @TODO save timestamp as part of key to keep timing actual for the chat feature
$username
),
$request->get('message')
)
)
{
// Send amount to profit address
$client->sendToAddress(
$this->getParameter('app.kevacoin.profit.address'),
$this->getParameter('app.add.post.cost.kva'),
$txid,
null,
true // subtract from amount
);
// Register event time
$memcached->set(
$memory,
time(),
(int) $this->getParameter('app.add.post.remote.ip.delay') // auto remove on cache expire
);
// Redirect back to room
return $this->redirectToRoute(
'room_namespace',
[
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'sign' => $request->get('sign'),
'error' => null,
'message' => null,
'_fragment' => 'latest'
]
);
}
}
$pool = new Pool();
// Send message to pending payment pool
else
{
$time = time();
$pool->setTime(
$time
);
$pool = new Pool();
$pool->setSent(
0
);
$pool->setTime(
$time
);
$pool->setExpired(
0
);
$pool->setSent(
0
);
$pool->setCost(
$this->getParameter('app.add.post.cost.kva')
);
$pool->setExpired(
0
);
$pool->setAddress(
$address = $client->getNewAddress(
$this->getParameter('app.kevacoin.pool.account')
)
);
$pool->setCost(
$this->getParameter('app.add.post.cost.kva')
);
$pool->setNamespace(
$request->get('namespace')
);
$pool->setAddress(
$address = $client->getNewAddress(
$this->getParameter('app.kevacoin.pool.account')
)
);
$pool->setKey(
sprintf(
'%s@%s',
$time,
$username
)
);
$pool->setNamespace(
$request->get('namespace')
);
$pool->setValue(
$request->get('message')
);
$pool->setKey(
sprintf(
'%s@%s',
$time,
$username
)
);
$entity->persist(
$pool
);
$pool->setValue(
$request->get('message')
);
$entity->flush();
$entity->persist(
$pool
);
// Register event time
$memcached->set(
$memory,
time(),
(int) $this->getParameter('app.add.post.remote.ip.delay') // auto remove on cache expire
);
$entity->flush();
// Redirect back to room
return $this->redirectToRoute(
'room_namespace',
[
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'sign' => $request->get('sign'),
'message' => null,
'error' => null,
'warning' => sprintf(
$translator->trans('Pending %s KVA to %s (expires at %s)'),
$this->getParameter('app.add.post.cost.kva'),
$address,
date(
'c',
$this->getParameter('app.pool.timeout') + $time
)
),
'_fragment' => 'latest'
]
);
// Register event time
$memcached->set(
$memory,
time(),
(int) $this->getParameter('app.add.post.remote.ip.delay') // auto remove on cache expire
);
// Redirect back to room
return $this->redirectToRoute(
'room_namespace',
[
'mode' => $request->get('mode'),
'namespace' => $request->get('namespace'),
'sign' => $request->get('sign'),
'message' => null,
'error' => null,
'warning' => sprintf(
$translator->trans('Pending %s KVA to %s (expires at %s)'),
$this->getParameter('app.add.post.cost.kva'),
$address,
date(
'c',
$this->getParameter('app.pool.timeout') + $time
)
),
'_fragment' => 'latest'
]
);
}
}
// Post has zero cost, send message to DHT

Loading…
Cancel
Save