Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocao committed Jun 24, 2024
1 parent 8ada728 commit ad5bb99
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cosmwasm = ["cosmwasm-schema", "cosmwasm-std"]
test-utils = []

[dependencies]
base64 = "0.22.1"
cosmwasm-schema = { version = "1.5.5", optional = true }
cosmwasm-std = { version = "1.5.5", optional = true }
cw-storage-plus = "1.2.0"
Expand Down
5 changes: 4 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use vrf_rs::error::VrfError;
#[cfg_attr(feature = "test-utils", derive(Clone))]
pub enum Error {
#[error(transparent)]
FromHexError(#[from] FromHexError),
FromHex(#[from] FromHexError),

#[error(transparent)]
FromBase64(#[from] base64::DecodeError),

#[cfg(not(feature = "test-utils"))]
#[error(transparent)]
Expand Down
15 changes: 8 additions & 7 deletions src/msgs/data_requests/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use base64::{prelude::BASE64_STANDARD, Engine};
#[cfg(feature = "cosmwasm")]
use cw_storage_plus::{Key, Prefixer, PrimaryKey};
use semver::Version;
Expand Down Expand Up @@ -139,15 +140,15 @@ pub struct DataResult {
impl TryHashSelf for DataResult {
fn try_hash(&self) -> Result<Hash> {
let version = self.version.hash();
let dr_id = hex::decode(&self.dr_id).unwrap();
let dr_id = hex::decode(&self.dr_id)?;
let consensus: [u8; 1] = [self.consensus.into()];
let exit_code = self.exit_code.to_be_bytes();

let mut result_hasher = Keccak256::new();
#[cfg(feature = "cosmwasm")]
result_hasher.update(&self.result.to_base64());
result_hasher.update(self.result.as_slice());
#[cfg(not(feature = "cosmwasm"))]
result_hasher.update(&self.result);
result_hasher.update(BASE64_STANDARD.decode(&self.result)?);
let result_hash = result_hasher.finalize();

let block_height = self.block_height.to_be_bytes();
Expand All @@ -162,16 +163,16 @@ impl TryHashSelf for DataResult {

let mut payback_hasher = Keccak256::new();
#[cfg(feature = "cosmwasm")]
payback_hasher.update(&self.payback_address.to_base64());
payback_hasher.update(self.payback_address.as_slice());
#[cfg(not(feature = "cosmwasm"))]
payback_hasher.update(&self.payback_address);
payback_hasher.update(BASE64_STANDARD.decode(&self.payback_address)?);
let seda_payback_hash = payback_hasher.finalize();

let mut seda_payload_hasher = Keccak256::new();
#[cfg(feature = "cosmwasm")]
seda_payload_hasher.update(&self.seda_payload.to_base64());
seda_payload_hasher.update(self.seda_payload.as_slice());
#[cfg(not(feature = "cosmwasm"))]
seda_payload_hasher.update(&self.seda_payload);
seda_payload_hasher.update(BASE64_STANDARD.decode(&self.seda_payload)?);
let seda_payload_hash = seda_payload_hasher.finalize();

let bytes = [
Expand Down

0 comments on commit ad5bb99

Please sign in to comment.