stampchain-io / btc_stamps

Bitcoin Stamps Indexer
https://stampchain.io
GNU Affero General Public License v3.0
14 stars 5 forks source link

fix: fix the issue where an invalid JSON string causing a `SyntaxError`… #380

Closed btcopenstamp closed 3 months ago

btcopenstamp commented 3 months ago

would result in the program terminating unexpectedly.

btcopenstamp commented 3 months ago

fix #379

An invalid JSON string caused a SyntaxError, resulting in the program terminating unexpectedly. The issue first appeared on the testnet during the bitname testing process. The same code is used in src20, and when added to the src20 test cases for verification, it was found that this issue indeed causes the program to terminate unexpectedly.

Error info:

Traceback (most recent call last):
  File "/code/btc_stamps/indexer/test_src20.py", line 68, in test_src20_variations
    stamp_result, parsed_stamp, valid_stamp, prevalidated_src20 = parse_stamp(
  File "/code/btc_stamps/indexer/src/index_core/stamp.py", line 231, in parse_stamp
    return processor.process_stamp(stamp_data)
  File "/code/btc_stamps/indexer/src/index_core/stamp.py", line 31, in process_stamp
    stamp_data.process_and_store_stamp_data(
  File "/code/btc_stamps/indexer/src/index_core/models.py", line 559, in process_and_store_stamp_data
    stamp = convert_to_dict_or_string(self.data, output_format="dict")
  File "/code/btc_stamps/indexer/src/index_core/util.py", line 315, in convert_to_dict_or_string
    input_data = ast.literal_eval(input_data)
  File "/Users/mac/.pyenv/versions/3.10.13/lib/python3.10/ast.py", line 64, in literal_eval
    node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
  File "/Users/mac/.pyenv/versions/3.10.13/lib/python3.10/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    {"p":"SRC-20","op":"DEPLOY","tick":"TEST","deci":8,"lim":1000000,"max":""1000000000"}
                                                                                       ^
SyntaxError: unterminated string literal (detected at line 1)

The location where the code execution failed:

https://github.com/stampchain-io/btc_stamps/blob/b6164a4284da464f4c92d1c2ee9c99b3f3903705/indexer/src/index_core/util.py#L314-L317

Resolve the issue by catching the SyntaxError:

https://github.com/stampchain-io/btc_stamps/blob/ebdb2965bf148877919ff0597492635e9e1c540a/indexer/src/index_core/util.py#L314-L317