Skip to content

Commit

Permalink
Merge pull request #165 from AtomicalsBuilder/fix-cbor
Browse files Browse the repository at this point in the history
fix CBORTag
  • Loading branch information
atomicals authored Apr 17, 2024
2 parents c7ccea3 + f5ecb6b commit 2ddfc75
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
25 changes: 15 additions & 10 deletions electrumx/lib/util_atomicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1282,27 +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 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):
Expand Down
7 changes: 4 additions & 3 deletions electrumx/server/block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@ python-dotenv
# For LevelDB
plyvel

# For RocksDB
Cython
rocksdb @ git+https://github.com/jansegre/python-rocksdb@6177a68
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2ddfc75

Please sign in to comment.