Skip to content

Handle duplicate ethscription prevention at the contract level#106

Merged
RogerPodacter merged 3 commits into
evm-backend-demofrom
remove_already_seen
Sep 20, 2025
Merged

Handle duplicate ethscription prevention at the contract level#106
RogerPodacter merged 3 commits into
evm-backend-demofrom
remove_already_seen

Conversation

@RogerPodacter

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements duplicate ethscription prevention at the contract level by refactoring how ethscription transactions are tracked and validated. The changes move away from application-level duplicate prevention to a more robust contract-based approach.

  • Refactored ethscription transaction tracking to use unified source metadata (source_type and source_index)
  • Removed application-level duplicate prevention logic in favor of contract-level validation
  • Added support for multiple ethscription transfers in a single transaction

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
contracts/test/EthscriptionsWithContent.t.sol New test file for testing the getEthscriptionWithContent method
app/services/eth_block_importer.rb Removed initialization of seen creates tracking
app/models/ethscription_transaction_builder.rb Updated to use new source tracking and removed duplicate prevention logic
app/models/ethscription_transaction.rb Major refactor to use unified source tracking and support multiple transfers

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread app/models/ethscription_transaction.rb Outdated
raise "Unknown ethscription operation: #{ethscription_operation}"
end
payload = ByteString.from_bin(
eth_transaction.block_hash.to_bin +

Copilot AI Sep 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method uses eth_transaction.block_hash but the EthTransaction model likely has block_hash as a Hash32 object, not a method that returns binary data. This should probably be eth_transaction.block_hash.to_bin.

Copilot uses AI. Check for mistakes.
Comment on lines +113 to +122
transaction = EthscriptionTransaction.transfer_multiple_ethscriptions(
eth_transaction: @eth_tx,
from_address: normalize_address(@eth_tx.from_address),
to_address: normalize_address(@eth_tx.to_address),
ethscription_ids: ids,
source_type: :input,
source_index: @eth_tx.transaction_index
)

@transactions << transaction
end
@transactions << transaction

Copilot AI Sep 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method creates a single transaction object for multiple ethscription transfers, but the logic doesn't handle the case where some transfers might be invalid. This could cause valid transfers to be rejected due to one invalid transfer in the batch.

Copilot uses AI. Check for mistakes.
Comment on lines +145 to +153
case ethscription_operation
when 'transfer'
if transfer_ids
# Multiple transfer (input-based)
transfer_ids.is_a?(Array) && transfer_ids.any?
else
# Single transfer (event-based)
ethscription_id.present?
end

Copilot AI Sep 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The validation logic mixes different transfer types in a single case branch, making it unclear when each branch applies. Consider separating validation for single transfers and multiple transfers into distinct methods for better clarity.

Copilot uses AI. Check for mistakes.
Comment thread app/models/ethscription_transaction.rb Outdated
@RogerPodacter

Copy link
Copy Markdown
Member Author

bugbot run

cursor[bot]

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread app/models/ethscription_transaction.rb Outdated
Comment on lines +136 to +137
source_tag = operation_source.to_s # "input" or "event"
source_tag_hash = Eth::Util.keccak256(source_tag.bytes.pack('C*')) # Hash for constant width

Copilot AI Sep 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting symbol to string and then hashing on every call is inefficient. Consider using a constant lookup table or memoization for the source tag hashes since there are only two possible values.

Copilot uses AI. Check for mistakes.
Comment on lines +162 to +170
case ethscription_operation
when 'transfer'
if transfer_ids
# Multiple transfer (input-based)
transfer_ids.is_a?(Array) && transfer_ids.any?
else
# Single transfer (event-based)
ethscription_id.present?
end

Copilot AI Sep 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation logic is inconsistent - it checks transfer_ids.is_a?(Array) but the property is already typed as T.nilable(T::Array[String]). This redundant type check should be removed since Sorbet already enforces the type.

Copilot uses AI. Check for mistakes.
@RogerPodacter RogerPodacter merged commit 0b40c0c into evm-backend-demo Sep 20, 2025
3 checks passed
@RogerPodacter RogerPodacter deleted the remove_already_seen branch September 20, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants