atomicals / atomicals-electrumx

Electrumx Atomicals Indexer Server
MIT License
187 stars 55 forks source link

Fix transaction inputs outputs calculation error. #195

Closed shadowv0vshadow closed 5 months ago

shadowv0vshadow commented 5 months ago

Refactor make_transfer_inputs and make_transfer_outputs function.

if blueprint_builder.ft_atomicals and atomicals_spent_at_inputs:
            if not operation_type and not op_raw:
                op_raw = "transfer"
            for atomical_id, input_ft in blueprint_builder.ft_atomicals.items():
                compact_atomical_id = location_id_bytes_to_compact(atomical_id)
                res["transfers"]["inputs"] = await make_transfer_inputs(tx.inputs, compact_atomical_id, input_ft, "FT")
            for k, v in blueprint_builder.ft_output_blueprint.outputs.items():
                res["transfers"]["outputs"] = make_transfer_outputs(k, v)
        if blueprint_builder.nft_atomicals and atomicals_spent_at_inputs:
            if not operation_type and not op_raw:
                op_raw = "transfer"
            for atomical_id, input_nft in blueprint_builder.nft_atomicals.items():
                compact_atomical_id = location_id_bytes_to_compact(atomical_id)
                res["transfers"]["inputs"] = await make_transfer_inputs(
                    tx.inputs, compact_atomical_id, input_nft, "NFT"
                )
            for k, v in blueprint_builder.nft_output_blueprint.outputs.items():
                res["transfers"]["outputs"] = make_transfer_outputs(k, v)

res["transfers"]["outputs"] need append, Direct assignment is not possible as it will cause overwriting. If the output contains both FT and NFT, the result will be overwritten, leading to errors.