From 250c1dc1377f7353fcc4864f17ed7ba7c6bedd6d Mon Sep 17 00:00:00 2001 From: ghost Date: Sun, 18 Feb 2024 03:32:20 +0200 Subject: [PATCH] apply account balance on available --- src/Controller/RoomController.php | 184 +++++++++++++++++++----------- 1 file changed, 120 insertions(+), 64 deletions(-) diff --git a/src/Controller/RoomController.php b/src/Controller/RoomController.php index f50adb4..de95407 100644 --- a/src/Controller/RoomController.php +++ b/src/Controller/RoomController.php @@ -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