Skip to content

Commit

Permalink
Merge branch 'v7-bugfixes' of github.com:1200wd/bitcoinlib into v7-bu…
Browse files Browse the repository at this point in the history
…gfixes
  • Loading branch information
Cryp Toon committed Jul 20, 2024
2 parents e39c2a1 + f416cbb commit 0cb01ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 2 additions & 6 deletions bitcoinlib/services/blocksmurfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def getbalance(self, addresslist):
balance += res['balance']
return balance

# TODO: fix blocksmurfer api
def getutxos(self, address, after_txid='', limit=MAX_TRANSACTIONS):
res = self.compose_request('utxos', address, variables={'after_txid': after_txid})
self.latest_block = self.blockcount() if not self.latest_block else self.latest_block
Expand Down Expand Up @@ -85,11 +84,8 @@ def _parse_transaction(self, tx, block_height=None):
if block_height and not confirmations and tx['status'] == 'confirmed':
self.latest_block = self.blockcount() if not self.latest_block else self.latest_block
confirmations = self.latest_block - block_height
# FIXME: Blocksmurfer returns 'date' or 'time', should be consistent
tx_date = None if not tx.get('date') else (
datetime.strptime(tx['date'], "%Y-%m-%dT%H:%M:%S").replace(tzinfo=timezone.utc))
if not tx_date and 'time' in tx:
tx_date = datetime.fromtimestamp(tx['time'], timezone.utc)
datetime.strptime(tx['date'][:19], "%Y-%m-%dT%H:%M:%S").replace(tzinfo=timezone.utc))
t = Transaction(locktime=tx['locktime'], version=tx['version'], network=self.network,
fee=tx['fee'], size=tx['size'], txid=tx['txid'], date=tx_date, input_total=tx['input_total'],
output_total=tx['output_total'], confirmations=confirmations, block_height=block_height,
Expand All @@ -101,7 +97,7 @@ def _parse_transaction(self, tx, block_height=None):
public_hash=bytes.fromhex(ti['public_hash']), address=ti['address'],
witness_type=ti['witness_type'], locktime_cltv=ti['locktime_cltv'],
locktime_csv=ti['locktime_csv'], signatures=ti['signatures'], compressed=ti['compressed'],
encoding=ti['encoding'], locking_script=ti['script_code'],
encoding=ti['encoding'], locking_script=ti['locking_script'],
sigs_required=ti['sigs_required'], sequence=ti['sequence'],
witnesses=[bytes.fromhex(w) for w in ti['witnesses']], script_type=ti['script_type'],
strict=self.strict)
Expand Down
9 changes: 7 additions & 2 deletions bitcoinlib/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def getinputvalues(self, t):
prev_txs = []
for i in t.inputs:
if not i.value:
if i.prev_txid not in prev_txs:
if i.prev_txid not in prev_txs and i.prev_txid != 32 * b'\0':
prev_t = self.gettransaction(i.prev_txid.hex())
else:
prev_t = [t for t in prev_txs if t.txid == i.prev_txid][0]
Expand Down Expand Up @@ -727,12 +727,17 @@ def _parse_db_transaction(db_tx):
fee=db_tx.fee, txid=db_tx.txid.hex(), date=db_tx.date, confirmations=db_tx.confirmations,
block_height=db_tx.block_height, status='confirmed', witness_type=db_tx.witness_type.value,
index=db_tx.index)
if t.date and not t.date.tzinfo:
t.date = t.date.replace(tzinfo=timezone.utc)
for n in db_tx.nodes:
if n.is_input:
witness_type = None
if n.ref_txid == b'\00' * 32:
t.coinbase = True
witness_type = db_tx.witness_type.value
t.add_input(n.ref_txid.hex(), n.ref_index_n, unlocking_script=n.script, address=n.address,
sequence=n.sequence, value=n.value, index_n=n.index_n, witnesses=n.witnesses, strict=False)
sequence=n.sequence, value=n.value, index_n=n.index_n, witnesses=n.witnesses,
strict=False, witness_type=witness_type)
else:
t.add_output(n.value, n.address, lock_script=n.script, spent=n.spent, output_n=n.index_n,
spending_txid=None if not n.ref_txid else n.ref_txid.hex(),
Expand Down

0 comments on commit 0cb01ac

Please sign in to comment.