feat: fetch round data from crisp server#811
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughIntroduces a CRISP SDK package with TypeScript source, types, constants, and tests for fetching round details and token tree data. Updates server models, repository, indexer, and routes to persist token parameters, separate initialize vs. start round, and expose new endpoints. Adjusts workspace, formatting ignores, and a deploy script. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Chain as Chain Events
participant Indexer as Server Indexer
participant Repo as CrispE3Repository
Note over Indexer,Repo: E3 lifecycle control flow (new/changed)
Chain->>Indexer: E3 Requested
Indexer->>Repo: initialize_round(token_address, balance_threshold)
Repo-->>Indexer: Ok / Err
Chain->>Indexer: E3 Activated
Indexer->>Repo: start_round()
Repo-->>Indexer: Ok / Err
sequenceDiagram
autonumber
actor App as Client App
participant SDK as CRISP SDK
participant API as CRISP Server
rect rgb(240,248,255)
note right of SDK: New SDK fetch APIs
App->>SDK: getRoundDetails(serverUrl, e3Id)
SDK->>API: POST /state/lite { id: e3Id }
API-->>SDK: IRoundDetailsResponse
SDK-->>App: IRoundDetails
end
App->>SDK: getTreeData(serverUrl, e3Id)
SDK->>API: POST /token-holders { round_id: e3Id }
API-->>SDK: token holder hashes
SDK-->>App: data
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 10
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
examples/CRISP/server/src/server/indexer.rs (1)
50-66: Persist after validation to avoid stale "Requested" rounds.You call initialize_round before fetching/validating token holders. If Bitquery fails or returns empty, you return Err leaving a persisted "Requested" round with no data.
Apply this local change: remove the early initialize_round call here and invoke it only after token_holders is verified non-empty.
- // save the e3 details - repo.initialize_round(custom_params.token_address, custom_params.balance_threshold).await?; + // defer persistence until after token_holders are verified non-emptyThen, after the
if token_holders.is_empty()check (on success path), initialize:// After verifying token_holders is not empty repo.initialize_round(custom_params.token_address, custom_params.balance_threshold).await?;Optionally, if you prefer keeping the early write, add a compensating action on error (e.g., set status="Error" or delete the entry) to avoid dangling state.
🧹 Nitpick comments (9)
examples/CRISP/sdk/tests/token.test.ts (1)
14-17: Strengthen test assertions to validate data structure.The test only verifies that
data.length > 0but doesn't validate the structure or content of the returned data. Consider adding assertions to check that the data conforms to expected shape (e.g., array of objects with specific properties).examples/CRISP/sdk/tests/state.test.ts (2)
14-17: Strengthen test assertions to validate state structure.The test only checks that
stateis defined but doesn't validate the structure or content. Consider adding assertions for key properties (e.g.,e3Id,tokenAddress,status) to ensure the returned data conforms toIRoundDetails.
21-25: Strengthen test assertions to validate token details structure.The test checks that
tokenAddressandthresholdare defined but doesn't validate their types or values. Consider adding type checks or value validations to ensure data integrity.examples/CRISP/sdk/src/token.ts (3)
14-26: Add explicit return type for type safety.The function has an implicit
anyreturn type. Consider defining a proper type for the tree data structure and using it as the return type.
23-23: Consider renaming variable for clarity.The variable name
hashessuggests it contains hash values, but based on the endpoint nametoken-holdersand the generic return, it might contain broader data. Consider using a more descriptive name likedataortreeData.
31-31: Document TODO for stub functions.The stub functions
generateMerkleProofandgetBalanceAtare placeholders. Consider adding TODO comments or tracking these in an issue.Would you like me to open an issue to track the implementation of these placeholder functions?
Also applies to: 36-36
examples/CRISP/server/src/server/repo.rs (3)
14-14: Remove unused import.num_bigint::BigUint is not used in this file.
-use num_bigint::BigUint;
115-128: Consider making initialize_round idempotent and validating inputs.To handle duplicate E3Requested events safely, skip overwriting if a CRISP entry already exists, and optionally validate non-empty token_address/balance_threshold.
Example:
pub async fn initialize_round(&mut self, token_address: String, balance_threshold: String) -> Result<()> { // If already initialized, return early (idempotent) if self.store.get::<E3Crisp>(&self.crisp_key()).await?.is_some() { return Ok(()); } // Optionally validate inputs here self.set_crisp(E3Crisp { has_voted: vec![], start_time: 0, status: "Requested".to_string(), votes_option_1: 0, votes_option_2: 0, emojis: generate_emoji(), token_holder_hashes: vec![], token_address, balance_threshold, }).await }
268-279: LGTM: persist token_holder_hashes.Closure clone is fine here; consider moving clone outside only if hot path.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (19)
examples/CRISP/scripts/evm_deploy.sh(0 hunks)examples/CRISP/sdk/.prettierignore(1 hunks)examples/CRISP/sdk/.prettierrc(1 hunks)examples/CRISP/sdk/package.json(1 hunks)examples/CRISP/sdk/src/constants.ts(1 hunks)examples/CRISP/sdk/src/index.ts(1 hunks)examples/CRISP/sdk/src/state.ts(1 hunks)examples/CRISP/sdk/src/token.ts(1 hunks)examples/CRISP/sdk/src/types.ts(1 hunks)examples/CRISP/sdk/tests/constants.ts(1 hunks)examples/CRISP/sdk/tests/state.test.ts(1 hunks)examples/CRISP/sdk/tests/token.test.ts(1 hunks)examples/CRISP/sdk/tsconfig.json(1 hunks)examples/CRISP/server/src/server/indexer.rs(3 hunks)examples/CRISP/server/src/server/models.rs(4 hunks)examples/CRISP/server/src/server/repo.rs(5 hunks)examples/CRISP/server/src/server/routes/state.rs(3 hunks)packages/enclave-contracts/.prettierignore(1 hunks)pnpm-workspace.yaml(1 hunks)
💤 Files with no reviewable changes (1)
- examples/CRISP/scripts/evm_deploy.sh
🧰 Additional context used
🧬 Code graph analysis (7)
examples/CRISP/sdk/src/types.ts (1)
examples/CRISP/sdk/src/index.ts (2)
IRoundDetails(11-11)ITokenDetails(11-11)
examples/CRISP/sdk/src/token.ts (1)
examples/CRISP/sdk/src/constants.ts (1)
CRISP_SERVER_TOKEN_TREE_ENDPOINT(7-7)
examples/CRISP/sdk/src/state.ts (2)
examples/CRISP/sdk/src/types.ts (3)
IRoundDetails(31-46)IRoundDetailsResponse(10-26)ITokenDetails(51-54)examples/CRISP/sdk/src/constants.ts (1)
CRISP_SERVER_STATE_LITE_ENDPOINT(8-8)
examples/CRISP/sdk/tests/state.test.ts (2)
examples/CRISP/sdk/src/state.ts (2)
getRoundDetails(14-41)getRoundTokenAndThreshold(49-55)examples/CRISP/sdk/tests/constants.ts (1)
CRISP_SERVER_URL(7-7)
examples/CRISP/sdk/tests/token.test.ts (1)
examples/CRISP/sdk/src/token.ts (1)
getTreeData(14-26)
examples/CRISP/server/src/server/routes/state.rs (2)
crates/evm-helpers/src/contracts.rs (1)
create_write(251-271)examples/CRISP/server/src/server/repo.rs (2)
store(36-38)store(79-81)
examples/CRISP/server/src/server/repo.rs (1)
examples/CRISP/server/src/server/database.rs (1)
generate_emoji(80-101)
⏰ 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: test_enclave_init
- GitHub Check: crisp_e2e
- GitHub Check: integration_prebuild
- GitHub Check: test_net
- GitHub Check: rust_unit
- GitHub Check: build_sdk
- GitHub Check: test_contracts
- GitHub Check: Build & Push Image
🔇 Additional comments (18)
examples/CRISP/server/src/server/routes/state.rs (4)
13-16: LGTM!The expanded imports are correctly aligned with the contract creation and interaction code below.
29-29: Evaluate access control requirements for token holder data.The new
/token-holdersendpoint exposes token holder hashes (hash of address and token balance) for any round. Consider whether this data should be publicly accessible or if it requires authentication/authorization, as it could reveal:
- Token distribution patterns
- Voting power distribution (if used in governance)
- Round participation information
If this data is intentionally public for transparency purposes, consider documenting this design decision. Otherwise, add appropriate access controls.
34-39: LGTM!The added documentation improves code maintainability by clearly describing the webhook callback's purpose, arguments, and return value.
43-46: LGTM!The logging and error handling improvements enhance observability:
- Structured logging with E3 ID and transaction hash aids debugging
- JSON error responses provide consistency across the API
- Error handling properly propagates failures with descriptive messages
Also applies to: 48-62, 82-86
examples/CRISP/sdk/.prettierignore (1)
3-3: Verify: ignoring .prettierrc may prevent formatting validation.It's unusual to ignore the
.prettierrcconfiguration file itself. This prevents Prettier from formatting or checking the config file, which might hide formatting inconsistencies if the config is manually edited.If this was intentional (e.g., to avoid conflicts), document the reason. Otherwise, consider removing this entry to allow Prettier to validate its own configuration file.
packages/enclave-contracts/.prettierignore (1)
24-24: LGTM!Adding
deployed_contracts.jsonto the ignore list is appropriate, as deployment artifacts are typically generated files that should not be formatted.examples/CRISP/sdk/.prettierrc (1)
1-10: LGTM!The Prettier configuration is well-structured with reasonable formatting preferences. The wider
printWidthof 140 is acceptable for modern development, and all other settings follow common conventions.pnpm-workspace.yaml (1)
6-6: LGTM!Adding the SDK package to the workspace correctly integrates it into the monorepo, enabling proper dependency management and linking.
examples/CRISP/sdk/tests/constants.ts (1)
7-7: LGTM!The test server URL constant is appropriately defined for local testing. Hardcoding
localhost:4000is standard practice for test configurations.examples/CRISP/sdk/src/types.ts (1)
10-26: Verify and align naming in IRoundDetailsResponse
The interface mixes snake_case (token_address,balance_threshold) and camelCase (tokenAddress,snapshotBlock), creating apparent duplicates. Confirm the actual server response naming convention and remove or rename duplicates accordingly.examples/CRISP/sdk/tsconfig.json (1)
6-6: moduleResolution "bundler" is supported by the project’s TypeScript 5.8.3—no changes required.examples/CRISP/sdk/src/constants.ts (1)
7-8: LGTM!The endpoint constants are well-defined and follow a clear naming convention.
examples/CRISP/sdk/src/index.ts (1)
7-11: LGTM!The public API surface is well-organized with clear re-exports of functionality and types.
examples/CRISP/sdk/src/state.ts (1)
49-55: LGTM!The function provides a clean abstraction for fetching just the token details, making the API more convenient for callers who don't need the full round details.
examples/CRISP/server/src/server/models.rs (1)
132-135: LGTM: token params plumbed through models and mapping.Added fields and From mapping are consistent with repo/indexer usage.
Also applies to: 171-173, 184-186, 216-218
examples/CRISP/server/src/server/indexer.rs (1)
140-140: Activation flow looks good; ensure start_round fails if CRISP not initialized.Assuming repo.start_round() errors when the CRISP record is absent; otherwise this silently no-ops. See repo fix.
examples/CRISP/server/src/server/repo.rs (2)
214-216: LGTM: expose token params in E3StateLite.Mapping from CRISP to E3StateLite looks correct.
284-286: LGTM: return holder hashes.Returning owned Vec is appropriate.
ab3aecb to
6f23863
Compare
59546e3 to
cd33596
Compare
* fix: server resetting data * chore: add license * feat: get round data from crisp server * chore: add snapshot block to round data * chore: update start_round
* fix: server resetting data * chore: add license * feat: get round data from crisp server * chore: add snapshot block to round data * chore: update start_round
* fix: server resetting data * chore: add license * feat: get round data from crisp server * chore: add snapshot block to round data * chore: update start_round
* fix: server resetting data * chore: add license * feat: get round data from crisp server * chore: add snapshot block to round data * chore: update start_round
fix #808
merge #804 first
Summary by CodeRabbit
New Features
Tests
Chores/Tooling