Loading Core/Blockchain/Wallets/OffChain/Transactions.php +31 −2 Original line number Original line Diff line number Diff line Loading @@ -98,6 +98,9 @@ class Transactions if ($balance->add($this->amount)->lt(0)) { if ($balance->add($this->amount)->lt(0)) { throw new \Exception('Not enough funds'); throw new \Exception('Not enough funds'); } } if ($this->countOffchainBoosts(time() - (60*60*24), time()) > 10) { throw new \Exception('Maximum of 10 offchain tokens per day exceeded.'); } $transaction = new Transaction(); $transaction = new Transaction(); Loading Loading @@ -200,7 +203,6 @@ class Transactions } } // Receiver Transaction // Receiver Transaction $receiverTxGuid = $this->guid->build(); $receiverTxGuid = $this->guid->build(); $receiverTx = new Transaction(); $receiverTx = new Transaction(); Loading Loading @@ -274,4 +276,31 @@ class Transactions return (string) BigNumber::toPlain($value, 18); return (string) BigNumber::toPlain($value, 18); } } /** * Counts the amount of offchain boosts for the user. * * @param integer from - unix timestamp 'from' time. * @param integer to - unix timestamp 'to' time. * @return integer the amount of offchain boosts. */ private function countOffchainBoosts($from, $to) { $repo = Di::_()->get('Blockchain\Transactions\Repository'); $opts = [ 'timestamp' => [ 'gte' => $from, 'lte' => $to, ], 'user_guid' => $this->user->guid, 'offset' => 0, ]; $result = $repo->getList($opts); $result = array_filter($result['transactions'], function(Transaction $transaction) { return $transaction->getContract() === 'offchain:boost'; }); return array_reduce($result, function($acc, $transaction) { $acc -= $transaction->getAmount() / 1000000000000000000; return $acc; }); } } } Loading
Core/Blockchain/Wallets/OffChain/Transactions.php +31 −2 Original line number Original line Diff line number Diff line Loading @@ -98,6 +98,9 @@ class Transactions if ($balance->add($this->amount)->lt(0)) { if ($balance->add($this->amount)->lt(0)) { throw new \Exception('Not enough funds'); throw new \Exception('Not enough funds'); } } if ($this->countOffchainBoosts(time() - (60*60*24), time()) > 10) { throw new \Exception('Maximum of 10 offchain tokens per day exceeded.'); } $transaction = new Transaction(); $transaction = new Transaction(); Loading Loading @@ -200,7 +203,6 @@ class Transactions } } // Receiver Transaction // Receiver Transaction $receiverTxGuid = $this->guid->build(); $receiverTxGuid = $this->guid->build(); $receiverTx = new Transaction(); $receiverTx = new Transaction(); Loading Loading @@ -274,4 +276,31 @@ class Transactions return (string) BigNumber::toPlain($value, 18); return (string) BigNumber::toPlain($value, 18); } } /** * Counts the amount of offchain boosts for the user. * * @param integer from - unix timestamp 'from' time. * @param integer to - unix timestamp 'to' time. * @return integer the amount of offchain boosts. */ private function countOffchainBoosts($from, $to) { $repo = Di::_()->get('Blockchain\Transactions\Repository'); $opts = [ 'timestamp' => [ 'gte' => $from, 'lte' => $to, ], 'user_guid' => $this->user->guid, 'offset' => 0, ]; $result = $repo->getList($opts); $result = array_filter($result['transactions'], function(Transaction $transaction) { return $transaction->getContract() === 'offchain:boost'; }); return array_reduce($result, function($acc, $transaction) { $acc -= $transaction->getAmount() / 1000000000000000000; return $acc; }); } } }