Skip to content

Commit

Permalink
Add utxo_value parameter for attach and move
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Jan 3, 2025
1 parent 59348a8 commit d1ed85d
Show file tree
Hide file tree
Showing 11 changed files with 5,328 additions and 4,893 deletions.
5,410 changes: 2,766 additions & 2,644 deletions apiary.apib

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion counterparty-core/counterpartycore/lib/api/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ def compose_attach(
address: str,
asset: str,
quantity: int,
utxo_value: int = None,
destination_vout: str = None,
**construct_params,
):
Expand All @@ -473,12 +474,14 @@ def compose_attach(
: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)
:param utxo_value: The value of the UTXO to attach the assets to (in satoshis, hence integer)
:param destination_vout: The vout of the destination output
"""
params = {
"source": address,
"asset": asset,
"quantity": quantity,
"utxo_value": utxo_value,
"destination_vout": destination_vout,
}
return composer.compose_transaction(db, "attach", params, construct_params)
Expand Down Expand Up @@ -509,15 +512,17 @@ def get_attach_estimate_xcp_fee(db):
return gas.get_transaction_fee(db, UTXO_ID, util.CURRENT_BLOCK_INDEX)


def compose_movetoutxo(db, utxo: str, destination: str, **construct_params):
def compose_movetoutxo(db, utxo: str, destination: str, utxo_value: int = None, **construct_params):
"""
Composes a transaction like a send but for moving from one UTXO to another, with the destination is specified as an address.
:param utxo: The utxo from which the assets are moved (e.g. $UTXO_WITH_BALANCE)
:param destination: the address for which the destination utxo will be created (e.g. $ADDRESS_1)
:param utxo_value: The value of the UTXO to move the assets from (in satoshis, hence integer)
"""
params = {
"source": utxo,
"destination": destination,
"utxo_value": utxo_value,
}
return composer.compose_transaction(db, "move", params, construct_params)

Expand Down
12 changes: 10 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def validate(db, source, asset, quantity, destination_vout=None, block_index=Non
return problems


def compose(db, source, asset, quantity, destination_vout=None, skip_validation=False):
def compose(

Check warning

Code scanning / pylint

Too many positional arguments (7/5). Warning

Too many positional arguments (7/5).
db, source, asset, quantity, utxo_value=None, destination_vout=None, skip_validation=False
):
problems = validate(db, source, asset, quantity, destination_vout)
if problems and not skip_validation:
raise exceptions.ComposeError(problems)
Expand All @@ -103,8 +105,14 @@ def compose(db, source, asset, quantity, destination_vout=None, skip_validation=
# build a transaction with the destination UTXO
destinations = []
if destination_vout is None:
value = config.DEFAULT_UTXO_VALUE
if utxo_value is not None:
try:
value = int(utxo_value)
except ValueError as e:
raise exceptions.ComposeError(["utxo_value must be an integer"]) from e
# else we use the source address as the destination
destinations.append((source, config.DEFAULT_UTXO_VALUE))
destinations.append((source, value))

return (source, destinations, data)

Expand Down
11 changes: 9 additions & 2 deletions counterparty-core/counterpartycore/lib/messages/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
logger = logging.getLogger(config.LOGGER_NAME)


def compose(db, source, destination, skip_validation=False):
def compose(db, source, destination, utxo_value=None, skip_validation=False):
if not skip_validation:
if not util.is_utxo_format(source):
raise exceptions.ComposeError("Invalid source utxo format")
Expand All @@ -20,7 +20,14 @@ def compose(db, source, destination, skip_validation=False):
except script.AddressError as e:
raise exceptions.ComposeError("destination must be an address") from e

return (source, [(destination, config.DEFAULT_UTXO_VALUE)], None)
value = config.DEFAULT_UTXO_VALUE
if utxo_value is not None:
try:
value = int(utxo_value)
except ValueError as e:
raise exceptions.ComposeError(["utxo_value must be an integer"]) from e

return (source, [(destination, value)], None)


def move_balances(db, tx, source, destination):
Expand Down
4 changes: 4 additions & 0 deletions counterparty-core/counterpartycore/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ def determine_encoding(data, construct_params):

return encoding

def convert_to_psbt(tx_hex):
return tx_hex

monkeypatch.setattr("counterpartycore.lib.arc4.init_arc4", init_arc4)
monkeypatch.setattr("counterpartycore.lib.backend.electrs.get_utxos", get_utxos)
monkeypatch.setattr("counterpartycore.lib.log.isodt", isodt)
Expand All @@ -663,6 +666,7 @@ def determine_encoding(data, construct_params):
"counterpartycore.lib.backend.bitcoind.getrawtransaction_batch",
mocked_getrawtransaction_batch,
)
monkeypatch.setattr("counterpartycore.lib.backend.bitcoind.convert_to_psbt", convert_to_psbt)
monkeypatch.setattr(
"counterpartycore.lib.backend.electrs.get_history",
mocked_get_history,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16489,6 +16489,13 @@
"type": "int",
"description": "The quantity of the asset to attach (in satoshis, hence integer) (e.g. 1000)"
},
{
"name": "utxo_value",
"default": null,
"required": false,
"type": "int",
"description": "The value of the UTXO to attach the assets to (in satoshis, hence integer)"
},
{
"name": "destination_vout",
"default": null,
Expand Down Expand Up @@ -16967,6 +16974,13 @@
"type": "str",
"description": "the address for which the destination utxo will be created (e.g. $ADDRESS_1)"
},
{
"name": "utxo_value",
"default": null,
"required": false,
"type": "int",
"description": "The value of the UTXO to move the assets from (in satoshis, hence integer)"
},
{
"name": "encoding",
"type": "str",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,148 @@
"rawtransaction": "0200000001c1d8c075936c3495f6d653c50f73d987f75448d97a750249b1eb83bee71b24ae0000000000ffffffff020000000000000000386a362a504df746f83442653dd7afa4dc727a030865749e9fba5aec80c39a9e68edbc79e78ed45723c1072c38aededa458f95fa42b8b188e8115cea0b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000"
},
},
{
"in": (
"attach",
{
"source": ADDR[0],
"asset": "XCP",
"quantity": 10,
},
{"verbose": True},
),
"out": {
"rawtransaction": "0200000001c1d8c075936c3495f6d653c50f73d987f75448d97a750249b1eb83bee71b24ae0000000000ffffffff0310270000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac0000000000000000126a102a504df746f83442006594fdd8ed42060d35ea0b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000",
"btc_in": 199909140,
"btc_out": 10000,
"btc_change": 199898381,
"btc_fee": 759,
"data": b"TESTXXXXeXCP|10|",
"lock_scripts": ["76a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac"],
"signed_tx_estimated_size": {
"vsize": 253,
"adjusted_vsize": 253,
"sigops_count": 8,
},
"psbt": "0200000001c1d8c075936c3495f6d653c50f73d987f75448d97a750249b1eb83bee71b24ae0000000000ffffffff0310270000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac0000000000000000126a102a504df746f83442006594fdd8ed42060d35ea0b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000",
"params": {
"source": "mn6q3dS2EnDUx3bmyWc6D4szJNVGtaR7zc",
"asset": "XCP",
"quantity": 10,
"utxo_value": None,
"destination_vout": None,
"skip_validation": False,
},
"name": "attach",
},
},
{
"in": (
"attach",
{
"source": ADDR[0],
"asset": "XCP",
"quantity": 10,
"utxo_value": 666,
},
{"verbose": True},
),
"out": {
"rawtransaction": "0200000001c1d8c075936c3495f6d653c50f73d987f75448d97a750249b1eb83bee71b24ae0000000000ffffffff039a020000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac0000000000000000126a102a504df746f83442006594fdd8ed42068359ea0b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000",
"btc_in": 199909140,
"btc_out": 666,
"btc_change": 199907715,
"btc_fee": 759,
"data": b"TESTXXXXeXCP|10|",
"lock_scripts": ["76a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac"],
"signed_tx_estimated_size": {
"vsize": 253,
"adjusted_vsize": 253,
"sigops_count": 8,
},
"psbt": "0200000001c1d8c075936c3495f6d653c50f73d987f75448d97a750249b1eb83bee71b24ae0000000000ffffffff039a020000000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac0000000000000000126a102a504df746f83442006594fdd8ed42068359ea0b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000",
"params": {
"source": "mn6q3dS2EnDUx3bmyWc6D4szJNVGtaR7zc",
"asset": "XCP",
"quantity": 10,
"utxo_value": 666,
"destination_vout": None,
"skip_validation": False,
},
"name": "attach",
},
},
{
"in": (
"move",
{
"source": "ea0962df1a71c3d76e08ee80c7a24b2ea670e31639c39cd897fca3bc008e81a0:0",
"destination": ADDR[1],
},
{
"verbose": True,
"inputs_set": "ea0962df1a71c3d76e08ee80c7a24b2ea670e31639c39cd897fca3bc008e81a0:0:999999999:76a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac",
},
),
"out": {
"rawtransaction": "0200000001a0818e00bca3fc97d89cc33916e370a62e4ba2c780ee086ed7c3711adf6209ea0000000000ffffffff0210270000000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac49a09a3b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000",
"btc_in": 999999999,
"btc_out": 10000,
"btc_change": 999989321,
"btc_fee": 678,
"data": None,
"lock_scripts": ["76a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac"],
"signed_tx_estimated_size": {
"vsize": 226,
"adjusted_vsize": 226,
"sigops_count": 8,
},
"psbt": "0200000001a0818e00bca3fc97d89cc33916e370a62e4ba2c780ee086ed7c3711adf6209ea0000000000ffffffff0210270000000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88ac49a09a3b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000",
"params": {
"source": "ea0962df1a71c3d76e08ee80c7a24b2ea670e31639c39cd897fca3bc008e81a0:0",
"destination": "mtQheFaSfWELRB2MyMBaiWjdDm6ux9Ezns",
"utxo_value": None,
"skip_validation": False,
},
"name": "move",
},
},
{
"in": (
"move",
{
"source": "ea0962df1a71c3d76e08ee80c7a24b2ea670e31639c39cd897fca3bc008e81a0:0",
"destination": ADDR[1],
"utxo_value": 666,
},
{
"verbose": True,
"inputs_set": "ea0962df1a71c3d76e08ee80c7a24b2ea670e31639c39cd897fca3bc008e81a0:0:999999999:76a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac",
},
),
"out": {
"rawtransaction": "0200000001a0818e00bca3fc97d89cc33916e370a62e4ba2c780ee086ed7c3711adf6209ea0000000000ffffffff029a020000000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acbfc49a3b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000",
"btc_in": 999999999,
"btc_out": 666,
"btc_change": 999998655,
"btc_fee": 678,
"data": None,
"lock_scripts": ["76a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac"],
"signed_tx_estimated_size": {
"vsize": 226,
"adjusted_vsize": 226,
"sigops_count": 8,
},
"psbt": "0200000001a0818e00bca3fc97d89cc33916e370a62e4ba2c780ee086ed7c3711adf6209ea0000000000ffffffff029a020000000000001976a9148d6ae8a3b381663118b4e1eff4cfc7d0954dd6ec88acbfc49a3b000000001976a9144838d8b3588c4c7ba7c1d06f866e9b3739c6303788ac00000000",
"params": {
"source": "ea0962df1a71c3d76e08ee80c7a24b2ea670e31639c39cd897fca3bc008e81a0:0",
"destination": "mtQheFaSfWELRB2MyMBaiWjdDm6ux9Ezns",
"utxo_value": 666,
"skip_validation": False,
},
"name": "move",
},
},
],
},
}
4 changes: 2 additions & 2 deletions counterparty-core/counterpartycore/test/fixtures/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
DEFAULT_PARAMS as DP,
)

# UNITTEST_VECTOR = COMPOSER_VECTOR
UNITTEST_VECTOR = COMPOSER_VECTOR

UNITTEST_VECTOR = (
UNITTEST_VECTOR_ = (
FAIRMINTER_VECTOR
| FAIRMINT_VECTOR
| LEDGER_VECTOR
Expand Down
Loading

0 comments on commit d1ed85d

Please sign in to comment.