Skip to content

Conversation

@shumkov
Copy link
Collaborator

@shumkov shumkov commented Nov 27, 2025

Issue being fixed or feature implemented

Some of the methods aren't verifiable or do not provide proof information.

What was done?

  • Fixed getTokenPerpetualDistributionLastClaim to prefetch token configuration before proof-verified queries
  • Implemented proof-verified variants for getProtocolVersionUpgradeVoteStatus, getEvonodesProposedEpochBlocksByIds, and getEvonodesProposedEpochBlocksByRange
  • Added token configuration caching to TrustedHttpContextProvider

How Has This Been Tested?

  • Added functional tests for all new proof variants in wasm-sdk and js-evo-sdk

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Token configuration cache to improve token-related query performance and a prefetch helper to prime it.
    • Proof-enabled query responses for epoch proposed blocks, protocol upgrade votes, and token last-claim (now include data + proof + metadata).
    • New client APIs returning "with proof" variants and a unified moment-based representation for token distribution claims.
  • Tests

    • Functional tests added to validate data, proof, and metadata for the new "with proof" endpoints.
  • Documentation

    • Added TODO outlining planned type/network wrapper improvements.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 27, 2025

📝 Walkthrough

Walkthrough

Implements proof-enabled query endpoints in the Wasm SDK and JS SDK tests, adds trusted-context token-configuration caching APIs in the Rust provider, and introduces token-prefetching and moment-based last-claim conversions in Wasm token queries.

Changes

Cohort / File(s) Summary
JS & Wasm Tests: Epoch Proof Queries
packages/js-evo-sdk/tests/functional/epoch.spec.mjs, packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs
Adds tests for ByIdsWithProofInfo and ByRangeWithProofInfo evonode epoch endpoints; assert data is a Map and proof and metadata are present.
JS & Wasm Tests: Protocol Proof Queries
packages/js-evo-sdk/tests/functional/protocol.spec.mjs, packages/wasm-sdk/tests/functional/protocol.spec.mjs
Adds tests for protocol upgrade endpoints with proofs (versionUpgradeStateWithProof, versionUpgradeVoteStatusWithProof), asserting data, proof, and metadata.
Rust Trusted Context: Token Cache
packages/rs-sdk-trusted-context-provider/src/provider.rs
Adds public known_token_configurations: Arc<Mutex<HashMap<Identifier, TokenConfiguration>>>, initializes it in constructors, exposes add_known_token_configuration(s), and makes get_token_configuration consult the cache before fallback.
Wasm Context Integration
packages/wasm-sdk/src/context_provider.rs
Adds pub fn add_known_token_configuration(&self, token_id: Identifier, config: TokenConfiguration) delegating to the inner provider to populate the cache.
Wasm Epoch Queries
packages/wasm-sdk/src/queries/epoch.rs
Implements get_evonodes_proposed_epoch_blocks_by_ids_with_proof_info and get_evonodes_proposed_epoch_blocks_by_range_with_proof_info; parse IDs/range, fetch counts with metadata+proof, and return ProofMetadataResponseWasm wrapping Map<Identifier, bigint>; removes order_ascending from range query types.
Wasm Protocol Query
packages/wasm-sdk/src/queries/protocol.rs
Implements get_protocol_version_upgrade_vote_status_with_proof_info: parses startProTxHash (string/Uint8Array), builds LimitQuery, fetches votes with metadata+proof, converts to wasm Map, and returns ProofMetadataResponseWasm.
Wasm Token Query Enhancements
packages/wasm-sdk/src/queries/token.rs
Replaces last-claim representation with RewardDistributionMomentWasm, adds From<RewardDistributionMoment> conversion, adds prefetch_token_configuration(token_id) helper, wires prefetch into proof paths, and adapts last-claim proof-aware flows.
Planning / Docs
packages/wasm-dpp2/TODO.md
New TODO describing planned ProTxHashWasm and NetworkWasm wrappers and intended effects (documentation only).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Client
    participant WASM as Wasm SDK
    participant EpochQuery as Epoch Query Handler
    participant Service as ProposerBlockCount Service
    participant Context as Trusted Context

    Client->>WASM: getEvonodesProposedEpochBlocksByIdsWithProofInfo(epoch, ids)
    WASM->>EpochQuery: validate & parse ProTxHash ids
    EpochQuery->>Service: fetch_many_with_metadata_and_proof(ids, epoch)
    Service-->>EpochQuery: counts, metadata, proof
    EpochQuery->>Context: (optional) check/add known token configuration
    EpochQuery-->>WASM: ProofMetadataResponseWasm{data: Map, proof, metadata}
    WASM-->>Client: return proof-enabled response
Loading
sequenceDiagram
    autonumber
    actor Client
    participant WASM as Wasm SDK
    participant ProtocolQuery as Protocol Query Handler
    participant VoteService as MasternodeProtocolVote Service

    Client->>WASM: getProtocolVersionUpgradeVoteStatusWithProofInfo(startProTxHash, count)
    WASM->>ProtocolQuery: parse startProTxHash (string|Uint8Array)
    ProtocolQuery->>VoteService: fetch_many_with_metadata_and_proof(LimitQuery)
    VoteService-->>ProtocolQuery: votes, metadata, proof
    ProtocolQuery-->>WASM: ProofMetadataResponseWasm{Map<string, VoteStatus>, proof, metadata}
    WASM-->>Client: return proof-enabled response
Loading
sequenceDiagram
    autonumber
    actor Client
    participant WASM as Wasm SDK
    participant TokenQuery as Token Query Handler
    participant Context as Trusted Context
    participant Fallback as Fallback Provider

    Client->>WASM: token query requiring configuration (token_id)
    WASM->>TokenQuery: prefetch_token_configuration(token_id)
    TokenQuery->>Context: check known_token_configurations cache
    alt cached
        Context-->>TokenQuery: cached TokenConfiguration
    else not cached
        TokenQuery->>Fallback: fetch TokenContractInfo & DataContract
        Fallback-->>TokenQuery: contract data
        TokenQuery->>Context: add_known_token_configuration(token_id, config)
        Context-->>TokenQuery: cache stored
    end
    TokenQuery->>TokenQuery: perform proof-aware fetch (e.g., last-claim)
    TokenQuery-->>WASM: ProofMetadataResponseWasm
    WASM-->>Client: return result with proof and metadata
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 I parsed the hashes, cached the seeds,

proofs hop in where logic leads.
Tests clap paws, the queries hum—
cached tokens rest, results come. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix(sdk): non proved JS SDK methods' accurately captures the main objective of implementing proof verification for JavaScript SDK methods.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 fix/sdk/non-proved-token-query

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.

@shumkov shumkov marked this pull request as ready for review December 27, 2025 09:52
@shumkov shumkov self-assigned this Dec 27, 2025
@shumkov shumkov added this to the v3.0.0 milestone Dec 27, 2025
@shumkov shumkov changed the title fix: non proved get_token_perpetual_distribution_last_claim fix(sdk): non proved JS SDK methods Dec 27, 2025
@github-actions
Copy link

github-actions bot commented Dec 27, 2025

✅ gRPC Query Coverage Report

================================================================================
gRPC Query Coverage Report - NEW QUERIES ONLY
================================================================================

Total queries in proto: 51
Previously known queries: 51
New queries found: 0


================================================================================
Summary:
--------------------------------------------------------------------------------
No new queries found

Total known queries: 51
  - Implemented: 46
  - Not implemented: 4
  - Excluded: 1

Not implemented queries:
  - getAddressesBranchState
  - getAddressesTrunkState
  - getConsensusParams
  - getTokenPreProgrammedDistributions

@github-actions github-actions bot modified the milestones: v3.0.0, v2.2.0 Dec 27, 2025
@shumkov shumkov changed the base branch from v2.2-dev to v3.0-dev December 27, 2025 12:29
@github-actions github-actions bot modified the milestones: v2.2.0, v3.0.0 Dec 27, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
packages/wasm-sdk/tests/functional/protocol.spec.mjs (1)

39-46: Consider extracting START_PROTX to describe-level scope.

The START_PROTX constant is duplicated at lines 34 and 40. Consider defining it once at the describe block level for better maintainability.

