Skip to content

Commit

Permalink
exclude silently utxo with balances when inputs_set is not provided; …
Browse files Browse the repository at this point in the history
…fixes
  • Loading branch information
Ouziel committed Dec 31, 2024
1 parent 419fe65 commit 16d874b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
11 changes: 10 additions & 1 deletion counterparty-core/counterpartycore/lib/backend/bitcoind.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def rpc_call(payload, retry=0):


def rpc(method, params):
# if current_process().name != "MainProcess" and current_thread().name not in ["MainThread", "Watcher"]:
# return safe_rpc(method, params)

payload = {
"method": method,
"params": params,
Expand All @@ -127,6 +130,7 @@ def rpc(method, params):

# no retry for requests from the API
def safe_rpc(method, params):
start_time = time.time()
try:
payload = {
"method": method,
Expand All @@ -144,6 +148,9 @@ def safe_rpc(method, params):
return response["result"]
except (requests.exceptions.RequestException, json.decoder.JSONDecodeError, KeyError) as e:
raise exceptions.BitcoindRPCError(f"Error calling {method}: {str(e)}") from e
finally:
elapsed = time.time() - start_time
logger.trace(f"Bitcoin Core RPC call {method} took {elapsed:.3f}s")


def getblockcount():
Expand Down Expand Up @@ -432,10 +439,12 @@ def search_pubkey_in_transactions(pubkeyhash, tx_hashes):


def list_unspent(source, allow_unconfirmed_inputs):
# print(current_process().name, current_thread().name)

min_conf = 0 if allow_unconfirmed_inputs else 1
bitcoind_unspent_list = []
try:
bitcoind_unspent_list = safe_rpc("listunspent", [min_conf, 9999999, [source]])
bitcoind_unspent_list = safe_rpc("listunspent", [min_conf, 9999999, [source]]) or []
except exceptions.BitcoindRPCError:
pass

Expand Down
22 changes: 9 additions & 13 deletions counterparty-core/counterpartycore/lib/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ def create_tx_output(value, address_or_script, unspent_list, construct_params):


def regular_dust_size(construct_params):
if "regular_dust_size" in construct_params:
if construct_params.get("regular_dust_size") is not None:
return construct_params["regular_dust_size"]
return config.DEFAULT_REGULAR_DUST_SIZE


def multisig_dust_size(construct_params):
if "multisig_dust_size" in construct_params:
if construct_params.get("multisig_dust_size") is not None:
return construct_params["multisig_dust_size"]
return config.DEFAULT_MULTISIG_DUST_SIZE

Expand Down Expand Up @@ -481,6 +481,10 @@ def prepare_unspent_list(db, source, construct_params):
else:
source_address = source
unspent_list = backend.list_unspent(source_address, allow_unconfirmed_inputs)
# exclude silentely utxos with balances
unspent_list = filter_utxos_with_balances(
db, source, unspent_list, construct_params | {"exclude_utxos_with_balances": True}
)
else:
# prepare unspent list provided by the user
unspent_list = prepare_inputs_set(inputs_set)
Expand Down Expand Up @@ -827,16 +831,8 @@ def check_transaction_sanity(tx_info, composed_tx, construct_params):
"unspent_tx_hash": (str, None, "Deprecated, use `inputs_set` instead"),
"dust_return_pubkey": (str, None, "Deprecated, use `mutlisig_pubkey` instead"),
"return_psbt": (bool, False, "Deprecated, use `verbose` instead"),
"regular_dust_size": (
int,
config.DEFAULT_REGULAR_DUST_SIZE,
"Deprecated, automatically calculated",
),
"multisig_dust_size": (
int,
config.DEFAULT_MULTISIG_DUST_SIZE,
"Deprecated, automatically calculated",
),
"regular_dust_size": (int, None, "Deprecated, automatically calculated"),
"multisig_dust_size": (int, None, "Deprecated, automatically calculated"),
"extended_tx_info": (bool, False, "Deprecated (API v1 only), use API v2 instead"),
"old_style_api": (bool, False, "Deprecated (API v1 only), use API v2 instead"),
"p2sh_pretx_txid": (str, None, "Ignored, P2SH disabled"),
Expand Down Expand Up @@ -874,7 +870,7 @@ def prepare_construct_params(construct_params):
"segwit",
"unspent_tx_hash",
]:
if field in construct_params:
if field in construct_params and construct_params[field] not in [None, False]:
warnings.append(f"The `{field}` parameter is {CONSTRUCT_PARAMS[field][2].lower()}")

return cleaned_construct_params, warnings
Expand Down

0 comments on commit 16d874b

Please sign in to comment.