diff --git a/packages/common/src/types.rs b/packages/common/src/types.rs index f779e781..0e544bc1 100644 --- a/packages/common/src/types.rs +++ b/packages/common/src/types.rs @@ -3,6 +3,7 @@ use schemars::{ schema::{Schema, SchemaObject, SingleOrVec}, JsonSchema, }; +use semver::Version; use serde::{Deserialize, Serialize}; use serde_big_array::BigArray; use sha3::{Digest, Keccak256}; @@ -24,6 +25,12 @@ impl SimpleHash for String { hasher.finalize().into() } } + +impl SimpleHash for Version { + fn simple_hash(&self) -> Hash { + self.to_string().simple_hash() + } +} #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Signature(#[serde(with = "BigArray")] pub(crate) [u8; 65]); diff --git a/packages/data-requests/src/utils.rs b/packages/data-requests/src/utils.rs index eba8ce8a..605d753b 100644 --- a/packages/data-requests/src/utils.rs +++ b/packages/data-requests/src/utils.rs @@ -2,7 +2,7 @@ use common::error::ContractError; use common::msg::StakingQueryMsg; use common::msg::{IsDataRequestExecutorEligibleResponse, PostDataRequestArgs}; use common::state::DataRequest; -use common::types::{Bytes, Hash, Secpk256k1PublicKey}; +use common::types::{Bytes, Hash, Secpk256k1PublicKey, SimpleHash}; use cosmwasm_std::{to_json_binary, Addr, DepsMut, QueryRequest, WasmQuery}; use sha3::{Digest, Keccak256}; @@ -40,7 +40,7 @@ pub fn hash_data_request(posted_dr: &PostDataRequestArgs) -> Hash { // hash data request let mut dr_hasher = Keccak256::new(); - dr_hasher.update(posted_dr.version.to_string().as_bytes()); + dr_hasher.update(posted_dr.version.simple_hash()); dr_hasher.update(posted_dr.dr_binary_id); dr_hasher.update(dr_inputs_hash); dr_hasher.update(posted_dr.tally_binary_id); @@ -70,7 +70,7 @@ pub fn hash_data_result( // hash data result let mut dr_hasher = Keccak256::new(); - dr_hasher.update(dr.version.to_string().as_bytes()); + dr_hasher.update(dr.version.simple_hash()); dr_hasher.update(dr.id); dr_hasher.update(block_height.to_be_bytes()); dr_hasher.update(exit_code.to_be_bytes());