Skip to content

Commit

Permalink
🐛 Fix auto_encode_bytes_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Apr 17, 2024
1 parent 5783a27 commit f5ecb6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions electrumx/lib/util_atomicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,31 +1282,32 @@ 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 {
'$b': state.hex(),
'$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):
Expand Down
2 changes: 1 addition & 1 deletion electrumx/server/block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit f5ecb6b

Please sign in to comment.