Fix hash_value with new serialization method
This commit is contained in:
parent
bdd100120a
commit
73d009a952
16
src/api.rs
16
src/api.rs
@ -1726,18 +1726,16 @@ pub fn decode_value(value: Vec<u8>) -> ApiResult<JsValue> {
|
||||
Err(ApiError::new("Invalid or unsupported PCD data".to_owned()))
|
||||
}
|
||||
|
||||
// #[wasm_bindgen]
|
||||
// pub fn hash_value(value: JsValue, commited_in: String, label: String) -> ApiResult<String> {
|
||||
// let outpoint = OutPoint::from_str(&commited_in)?;
|
||||
// let encoded_value = sdk_common::serialization::ciborium_serialize(&serde_wasm_bindgen::from_value::<FileBlob>(value)?)?;
|
||||
// let hash = AnkPcdHash::from_pcd_value(encoded_value.as_slice(), label.as_bytes(), &outpoint);
|
||||
// Ok(hash.as_byte_array().to_lower_hex_string())
|
||||
// }
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn hash_value(value: JsValue, commited_in: String, label: String) -> ApiResult<String> {
|
||||
let outpoint = OutPoint::from_str(&commited_in)?;
|
||||
let encoded_value = sdk_common::serialization::ciborium_serialize(&serde_wasm_bindgen::from_value::<FileBlob>(value)?)?;
|
||||
let encoded_value = if let Ok(file_blob) = serde_wasm_bindgen::from_value::<FileBlob>(value.clone()) {
|
||||
file_blob.serialize_to_pcd()?
|
||||
} else if let Ok(json) = serde_wasm_bindgen::from_value::<Value>(value) {
|
||||
json.serialize_to_pcd()?
|
||||
} else {
|
||||
return Err(ApiError::new("Invalid or unsupported PCD data".to_owned()));
|
||||
};
|
||||
let hash = AnkPcdHash::from_pcd_value(encoded_value.as_slice(), label.as_bytes(), &outpoint);
|
||||
Ok(hash.as_byte_array().to_lower_hex_string())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user