def add(self, payment: Payment) -> int: if payment.status is not PaymentStatus.awaiting: raise RuntimeError("Invalid payment status: {}".format( payment.status)) log.info("Payment {:.6} to {:.6} ({:.6f})".format( payment.subtask, encode_hex(payment.payee), payment.value / denoms.ether)) if not payment.processed_ts: payment.processed_ts = get_timestamp() payment.save() self._awaiting.add(payment) self._gntb_reserved += payment.value log.info("GNTB reserved %.6f", self._gntb_reserved / denoms.ether) return payment.processed_ts
def test_create(self): p = Payment(payee="DEF", subtask="xyz", value=5, status=PaymentStatus.awaiting) self.assertEquals(p.save(force_insert=True), 1) with self.assertRaises(IntegrityError): Payment.create(payee="DEF", subtask="xyz", value=5, status=PaymentStatus.awaiting) Payment.create(payee="DEF", subtask="xyz2", value=4, status=PaymentStatus.confirmed) Payment.create(payee="DEF2", subtask="xyz4", value=5, status=PaymentStatus.sent) self.assertEqual(3, len([payment for payment in Payment.select()]))