From 2ec91dbca70fde7109afb216b1c30e5c1a8962d2 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Sat, 17 Oct 2020 10:20:49 -0400 Subject: [PATCH] send dict instead of Account and PubKey objects when adding keys --- lbry/db/database.py | 10 +++++++++- lbry/db/queries/address.py | 20 +++----------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/lbry/db/database.py b/lbry/db/database.py index 03d4685d7..829ed8ed5 100644 --- a/lbry/db/database.py +++ b/lbry/db/database.py @@ -290,7 +290,15 @@ class Database: return address async def add_keys(self, account, chain, pubkeys): - return await self.run(q.add_keys, account, chain, pubkeys) + return await self.run(q.add_keys, [{ + 'account': account.id, + 'address': k.address, + 'chain': chain, + 'pubkey': k.pubkey_bytes, + 'chain_code': k.chain_code, + 'n': k.n, + 'depth': k.depth + } for k in pubkeys]) async def get_transactions(self, **constraints) -> Result[Transaction]: return await self.fetch_result(q.get_transactions, **constraints) diff --git a/lbry/db/queries/address.py b/lbry/db/queries/address.py index c2f194cb1..5873384e2 100644 --- a/lbry/db/queries/address.py +++ b/lbry/db/queries/address.py @@ -58,21 +58,7 @@ def get_all_addresses(self): return context().execute(select(PubkeyAddress.c.address)) -def add_keys(account, chain, pubkeys): +def add_keys(pubkeys): c = context() - c.execute( - c.insert_or_ignore(PubkeyAddress) - .values([{'address': k.address} for k in pubkeys]) - ) - c.execute( - c.insert_or_ignore(AccountAddress) - .values([{ - 'account': account.id, - 'address': k.address, - 'chain': chain, - 'pubkey': k.pubkey_bytes, - 'chain_code': k.chain_code, - 'n': k.n, - 'depth': k.depth - } for k in pubkeys]) - ) + c.execute(c.insert_or_ignore(PubkeyAddress).values([{'address': k['address']} for k in pubkeys])) + c.execute(c.insert_or_ignore(AccountAddress).values(pubkeys))