diff --git a/electrumx/lib/util_atomicals.py b/electrumx/lib/util_atomicals.py index 76568fa9..a8ee9989 100644 --- a/electrumx/lib/util_atomicals.py +++ b/electrumx/lib/util_atomicals.py @@ -39,7 +39,7 @@ import pickle import math from electrumx.lib.hash import sha256, double_sha256 -from cbor2 import dumps, loads, CBORDecodeError +from cbor2 import dumps, loads, CBORDecodeError, CBORTag from collections.abc import Mapping from functools import reduce from merkletools import MerkleTools @@ -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,19 +1291,23 @@ def auto_encode_bytes_elements(state): '$len': sys.getsizeof(state), '$auto': True } - if not isinstance(state, dict) and not isinstance(state, list): - return state - + + if isinstance(state, CBORTag): + 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 + return reformatted_list + + if isinstance(state, dict): + for key, value in state.items(): + state[key] = auto_encode_bytes_elements(value) + + return state - 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 37366458..6fa82a7d 100644 --- a/electrumx/server/block_processor.py +++ b/electrumx/server/block_processor.py @@ -1617,9 +1617,10 @@ def put_or_delete_init_state_updates(self, mint_info, data_payload, Delete): height = mint_info['reveal_location_height'] # Make a deep copy of the data payload and remove the reserved sections - copied_data_state = copy.deepcopy(data_payload) - # Remove any of the reserved sections - copied_data_state.pop('args', None) + copied_data_state = {} + for k, v in data_payload.items(): + if k != 'args': + copied_data_state[k] = v init_payload_bytes = dumps(copied_data_state) op_struct = { 'op': 'mod', diff --git a/requirements.txt b/requirements.txt index a842b5fc..e34c676d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,3 @@ python-dotenv # For LevelDB plyvel -# For RocksDB -Cython -rocksdb @ git+https://github.com/jansegre/python-rocksdb@6177a68 diff --git a/setup.py b/setup.py index 927f5048..d0cce275 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def find_version(): extras_require={ 'dev': ['objgraph'], 'rapidjson': ['python-rapidjson>=0.4.1,<2.0'], - 'rocksdb': ['python-rocksdb>=0.6.9'], + 'rocksdb': ['Cython', 'rocksdb @ git+https://github.com/jansegre/python-rocksdb@6177a68'], 'ujson': ['ujson>=2.0.0,<4.0.0'], 'uvloop': ['uvloop>=0.14'], # For various coins