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

Put the parent realm to vout:1 if the claim type is *direct* #234

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
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
32 changes: 28 additions & 4 deletions electrumx/lib/atomicals_blueprint_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
compact_to_location_id_bytes,
is_compact_atomical_id,
is_custom_colored_operation,
is_integer_num,
is_mint_operation,
is_op_return_dmitem_payment_marker_atomical_id,
is_op_return_subrealm_payment_marker_atomical_id,
Expand Down Expand Up @@ -318,6 +317,7 @@ def __init__(
get_atomicals_id_mint_info,
sort_fifo,
is_custom_coloring_activated,
is_subrealm_direct_minting_fixture_activated,
):
self.logger = logger
self.atomicals_spent_at_inputs = atomicals_spent_at_inputs
Expand All @@ -327,6 +327,7 @@ def __init__(
self.get_atomicals_id_mint_info = get_atomicals_id_mint_info
self.sort_fifo = sort_fifo
self.is_custom_coloring_activated = is_custom_coloring_activated
self.is_subrealm_direct_minting_fixture_activated = is_subrealm_direct_minting_fixture_activated
(
nft_atomicals,
ft_atomicals,
Expand All @@ -348,6 +349,7 @@ def __init__(
self.operations_found_at_inputs,
self.sort_fifo,
self.is_custom_coloring_activated,
self.is_subrealm_direct_minting_fixture_activated,
)
self.nft_output_blueprint = nft_output_blueprint
self.ft_output_blueprint = ft_output_blueprint
Expand Down Expand Up @@ -418,10 +420,24 @@ def build_nft_input_idx_to_atomical_map(cls, get_atomicals_id_mint_info, atomica
return input_idx_to_atomical_ids_map

@classmethod
def calculate_nft_atomicals_regular(cls, nft_map, nft_atomicals, tx, operations_found_at_inputs, sort_fifo):
def calculate_nft_atomicals_regular(
cls,
nft_map,
nft_atomicals,
tx,
operations_found_at_inputs,
sort_fifo,
is_subrealm_direct_minting_fixture_activated,
):
# Use a simplified mapping of NFTs using FIFO to the outputs
if sort_fifo:
next_output_idx = 0
# Extra handling for the sub-realm:
# Put the parent realm to vout:1 if the claim type is *direct* and have more than 1 output,
# otherwise they will be merged into vout:0.
claim_type = operations_found_at_inputs.get("payload", {}).get("args", {}).get("claim_type")
if is_subrealm_direct_minting_fixture_activated and claim_type == "direct" and len(tx.outputs) > 1:
next_output_idx = 1
map_output_idxs_for_atomicals = {}
# Build a map of input ids to NFTs
for _input_idx, atomicals_ids_map in nft_map.items():
Expand Down Expand Up @@ -538,6 +554,7 @@ def calculate_output_blueprint_nfts(
operations_found_at_inputs,
sort_fifo,
is_custom_coloring_activated,
is_subrealm_direct_minting_fixture_activated,
) -> AtomicalNftOutputBlueprintAssignmentSummary:
if not nft_atomicals or len(nft_atomicals) == 0:
return AtomicalNftOutputBlueprintAssignmentSummary({})
Expand All @@ -556,7 +573,12 @@ def calculate_output_blueprint_nfts(
get_atomicals_id_mint_info, atomicals_spent_at_inputs
)
return AtomicalsTransferBlueprintBuilder.calculate_nft_atomicals_regular(
nft_map, nft_atomicals, tx, operations_found_at_inputs, sort_fifo
nft_map,
nft_atomicals,
tx,
operations_found_at_inputs,
sort_fifo,
is_subrealm_direct_minting_fixture_activated,
)

@classmethod
Expand Down Expand Up @@ -786,6 +808,7 @@ def calculate_output_blueprint(
operations_found_at_inputs,
sort_fifo,
is_custom_coloring_activated,
is_subrealm_direct_minting_fixture_activated,
) -> Tuple[
AtomicalNftOutputBlueprintAssignmentSummary,
AtomicalFtOutputBlueprintAssignmentSummary,
Expand All @@ -798,6 +821,7 @@ def calculate_output_blueprint(
operations_found_at_inputs,
sort_fifo,
is_custom_coloring_activated,
is_subrealm_direct_minting_fixture_activated,
)
ft_blueprint = AtomicalsTransferBlueprintBuilder.calculate_output_blueprint_fts(
tx,
Expand Down Expand Up @@ -1002,7 +1026,7 @@ def are_payments_satisfied(self, expected_payment_outputs):
# There is no value defined or the expected payment is below the dust limit, or skip it
expected_output_payment_value = expected_output_payment_value_dict.get("v", None)
if (
not is_integer_num(expected_output_payment_value)
not isinstance(expected_output_payment_value, int)
or expected_output_payment_value < SUBNAME_MIN_PAYMENT_DUST_LIMIT
):
continue
Expand Down
4 changes: 4 additions & 0 deletions electrumx/lib/coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ class AtomicalsCoinMixin:
ATOMICALS_ACTIVATION_HEIGHT_DENSITY: int
ATOMICALS_ACTIVATION_HEIGHT_DFT_BITWORK_ROLLOVER: int
ATOMICALS_ACTIVATION_HEIGHT_CUSTOM_COLORING: int
ATOMICALS_ACTIVATION_HEIGHT_SUBREALM_DIRECT_MINTING_FIXTURE: int


class AuxPowMixin:
Expand Down Expand Up @@ -695,6 +696,7 @@ class Bitcoin(BitcoinMixin, AtomicalsCoinMixin, Coin):
ATOMICALS_ACTIVATION_HEIGHT_DENSITY = 828128
ATOMICALS_ACTIVATION_HEIGHT_DFT_BITWORK_ROLLOVER = 828628
ATOMICALS_ACTIVATION_HEIGHT_CUSTOM_COLORING = 848484
ATOMICALS_ACTIVATION_HEIGHT_SUBREALM_DIRECT_MINTING_FIXTURE = 866000

@classmethod
def warn_old_client_on_tx_broadcast(cls, client_ver):
Expand Down Expand Up @@ -977,6 +979,7 @@ class BitcoinTestnet(BitcoinTestnetMixin, AtomicalsCoinMixin, Coin):
ATOMICALS_ACTIVATION_HEIGHT_DENSITY = 2572729
ATOMICALS_ACTIVATION_HEIGHT_DFT_BITWORK_ROLLOVER = 2576412
ATOMICALS_ACTIVATION_HEIGHT_CUSTOM_COLORING = 2584936
ATOMICALS_ACTIVATION_HEIGHT_SUBREALM_DIRECT_MINTING_FIXTURE = 2585000

@classmethod
def warn_old_client_on_tx_broadcast(cls, client_ver):
Expand Down Expand Up @@ -1007,6 +1010,7 @@ class BitcoinTestnet4(BitcoinTestnetMixin, AtomicalsCoinMixin, Coin):
ATOMICALS_ACTIVATION_HEIGHT_DENSITY = 27000
ATOMICALS_ACTIVATION_HEIGHT_DFT_BITWORK_ROLLOVER = 27000
ATOMICALS_ACTIVATION_HEIGHT_CUSTOM_COLORING = 27000
ATOMICALS_ACTIVATION_HEIGHT_SUBREALM_DIRECT_MINTING_FIXTURE = 27000

@classmethod
def warn_old_client_on_tx_broadcast(cls, client_ver):
Expand Down
8 changes: 1 addition & 7 deletions electrumx/lib/util_atomicals.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ def is_sanitized_dict_whitelist_only(d: dict, allow_bytes=False):
return True


def is_integer_num(n):
if isinstance(n, int):
return True
return False


# Check whether the value is hex string
def is_hex_string(value):
if not isinstance(value, str):
Expand Down Expand Up @@ -1518,7 +1512,7 @@ def validate_subrealm_rules_outputs_format(outputs):
return False # Reject if one of the entries expects less than the minimum payment amount
expected_output_id = expected_output_value.get("id")
expected_output_qty = expected_output_value.get("v")
if not is_integer_num(expected_output_qty) or expected_output_qty < SUBNAME_MIN_PAYMENT_DUST_LIMIT:
if not isinstance(expected_output_qty, int) or expected_output_qty < SUBNAME_MIN_PAYMENT_DUST_LIMIT:
print_subrealm_calculate_log("validate_subrealm_rules_outputs_format: invalid expected output value")
return False # Reject if one of the entries expects less than the minimum payment amount
# If there is a type restriction on the payment type then ensure it is a valid atomical id
Expand Down
9 changes: 9 additions & 0 deletions electrumx/server/block_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,7 @@ def color_atomicals_outputs(
self.get_atomicals_id_mint_info,
self.is_dmint_activated(height),
self.is_custom_coloring_activated(height),
self.is_subrealm_direct_minting_fixture_activated(height),
)

nft_output_blueprint = blueprint_builder.get_nft_output_blueprint()
Expand Down Expand Up @@ -3511,6 +3512,13 @@ def is_custom_coloring_activated(self, height):
return True
return False

def is_subrealm_direct_minting_fixture_activated(self, height):
if height >= self.coin.ATOMICALS_ACTIVATION_HEIGHT_SUBREALM_DIRECT_MINTING_FIXTURE:
return True
if height <= 0:
return True
return False

# Builds a map of the atomicals spent at a tx
# It uses the spend_atomicals_utxo method but with live_run == False
def build_atomicals_spent_at_inputs_for_validation_only(self, tx):
Expand Down Expand Up @@ -3921,6 +3929,7 @@ def create_or_delete_subname_payment_output_if_valid(
self.get_atomicals_id_mint_info,
self.is_dmint_activated(height),
self.is_custom_coloring_activated(height),
self.is_subrealm_direct_minting_fixture_activated(height),
)
if blueprint_builder.is_split_operation():
self.logger.warning(
Expand Down
3 changes: 3 additions & 0 deletions electrumx/server/session/session_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ def validate_raw_tx_blueprint(self, raw_tx, raise_if_burned=True) -> AtomicalsVa
self.bp.get_atomicals_id_mint_info,
True,
self.bp.is_custom_coloring_activated(self.bp.height),
self.bp.is_subrealm_direct_minting_fixture_activated(self.bp.height),
)
encoded_atomicals_spent_at_inputs = encode_atomical_ids_hex(atomicals_spent_at_inputs)
ft_output_blueprint = blueprint_builder.get_ft_output_blueprint()
Expand Down Expand Up @@ -895,6 +896,7 @@ async def transaction_decode_raw_tx_blueprint(
self.bp.get_atomicals_id_mint_info,
True,
self.bp.is_custom_coloring_activated(self.bp.height),
self.bp.is_subrealm_direct_minting_fixture_activated(self.bp.height),
)
ft_output_blueprint = blueprint_builder.get_ft_output_blueprint()
nft_output_blueprint = blueprint_builder.get_nft_output_blueprint()
Expand Down Expand Up @@ -1021,6 +1023,7 @@ async def get_transaction_detail(self, tx_id: str, height=None, tx_num=-1):
self.bp.get_atomicals_id_mint_info,
self.bp.is_dmint_activated(height),
self.bp.is_custom_coloring_activated(height),
self.bp.is_subrealm_direct_minting_fixture_activated(height),
)
is_burned = blueprint_builder.are_fts_burned
is_cleanly_assigned = blueprint_builder.cleanly_assigned
Expand Down
Loading
Loading