Skip to content

feat: get_policies_batch contract cap + chain simulation API - #245

Merged
jhayniffy merged 2 commits into
InsurNiffy:mainfrom
aji70:feat/get-policies-batch
Mar 28, 2026
Merged

feat: get_policies_batch contract cap + chain simulation API#245
jhayniffy merged 2 commits into
InsurNiffy:mainfrom
aji70:feat/get-policies-batch

Conversation

@aji70

@aji70 aji70 commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds get_policies_batch to the niffyinsure contract (hard cap 20, aligned with PAGE_SIZE_MAX), exposes it via Nest POST /api/chain/policies/batch, and adds a frontend getPoliciesBatch helper for bulk chain reads.
closes #192

Contract

  • New PolicyLookupKey { holder, policy_id } and POLICY_BATCH_GET_MAX (= 20, same as pagination cap).
  • get_policies_batch(ids) -> Vec<Option<Policy>>: cap enforced before any storage reads; missing keys → None at that index; over cap → validate::Error::PolicyBatchTooLarge (49).
  • quote_error_message / map_quote_error updated for error 49 and appeal-related codes 43–48.
  • Removes duplicate file_claim / vote_on_claim / finalize_claim definitions and fixes admin import so the crate builds.

Tests

  • cargo test --test get_policies_batch (empty, full 20, mixed None, over-cap).

Backend

  • ChainModule: POST /api/chain/policies/batchSorobanService.simulateGetPoliciesBatch (sorted-map encoding for PolicyLookupKey).
  • DTO validates max 20 keys; optional source_account (defaults to first holder).

Frontend

  • getPoliciesBatch, POLICY_BATCH_GET_MAX, PolicyBatchKey.
  • handleResponse parses Nest BadRequestException({ code, message }) bodies.

Deploy / ops

  • Redeploy contract WASM so get_policies_batch exists on the target network before relying on the new simulation path.

Notes

  • Full cargo test / nest build may still fail on unrelated pre-existing issues (e.g. tests/events.rs, indexer/idempotency).

- Add PolicyLookupKey, POLICY_BATCH_GET_MAX (20), and get_policies_batch:
  enforce cap before storage reads; None for missing keys; revert on over-cap
  with validate::Error::PolicyBatchTooLarge (49).
- Extend quote_error_message / map_quote_error for new and appeal error codes.
- Fix duplicate file_claim/vote_on_claim/finalize_claim definitions and admin
  events import so the contract crate builds.
- Add integration tests (empty, full 20, mixed None, over-cap).
- Nest: ChainModule POST /api/chain/policies/batch calling SorobanService
  simulateGetPoliciesBatch with scvSortedMap-encoded keys.
- Frontend: getPoliciesBatch, POLICY_BATCH_GET_MAX, and Nest-style error parsing
  in chain handleResponse.

Made-with: Cursor
@drips-wave

drips-wave Bot commented Mar 27, 2026

Copy link
Copy Markdown

@aji70 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@jhayniffy
jhayniffy merged commit 7889889 into InsurNiffy:main Mar 28, 2026
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.

Contract — Policy batch query: fetch multiple policies in one simulation call

2 participants