Skip to content

chore: Include scripts on indexes#899

Open
gonzalezzfelipe wants to merge 1 commit intomainfrom
chore/include-scripts-on-index
Open

chore: Include scripts on indexes#899
gonzalezzfelipe wants to merge 1 commit intomainfrom
chore/include-scripts-on-index

Conversation

@gonzalezzfelipe
Copy link
Contributor

@gonzalezzfelipe gonzalezzfelipe commented Feb 13, 2026

Summary by CodeRabbit

Release Notes

  • New Features
    • Added ability to query and retrieve scripts by their hash value
    • Extended support for multiple script types: Native, PlutusV1, PlutusV2, and PlutusV3
    • Enhanced script discovery across transaction witnesses and outputs

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

This change introduces script hash indexing functionality by enabling transaction output and witness scripts to be captured into the archive index. It adds script type definitions, a delta builder method for tagging script hashes, and batch processing logic to extract and index scripts from outputs.

Changes

Cohort / File(s) Summary
Script Type Definitions
crates/cardano/src/indexes/query.rs, crates/cardano/src/indexes/mod.rs
Introduces ScriptLanguage enum (Native, PlutusV1/V2/V3) and ScriptData struct, adds script_by_hash method to AsyncCardanoQueryExt trait to retrieve scripts from archive blocks by hash, and re-exports new types.
Delta Builder Extension
crates/cardano/src/indexes/delta.rs
Adds public add_script_hash method to CardanoIndexDeltaBuilder to push SCRIPT tags containing script hashes into block tag accumulation.
Batch Processing Integration
crates/cardano/src/roll/batch.rs
Imports script handling traits, detects script references in transaction outputs (NativeScript and PlutusV variants), calls add_script_hash with computed hashes, and consolidates script hash extraction by removing local trait scope imports.

Sequence Diagram

sequenceDiagram
    participant BP as Block Processor
    participant DB as DeltaBuilder
    participant AR as Archive Index
    participant QF as QueryFacade

    BP->>BP: Process transaction output
    alt Output has script_ref
        BP->>BP: Determine script language & hash
        BP->>DB: add_script_hash(hash)
        DB->>AR: Push SCRIPT tag
    end
    
    Note over BP,AR: Later...
    
    QF->>AR: Iterate blocks by SCRIPT tag
    AR-->>QF: Block with native/plutus scripts
    QF->>QF: Search all script sources
    QF-->>QF: Match script_hash
    QF->>QF: Build ScriptData
    QF-->>QF: Return ScriptData with language
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • scarmuega

Poem

🐰 Scripts in hashes, indexed with care,
Through outputs and witnesses everywhere,
Tags accumulate, the archive grows bright,
Now query them back in the pale moonlight!
—The Cardano Rabbit 🌙✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Include scripts on indexes' accurately summarizes the main change: adding script support to the indexing system through new methods, types, and re-exports across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/include-scripts-on-index

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
crates/cardano/src/roll/batch.rs (1)

403-435: Potential duplicate script hash tags when a script appears in both witnesses and output script_ref.

If a transaction includes a script both as a witness and as a script_ref on an output, add_script_hash will be called twice for the same hash. This is functionally harmless for index lookups (the block will still be found), but it inflates tag storage. Consider whether deduplication is worthwhile — the existing code doesn't deduplicate other tag types (e.g., addresses appearing in multiple outputs), so this is consistent with current behavior.

crates/cardano/src/indexes/query.rs (1)

378-480: Consider extracting a helper to reduce the repetitive ScriptRef matching.

The ScriptRef match block (lines 439-472) is structurally identical to the one in batch.rs (lines 405-418). The witness-script iteration (lines 401-435) also mirrors the pattern in batch.rs (lines 424-435). While each context does something slightly different (one indexes, one queries), you could extract a small helper like script_hash_from_ref(script_ref: &ScriptRef) -> (ScriptLanguage, Hash<28>, Vec<u8>) to at least unify the hash computation and language tagging logic.

That said, the current implementation is correct and follows the same style as plutus_data. This is a nice-to-have.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant