Skip to content

Commit 2ddfc75

Browse files
authored
Merge pull request #165 from AtomicalsBuilder/fix-cbor
fix CBORTag
2 parents c7ccea3 + f5ecb6b commit 2ddfc75

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

electrumx/lib/util_atomicals.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import pickle
4040
import math
4141
from electrumx.lib.hash import sha256, double_sha256
42-
from cbor2 import dumps, loads, CBORDecodeError
42+
from cbor2 import dumps, loads, CBORDecodeError, CBORTag
4343
from collections.abc import Mapping
4444
from functools import reduce
4545
from merkletools import MerkleTools
@@ -1282,27 +1282,32 @@ def encode_tx_hash_hex(state):
12821282
cloned_state[encode_tx_hash_hex(key)] = encode_tx_hash_hex(value)
12831283
return cloned_state
12841284

1285-
# Auto detect any bytes data and encoded it
1285+
1286+
# Auto encodes data into structured bytes data.
12861287
def auto_encode_bytes_elements(state):
12871288
if isinstance(state, bytes):
12881289
return {
12891290
'$b': state.hex(),
12901291
'$len': sys.getsizeof(state),
12911292
'$auto': True
12921293
}
1293-
if not isinstance(state, dict) and not isinstance(state, list):
1294-
return state
1295-
1294+
1295+
if isinstance(state, CBORTag):
1296+
dumped_bytes = dumps(state)
1297+
return auto_encode_bytes_elements(dumped_bytes)
1298+
12961299
if isinstance(state, list):
12971300
reformatted_list = []
12981301
for item in state:
12991302
reformatted_list.append(auto_encode_bytes_elements(item))
1300-
return reformatted_list
1303+
return reformatted_list
1304+
1305+
if isinstance(state, dict):
1306+
for key, value in state.items():
1307+
state[key] = auto_encode_bytes_elements(value)
1308+
1309+
return state
13011310

1302-
for key, value in state.items():
1303-
state[key] = auto_encode_bytes_elements(value)
1304-
return state
1305-
13061311

13071312
# Base atomical commit to reveal delay allowed
13081313
def is_within_acceptable_blocks_for_general_reveal(commit_height, reveal_location_height):

electrumx/server/block_processor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,9 +1617,10 @@ def put_or_delete_init_state_updates(self, mint_info, data_payload, Delete):
16171617
height = mint_info['reveal_location_height']
16181618

16191619
# Make a deep copy of the data payload and remove the reserved sections
1620-
copied_data_state = copy.deepcopy(data_payload)
1621-
# Remove any of the reserved sections
1622-
copied_data_state.pop('args', None)
1620+
copied_data_state = {}
1621+
for k, v in data_payload.items():
1622+
if k != 'args':
1623+
copied_data_state[k] = v
16231624
init_payload_bytes = dumps(copied_data_state)
16241625
op_struct = {
16251626
'op': 'mod',

requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@ python-dotenv
1313
# For LevelDB
1414
plyvel
1515

16-
# For RocksDB
17-
Cython
18-
rocksdb @ git+https://github.com/jansegre/python-rocksdb@6177a68

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def find_version():
2929
extras_require={
3030
'dev': ['objgraph'],
3131
'rapidjson': ['python-rapidjson>=0.4.1,<2.0'],
32-
'rocksdb': ['python-rocksdb>=0.6.9'],
32+
'rocksdb': ['Cython', 'rocksdb @ git+https://github.com/jansegre/python-rocksdb@6177a68'],
3333
'ujson': ['ujson>=2.0.0,<4.0.0'],
3434
'uvloop': ['uvloop>=0.14'],
3535
# For various coins

0 commit comments

Comments
 (0)