-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add nft custom color #190
Add nft custom color #190
Changes from all commits
b4f8e05
42bebe6
c86e77e
1651a9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,6 +400,29 @@ def calculate_nft_atomicals_splat(cls, nft_atomicals, tx): | |
output_colored_map[expected_output_index]['atomicals'][atomical_id] = atomical_summary_info | ||
expected_output_index_incrementing += 1 | ||
return AtomicalNftOutputBlueprintAssignmentSummary(output_colored_map) | ||
|
||
@classmethod | ||
def custom_color_nft_atomicals(cls, nft_atomicals, operations_found_at_inputs, tx): | ||
# define op `z` to custom-color nft | ||
output_colored_map = {} | ||
for atomical_id, atomical_info in sorted(nft_atomicals.items()): | ||
for out_idx, txout in enumerate(tx.outputs): | ||
compact_atomical_id = location_id_bytes_to_compact(atomical_id) | ||
compact_atomical_id_data = operations_found_at_inputs["payload"].get(compact_atomical_id, {}) | ||
# if payload try to color two or more outputs, it will try to color output 0. | ||
if len(compact_atomical_id_data.keys()) > 1: | ||
expected_output_index = 0 | ||
else: | ||
# if out_idx not in payload keys, skip | ||
if str(out_idx) not in compact_atomical_id_data.keys(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens to the nft if it's not specified and skipped? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not specified defined, it will try to color output0. If defined, and the quantity is set to 0 or a negative number, it will burn. |
||
continue | ||
# if payload value <= 0, this nft will burn | ||
if compact_atomical_id_data.get(str(out_idx), 0) <= 0: | ||
continue | ||
expected_output_index = out_idx | ||
output_colored_map[expected_output_index] = output_colored_map.get(expected_output_index) or {'atomicals': {}} | ||
output_colored_map[expected_output_index]['atomicals'][atomical_id] = atomical_info | ||
return AtomicalNftOutputBlueprintAssignmentSummary(output_colored_map) | ||
|
||
@classmethod | ||
def calculate_output_blueprint_nfts( | ||
|
@@ -409,13 +432,17 @@ def calculate_output_blueprint_nfts( | |
nft_atomicals, | ||
atomicals_spent_at_inputs, | ||
operations_found_at_inputs, | ||
sort_fifo | ||
sort_fifo, | ||
is_custom_coloring_activated | ||
): | ||
if not nft_atomicals or len(nft_atomicals) == 0: | ||
return AtomicalNftOutputBlueprintAssignmentSummary({}) | ||
should_splat_nft_atomicals = is_splat_operation(operations_found_at_inputs) | ||
if should_splat_nft_atomicals and len(nft_atomicals.keys()) > 0: | ||
return AtomicalsTransferBlueprintBuilder.calculate_nft_atomicals_splat(nft_atomicals, tx) | ||
should_custom_colored_nft_atomicals = is_custom_coloring_activated and is_custom_colored_operation(operations_found_at_inputs) | ||
if should_custom_colored_nft_atomicals and len(nft_atomicals.keys()) > 0: | ||
return AtomicalsTransferBlueprintBuilder.custom_color_nft_atomicals(nft_atomicals, operations_found_at_inputs, tx) | ||
else: | ||
# To sort by fifo for NFTs, we also need to calculate a mapping of the nfts to inputs first | ||
nft_map = AtomicalsTransferBlueprintBuilder.build_nft_input_idx_to_atomical_map( | ||
|
@@ -481,6 +508,7 @@ def custom_color_ft_atomicals(cls, ft_atomicals, operations_found_at_inputs, tx) | |
str(expected_output_index), | ||
0 | ||
) | ||
# if expected_value <= 0, ft will burn | ||
if expected_value <= 0 or remaining_value <= 0: | ||
continue | ||
# if expected_value > txout.value | ||
|
@@ -666,7 +694,8 @@ def calculate_output_blueprint( | |
nft_atomicals, | ||
atomicals_spent_at_inputs, | ||
operations_found_at_inputs, | ||
sort_fifo | ||
sort_fifo, | ||
is_custom_coloring_activated | ||
) | ||
ft_blueprint = AtomicalsTransferBlueprintBuilder.calculate_output_blueprint_fts( | ||
tx, | ||
|
@@ -957,4 +986,4 @@ def get_fts_burned(self): | |
return self.fts_burned | ||
|
||
def get_atomical_ids_spent(self): | ||
return self.atomical_ids_spent | ||
return self.atomical_ids_spent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it for 'z' ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, same with the Ft