Skip to content

Commit

Permalink
use new encode/decode_data for enhancedsend and sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Mar 4, 2025
1 parent 6dc4a0b commit 4457003
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
13 changes: 5 additions & 8 deletions counterparty-core/counterpartycore/lib/messages/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,12 @@ def compose(

if protocol.enabled("taproot_support"):
data = struct.pack(config.SHORT_TXTYPE_FORMAT, ID)
data_content = b"|".join(
[
short_address_bytes,
helpers.int_to_bytes(flags),
memo_bytes,
]
data += helpers.encode_data(

Check warning on line 89 in counterparty-core/counterpartycore/lib/messages/sweep.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/sweep.py#L87-L89

Added lines #L87 - L89 were not covered by tests
short_address_bytes,
helpers.int_to_bytes(flags),
memo_bytes,
)
logger.warning(f"data_content: {data_content}")
data += struct.pack(f">{len(data_content)}s", data_content)
logger.warning(f"data_content: {data}")

Check warning

Code scanning / pylint

Use lazy % formatting in logging functions. Warning

Use lazy % formatting in logging functions.

Check warning on line 94 in counterparty-core/counterpartycore/lib/messages/sweep.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/messages/sweep.py#L94

Added line #L94 was not covered by tests
else:
data = messagetype.pack(ID)
data += struct.pack(FORMAT, short_address_bytes, flags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@

def new_unpack(message):
try:
data_content = struct.unpack(f">{len(message)}s", message)[0].split(b"|")
logger.warning(f"data_content unpack: {data_content}")
arg_count = len(data_content)
(
asset_id_bytes,
quantity_bytes,
short_address_bytes,
) = data_content[0 : arg_count - 1]
# The memo is placed last to be able to contain `|`.
memo_bytes = b"|".join(data_content[arg_count - 1 :])
(asset_id_bytes, quantity_bytes, short_address_bytes, memo_bytes) = helpers.decode_data(

Check warning

Code scanning / pylint

Possible unbalanced tuple unpacking with sequence defined at line 211 of counterpartycore.lib.utils.helpers: left side has 4 labels, right side has 0 values. Warning

Possible unbalanced tuple unpacking with sequence defined at line 211 of counterpartycore.lib.utils.helpers: left side has 4 labels, right side has 0 values.
message
)

asset_id = helpers.bytes_to_int(asset_id_bytes)
asset = ledger.issuances.generate_asset_name(asset_id)
Expand Down Expand Up @@ -188,15 +181,12 @@ def compose(

if protocol.enabled("taproot_support"):
data = struct.pack(config.SHORT_TXTYPE_FORMAT, ID)
data_content = b"|".join(
[
helpers.int_to_bytes(asset_id),
helpers.int_to_bytes(quantity),
short_address_bytes,
memo_bytes,
]
data += helpers.encode_data(
asset_id,
quantity,
short_address_bytes,
memo_bytes,
)
data += struct.pack(f">{len(data_content)}s", data_content)
logger.warning(f"data1: {data}")

Check warning

Code scanning / pylint

Use lazy % formatting in logging functions. Warning

Use lazy % formatting in logging functions.
else:
data = messagetype.pack(ID)
Expand Down

0 comments on commit 4457003

Please sign in to comment.