From f5ecb6bf1cec9ed13f48bd89ec770ba7a0f72edb Mon Sep 17 00:00:00 2001 From: Alex Li Date: Wed, 17 Apr 2024 21:53:47 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`auto=5Fencode=5Fbytes=5Fe?= =?UTF-8?q?lements`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electrumx/lib/util_atomicals.py | 25 +++++++++++++------------ electrumx/server/block_processor.py | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/electrumx/lib/util_atomicals.py b/electrumx/lib/util_atomicals.py index 3de54566..a8ee9989 100644 --- a/electrumx/lib/util_atomicals.py +++ b/electrumx/lib/util_atomicals.py @@ -1282,7 +1282,8 @@ def encode_tx_hash_hex(state): cloned_state[encode_tx_hash_hex(key)] = encode_tx_hash_hex(value) return cloned_state -# Auto detect any bytes data and encoded it + +# Auto encodes data into structured bytes data. def auto_encode_bytes_elements(state): if isinstance(state, bytes): return { @@ -1290,23 +1291,23 @@ def auto_encode_bytes_elements(state): '$len': sys.getsizeof(state), '$auto': True } - + if isinstance(state, CBORTag): - return dumps(state) - - if not isinstance(state, dict) and not isinstance(state, list): - return state - + dumped_bytes = dumps(state) + return auto_encode_bytes_elements(dumped_bytes) + if isinstance(state, list): reformatted_list = [] for item in state: reformatted_list.append(auto_encode_bytes_elements(item)) return reformatted_list - - for key, value in state.items(): - state[key] = auto_encode_bytes_elements(value) - return state - + + if isinstance(state, dict): + for key, value in state.items(): + state[key] = auto_encode_bytes_elements(value) + + return state + # Base atomical commit to reveal delay allowed def is_within_acceptable_blocks_for_general_reveal(commit_height, reveal_location_height): diff --git a/electrumx/server/block_processor.py b/electrumx/server/block_processor.py index 4db37869..6fa82a7d 100644 --- a/electrumx/server/block_processor.py +++ b/electrumx/server/block_processor.py @@ -1619,7 +1619,7 @@ def put_or_delete_init_state_updates(self, mint_info, data_payload, Delete): # Make a deep copy of the data payload and remove the reserved sections copied_data_state = {} for k, v in data_payload.items(): - if k != "args": + if k != 'args': copied_data_state[k] = v init_payload_bytes = dumps(copied_data_state) op_struct = {