Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 10 additions & 5 deletions packages/wasm-sdk/src/dpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,18 @@ impl IdentityWasm {
// }

#[wasm_bindgen]
pub struct DataContractWasm(DataContract);
pub struct DataContractWasm(DataContract, &'static PlatformVersion);

impl DataContractWasm {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through DPP methods. Actually, I think your idea to pass the platfrom version to the constructor was the best option we have. But all constructors should always require platform version then. We shouldn't create with default or first version in any case. I'm sorry, that I wasn't clear enough in my first comment, so you reverted half correct code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about fd435e3?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No there actually is a trait FromWithVersion that should be used instead

pub fn new(data_contract: DataContract, platform_version: &'static PlatformVersion) -> Self {
Self(data_contract, platform_version)
}
}

impl From<DataContract> for DataContractWasm {
fn from(value: DataContract) -> Self {
Self(value)
// Use first version as fallback for backward compatibility
Self(value, PlatformVersion::first())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a safe approach. For now, I would just pass platfrom version to all methods that require it (as rust dpp does). There are non-instance methods and you would need to do it anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed some updates, but I see you've been working on dpp.rs in #2791 so maybe I will pause (since I don't exactly know what I'm doing here 🤪)

}
}

Expand All @@ -311,9 +318,7 @@ impl DataContractWasm {

#[wasm_bindgen(js_name=toJSON)]
pub fn to_json(&self) -> Result<JsValue, WasmSdkError> {
let platform_version = PlatformVersion::first();

let json = self.0.to_json(platform_version).map_err(|e| {
let json = self.0.to_json(self.1).map_err(|e| {
WasmSdkError::serialization(format!(
"failed to convert data contract convert to json: {}",
e
Expand Down
8 changes: 5 additions & 3 deletions packages/wasm-sdk/src/queries/data_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ impl WasmSdk {
)
.map_err(|e| WasmSdkError::invalid_argument(format!("Invalid data contract ID: {}", e)))?;

DataContract::fetch_by_identifier(self.as_ref(), id)
let contract = DataContract::fetch_by_identifier(self.as_ref(), id)
.await?
.ok_or_else(|| WasmSdkError::not_found("Data contract not found"))
.map(Into::into)
.ok_or_else(|| WasmSdkError::not_found("Data contract not found"))?;

let platform_version = dash_sdk::dpp::version::PlatformVersion::get(self.version()).unwrap();
Ok(DataContractWasm::new(contract, platform_version))
}

#[wasm_bindgen(js_name = "getDataContractWithProofInfo")]
Expand Down
2 changes: 1 addition & 1 deletion packages/wasm-sdk/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub async fn verify_data_contract() -> Option<DataContractWasm> {
)
.expect("parse proof");

response.map(DataContractWasm::from)
response.map(|contract| DataContractWasm::new(contract, PlatformVersion::latest()))
}

#[wasm_bindgen(js_name = "verifyDocuments")]
Expand Down
Loading