Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix circulating_supply ValueError, and fix custom color payload #218

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions electrumx/lib/atomicals_blueprint_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
is_splat_operation,
is_split_operation,
location_id_bytes_to_compact,
safe_int_conversion,
)


Expand Down Expand Up @@ -491,7 +492,7 @@ def custom_color_nft_atomicals(cls, nft_atomicals, operations_found_at_inputs, t
for out_idx, _txout in enumerate(tx.outputs):
compact_atomical_id = location_id_bytes_to_compact(atomical_id)
compact_atomical_id_data = {
int(k): v
safe_int_conversion(k, -1): safe_int_conversion(v, 0)
for k, v in operations_found_at_inputs.get("payload", {}).get(compact_atomical_id, {}).items()
}
expected_value = compact_atomical_id_data.get(out_idx, 0)
Expand Down Expand Up @@ -588,7 +589,7 @@ def custom_color_ft_atomicals(cls, ft_atomicals, operations_found_at_inputs, tx)
expected_output_index = out_idx
compact_atomical_id = location_id_bytes_to_compact(atomical_id)
compact_atomical_id_data = {
int(k): v
safe_int_conversion(k, -1): safe_int_conversion(v, 0)
for k, v in operations_found_at_inputs.get("payload", {}).get(compact_atomical_id, {}).items()
}
expected_value = compact_atomical_id_data.get(expected_output_index, 0)
Expand Down
7 changes: 7 additions & 0 deletions electrumx/lib/util_atomicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2134,3 +2134,10 @@ def check_validate_proof(target_hash, proof):
return True, concat_str4, target_hash

return False, None, None


def safe_int_conversion(x, default=0):
try:
return int(x)
except (ValueError, TypeError):
return default
9 changes: 4 additions & 5 deletions electrumx/server/block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2720,13 +2720,12 @@ def populate_location_info_summary(self, atomical_id, atomical_result):
active_supply = 0
atomical_active_location_key_prefix = b"a" + atomical_id
for (
_atomical_active_location_key,
atomical_active_location_key,
atomical_active_location_value,
) in self.db.utxo_db.iterator(prefix=atomical_active_location_key_prefix):
(location_value,) = unpack_le_uint64(
atomical_active_location_value[HASHX_LEN + SCRIPTHASH_LEN : HASHX_LEN + SCRIPTHASH_LEN + 8]
)
active_supply += location_value
location = atomical_active_location_key[1 + ATOMICAL_ID_LEN : 1 + ATOMICAL_ID_LEN + ATOMICAL_ID_LEN]
atomical_value = self.db.get_uxto_atomicals_value(location, atomical_id)
active_supply += atomical_value
scripthash = atomical_active_location_value[HASHX_LEN : HASHX_LEN + SCRIPTHASH_LEN]
unique_holders[scripthash] = True
atomical_result["unique_holders"] = len(unique_holders)
Expand Down
Loading