Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/wasm-sdk/src/queries/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsValue>,
contestant_id: &str,
start_at_identifier_info: Option<String>,
count: Option<u32>,
Expand All @@ -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<Vec<u8>> using bincode serialization
let mut index_values_bytes: Vec<Vec<u8>> = 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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading