Skip to content

Commit

Permalink
Merge pull request #172 from atomicals/develop
Browse files Browse the repository at this point in the history
Minor Release: v1.4.0
  • Loading branch information
AlexV525 authored Apr 26, 2024
2 parents f89613b + 3b7212a commit dd15e23
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
pull_request:
branches:
- 'master'
- 'develop'
paths-ignore:
- '**/*.md'
- '**/*.rst'
Expand Down
36 changes: 36 additions & 0 deletions electrumx/lib/util_atomicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,42 @@ def auto_encode_bytes_elements(state):
return state


# Auto-detect any bytes keys and values and encoded it.
def auto_encode_bytes_items(state):
if isinstance(state, bytes):
return {
'$b': state.hex(),
'$len': sys.getsizeof(state),
'$auto': True
}

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

cloned_state = {}
try:
if isinstance(state, dict):
items = state.items()
else:
items = state.__dict__.items()
except AttributeError:
return state
for key, value in items:
if isinstance(key, bytes):
cloned_state[key.hex()] = auto_encode_bytes_items(value)
else:
cloned_state[auto_encode_bytes_items(key)] = auto_encode_bytes_items(value)

return cloned_state


# Base atomical commit to reveal delay allowed
def is_within_acceptable_blocks_for_general_reveal(commit_height, reveal_location_height):
return commit_height >= reveal_location_height - MINT_GENERAL_COMMIT_REVEAL_DELAY_BLOCKS
Expand Down
16 changes: 13 additions & 3 deletions electrumx/server/block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
is_event_operation,
encode_atomical_ids_hex,
is_mint_pow_valid,
is_txid_valid_for_perpetual_bitwork
is_txid_valid_for_perpetual_bitwork,
auto_encode_bytes_items
)

from electrumx.lib.atomicals_blueprint_builder import AtomicalsTransferBlueprintBuilder
Expand Down Expand Up @@ -546,8 +547,17 @@ def validate_ft_rules_raw_tx(self, raw_tx):
# Log that there were tokens burned due to not being cleanly assigned
if blueprint_builder.get_are_fts_burned() or not blueprint_builder.cleanly_assigned:
encoded_atomicals_spent_at_inputs = encode_atomical_ids_hex(atomicals_spent_at_inputs)
encoded_ft_output_blueprint = encode_atomical_ids_hex(ft_output_blueprint)
raise AtomicalsValidationError(f'detected invalid ft token inputs and outputs for tx_hash={hash_to_hex_str(tx_hash)}, operations_found_at_inputs={operations_found_at_inputs}, atomicals_spent_at_inputs={encoded_atomicals_spent_at_inputs}, ft_output_blueprint.outputs={encoded_ft_output_blueprint.outputs} ft_output_blueprint.fts_burned={encoded_ft_output_blueprint.fts_burned}')
encoded_ft_output_blueprint = auto_encode_bytes_items(encode_atomical_ids_hex(ft_output_blueprint))
outputs = encoded_ft_output_blueprint['outputs']
fts_burned = encoded_ft_output_blueprint['fts_burned']
raise AtomicalsValidationError(
f'Invalid FT token inputs/outputs:\n'
f'tx_hash={hash_to_hex_str(tx_hash)}\n'
f'operations_found_at_inputs={operations_found_at_inputs}\n'
f'atomicals_spent_at_inputs={encoded_atomicals_spent_at_inputs}\n'
f'ft_output_blueprint.outputs={outputs}\n'
f'ft_output_blueprint.fts_burned={fts_burned}'
)

# Query general data including the cache
def get_general_data_with_cache(self, key):
Expand Down
3 changes: 2 additions & 1 deletion electrumx_server
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ load_dotenv()
def main():
'''Set up logging and run the server.'''
log_fmt = Env.default('LOG_FORMAT', '%(levelname)s:%(name)s:%(message)s')
log_level = Env.default('LOG_LEVEL', 'INFO')
log_path = Env.default('LOG_PATH', None)
if log_path:
exist =os.path.exists(log_path)
Expand All @@ -34,7 +35,7 @@ def main():
else:
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(CompactFormatter(log_fmt))
logger = make_logger('electrumx', handler=handler, level='INFO')
logger = make_logger('electrumx', handler=handler, level=log_level)

logger.info('ElectrumX server starting')
try:
Expand Down

0 comments on commit dd15e23

Please sign in to comment.