Skip to content

Commit fd435e3

Browse files
thephezclaude
andcommitted
fix(wasm-sdk): store platform version in DataContractWasm struct
DataContractWasm now stores platform_version internally as u32, ensuring consistent version handling across all operations. The toJSON method no longer requires a platform_version parameter since it uses the stored value. All constructors now require explicit platform version, following the pattern that platform version should never use defaults. BREAKING CHANGE: DataContractWasm.toJSON() no longer accepts a platform_version parameter 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 74a10aa commit fd435e3

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

packages/wasm-sdk/src/dpp.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,27 +295,34 @@ impl IdentityWasm {
295295
// }
296296

297297
#[wasm_bindgen(js_name=DataContract)]
298-
pub struct DataContractWasm(DataContract);
298+
pub struct DataContractWasm {
299+
contract: DataContract,
300+
platform_version: u32,
301+
}
299302

300303
impl DataContractWasm {
301-
/// Create a DataContractWasm from a DataContract.
304+
/// Create a DataContractWasm from a DataContract with platform version.
302305
///
303306
/// This is the primary constructor for wrapping a data contract.
304-
/// Note that serialization via `to_json()` requires providing an explicit
305-
/// platform version to ensure version-specific fields (e.g., `groups` and
306-
/// `tokens` for token contracts) are correctly included.
307+
/// The platform version is stored and used for consistent serialization
308+
/// to ensure version-specific fields (e.g., `groups` and `tokens` for
309+
/// token contracts) are correctly included.
307310
///
308311
/// # Arguments
309312
/// * `data_contract` - The data contract to wrap
310-
pub(crate) fn from_data_contract(data_contract: DataContract) -> Self {
311-
Self(data_contract)
313+
/// * `platform_version` - The platform version to use for operations
314+
pub(crate) fn from_data_contract(data_contract: DataContract, platform_version: u32) -> Self {
315+
Self {
316+
contract: data_contract,
317+
platform_version,
318+
}
312319
}
313320
}
314321

315322
#[wasm_bindgen(js_class=DataContract)]
316323
impl DataContractWasm {
317324
pub fn id(&self) -> String {
318-
self.0.id().to_string(Encoding::Base58)
325+
self.contract.id().to_string(Encoding::Base58)
319326
}
320327

321328
#[wasm_bindgen(js_name=fromJSON)]
@@ -340,18 +347,22 @@ impl DataContractWasm {
340347
WasmSdkError::serialization(format!("failed to create DataContract from json: {}", e))
341348
})?;
342349

343-
Ok(DataContractWasm::from_data_contract(data_contract))
350+
Ok(DataContractWasm::from_data_contract(
351+
data_contract,
352+
platform_version.protocol_version,
353+
))
344354
}
345355

346356
#[wasm_bindgen(js_name=toJSON)]
347-
pub fn to_json(&self, platform_version: u32) -> Result<JsValue, WasmSdkError> {
348-
let platform_version = &PlatformVersion::get(platform_version).map_err(|e| {
357+
pub fn to_json(&self) -> Result<JsValue, WasmSdkError> {
358+
let platform_version = &PlatformVersion::get(self.platform_version).map_err(|e| {
349359
WasmSdkError::invalid_argument(format!(
350-
"unknown platform version {platform_version}: {e}"
360+
"unknown platform version {}: {e}",
361+
self.platform_version
351362
))
352363
})?;
353364

354-
let json = self.0.to_json(platform_version).map_err(|e| {
365+
let json = self.contract.to_json(platform_version).map_err(|e| {
355366
WasmSdkError::serialization(format!(
356367
"failed to convert data contract convert to json: {}",
357368
e

packages/wasm-sdk/src/queries/data_contract.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ impl WasmSdk {
4040
.await?
4141
.ok_or_else(|| WasmSdkError::not_found("Data contract not found"))?;
4242

43-
Ok(DataContractWasm::from_data_contract(contract))
43+
Ok(DataContractWasm::from_data_contract(
44+
contract,
45+
self.version(),
46+
))
4447
}
4548

4649
#[wasm_bindgen(js_name = "getDataContractWithProofInfo")]

packages/wasm-sdk/src/verify.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ pub async fn verify_data_contract() -> Option<DataContractWasm> {
122122
)
123123
.expect("parse proof");
124124

125-
response.map(DataContractWasm::from_data_contract)
125+
response.map(|contract| {
126+
DataContractWasm::from_data_contract(contract, PlatformVersion::latest().protocol_version)
127+
})
126128
}
127129

128130
#[wasm_bindgen(js_name = "verifyDocuments")]

0 commit comments

Comments
 (0)