Skip to content

Commit

Permalink
Cleaning; no need to pass inputs_set and keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Dec 26, 2024
1 parent 23dfc8d commit 53f9500
Show file tree
Hide file tree
Showing 9 changed files with 4,214 additions and 4,286 deletions.
4,537 changes: 2,269 additions & 2,268 deletions apiary.apib

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions counterparty-core/counterpartycore/lib/api/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ def compose_attach(
):
"""
Composes a transaction to attach assets from an address to UTXO.
Warning: after attaching assets to a UTXO, remember to use the `exclude_utxos` parameter to exclude it from subsequent transactions. This is done automatically by the Composer but only once the attach is confirmed.
:param address: The address from which the assets are attached (e.g. $ADDRESS_1)
:param asset: The asset or subasset to attach (e.g. XCP)
:param quantity: The quantity of the asset to attach (in satoshis, hence integer) (e.g. 1000)
Expand Down
3 changes: 2 additions & 1 deletion counterparty-core/counterpartycore/lib/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,14 @@ def prepare_inputs_and_change(db, source, outputs, unspent_list, construct_param

change_outputs = []
btc_in = 0
needed_fee = 0
# try with one input and increase until the change is enough for the fee
use_all_inputs_set = construct_params.get("use_all_inputs_set", False)
input_count = len(unspent_list) if use_all_inputs_set else 1
while True:
if input_count > len(unspent_list):
raise exceptions.ComposeError(
f"Insufficient funds for the target amount: {btc_in} < {outputs_total}"
f"Insufficient funds for the target amount: {btc_in} < {outputs_total + needed_fee}"
)

selected_utxos = unspent_list[:input_count]
Expand Down
3,872 changes: 1,936 additions & 1,936 deletions counterparty-core/counterpartycore/test/regtest/apidoc/apicache.json

Large diffs are not rendered by default.

40 changes: 3 additions & 37 deletions counterparty-core/counterpartycore/test/regtest/dreddhooks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import json

import dredd_hooks as hooks
import requests
import sh
from counterpartycore.lib import config
from counterpartycore.lib.backend.bitcoind import pubkey_from_inputs_set

config.BACKEND_URL = "http://rpc:rpc@localhost:18443"
config.BACKEND_SSL_NO_VERIFY = True
Expand All @@ -15,40 +10,11 @@
API_ROOT = "http://localhost:24000"


def get_inputs_set(address):
bitcoin_cli = sh.bitcoin_cli.bake(
"-regtest",
"-rpcuser=rpc",
"-rpcpassword=rpc",
"-rpcconnect=localhost",
)
list_unspent = json.loads(bitcoin_cli("listunspent", 0, 9999999, json.dumps([address])).strip())
sorted(list_unspent, key=lambda x: -x["amount"])
inputs = []
for utxo in list_unspent[0:99]:
inputs.append(f"{utxo['txid']}:{utxo['vout']}")
return ",".join(inputs)


@hooks.before_each
def my_before_all_hook(transaction):
if "/compose" in transaction["fullPath"]:
source = None
if "/addresses/" in transaction["fullPath"]:
source = transaction["fullPath"].split("/addresses/")[1].split("/")[0]
elif "/utxos/" in transaction["fullPath"]:
utxo = transaction["fullPath"].split("/utxos/")[1].split("/")[0]
source = requests.get(f"{API_ROOT}/v2/utxos/{utxo}/balances?limit=1").json()["result"][ # noqa S113
0
]["utxo_address"]
if source is not None:
inputs_set = get_inputs_set(source)
transaction["fullPath"] += f"&inputs_set={inputs_set}"
transaction["fullPath"] += f"&pubkeys={pubkey_from_inputs_set(inputs_set, source)}"
transaction["fullPath"] = transaction["fullPath"].replace("&inputs_set=None", "")
transaction["fullPath"] = transaction["fullPath"].replace("&pubkeys=None", "")
transaction["fullPath"] = transaction["fullPath"].replace(
"exclude_utxos_with_balances=False", "exclude_utxos_with_balances=True"
)
transaction["fullPath"] = transaction["fullPath"].replace(
"exclude_utxos_with_balances=False", "exclude_utxos_with_balances=True"
)

return transaction
27 changes: 1 addition & 26 deletions counterparty-core/counterpartycore/test/regtest/genapidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
import requests
import sh
import yaml
from counterpartycore.lib import config, database
from counterpartycore.lib import database
from counterpartycore.lib.api import routes
from counterpartycore.lib.backend.bitcoind import pubkey_from_inputs_set

config.BACKEND_URL = "http://rpc:rpc@localhost:18443"
config.BACKEND_SSL_NO_VERIFY = True
config.REQUESTS_TIMEOUT = 20
config.ADDRESSVERSION = config.ADDRESSVERSION_REGTEST
config.NETWORK_NAME = "regtest"

CURR_DIR = os.path.dirname(os.path.realpath(__file__))
API_BLUEPRINT_FILE = os.path.join(CURR_DIR, "../../../../apiary.apib")
Expand Down Expand Up @@ -140,21 +133,6 @@
}


def get_inputs_set(address):
bitcoin_cli = sh.bitcoin_cli.bake(
"-regtest",
"-rpcuser=rpc",
"-rpcpassword=rpc",
"-rpcconnect=localhost",
)
list_unspent = json.loads(bitcoin_cli("listunspent", 0, 9999999, json.dumps([address])).strip())
sorted(list_unspent, key=lambda x: -x["amount"])
inputs = []
for utxo in list_unspent[0:99]:
inputs.append(f"{utxo['txid']}:{utxo['vout']}")
return ",".join(inputs)


def get_example_output(path, args):
print(f"args: {args}")
url_keys = []
Expand Down Expand Up @@ -182,10 +160,7 @@ def get_example_output(path, args):
]["utxo_address"]
if source is not None:
print(f"source: {source}")
inputs_set = get_inputs_set(source)
args["inputs_set"] = inputs_set
args["exclude_utxos_with_balances"] = True
args["pubkeys"] = pubkey_from_inputs_set(inputs_set, source)
args["validate"] = False

response = requests.get(url, params=args) # noqa S113
Expand Down
17 changes: 0 additions & 17 deletions counterparty-core/counterpartycore/test/regtest/regtestnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
from bitcoinutils.setup import setup
from bitcoinutils.transactions import Transaction, TxInput, TxOutput
from counterpartycore.lib import arc4, config, database
from counterpartycore.lib.backend.bitcoind import pubkey_from_inputs_set

config.BACKEND_URL = "http://rpc:rpc@localhost:18443"
config.BACKEND_SSL_NO_VERIFY = True
config.REQUESTS_TIMEOUT = 20
config.ADDRESSVERSION = config.ADDRESSVERSION_REGTEST
config.NETWORK_NAME = "regtest"

setup("regtest")

Expand Down Expand Up @@ -198,16 +191,6 @@ def send_transaction(
retry=0,
):
self.wait_for_counterparty_server()
if "inputs_source" in params:
inputs_source = params.pop("inputs_source")
params["inputs_set"] = self.get_inputs_set(inputs_source)
if "inputs_set" not in params and ":" not in source:
params["inputs_set"] = self.get_inputs_set(source)

if "inputs_set" in params and "pubkeys" not in params:
pubkey = pubkey_from_inputs_set(params["inputs_set"], source)
if pubkey:
params["pubkeys"] = pubkey

if return_only_data:
params["return_only_data"] = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
"asset": "SUBASSETC",
"asset_parent": "PARENTA",
"max_mint_per_tx": 100,
"exact_fee": 0,
},
"set_variables": {
"FREEFAIRMINT_SUBASSETC_TX_HASH": "$TX_HASH",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
"source": "",
"tx_hash": "$TX_HASH",
"tx_index": "$TX_INDEX",
"utxos_info": "$UTXO_ATTACH_1_TX_HASH:0 $TX_HASH:0 2 ",
"utxos_info": "$UTXO_ATTACH_1_TX_HASH:0 $TX_HASH:0 1 ",
"transaction_type": "utxomove",
},
"tx_hash": "$TX_HASH",
Expand Down

0 comments on commit 53f9500

Please sign in to comment.