Skip to content

Commit

Permalink
Merge pull request #1258 from pataegrillo/issuance_new_id_format
Browse files Browse the repository at this point in the history
Issuance backwards compatibility
  • Loading branch information
jdogresorg authored Oct 3, 2023
2 parents 6d6623d + 135e880 commit 403b6a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions counterpartylib/lib/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def parse_tx(db, tx):
order.parse(db, tx, message)
elif message_type_id == btcpay.ID:
btcpay.parse(db, tx, message)
elif message_type_id == issuance.ID:
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']):
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)
Expand Down
19 changes: 16 additions & 3 deletions counterpartylib/lib/messages/issuance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
SUBASSET_ID = 21
# NOTE: Pascal strings are used for storing descriptions for backwards‐compatibility.

#Lock Reset issuances. Default composed message
LR_ISSUANCE_ID = 22
LR_SUBASSET_ID = 23


def initialise(db):
cursor = db.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS issuances(
Expand Down Expand Up @@ -342,7 +347,11 @@ def compose (db, source, transfer_destination, asset, quantity, divisible, lock,

# Type 20 standard issuance FORMAT_2 >QQ??If
# used for standard issuances and all reissuances
data = message_type.pack(ID)
if util.enabled("issuance_backwards_compatibility"):
data = message_type.pack(LR_ISSUANCE_ID)
else:
data = message_type.pack(ID)

if (len(description) <= 42) and not util.enabled('pascal_string_removed'):
curr_format = FORMAT_2 + '{}p'.format(len(description) + 1)
else:
Expand All @@ -368,7 +377,11 @@ def compose (db, source, transfer_destination, asset, quantity, divisible, lock,
# compacts a subasset name to save space
compacted_subasset_longname = util.compact_subasset_longname(subasset_longname)
compacted_subasset_length = len(compacted_subasset_longname)
data = message_type.pack(SUBASSET_ID)
if util.enabled("issuance_backwards_compatibility"):
data = message_type.pack(LR_SUBASSET_ID)
else:
data = message_type.pack(SUBASSET_ID)

curr_format = subasset_format + '{}s'.format(compacted_subasset_length) + '{}s'.format(len(description))

if subasset_format_length <= 18:
Expand All @@ -394,7 +407,7 @@ def parse (db, tx, message, message_type_id):
# Unpack message.
try:
subasset_longname = None
if message_type_id == SUBASSET_ID:
if message_type_id == LR_SUBASSET_ID or message_type_id == SUBASSET_ID:
if not util.enabled('subassets', block_index=tx['block_index']):
logger.warn("subassets are not enabled at block %s" % tx['block_index'])
raise exceptions.UnpackError
Expand Down
7 changes: 7 additions & 0 deletions counterpartylib/protocol_changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -419,5 +419,12 @@
"minimum_version_revision": 2,
"block_index": 825000,
"testnet_block_index": 2412394
},
"issuance_backwards_compatibility": {
"minimum_version_major": 9,
"minimum_version_minor": 60,
"minimum_version_revision": 2,
"block_index": 825000,
"testnet_block_index": 2422000
}
}

0 comments on commit 403b6a4

Please sign in to comment.