Skip to content

Commit

Permalink
use vin info from RSFecther in gettxinfo_legacy()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Feb 20, 2025
1 parent 2e76f75 commit d0fc208
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
15 changes: 11 additions & 4 deletions counterparty-core/counterpartycore/lib/backend/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,17 @@ def list_unspent(source, allow_unconfirmed_inputs):


def get_vin_info(vin, no_retry=False):
vin_ctx = get_decoded_transaction(vin["hash"], no_retry=no_retry)
is_segwit = vin_ctx["segwit"]
vout = vin_ctx["vout"][vin["n"]]
return vout["value"], vout["script_pub_key"], is_segwit
vin_info = vin.get("info")
if vin_info is None:
try:
vin_ctx = get_decoded_transaction(vin["hash"], no_retry=no_retry)
is_segwit = vin_ctx["segwit"]
vout = vin_ctx["vout"][vin["n"]]
return vout["value"], vout["script_pub_key"], is_segwit
except exceptions.BitcoindRPCError as e:
raise exceptions.DecodeError("vin not found") from e

Check warning on line 551 in counterparty-core/counterpartycore/lib/backend/bitcoind.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/backend/bitcoind.py#L543-L551

Added lines #L543 - L551 were not covered by tests
else:
return vin_info["value"], vin_info["script_pub_key"], vin_info["is_segwit"]

Check warning on line 553 in counterparty-core/counterpartycore/lib/backend/bitcoind.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/backend/bitcoind.py#L553

Added line #L553 was not covered by tests


def get_vins_info(vins, no_retry=False):
Expand Down
19 changes: 6 additions & 13 deletions counterparty-core/counterpartycore/lib/parser/gettxinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,14 @@ def check_signatures_sighash_flag(decoded_tx):
raise SighashFlagError(error)


def get_vin_info(vin):
vin_info = vin.get("info")
if vin_info is None:
try:
return backend.bitcoind.get_vin_info(vin, no_retry=CurrentState().parsing_mempool())
except exceptions.BitcoindRPCError as e:
raise DecodeError("vin not found") from e
else:
return vin_info["value"], vin_info["script_pub_key"], vin_info["is_segwit"]


def get_transaction_sources(decoded_tx):
sources = []
outputs_value = 0

for vin in decoded_tx["vin"]: # Loop through inputs.
vout_value, script_pubkey, _is_segwit = get_vin_info(vin)
vout_value, script_pubkey, _is_segwit = backend.bitcoind.get_vin_info(
vin, no_retry=CurrentState().parsing_mempool()
)

outputs_value += vout_value

Expand Down Expand Up @@ -282,7 +273,9 @@ def get_transaction_source_from_p2sh(decoded_tx, p2sh_is_segwit):
outputs_value = 0

for vin in decoded_tx["vin"]:
vout_value, _script_pubkey, is_segwit = get_vin_info(vin)
vout_value, _script_pubkey, is_segwit = backend.bitcoind.get_vin_info(

Check warning on line 276 in counterparty-core/counterpartycore/lib/parser/gettxinfo.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/parser/gettxinfo.py#L275-L276

Added lines #L275 - L276 were not covered by tests
vin, no_retry=CurrentState().parsing_mempool()
)

if protocol.enabled("prevout_segwit_fix"):
prevout_is_segwit = is_segwit
Expand Down
15 changes: 5 additions & 10 deletions counterparty-core/counterpartycore/lib/parser/gettxinfolegacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from arc4 import ARC4

from counterpartycore.lib import backend, config, exceptions
from counterpartycore.lib import backend, config
from counterpartycore.lib.exceptions import BTCOnlyError, DecodeError
from counterpartycore.lib.ledger.currentstate import CurrentState
from counterpartycore.lib.parser import protocol
Expand Down Expand Up @@ -146,16 +146,11 @@ def get_tx_info_legacy(decoded_tx, block_index):
raise BTCOnlyError("no data and not unspendable")

# Collect all possible source addresses; ignore coinbase transactions and anything but the simplest Pay‐to‐PubkeyHash inputs.
# get inputs info by batch
try:
vins_info = backend.bitcoind.get_vins_info(
decoded_tx["vin"], no_retry=CurrentState().parsing_mempool()
)
except exceptions.BitcoindRPCError as e:
raise DecodeError("vin not found") from e

source_list = []
for vout_value, script_pubkey, _is_segwit in vins_info: # Loop through input transactions.
for vin in decoded_tx["vin"]: # Loop through input transactions.
vout_value, script_pubkey, _is_segwit = backend.bitcoind.get_vin_info(

Check warning on line 151 in counterparty-core/counterpartycore/lib/parser/gettxinfolegacy.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/parser/gettxinfolegacy.py#L150-L151

Added lines #L150 - L151 were not covered by tests
vin, no_retry=CurrentState().parsing_mempool()
)
fee += vout_value

address = get_address(script_pubkey, block_index)
Expand Down

0 comments on commit d0fc208

Please sign in to comment.