Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v11.1.0] New Transaction Format #2189

Draft
wants to merge 16 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions counterparty-core/counterpartycore/lib/api/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@
except Exception as e:
capture_exception(e)
logger.error("Error in API: %s", e)
# import traceback
# print(traceback.format_exc()) # for debugging
import traceback

Check warning

Code scanning / pylint

Import outside toplevel (traceback). Warning

Import outside toplevel (traceback).

print(traceback.format_exc()) # for debugging
return return_result(
503, error="Unknown error", start_time=start_time, query_args=query_args
)
Expand Down
2 changes: 1 addition & 1 deletion counterparty-core/counterpartycore/lib/api/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ def get_tx_info(tx_hex, block_index=None):
@dispatcher.add_method
def unpack(data_hex):
data = binascii.unhexlify(data_hex)
message_type_id, message = message_type.unpack(data)
message_type_id, message = message_type.unpack(data)[0]

# TODO: Enabled only for `send`.
if message_type_id == send.ID:
Expand Down
1 change: 1 addition & 0 deletions counterparty-core/counterpartycore/lib/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"/v2/addresses/<address>/compose/attach": transaction.compose_attach,
"/v2/utxos/<utxo>/compose/detach": transaction.compose_detach,
"/v2/utxos/<utxo>/compose/movetoutxo": transaction.compose_movetoutxo,
"/v2/compose": transaction.compose_multiple,
### /assets ###
"/v2/assets": queries.get_valid_assets,
"/v2/assets/<asset>": queries.get_asset,
Expand Down
155 changes: 78 additions & 77 deletions counterparty-core/counterpartycore/lib/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,88 +125,89 @@ def parse_tx(db, tx):

if len(tx["data"]) > 1:
try:
message_type_id, message = message_type.unpack(tx["data"], tx["block_index"])
except struct.error: # Deterministically raised.
message_type_id = None
message = None
messages = message_type.unpack(tx["data"], tx["block_index"])
except (struct.error, TypeError): # Deterministically raised.
messages = [(None, None)]
else:
message_type_id = None
message = None
messages = [(None, None)]

# Protocol change.
rps_enabled = tx["block_index"] >= 308500 or config.TESTNET or config.REGTEST

supported = True

if message_type_id == send.ID:
send.parse(db, tx, message)
elif message_type_id == enhanced_send.ID and util.enabled(
"enhanced_sends", block_index=tx["block_index"]
):
enhanced_send.parse(db, tx, message)
elif message_type_id == mpma.ID and util.enabled(
"mpma_sends", block_index=tx["block_index"]
):
mpma.parse(db, tx, message)
elif message_type_id == order.ID:
order.parse(db, tx, message)
elif message_type_id == btcpay.ID:
btcpay.parse(db, tx, message)
elif message_type_id == issuance.ID or (
util.enabled("issuance_backwards_compatibility", block_index=tx["block_index"])
and message_type_id == issuance.LR_ISSUANCE_ID
):
issuance.parse(db, tx, message, message_type_id)
elif (
message_type_id == issuance.SUBASSET_ID
and util.enabled("subassets", block_index=tx["block_index"])
) or (
util.enabled("issuance_backwards_compatibility", block_index=tx["block_index"])
and message_type_id == issuance.LR_SUBASSET_ID
):
issuance.parse(db, tx, message, message_type_id)
elif message_type_id == broadcast.ID:
broadcast.parse(db, tx, message)
elif message_type_id == bet.ID:
bet.parse(db, tx, message)
elif message_type_id == dividend.ID:
dividend.parse(db, tx, message)
elif message_type_id == cancel.ID:
cancel.parse(db, tx, message)
elif message_type_id == rps.ID and rps_enabled:
rps.parse(db, tx, message)
elif message_type_id == rpsresolve.ID and rps_enabled:
rpsresolve.parse(db, tx, message)
elif message_type_id == destroy.ID and util.enabled(
"destroy_reactivated", block_index=tx["block_index"]
):
destroy.parse(db, tx, message)
elif message_type_id == sweep.ID and util.enabled(
"sweep_send", block_index=tx["block_index"]
):
sweep.parse(db, tx, message)
elif message_type_id == dispenser.ID and util.enabled(
"dispensers", block_index=tx["block_index"]
):
dispenser.parse(db, tx, message)
elif message_type_id == dispenser.DISPENSE_ID and util.enabled(
"dispensers", block_index=tx["block_index"]
):
dispense.parse(db, tx)
elif message_type_id == fairminter.ID and util.enabled(
"fairminter", block_index=tx["block_index"]
):
fairminter.parse(db, tx, message)
elif message_type_id == fairmint.ID and util.enabled(
"fairminter", block_index=tx["block_index"]
):
fairmint.parse(db, tx, message)
elif message_type_id == utxo.ID and util.enabled(
"utxo_support", block_index=tx["block_index"]
):
utxo.parse(db, tx, message)
else:
supported = False
supported = []

