Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

Commit

Permalink
revert insert many due to lbrynet
Browse files Browse the repository at this point in the history
  • Loading branch information
shyba authored and eukreign committed Oct 20, 2018
1 parent 8bbda75 commit dce5541
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions torba/basedatabase.py
Expand Up @@ -293,21 +293,14 @@ def _transaction(conn: sqlite3.Connection, save_tx, tx: BaseTransaction, address
"SELECT position FROM txo", txid=tx.id
))))

txos_insert = []
for txo in tx.outputs:
if txo.position in existing_txos:
continue
if txo.script.is_pay_pubkey_hash and txo.script.values['pubkey_hash'] == txhash:
txos_insert.append(
(tx.id, txo.id, address, txo.position, txo.amount, sqlite3.Binary(txo.script.source))
)
conn.execute(*self._insert_sql("txo", self.txo_to_row(tx, address, txo)))
elif txo.script.is_pay_script_hash:
# TODO: implement script hash payments
log.warning('Database.save_transaction_io: pay script hash is not implemented!')
conn.executemany(
'INSERT INTO txo (txid, txoid, address, position, amount, script) values (?, ?, ?, ?, ?, ?)',
txos_insert
)

# lookup the address associated with each TXI (via its TXO)
txoid_to_address = {r[0]: r[1] for r in conn.execute(*query(
Expand All @@ -319,14 +312,16 @@ def _transaction(conn: sqlite3.Connection, save_tx, tx: BaseTransaction, address
"SELECT txoid FROM txi", txid=tx.id
))}

txis_insert = []
for txi in tx.inputs:
txoid = txi.txo_ref.id
new_txi = txoid not in existing_txis
address_matches = txoid_to_address.get(txoid) == address
if new_txi and address_matches:
txis_insert.append((tx.id, txoid, address))
conn.executemany('INSERT INTO txi (txid, txoid, address) VALUES (?, ?, ?)', txis_insert)
conn.execute(*self._insert_sql("txi", {
'txid': tx.id,
'txoid': txoid,
'address': address,
}))
conn.execute(
"UPDATE pubkey_address SET history = ?, used_times = ? WHERE address = ?",
(history, history.count(':')//2, address)
Expand Down

0 comments on commit dce5541

Please sign in to comment.