internal payments.

This commit is contained in:
arcbtc
2020-09-02 11:10:48 -03:00
committed by fiatjaf
parent d4f957a5c8
commit c96b22664e
5 changed files with 117 additions and 18 deletions
+20 -11
View File
@@ -140,9 +140,9 @@ def get_wallet_payment(wallet_id: str, checking_id: str) -> Optional[Payment]:
with open_db() as db:
row = db.fetchone(
"""
SELECT payhash as checking_id, amount, fee, pending, memo, time
FROM apipayments
WHERE wallet = ? AND payhash = ?
SELECT id as checking_id, amount, fee, pending, memo, time
FROM apipayment
WHERE wallet = ? AND id = ?
""",
(wallet_id, checking_id),
)
@@ -179,7 +179,7 @@ def get_wallet_payments(
with open_db() as db:
rows = db.fetchall(
f"""
SELECT payhash as checking_id, amount, fee, pending, memo, time
SELECT id as checking_id, amount, fee, pending, memo, time
FROM apipayments
WHERE wallet = ? {clause}
ORDER BY time DESC
@@ -195,7 +195,7 @@ def delete_wallet_payments_expired(wallet_id: str, *, seconds: int = 86400) -> N
db.execute(
"""
DELETE
FROM apipayments WHERE wallet = ? AND pending = 1 AND time < strftime('%s', 'now') - ?
FROM apipayment WHERE wallet = ? AND pending = 1 AND time < strftime('%s', 'now') - ?
""",
(wallet_id, seconds),
)
@@ -206,15 +206,15 @@ def delete_wallet_payments_expired(wallet_id: str, *, seconds: int = 86400) -> N
def create_payment(
*, wallet_id: str, checking_id: str, amount: int, memo: str, fee: int = 0, pending: bool = True
*, wallet_id: str, checking_id: str, payment_hash: str, amount: int, memo: str, fee: int = 0, pending: bool = True
) -> Payment:
with open_db() as db:
db.execute(
"""
INSERT INTO apipayments (wallet, payhash, amount, pending, memo, fee)
VALUES (?, ?, ?, ?, ?, ?)
INSERT INTO apipayment (wallet, id, payment_hash, amount, pending, memo, fee)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(wallet_id, checking_id, amount, int(pending), memo, fee),
(wallet_id, checking_id, payment_hash, amount, int(pending), memo, fee),
)
new_payment = get_wallet_payment(wallet_id, checking_id)
@@ -225,9 +225,18 @@ def create_payment(
def update_payment_status(checking_id: str, pending: bool) -> None:
with open_db() as db:
db.execute("UPDATE apipayments SET pending = ? WHERE payhash = ?", (int(pending), checking_id,))
db.execute("UPDATE apipayment SET pending = ? WHERE id = ?", (int(pending), checking_id,))
def delete_payment(checking_id: str) -> None:
with open_db() as db:
db.execute("DELETE FROM apipayments WHERE payhash = ?", (checking_id,))
db.execute("DELETE FROM apipayment WHERE id = ?", (checking_id,))
def check_internal(payment_hash: str) -> None:
with open_db() as db:
row = db.fetchone("SELECT * FROM apipayment WHERE payment_hash = ?", (payment_hash,))
if not row:
return False
else:
return row['id']