for message_type_id, message in messages:
supported.append(True)
if message_type_id == send.ID:
send.parse(db, tx, message)
elif message_type_id == enhanced_send.ID and util.enabled(
"enhanced_sends", block_index=tx["block_index"]
):
enhanced_send.parse(db, tx, message)
elif message_type_id == mpma.ID and util.enabled(
"mpma_sends", block_index=tx["block_index"]
):
mpma.parse(db, tx, message)
elif message_type_id == order.ID:
order.parse(db, tx, message)
elif message_type_id == btcpay.ID:
btcpay.parse(db, tx, message)
elif message_type_id == issuance.ID or (
util.enabled("issuance_backwards_compatibility", block_index=tx["block_index"])
and message_type_id == issuance.LR_ISSUANCE_ID
):
issuance.parse(db, tx, message, message_type_id)
elif (
message_type_id == issuance.SUBASSET_ID
and util.enabled("subassets", block_index=tx["block_index"])
) or (
util.enabled("issuance_backwards_compatibility", block_index=tx["block_index"])
and message_type_id == issuance.LR_SUBASSET_ID
):
issuance.parse(db, tx, message, message_type_id)
elif message_type_id == broadcast.ID:
broadcast.parse(db, tx, message)
elif message_type_id == bet.ID:
bet.parse(db, tx, message)
elif message_type_id == dividend.ID:
dividend.parse(db, tx, message)
elif message_type_id == cancel.ID:
cancel.parse(db, tx, message)
elif message_type_id == rps.ID and rps_enabled:
rps.parse(db, tx, message)
elif message_type_id == rpsresolve.ID and rps_enabled:
rpsresolve.parse(db, tx, message)
elif message_type_id == destroy.ID and util.enabled(
"destroy_reactivated", block_index=tx["block_index"]
):
destroy.parse(db, tx, message)
elif message_type_id == sweep.ID and util.enabled(
"sweep_send", block_index=tx["block_index"]
):
sweep.parse(db, tx, message)
elif message_type_id == dispenser.ID and util.enabled(
"dispensers", block_index=tx["block_index"]
):
dispenser.parse(db, tx, message)
elif message_type_id == dispenser.DISPENSE_ID and util.enabled(
"dispensers", block_index=tx["block_index"]
):
dispense.parse(db, tx)
elif message_type_id == fairminter.ID and util.enabled(
"fairminter", block_index=tx["block_index"]
):
fairminter.parse(db, tx, message)
elif message_type_id == fairmint.ID and util.enabled(
"fairminter", block_index=tx["block_index"]
):
fairmint.parse(db, tx, message)
elif message_type_id == utxo.ID and util.enabled(
"utxo_support", block_index=tx["block_index"]
):
utxo.parse(db, tx, message)
else:
supported[-1] = False
supported = any(supported)

ledger.add_to_journal(
db,
Expand Down
Loading
Loading