From be43b557d457b09b10256699fce785b5a8d3b20e Mon Sep 17 00:00:00 2001 From: thephez Date: Tue, 19 Aug 2025 11:25:48 -0400 Subject: [PATCH] feat(wasm-sdk): add index_values parameter to contested resource voters query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add index_values parameter to get_contested_resource_voters_for_identity_with_proof_info - Implement proper serialization of index values using bincode - Enable proof support for getContestedResourceVotersForIdentity in tests 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- packages/wasm-sdk/src/queries/voting.rs | 18 +++++++++++++++++- .../tests/query-execution.spec.js | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/wasm-sdk/src/queries/voting.rs b/packages/wasm-sdk/src/queries/voting.rs index e108bdb320c..4910e8cf5ed 100644 --- a/packages/wasm-sdk/src/queries/voting.rs +++ b/packages/wasm-sdk/src/queries/voting.rs @@ -457,6 +457,7 @@ pub async fn get_contested_resource_voters_for_identity_with_proof_info( data_contract_id: &str, document_type_name: &str, index_name: &str, + index_values: Vec, contestant_id: &str, start_at_identifier_info: Option, count: Option, @@ -475,6 +476,21 @@ pub async fn get_contested_resource_voters_for_identity_with_proof_info( dash_sdk::dpp::platform_value::string_encoding::Encoding::Base58, )?; + // Convert JsValue index values to Vec> using bincode serialization + let mut index_values_bytes: Vec> = Vec::new(); + for value in index_values { + if let Some(s) = value.as_string() { + // Create a platform Value from the string + let platform_value = Value::Text(s); + // Serialize using bincode + let serialized = bincode::encode_to_vec(&platform_value, BINCODE_CONFIG) + .map_err(|e| JsError::new(&format!("Failed to serialize index value: {}", e)))?; + index_values_bytes.push(serialized); + } else { + return Err(JsError::new("Index values must be strings")); + } + } + // Parse start_at_identifier_info if provided let start_at_identifier_info = if let Some(info_str) = start_at_identifier_info { let info: serde_json::Value = serde_json::from_str(&info_str) @@ -505,7 +521,7 @@ pub async fn get_contested_resource_voters_for_identity_with_proof_info( contract_id: contract_id.to_vec(), document_type_name: document_type_name.to_string(), index_name: index_name.to_string(), - index_values: vec![], // Empty to query all contested resources + index_values: index_values_bytes, contestant_id: contestant_identifier.to_vec(), start_at_identifier_info, count, diff --git a/packages/wasm-sdk/test/ui-automation/tests/query-execution.spec.js b/packages/wasm-sdk/test/ui-automation/tests/query-execution.spec.js index 4cc8d7661e3..6a03e604f32 100644 --- a/packages/wasm-sdk/test/ui-automation/tests/query-execution.spec.js +++ b/packages/wasm-sdk/test/ui-automation/tests/query-execution.spec.js @@ -829,7 +829,7 @@ test.describe('WASM SDK Query Execution Tests', () => { }, { name: 'getContestedResourceVotersForIdentity', - hasProofSupport: false, // Not working + hasProofSupport: true, needsParameters: true, validateFn: (result) => { expect(() => JSON.parse(result)).not.toThrow();