-
Notifications
You must be signed in to change notification settings - Fork 56
feat(sdk): expose the label each contender actually requested #4331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5b338bc
1213642
53b6bab
275e48a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| use crate::types::SDKHandle; | ||
| use crate::{DashSDKError, DashSDKErrorCode, DashSDKResult, DashSDKResultDataType}; | ||
| use dash_sdk::dpp::data_contract::accessors::v0::DataContractV0Getters; | ||
| use dash_sdk::dpp::document::DocumentV0Getters; | ||
| use dash_sdk::dpp::platform_value::Value; | ||
| use dash_sdk::dpp::voting::contender_structs::ContenderWithSerializedDocument; | ||
| use dash_sdk::dpp::voting::vote_info_storage::contested_document_vote_poll_winner_info::ContestedDocumentVotePollWinnerInfo; | ||
| use dash_sdk::dpp::voting::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePoll; | ||
| use dash_sdk::drive::query::vote_poll_vote_state_query::ContestedDocumentVotePollDriveQuery; | ||
| use dash_sdk::platform::FetchMany; | ||
| use dash_sdk::platform::{DataContract, Fetch}; | ||
| use dash_sdk::query_types::Contenders; | ||
| use std::ffi::{c_char, c_void, CStr, CString}; | ||
|
|
||
|
|
@@ -235,6 +238,19 @@ fn get_contested_resource_vote_state( | |
| } | ||
| // Add contenders | ||
| if result_type.has_documents() { | ||
| // Decode each contender's document so callers get the | ||
| // label the requester actually typed ("pizza") next to the | ||
| // homograph-normalized index value ("p1zza"). Without this | ||
| // a UI can only show the normalized form, which reads as a | ||
| // typo to the person who submitted it. | ||
| // | ||
| // Best-effort: the contract fetch or a single decode | ||
| // failing must not fail the whole query, so `label` is | ||
| // simply absent for rows that could not be decoded and the | ||
| // caller falls back to the normalized value. | ||
| let contract: Option<DataContract> = | ||
| DataContract::fetch(&sdk, contract_id).await.ok().flatten(); | ||
|
|
||
| let contenders_json: Vec<String> = contenders.contenders | ||
| .iter() | ||
| .map(|(id, contender)| { | ||
|
|
@@ -245,13 +261,36 @@ fn get_contested_resource_vote_state( | |
| r#""document":null"#.to_string() | ||
| }; | ||
|
|
||
| let label_json = contract | ||
| .as_ref() | ||
| .and_then(|contract| { | ||
| let doc_type = contract | ||
| .document_type_for_name(document_type_name_str) | ||
| .ok()?; | ||
| let decoded = contender | ||
| .try_to_contender(doc_type, sdk.version()) | ||
| .ok()?; | ||
| let label = decoded | ||
| .document() | ||
| .as_ref()? | ||
| .get("label")? | ||
| .as_str()? | ||
| .to_string(); | ||
| Some(format!( | ||
| r#","label":{}"#, | ||
| serde_json::to_string(&label).ok()? | ||
| )) | ||
| }) | ||
| .unwrap_or_default(); | ||
|
Comment on lines
+264
to
+284
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 Nitpick: document_type_for_name looked up per contender instead of once per query
source: ['claude'] |
||
|
|
||
| let vote_count = contender.vote_tally().unwrap_or(0); | ||
|
|
||
| format!( | ||
| r#"{{"identity_id":"{}","vote_count":{},{}}}"#, | ||
| r#"{{"identity_id":"{}","vote_count":{},{}{}}}"#, | ||
| bs58::encode(id.as_bytes()).into_string(), | ||
| vote_count, | ||
| document_json | ||
| document_json, | ||
| label_json | ||
| ) | ||
| }) | ||
| .collect(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: New label-decoding logic has no Rust-side test coverage
Verified: the only tests in this file's
#[cfg(test)]module (lines 306-347) cover null-handle and null-contract-id guard paths — nothing exercises the new label-decoding logic added in this PR (contract fetch,document_type_for_name,try_to_contender, JSON-embedded label extraction), nor the mirrored logic indpns/queries/contested.rs. The new Swift tests inject already-decoded label JSON directly, so they validate JSON consumption but not the Rust-side production logic — e.g. that a document lacking alabelfield, or one that fails to deserialize against the fetched contract, is silently omitted rather than producing malformed JSON or panicking.source: ['claude', 'codex']