Repository navigation
fix(platform)!: one vote poll per contest for index values sent in different forms (PV15) #5886
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
Merged
QuantumExplorer
merged 5 commits into
v5.1-dev
from
claude/contest-poll-index-value-forms
Nov 12, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ffff719
fix(platform)!: one vote poll per contest for index values sent in di…
QuantumExplorer ae9fa08
Merge remote-tracking branch 'origin/v5.1-dev' into claude/contest-po…
QuantumExplorer 62a536f
fix(platform): a contest under way keeps the poll it was opened under…
QuantumExplorer 9a76ce1
fix(drive-abci): keep protocol version 14's whole-poll comparison of …
QuantumExplorer f0ecd15
Merge remote-tracking branch 'origin/v5.1-dev' into claude/contest-po…
QuantumExplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
packages/rs-dpp/src/data_contract/document_type/index/extract_contested_values/v1/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| use super::contested_index_identifier; | ||
| use crate::data_contract::document_type::property::{DocumentProperty, DocumentPropertyType}; | ||
| use crate::data_contract::document_type::Index; | ||
| use indexmap::IndexMap; | ||
| use platform_value::Value; | ||
| use std::collections::BTreeMap; | ||
|
|
||
| impl Index { | ||
| /// The index values of `data`, each written the one way its property's type writes every | ||
| /// value that shares its key in the paths of a vote poll. | ||
| #[inline(always)] | ||
| pub(super) fn extract_contested_values_v1( | ||
| &self, | ||
| data: &BTreeMap<String, Value>, | ||
| document_properties: &IndexMap<String, DocumentProperty>, | ||
| ) -> Vec<Value> { | ||
| self.properties | ||
| .iter() | ||
| .zip(self.extract_values(data)) | ||
| .map( | ||
| |(index_property, value)| match document_properties.get(&index_property.name) { | ||
| Some(property) => { | ||
| canonical_contested_index_value(&property.property_type, value) | ||
| } | ||
| // Not a top-level property of the type: a contested create reads its | ||
| // index values from the document's top-level properties, so it finds | ||
| // no value here | ||
| None => value, | ||
| }, | ||
| ) | ||
| .collect() | ||
| } | ||
| } | ||
|
|
||
| /// `value` as a property of `property_type` writes every value with the same key in the paths | ||
| /// of a vote poll (`DocumentPropertyType::encode_value_for_tree_keys`), which is also the | ||
| /// value a query of the contest decodes from that key. A value the type does not key (one of | ||
| /// another kind, or an integer out of the type's range) is returned as it is: no contest holds | ||
| /// it. | ||
| /// | ||
| /// Every type is listed, so that a new type states the form it takes. | ||
| fn canonical_contested_index_value(property_type: &DocumentPropertyType, value: Value) -> Value { | ||
| if value.is_null() { | ||
| return value; | ||
| } | ||
| let canonical = match property_type { | ||
| // An integer in any integer form is keyed by its number alone | ||
| DocumentPropertyType::U128 => value.to_integer().ok().map(Value::U128), | ||
| DocumentPropertyType::I128 => value.to_integer().ok().map(Value::I128), | ||
| DocumentPropertyType::U64 => value.to_integer().ok().map(Value::U64), | ||
| DocumentPropertyType::I64 => value.to_integer().ok().map(Value::I64), | ||
| DocumentPropertyType::U32 | DocumentPropertyType::KeyIdWithReference(_) => { | ||
| value.to_integer().ok().map(Value::U32) | ||
| } | ||
| DocumentPropertyType::I32 => value.to_integer().ok().map(Value::I32), | ||
| DocumentPropertyType::U16 => value.to_integer().ok().map(Value::U16), | ||
| DocumentPropertyType::I16 => value.to_integer().ok().map(Value::I16), | ||
| DocumentPropertyType::U8 => value.to_integer().ok().map(Value::U8), | ||
| DocumentPropertyType::I8 => value.to_integer().ok().map(Value::I8), | ||
| // A date is keyed as its timestamp | ||
| DocumentPropertyType::Date => value.to_integer().ok().map(Value::U64), | ||
| // A float is keyed by its bits, and an integer as the float it converts to | ||
| DocumentPropertyType::F64 => value.to_float().ok().map(Value::Float), | ||
| // Only the empty string and `"\0"` share a key, `[0]` | ||
| DocumentPropertyType::String(_) => match &value { | ||
| Value::Text(text) if text == "\0" => Some(Value::Text(String::new())), | ||
| _ => None, | ||
| }, | ||
| // Bytes in any form are keyed by the bytes alone, and no bytes by the empty key, as | ||
| // a missing value is | ||
| DocumentPropertyType::ByteArray(_) => value.to_binary_bytes().ok().map(|bytes| { | ||
| if bytes.is_empty() { | ||
| Value::Null | ||
| } else { | ||
| Value::Bytes(bytes) | ||
| } | ||
| }), | ||
| // The forms protocol version 14 already wrote as an identifier, then every other | ||
| // form keyed by the same 32 bytes. A text is read only when it is short enough to be | ||
| // an identifier in base 58: no schema has bounded it yet, and decoding base 58 takes | ||
| // time quadratic in its length | ||
| DocumentPropertyType::Identifier | DocumentPropertyType::IdentifierWithReference(_) => { | ||
| contested_index_identifier(&value) | ||
| .or_else(|| { | ||
| value | ||
| .to_bounded_identifier() | ||
| .ok() | ||
| .map(|identifier| identifier.to_buffer()) | ||
| }) | ||
| .map(Value::Identifier) | ||
| } | ||
| // Keyed only as a boolean | ||
| DocumentPropertyType::Boolean => None, | ||
| // Never keyed whole: no index holds an object, and a contested index holds no array | ||
| DocumentPropertyType::Object(_) | ||
| | DocumentPropertyType::Array(_) | ||
| | DocumentPropertyType::VariableTypeArray(_) | ||
| | DocumentPropertyType::TypedArray(_) => None, | ||
| }; | ||
| canonical.unwrap_or(value) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.