Skip to content

feat(drive): add paginated fetch_contract_ids and fetch_contracts - #3480

Merged
QuantumExplorer merged 2 commits into
v3.1-devfrom
feat/drive-fetch-contracts
Apr 12, 2026
Merged

QuantumExplorer merged 2 commits into
v3.1-devfrom
feat/drive-fetch-contracts

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Apr 11, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add Drive::fetch_contract_ids(start_at, limit) — paginated query of contract IDs from the DataContractDocuments root tree
  • Add Drive::fetch_contracts(start_at, limit) — paginated fetch of deserialized DataContract objects using set_subquery_key([0]) for efficient single-query retrieval, with fallback reads for historical contracts
  • Both follow the established Option<([u8; 32], bool)> pagination pattern (same as identity balance and vote queries)
  • Version-dispatched via DriveContractGetMethodVersions

Test plan

  • fetch_all_contract_ids — fetches all IDs from state
  • fetch_contract_ids_with_limit — respects limit parameter
  • fetch_contract_ids_with_pagination — multi-page traversal reconstructs full set
  • fetch_contract_ids_start_at_included — inclusive start boundary
  • fetch_contract_ids_start_at_excluded — exclusive start boundary
  • fetch_contract_ids_empty_state — empty state returns empty vec
  • fetch_all_contracts — fetches and deserializes all contracts
  • fetch_contracts_with_limit — respects limit
  • fetch_contracts_with_pagination — multi-page works correctly
  • fetch_contracts_returns_valid_data — deserialized contracts have document types
  • fetch_contracts_empty_state — empty state returns empty vec

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Paginated contract ID retrieval with optional cursors and limits for efficient browsing.
    • Paginated contract details retrieval with optional cursors and limits for accessing full contract data and metadata.
  • Tests

    • Added unit tests covering full fetch, limits, pagination semantics (inclusive/exclusive), empty state, and historical contract handling.
  • Platform Versions

    • Registered new method versions for fetch_contract_ids and fetch_contracts.

@coderabbitai

coderabbitai Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b1f98375-f029-4ae3-bc79-ef68548101a1

📥 Commits

Reviewing files that changed from the base of the PR and between 496b304 and 0d12c2c.

📒 Files selected for processing (1)
  • packages/rs-drive/src/drive/contract/get_fetch/fetch_contracts/v0/mod.rs
✅ Files skipped from review due to trivial changes (1)
  • packages/rs-drive/src/drive/contract/get_fetch/fetch_contracts/v0/mod.rs

📝 Walkthrough

Walkthrough

Adds two new Drive APIs—fetch_contract_ids and fetch_contracts—with platform-version dispatching and v0 implementations that query GroveDB using cursor-based pagination, plus platform-version schema updates and unit tests.

Changes

Cohort / File(s) Summary
fetch_contract_ids API
packages/rs-drive/src/drive/contract/get_fetch/fetch_contract_ids/mod.rs
Public entrypoint Drive::fetch_contract_ids(...) with platform-version dispatch to v0 or UnknownVersionMismatch.
fetch_contract_ids v0 Implementation
packages/rs-drive/src/drive/contract/get_fetch/fetch_contract_ids/v0/mod.rs
Builds GroveDB Query using start_at (inclusive/exclusive) or full range, wraps with SizedQuery(limit), executes raw path query, converts keys to [u8;32], errors on invalid key lengths; includes unit tests for pagination and limits.
fetch_contracts API
packages/rs-drive/src/drive/contract/get_fetch/fetch_contracts/mod.rs
Public entrypoint Drive::fetch_contracts(...) with platform-version dispatch to v0 or UnknownVersionMismatch.
fetch_contracts v0 Implementation
packages/rs-drive/src/drive/contract/get_fetch/fetch_contracts/v0/mod.rs
Queries GroveDB with range-based pagination and set_subquery_key, handles Item (direct contract) and Tree (historical contracts) resolution, deserializes bytes to DataContract, errors on unexpected shapes; includes comprehensive tests (pagination, limits, history).
Module Registration
packages/rs-drive/src/drive/contract/get_fetch/mod.rs
Registers new submodules fetch_contract_ids and fetch_contracts.
Platform Version Schema
packages/rs-platform-version/src/version/drive_versions/drive_contract_method_versions/mod.rs, .../v1.rs, .../v2.rs
Adds fetch_contract_ids and fetch_contracts FeatureVersion fields to DriveContractGetMethodVersions and sets both to 0 in v1 and v2 constants.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Drive
    participant PlatformVersion
    participant GroveDB

    Client->>Drive: fetch_contracts(start_at, limit, tx, platform_version)
    Drive->>PlatformVersion: read drive.methods.contract.get.fetch_contracts
    PlatformVersion-->>Drive: version (e.g., 0)
    Drive->>GroveDB: build Query (RangeFrom/RangeAfter/RangeFull) + SizedQuery(limit)
    GroveDB-->>Drive: Query results (path,key,element) / historical tree pointers
    Drive->>GroveDB: (if historical) get latest history item
    GroveDB-->>Drive: Element bytes
    Drive-->>Client: Vec<DataContract> (or error)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I dug a new tunnel through GroveDB's loam,
Fetching IDs and contracts to bring back home.
Cursor in paw, version map in sight,
Paginated hops through day and night.
Hooray — code and carrots, both snug and right! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main changes: adding two new paginated methods (fetch_contract_ids and fetch_contracts) to the Drive API.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/drive-fetch-contracts

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.

@thepastaclaw

thepastaclaw commented Apr 11, 2026 •

Copy link
Copy Markdown
Collaborator

Review Gate

Commit: 0d12c2c3

  • ⏳ Debounce: 3m ago (need 30m)

  • ⏳ CI checks: checks still running (3 pending)

  • ✅ CodeRabbit review: comment found

  • ✅ Off-peak hours: off-peak (11:42 PM PT Saturday)

  • Run review now (check to override)

@github-actions

Copy link
Copy Markdown
Contributor

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "ed555f8ff5eb7d40c0827450d2c6bf0d9cbd7b0359fdcda280f0babbc0765b00"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.

Add two new versioned Drive methods for querying data contracts from
the DataContractDocuments root tree with pagination support:

- `fetch_contract_ids(start_at, limit)` — returns contract IDs by
  querying the root tree for subtree keys
- `fetch_contracts(start_at, limit)` — returns deserialized DataContract
  objects using set_subquery_key([0]) for a single-query fetch, with
  fallback reads for historical contracts

Both follow the established `Option<([u8; 32], bool)>` pagination
pattern used by identity balance and vote queries.

Includes 11 tests covering: full fetch, limit, pagination across
multiple pages, start_at included/excluded, empty state, and
contract data validity.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@QuantumExplorer
QuantumExplorer force-pushed the feat/drive-fetch-contracts branch from 9bcb994 to 496b304 Compare April 11, 2026 22:24
@QuantumExplorer
QuantumExplorer changed the base branch from v2.1-dev to v3.1-dev April 11, 2026 22:24
@github-actions github-actions Bot added this to the v3.1.0 milestone Apr 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📖 Book Preview built successfully.

Download the preview from the workflow artifacts.
To view locally: download the artifact, unzip, and open index.html.

Updated at 2026-04-11T22:26:54.916Z

@codecov

codecov Bot commented Apr 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.66304% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.77%. Comparing base (153a02f) to head (0d12c2c).
⚠️ Report is 5 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
...drive/contract/get_fetch/fetch_contracts/v0/mod.rs 95.47% 9 Missing ⚠️
...ve/contract/get_fetch/fetch_contract_ids/v0/mod.rs 94.02% 8 Missing ⚠️
...drive/contract/get_fetch/fetch_contract_ids/mod.rs 75.00% 5 Missing ⚠️
...rc/drive/contract/get_fetch/fetch_contracts/mod.rs 66.66% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3480      +/-   ##
============================================
+ Coverage     84.76%   84.77%   +0.01%     
============================================
  Files          2469     2473       +4     
  Lines        266394   266762     +368     
============================================
+ Hits         225798   226139     +341     
- Misses        40596    40623      +27     
Components Coverage Δ
dpp 81.79% <ø> (ø)
drive 84.22% <92.66%> (+0.02%) ⬆️
drive-abci 87.39% <ø> (ø)
sdk ∅ <ø> (∅)
dapi-client ∅ <ø> (∅)
platform-version ∅ <ø> (∅)
platform-value 92.10% <ø> (ø)
platform-wallet ∅ <ø> (∅)
drive-proof-verifier 55.66% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Verify that fetch_contracts correctly handles contracts with
keeps_history=true, where key [0] under the contract subtree is a
Tree element (history subtree) rather than an Item.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Self Reviewed

@QuantumExplorer
QuantumExplorer merged commit 0fa0d5c into v3.1-dev Apr 12, 2026
12 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/drive-fetch-contracts branch April 12, 2026 06:46
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