🔎 Proposed refactor
 describe('Protocol versions', function describeProtocolVersions() {
   this.timeout(60000);

   let client;
   let builder;
+  const START_PROTX = '143dcd6a6b7684fde01e88a10e5d65de9a29244c5ecd586d14a342657025f113';

   // ... in tests, remove local declarations and use the shared constant
packages/wasm-sdk/src/queries/token.rs (2)

506-514: Clarify the semantic meaning of last_claim_block_height for EpochBasedMoment.

When handling EpochBasedMoment, the epoch value is stored in last_claim_block_height. This could be semantically confusing to consumers since an epoch is not a block height. Consider either:

  1. Adding a comment explaining this mapping, or
  2. Extending TokenLastClaimWasm with an epoch field for clearer semantics.

882-896: Reduce code duplication between proof and non-proof variants.

The RewardDistributionMoment to TokenLastClaimWasm mapping logic is duplicated between get_token_perpetual_distribution_last_claim (lines 506-514) and get_token_perpetual_distribution_last_claim_with_proof_info (lines 882-896). Consider extracting this to a helper function.

🔎 Proposed helper extraction
fn moment_to_last_claim_wasm(moment: RewardDistributionMoment) -> TokenLastClaimWasm {
    let (last_claim_timestamp_ms, last_claim_block_height) = match moment {
        RewardDistributionMoment::BlockBasedMoment(height) => (0, height),
        RewardDistributionMoment::TimeBasedMoment(timestamp) => (timestamp, 0),
        RewardDistributionMoment::EpochBasedMoment(epoch) => (0, epoch as u64),
    };
    TokenLastClaimWasm::new(last_claim_timestamp_ms, last_claim_block_height)
}
packages/wasm-sdk/src/queries/protocol.rs (1)

270-294: Consider extracting ProTxHash parsing logic to reduce duplication.

The ProTxHash parsing logic (lines 270-294) is duplicated from get_protocol_version_upgrade_vote_status (lines 160-183). Consider extracting this to a helper function.

🔎 Proposed helper extraction
fn parse_optional_pro_tx_hash(js_value: JsValue) -> Result<Option<ProTxHash>, WasmSdkError> {
    use dash_sdk::dpp::dashcore::hashes::{sha256d, Hash as _};
    use dash_sdk::dpp::dashcore::ProTxHash;
    use std::str::FromStr;

    if let Some(s) = js_value.as_string() {
        if s.is_empty() {
            Ok(None)
        } else {
            ProTxHash::from_str(&s)
                .map(Some)
                .map_err(|e| WasmSdkError::invalid_argument(format!("Invalid ProTxHash: {}", e)))
        }
    } else {
        let bytes = js_sys::Uint8Array::new(&js_value).to_vec();
        if bytes.is_empty() {
            Ok(None)
        } else if bytes.len() != 32 {
            Err(WasmSdkError::invalid_argument(
                "ProTxHash must be 32 bytes or an empty value",
            ))
        } else {
            let mut arr = [0u8; 32];
            arr.copy_from_slice(&bytes);
            let raw = sha256d::Hash::from_byte_array(arr);
            Ok(Some(ProTxHash::from_raw_hash(raw)))
        }
    }
}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6be3544 and 49035bc.

📒 Files selected for processing (10)
  • .github/grpc-queries-cache.json
  • packages/js-evo-sdk/tests/functional/epoch.spec.mjs
  • packages/js-evo-sdk/tests/functional/protocol.spec.mjs
  • packages/rs-sdk-trusted-context-provider/src/provider.rs
  • packages/wasm-sdk/src/context_provider.rs
  • packages/wasm-sdk/src/queries/epoch.rs
  • packages/wasm-sdk/src/queries/protocol.rs
  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs
  • packages/wasm-sdk/tests/functional/protocol.spec.mjs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Rust code must pass cargo clippy --workspace linter checks
Rust code must be formatted using cargo fmt --all

**/*.rs: Use 4-space indent for Rust files
Follow rustfmt defaults and keep code clippy-clean for Rust modules
Use snake_case for Rust module names
Use PascalCase for Rust type names
Use SCREAMING_SNAKE_CASE for Rust constants

Files:

  • packages/wasm-sdk/src/context_provider.rs
  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-sdk/src/queries/protocol.rs
  • packages/rs-sdk-trusted-context-provider/src/provider.rs
  • packages/wasm-sdk/src/queries/epoch.rs
🧠 Learnings (13)
📓 Common learnings
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.
📚 Learning: 2025-08-05T13:55:39.147Z
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.

Applied to files:

  • packages/wasm-sdk/tests/functional/protocol.spec.mjs
  • packages/wasm-sdk/src/queries/protocol.rs
  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2025-02-10T11:26:36.709Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.

Applied to files:

  • packages/wasm-sdk/tests/functional/protocol.spec.mjs
  • packages/wasm-sdk/src/queries/protocol.rs
  • packages/wasm-sdk/src/queries/epoch.rs
  • packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs
📚 Learning: 2025-11-25T13:10:38.019Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: packages/swift-sdk/SwiftExampleApp/CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:38.019Z
Learning: Applies to packages/swift-sdk/SwiftExampleApp/**/PersistentToken.swift : Provide predicate methods for PersistentToken querying: mintableTokensPredicate(), burnableTokensPredicate(), freezableTokensPredicate(), distributionTokensPredicate(), pausedTokensPredicate(), tokensByContractPredicate(contractId:), and tokensWithControlRulePredicate(rule:)

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-20T16:20:59.791Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2432
File: packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs:222-225
Timestamp: 2025-01-20T16:20:59.791Z
Learning: In the Dash Platform codebase, TokenAmount from crate::balances::credits is compatible with u64 when used for token base supply.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-20T16:20:59.791Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2432
File: packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs:222-225
Timestamp: 2025-01-20T16:20:59.791Z
Learning: In the Dash Platform codebase, TokenAmount is defined as `type TokenAmount = u64` in balances/credits.rs, making it directly compatible with u64 values without any conversion needed.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-15T08:09:59.365Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2422
File: packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs:152-163
Timestamp: 2025-01-15T08:09:59.365Z
Learning: In the `transition_to_version_8` function, errors from `grove_get_path_query` when retrieving active contested resource votes are intentionally logged and ignored (returning `Ok(())`) to allow the protocol upgrade to proceed despite query failures.

Applied to files:

  • packages/wasm-sdk/src/queries/protocol.rs
📚 Learning: 2025-07-28T20:00:08.502Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/AI_REFERENCE.md:771-783
Timestamp: 2025-07-28T20:00:08.502Z
Learning: In packages/wasm-sdk/AI_REFERENCE.md, the documentation correctly shows the actual SDK method signatures (including identityCreate and identityTopUp with their full parameter lists), which may differ from the UI inputs shown in fixed_definitions.json. The UI may collect fewer parameters from users while handling additional requirements internally.

Applied to files:

  • packages/wasm-sdk/src/queries/protocol.rs
📚 Learning: 2024-10-09T00:22:57.778Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2207
File: packages/rs-drive-proof-verifier/src/proof.rs:1646-1664
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the implementation of `FromProof<platform::GetContestedResourceIdentityVotesRequest>` in `packages/rs-drive-proof-verifier/src/proof.rs`, when matching `maybe_votes`, using `.expect()` on `v.into_iter().next()` is acceptable because the prior match arm `Some(v) if v.is_empty()` ensures that the map is not empty, preventing a panic.

Applied to files:

  • packages/wasm-sdk/src/queries/protocol.rs
📚 Learning: 2025-01-23T09:23:32.740Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/rs-sdk/src/sync.rs:88-95
Timestamp: 2025-01-23T09:23:32.740Z
Learning: The `block_on` function in `packages/rs-sdk/src/sync.rs` is currently only used in tests, and its WebAssembly implementation is deferred until there's a user request for it.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2025-01-23T09:23:32.740Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/rs-sdk/src/sync.rs:88-95
Timestamp: 2025-01-23T09:23:32.740Z
Learning: The `block_on` function in `packages/rs-sdk/src/sync.rs` requires true blocking behavior, which is why a non-blocking WebAssembly implementation using `wasm_bindgen_futures::spawn_local` is not suitable.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2025-09-03T19:33:21.688Z
Learnt from: thephez
Repo: dashpay/platform PR: 2754
File: packages/wasm-sdk/api-definitions.json:1285-1285
Timestamp: 2025-09-03T19:33:21.688Z
Learning: In packages/wasm-sdk/api-definitions.json, thephez prefers to keep the existing "ripemd160hash20bytes1234" placeholder for ECDSA_HASH160 data field in documentation examples rather than using a valid base64-encoded format, maintaining consistency with the previous documentation approach.

Applied to files:

  • packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs
🧬 Code graph analysis (6)
packages/js-evo-sdk/tests/functional/protocol.spec.mjs (1)
packages/wasm-sdk/tests/functional/protocol.spec.mjs (3)
  • res (26-26)
  • res (35-35)
  • res (41-41)
packages/js-evo-sdk/tests/functional/epoch.spec.mjs (2)
packages/js-evo-sdk/tests/functional/protocol.spec.mjs (5)
  • res (14-14)
  • res (19-19)
  • res (27-27)
  • res (32-32)
  • sdk (6-6)
packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs (2)
  • res (51-51)
  • res (59-62)
packages/wasm-sdk/src/context_provider.rs (2)
packages/rs-sdk-trusted-context-provider/src/provider.rs (1)
  • add_known_token_configuration (216-219)
packages/wasm-sdk/src/queries/token.rs (1)
  • token_id (43-45)
packages/wasm-sdk/tests/functional/protocol.spec.mjs (1)
packages/js-evo-sdk/tests/functional/protocol.spec.mjs (4)
  • res (14-14)
  • res (19-19)
  • res (27-27)
  • res (32-32)
packages/wasm-sdk/src/queries/protocol.rs (3)
packages/wasm-sdk/src/error.rs (1)
  • invalid_argument (75-77)
packages/wasm-sdk/src/queries/mod.rs (5)
  • metadata (278-280)
  • proof (288-290)
  • from (100-109)
  • from (212-221)
  • from_sdk_parts (333-339)
packages/rs-sdk/src/platform/fetch_many.rs (1)
  • fetch_many_with_metadata_and_proof (205-255)
packages/wasm-sdk/src/queries/epoch.rs (4)
packages/wasm-sdk/src/queries/mod.rs (5)
  • metadata (278-280)
  • proof (288-290)
  • from (100-109)
  • from (212-221)
  • from_sdk_parts (333-339)
packages/wasm-sdk/src/error.rs (1)
  • invalid_argument (75-77)
packages/rs-sdk/src/platform/fetch_many.rs (1)
  • fetch_many_with_metadata_and_proof (205-255)
packages/wasm-dpp2/src/identifier.rs (4)
  • from (23-25)
  • from (29-31)
  • from (35-37)
  • from (41-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Rust packages (wasm-sdk) / Tests
  • GitHub Check: Rust packages (wasm-sdk) / Linting
  • GitHub Check: Rust packages (wasm-sdk) / Unused dependencies
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (RS-DAPI, rs-dapi, rs-dapi) / Build RS-DAPI image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit
🔇 Additional comments (14)
.github/grpc-queries-cache.json (1)

145-156: Verify that these address-related queries belong in this PR.

The PR objectives state this PR is about fixing non-proved JS SDK methods for token, protocol, and evonode queries. However, these newly added address-related queries (getAddressInfo, getAddressesBranchState, getAddressesInfos, getAddressesTrunkState) are not mentioned anywhere in the PR description, commit messages, or related context.

Please confirm whether:

  • These changes are intentionally part of this PR, or
  • They should be moved to a separate PR focused on address query functionality
packages/js-evo-sdk/tests/functional/epoch.spec.mjs (1)

27-42: LGTM!

The new test cases for proof-enabled epoch query variants are well-structured, follow existing patterns in the file, and appropriately verify the presence of data, proof, and metadata in the responses.

packages/js-evo-sdk/tests/functional/protocol.spec.mjs (1)

18-37: LGTM!

The new tests for versionUpgradeStateWithProof() and versionUpgradeVoteStatusWithProof() follow the established pattern and correctly verify the presence of proof and metadata in the responses.

packages/wasm-sdk/src/context_provider.rs (2)

109-110: LGTM!

Enabling refetch_if_not_found by default for both mainnet and testnet aligns with the rs-sdk behavior and ensures token configurations (and other context) are pulled on demand.

Also applies to: 124-125


167-171: LGTM!

The new add_known_token_configuration method follows the same delegation pattern as the existing add_known_contract method and correctly exposes the inner provider's caching capability.

packages/wasm-sdk/tests/functional/protocol.spec.mjs (1)

25-31: LGTM!

The test correctly verifies that the protocol upgrade state with proof returns the expected structure including data, proof, and metadata.

packages/wasm-sdk/src/queries/token.rs (1)

913-984: LGTM with a minor observation.

The prefetch_token_configuration helper is well-structured. For networks other than Mainnet/Testnet (lines 976-979), the function silently continues without caching. This is acceptable since proof verification may still work if the context provider has the info through other means. The comment explains this behavior well.

packages/wasm-sdk/src/queries/protocol.rs (1)

254-325: LGTM - Implementation is correct.

The implementation properly handles ProTxHash parsing, creates the LimitQuery, fetches with metadata and proof, and constructs the response. The logic aligns with the non-proof variant.

packages/rs-sdk-trusted-context-provider/src/provider.rs (3)

64-66: LGTM!

The new known_token_configurations cache follows the same pattern as the existing known_contracts cache using Arc<Mutex<HashMap>>.


215-230: LGTM!

The add_known_token_configuration and add_known_token_configurations methods follow the same pattern as the existing add_known_contract and add_known_contracts methods.


771-776: LGTM!

The get_token_configuration method correctly checks the known token configurations cache first and properly drops the lock before delegating to the fallback provider, avoiding potential deadlocks.

packages/wasm-sdk/src/queries/epoch.rs (2)

520-563: LGTM!

The implementation correctly parses ProTxHash strings, fetches with metadata and proof, and constructs the response. The logic mirrors the non-proof variant with added proof handling.


565-608: LGTM!

The implementation correctly creates a LimitQuery, fetches proposed blocks by range with metadata and proof, and wraps the result in ProofMetadataResponseWasm.

Note: The order_ascending field is explicitly ignored (line 579), which is consistent with the non-proof version (line 380). If ordering support is planned for the future, consider adding a TODO comment.

packages/wasm-sdk/tests/functional/epochs-blocks.spec.mjs (1)

58-67: No critical syntax issues found, but verify intentional API differences.

The .ok() syntax is valid in Chai—both .ok (property) and .ok() (function-call) forms are supported and functionally identical, so the assertions at lines 63, 65, and 66 are correct as written.

However, the proof-enabled test (lines 58–67) omits the startAfter parameter that the non-proof variant includes (line 44). Clarify whether this difference is intentional or if the test should include startAfter for complete coverage.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/wasm-sdk/src/queries/epoch.rs (1)

532-556: Consider extracting shared logic into helper functions.

There's code duplication between the proof and non-proof variants:

  • ProTxHash parsing logic (lines 337-347 vs 532-542)
  • Map construction from counts (lines 353-358 vs 552-556, and lines 390-394 vs 595-599)

Extracting these into helper functions would improve maintainability and reduce duplication.

💡 Example refactoring approach

You could create helper functions like:

fn parse_pro_tx_hashes(hashes: Vec<String>) -> Result<Vec<ProTxHash>, WasmSdkError> {
    hashes
        .into_iter()
        .map(|hash_str| {
            ProTxHash::from_str(&hash_str).map_err(|e| {
                WasmSdkError::invalid_argument(format!(
                    "Invalid ProTxHash '{}': {}",
                    hash_str, e
                ))
            })
        })
        .collect()
}

fn counts_to_map(counts: ProposerBlockCounts) -> Map {
    let map = Map::new();
    for (identifier, count) in counts.0 {
        let key = JsValue::from(IdentifierWasm::from(identifier));
        map.set(&key, &JsValue::from(BigInt::from(count)));
    }
    map
}

Then use them in both proof and non-proof variants.

Also applies to: 595-599

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49035bc and 634ebcc.

📒 Files selected for processing (3)
  • packages/js-evo-sdk/tests/functional/epoch.spec.mjs
  • packages/wasm-sdk/src/queries/epoch.rs
  • packages/wasm-sdk/src/queries/protocol.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/js-evo-sdk/tests/functional/epoch.spec.mjs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Rust code must pass cargo clippy --workspace linter checks
Rust code must be formatted using cargo fmt --all

**/*.rs: Use 4-space indent for Rust files
Follow rustfmt defaults and keep code clippy-clean for Rust modules
Use snake_case for Rust module names
Use PascalCase for Rust type names
Use SCREAMING_SNAKE_CASE for Rust constants

Files:

  • packages/wasm-sdk/src/queries/epoch.rs
  • packages/wasm-sdk/src/queries/protocol.rs
🧠 Learnings (9)
📓 Common learnings
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.
📚 Learning: 2025-08-05T13:55:39.147Z
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
  • packages/wasm-sdk/src/queries/protocol.rs
📚 Learning: 2025-02-10T11:26:36.709Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
  • packages/wasm-sdk/src/queries/protocol.rs
📚 Learning: 2025-01-23T09:23:32.740Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/rs-sdk/src/sync.rs:88-95
Timestamp: 2025-01-23T09:23:32.740Z
Learning: The `block_on` function in `packages/rs-sdk/src/sync.rs` is currently only used in tests, and its WebAssembly implementation is deferred until there's a user request for it.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2024-10-29T14:40:54.727Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/rs-sdk/src/core/transaction.rs:0-0
Timestamp: 2024-10-29T14:40:54.727Z
Learning: In `packages/rs-sdk/src/platform/document_query.rs` and `packages/rs-sdk/src/core/transaction.rs`, certain places don't implement `IntoInner`, so direct error mappings cannot be simplified using `IntoInner`. A TODO comment has been added to address this in a future PR.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2025-01-23T09:23:32.740Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/rs-sdk/src/sync.rs:88-95
Timestamp: 2025-01-23T09:23:32.740Z
Learning: The `block_on` function in `packages/rs-sdk/src/sync.rs` requires true blocking behavior, which is why a non-blocking WebAssembly implementation using `wasm_bindgen_futures::spawn_local` is not suitable.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2025-01-15T08:09:59.365Z
Learnt from: shumkov
Repo: dashpay/platform PR: 2422
File: packages/rs-drive-abci/src/execution/platform_events/protocol_upgrade/perform_events_on_first_block_of_protocol_change/v0/mod.rs:152-163
Timestamp: 2025-01-15T08:09:59.365Z
Learning: In the `transition_to_version_8` function, errors from `grove_get_path_query` when retrieving active contested resource votes are intentionally logged and ignored (returning `Ok(())`) to allow the protocol upgrade to proceed despite query failures.

Applied to files:

  • packages/wasm-sdk/src/queries/protocol.rs
📚 Learning: 2025-07-28T20:00:08.502Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/AI_REFERENCE.md:771-783
Timestamp: 2025-07-28T20:00:08.502Z
Learning: In packages/wasm-sdk/AI_REFERENCE.md, the documentation correctly shows the actual SDK method signatures (including identityCreate and identityTopUp with their full parameter lists), which may differ from the UI inputs shown in fixed_definitions.json. The UI may collect fewer parameters from users while handling additional requirements internally.

Applied to files:

  • packages/wasm-sdk/src/queries/protocol.rs
📚 Learning: 2024-10-09T00:22:57.778Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2207
File: packages/rs-drive-proof-verifier/src/proof.rs:1646-1664
Timestamp: 2024-10-09T00:22:57.778Z
Learning: In the implementation of `FromProof<platform::GetContestedResourceIdentityVotesRequest>` in `packages/rs-drive-proof-verifier/src/proof.rs`, when matching `maybe_votes`, using `.expect()` on `v.into_iter().next()` is acceptable because the prior match arm `Some(v) if v.is_empty()` ensures that the map is not empty, preventing a panic.

Applied to files:

  • packages/wasm-sdk/src/queries/protocol.rs
🧬 Code graph analysis (1)
packages/wasm-sdk/src/queries/protocol.rs (3)
packages/wasm-sdk/src/error.rs (1)
  • invalid_argument (75-77)
packages/wasm-sdk/src/queries/mod.rs (5)
  • metadata (278-280)
  • proof (288-290)
  • from (100-109)
  • from (212-221)
  • from_sdk_parts (333-339)
packages/rs-sdk/src/platform/fetch_many.rs (1)
  • fetch_many_with_metadata_and_proof (205-255)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Rust packages (wasm-sdk) / Linting
  • GitHub Check: Rust packages (wasm-sdk) / Tests
  • GitHub Check: Rust packages (wasm-sdk) / Unused dependencies
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (RS-DAPI, rs-dapi, rs-dapi) / Build RS-DAPI image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit
🔇 Additional comments (3)
packages/wasm-sdk/src/queries/protocol.rs (1)

254-323: LGTM! Proof-enabled implementation is well-structured.

The implementation correctly replaces the placeholder with a full proof-enabled flow:

  • Proper input validation for both string and Uint8Array ProTxHash formats
  • Correct use of LimitQuery and fetch_many_with_metadata_and_proof
  • Appropriate error handling for invalid inputs
  • Follows the established pattern for proof-enabled wasm responses via from_sdk_parts
packages/wasm-sdk/src/queries/epoch.rs (2)

520-561: LGTM! Proof-enabled implementation for IDs query is correct.

The implementation properly:

  • Validates and parses ProTxHash strings with clear error messages
  • Uses fetch_many_with_metadata_and_proof to retrieve counts with verification
  • Constructs the response Map with correct type conversions
  • Returns ProofMetadataResponseWasm following the established pattern

563-604: LGTM! Proof-enabled range query implementation is correct.

The implementation correctly:

  • Parses the query parameters including ProTxHash validation
  • Constructs a proper LimitQuery for the range request
  • Uses fetch_many_with_metadata_and_proof for verified retrieval
  • Builds the response Map with appropriate type conversions
  • Returns ProofMetadataResponseWasm via from_sdk_parts

The order_ascending parameter is parsed but not used (line 577), consistent with the non-proof version (line 380), indicating ordering support is not yet implemented in the underlying SDK layer.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/wasm-sdk/src/queries/epoch.rs (1)

507-548: LGTM! Implementation follows the established proof pattern.

The proof-enabled method correctly:

  • Parses ProTxHash strings with clear error messages
  • Fetches counts with metadata and proof using the appropriate SDK method
  • Builds and returns the response with proper type conversions

The explicit parameter naming (proTxHashes in JS) improves API clarity compared to the non-proof variant's generic ids.

Minor observation: The ProTxHash parsing logic (lines 519-529) and Map building logic (lines 539-543) duplicate the non-proof variant. Consider extracting helper functions if more similar methods are added in the future.

🔎 Optional helper extraction example
fn parse_pro_tx_hashes(hashes: Vec<String>) -> Result<Vec<ProTxHash>, WasmSdkError> {
    hashes
        .into_iter()
        .map(|hash_str| {
            ProTxHash::from_str(&hash_str).map_err(|e| {
                WasmSdkError::invalid_argument(format!(
                    "Invalid ProTxHash '{}': {}",
                    hash_str, e
                ))
            })
        })
        .collect()
}

fn build_identifier_count_map(counts: impl IntoIterator<Item = (impl Into<IdentifierWasm>, u64)>) -> Map {
    let map = Map::new();
    for (identifier, count) in counts {
        let key = JsValue::from(identifier.into());
        map.set(&key, &JsValue::from(BigInt::from(count)));
    }
    map
}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 634ebcc and a19372a.

📒 Files selected for processing (4)
  • packages/wasm-dpp2/TODO.md
  • packages/wasm-sdk/src/context_provider.rs
  • packages/wasm-sdk/src/queries/epoch.rs
  • packages/wasm-sdk/src/queries/token.rs
✅ Files skipped from review due to trivial changes (1)
  • packages/wasm-dpp2/TODO.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/wasm-sdk/src/context_provider.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Rust code must pass cargo clippy --workspace linter checks
Rust code must be formatted using cargo fmt --all

**/*.rs: Use 4-space indent for Rust files
Follow rustfmt defaults and keep code clippy-clean for Rust modules
Use snake_case for Rust module names
Use PascalCase for Rust type names
Use SCREAMING_SNAKE_CASE for Rust constants

Files:

  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-sdk/src/queries/epoch.rs
🧠 Learnings (10)
📓 Common learnings
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.
📚 Learning: 2025-11-25T13:10:38.019Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: packages/swift-sdk/SwiftExampleApp/CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:38.019Z
Learning: Applies to packages/swift-sdk/SwiftExampleApp/**/PersistentToken.swift : Provide predicate methods for PersistentToken querying: mintableTokensPredicate(), burnableTokensPredicate(), freezableTokensPredicate(), distributionTokensPredicate(), pausedTokensPredicate(), tokensByContractPredicate(contractId:), and tokensWithControlRulePredicate(rule:)

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-05-28T16:22:26.334Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2644
File: packages/rs-drive/src/cache/system_contracts.rs:18-19
Timestamp: 2025-05-28T16:22:26.334Z
Learning: In packages/rs-drive/src/cache/system_contracts.rs, the `active_since_protocol_version` field in `ActiveSystemDataContract` struct is intentionally added for future use, not current implementation. QuantumExplorer confirmed this is "meant for later" when questioned about the `#[allow(unused)]` attribute.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-20T16:20:59.791Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2432
File: packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs:222-225
Timestamp: 2025-01-20T16:20:59.791Z
Learning: In the Dash Platform codebase, TokenAmount from crate::balances::credits is compatible with u64 when used for token base supply.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-20T16:20:59.791Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2432
File: packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs:222-225
Timestamp: 2025-01-20T16:20:59.791Z
Learning: In the Dash Platform codebase, TokenAmount is defined as `type TokenAmount = u64` in balances/credits.rs, making it directly compatible with u64 values without any conversion needed.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-02-10T11:26:36.709Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2025-08-05T13:55:39.147Z
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2025-01-23T09:23:32.740Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/rs-sdk/src/sync.rs:88-95
Timestamp: 2025-01-23T09:23:32.740Z
Learning: The `block_on` function in `packages/rs-sdk/src/sync.rs` is currently only used in tests, and its WebAssembly implementation is deferred until there's a user request for it.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
📚 Learning: 2025-01-23T09:23:32.740Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/rs-sdk/src/sync.rs:88-95
Timestamp: 2025-01-23T09:23:32.740Z
Learning: The `block_on` function in `packages/rs-sdk/src/sync.rs` requires true blocking behavior, which is why a non-blocking WebAssembly implementation using `wasm_bindgen_futures::spawn_local` is not suitable.

Applied to files:

  • packages/wasm-sdk/src/queries/epoch.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (5)
packages/wasm-sdk/src/queries/epoch.rs (1)

550-590: LGTM! Range query proof implementation is correct.

The implementation properly:

  • Reuses the existing parse_evonode_range_query parser
  • Constructs a LimitQuery with the parsed epoch, limit, and start_info
  • Fetches counts with proof using ProposerBlockCountByRange::fetch_many_with_metadata_and_proof
  • Returns the response in the expected ProofMetadataResponseWasm format

The approach is consistent with other proof-enabled methods in this file.

packages/wasm-sdk/src/queries/token.rs (4)

506-518: LGTM! Proper integration of token configuration prefetching.

The prefetch call ensures token configuration is cached before querying, and the new query structure provides a cleaner interface compared to the previous implementation.


869-887: LGTM! Proof-enabled variant properly implemented.

The prefetch ensures token configuration is available for proof verification, and the result conversion correctly handles the Option type with proper chaining.


894-896: Good code organization.

Separating internal helper methods into a dedicated impl block with clear comments improves code maintainability and readability.


75-85: No changes needed. The cast of EpochIndex (defined as u16) to u64 is safe—all u16 values fit within u64 bounds without overflow.

Likely an incorrect or invalid review comment.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/wasm-sdk/src/queries/token.rs (1)

506-508: Consider expanding the comment to explain the prefetch rationale.

The comment mentions that prefetching is "required for proof verification to work" but doesn't explain why. Consider adding a brief explanation of what would fail without prefetching (e.g., "Token configuration must be cached in the trusted context before proof verification; otherwise, the verifier cannot validate token-specific data structures").

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a19372a and 004f219.

📒 Files selected for processing (1)
  • packages/wasm-sdk/src/queries/token.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Rust code must pass cargo clippy --workspace linter checks
Rust code must be formatted using cargo fmt --all

**/*.rs: Use 4-space indent for Rust files
Follow rustfmt defaults and keep code clippy-clean for Rust modules
Use snake_case for Rust module names
Use PascalCase for Rust type names
Use SCREAMING_SNAKE_CASE for Rust constants

Files:

  • packages/wasm-sdk/src/queries/token.rs
🧠 Learnings (7)
📓 Common learnings
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WebAssembly as a bridge between Rust and JavaScript implementations
Learnt from: lklimek
Repo: dashpay/platform PR: 2277
File: packages/rs-sdk/tests/fetch/config.rs:233-233
Timestamp: 2024-10-30T11:19:59.163Z
Learning: In the Rust SDK's `rs-sdk/tests` integration tests (e.g., in `packages/rs-sdk/tests/fetch/config.rs`), we cannot create objects during tests because there is no support for object creation in this context. Therefore, hardcoded values for test identities must be used.
📚 Learning: 2025-07-28T20:00:08.502Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/AI_REFERENCE.md:771-783
Timestamp: 2025-07-28T20:00:08.502Z
Learning: In packages/wasm-sdk/AI_REFERENCE.md, the documentation correctly shows the actual SDK method signatures (including identityCreate and identityTopUp with their full parameter lists), which may differ from the UI inputs shown in fixed_definitions.json. The UI may collect fewer parameters from users while handling additional requirements internally.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-20T16:20:59.791Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2432
File: packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs:222-225
Timestamp: 2025-01-20T16:20:59.791Z
Learning: In the Dash Platform codebase, TokenAmount from crate::balances::credits is compatible with u64 when used for token base supply.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-20T16:20:59.791Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2432
File: packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs:222-225
Timestamp: 2025-01-20T16:20:59.791Z
Learning: In the Dash Platform codebase, TokenAmount is defined as `type TokenAmount = u64` in balances/credits.rs, making it directly compatible with u64 values without any conversion needed.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-02-10T11:26:36.709Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-08-05T13:55:39.147Z
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Rust packages (wasm-sdk) / Unused dependencies
  • GitHub Check: Rust packages (wasm-sdk) / Linting
  • GitHub Check: Rust packages (wasm-dpp2) / Linting
  • GitHub Check: Rust packages (wasm-dpp2) / Tests
  • GitHub Check: Rust packages (wasm-sdk) / Tests
  • GitHub Check: Rust packages (wasm-dpp2) / Unused dependencies
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (RS-DAPI, rs-dapi, rs-dapi) / Build RS-DAPI image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit
🔇 Additional comments (3)
packages/wasm-sdk/src/queries/token.rs (3)

8-12: LGTM: Imports aligned with new proof-enabled flow.

The added imports for RewardDistributionMoment and TokenLastClaimQuery support the refactored token claim query paths that now use SDK fetch with proof verification.


869-892: LGTM: Proof-enabled variant correctly implements prefetch and conversion flow.

The implementation correctly:

  • Prefetches token configuration for proof verification context
  • Uses fetch_with_metadata_and_proof to retrieve verified data
  • Converts RewardDistributionMoment to TokenLastClaimWasm via the From implementation

Same optional comment improvement applies here as in the non-proof variant (lines 506-508).


894-977: LGTM: Prefetch helper correctly implements token configuration caching.

The implementation properly:

  • Fetches token contract info and data contract in sequence
  • Extracts and validates token configuration
  • Returns descriptive errors if trusted context is uninitialized (addresses past review feedback)
  • Supports both Dash and Testnet networks with clear error for unsupported networks

The error handling is robust and includes relevant context (token_id, network) in error messages.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/wasm-sdk/src/queries/token.rs (1)

854-857: JSDoc return type is inconsistent with actual return type.

The unchecked_return_type annotation references TokenLastClaim but the method now returns RewardDistributionMoment. This mismatch could confuse TypeScript consumers relying on generated type definitions.

🔎 Proposed fix
     #[wasm_bindgen(
         js_name = "getTokenPerpetualDistributionLastClaimWithProofInfo",
-        unchecked_return_type = "ProofMetadataResponseTyped<TokenLastClaim | undefined>"
+        unchecked_return_type = "ProofMetadataResponseTyped<RewardDistributionMoment | undefined>"
     )]
🧹 Nitpick comments (2)
packages/wasm-sdk/src/queries/token.rs (2)

867-869: Consider removing redundant local imports.

TokenLastClaimQuery, RewardDistributionMoment, and Fetch are already imported at the module level (lines 8, 12-13). These local imports are redundant.

🔎 Proposed fix
     ) -> Result<ProofMetadataResponseWasm, WasmSdkError> {
-        use dash_sdk::platform::query::TokenLastClaimQuery;
-        use dash_sdk::dpp::data_contract::associated_token::token_perpetual_distribution::reward_distribution_moment::RewardDistributionMoment;
-        use dash_sdk::platform::Fetch;
-
         // Parse IDs

954-964: Consider handling poisoned mutex gracefully.

The .unwrap() calls on lock() could panic if the mutex was poisoned (i.e., a previous holder panicked). While rare, especially in WASM, you could handle this more gracefully:

🔎 Proposed approach
             Network::Dash => {
-                let guard = MAINNET_TRUSTED_CONTEXT.lock().unwrap();
+                let guard = MAINNET_TRUSTED_CONTEXT.lock().unwrap_or_else(|e| e.into_inner());
                 let ctx = guard.as_ref().ok_or_else(|| {

Alternatively, convert the poison error to a WasmSdkError for a more descriptive failure.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 004f219 and c0697bf.

📒 Files selected for processing (1)
  • packages/wasm-sdk/src/queries/token.rs
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.rs: Rust code must pass cargo clippy --workspace linter checks
Rust code must be formatted using cargo fmt --all

**/*.rs: Use 4-space indent for Rust files
Follow rustfmt defaults and keep code clippy-clean for Rust modules
Use snake_case for Rust module names
Use PascalCase for Rust type names
Use SCREAMING_SNAKE_CASE for Rust constants

Files:

  • packages/wasm-sdk/src/queries/token.rs
🧠 Learnings (9)
📓 Common learnings
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code
📚 Learning: 2025-07-28T20:00:08.502Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2711
File: packages/wasm-sdk/AI_REFERENCE.md:771-783
Timestamp: 2025-07-28T20:00:08.502Z
Learning: In packages/wasm-sdk/AI_REFERENCE.md, the documentation correctly shows the actual SDK method signatures (including identityCreate and identityTopUp with their full parameter lists), which may differ from the UI inputs shown in fixed_definitions.json. The UI may collect fewer parameters from users while handling additional requirements internally.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2024-10-06T16:17:34.571Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2215
File: packages/rs-drive-abci/src/execution/engine/run_block_proposal/mod.rs:105-105
Timestamp: 2024-10-06T16:17:34.571Z
Learning: In `run_block_proposal` in `packages/rs-drive-abci/src/execution/engine/run_block_proposal/mod.rs`, when retrieving `last_block_time_ms`, it's acceptable to use `platform_state` instead of `block_platform_state`, even after updating the protocol version.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-02-03T23:39:10.579Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2450
File: packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/v0/methods.rs:10-12
Timestamp: 2025-02-03T23:39:10.579Z
Learning: Block interval calculations in token distribution logic should use checked arithmetic operations (checked_sub, checked_add) to prevent potential overflows, especially when dealing with block heights and intervals.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-20T16:20:59.791Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2432
File: packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs:222-225
Timestamp: 2025-01-20T16:20:59.791Z
Learning: In the Dash Platform codebase, TokenAmount from crate::balances::credits is compatible with u64 when used for token base supply.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-01-20T16:20:59.791Z
Learnt from: QuantumExplorer
Repo: dashpay/platform PR: 2432
File: packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs:222-225
Timestamp: 2025-01-20T16:20:59.791Z
Learning: In the Dash Platform codebase, TokenAmount is defined as `type TokenAmount = u64` in balances/credits.rs, making it directly compatible with u64 values without any conversion needed.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-11-25T13:10:23.481Z
Learnt from: CR
Repo: dashpay/platform PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T13:10:23.481Z
Learning: Use WASM bindings to connect Rust and JavaScript code

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-02-10T11:26:36.709Z
Learnt from: lklimek
Repo: dashpay/platform PR: 2405
File: packages/wasm-sdk/src/verify.rs:26-68
Timestamp: 2025-02-10T11:26:36.709Z
Learning: In the wasm-sdk package, empty vectors and placeholder values are intentionally used in verification functions during the proof-of-concept stage to ensure proper compilation and type checking.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
📚 Learning: 2025-08-05T13:55:39.147Z
Learnt from: thephez
Repo: dashpay/platform PR: 2718
File: packages/wasm-sdk/index.html:0-0
Timestamp: 2025-08-05T13:55:39.147Z
Learning: The get_identity_keys_with_proof_info function in the Rust WASM bindings does not support the "search" key request type and lacks the searchPurposeMap parameter. When proof mode is enabled with keyRequestType === 'search', the implementation falls back to the non-proof version (get_identity_keys) to maintain functionality.

Applied to files:

  • packages/wasm-sdk/src/queries/token.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Rust packages (wasm-dpp2) / Linting
  • GitHub Check: Rust packages (wasm-dpp2) / Tests
  • GitHub Check: Rust packages (wasm-sdk) / Linting
  • GitHub Check: Rust packages (wasm-sdk) / Tests
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (RS-DAPI, rs-dapi, rs-dapi) / Build RS-DAPI image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit
🔇 Additional comments (4)
packages/wasm-sdk/src/queries/token.rs (4)

8-13: LGTM!

The new imports for RewardDistributionMoment, TokenLastClaimQuery, and the updated Fetch/FetchMany imports are correctly added to support the new proof-verified token query functionality.


58-105: Well-designed wrapper with clear type discrimination.

The RewardDistributionMomentWasm struct addresses the previous concern about semantic mapping by providing:

  • A moment_type getter that returns "block", "time", or "epoch" as a discriminant
  • Type-specific accessors (block_height, timestamp_ms, epoch_index) that return Option<T>, making it clear when values are applicable

This is a clean, self-documenting API for JavaScript consumers.


507-525: LGTM!

The updated method correctly:

  1. Prefetches token configuration before proof-verified queries (addressing the PR objective)
  2. Uses the SDK's Fetch trait with proper query construction
  3. Returns the new RewardDistributionMomentWasm type with clean conversion

900-982: Well-structured prefetch helper that addresses previous review concerns.

The implementation correctly:

  1. Fetches token contract info and data contract to obtain the configuration
  2. Returns descriptive errors when context is not initialized (addressing the past review)
  3. Supports both mainnet and testnet networks with clear error messages

The mutex usage is safe here since the lock is held briefly without crossing await points.

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.

3 participants