diff --git a/apps/hermes/server/src/api/rest/v2/latest_twaps.rs b/apps/hermes/server/src/api/rest/v2/latest_twaps.rs index 34c10c81cd..7428ace909 100644 --- a/apps/hermes/server/src/api/rest/v2/latest_twaps.rs +++ b/apps/hermes/server/src/api/rest/v2/latest_twaps.rs @@ -131,22 +131,17 @@ where })?; let twap_update_data = twaps_with_update_data.update_data; - let binary: Vec = twap_update_data + let encoded_data = twap_update_data .into_iter() - .map(|data_vec| { - let encoded_data = data_vec - .into_iter() - .map(|data| match params.encoding { - EncodingType::Base64 => base64_standard_engine.encode(data), - EncodingType::Hex => hex::encode(data), - }) - .collect(); - BinaryUpdate { - encoding: params.encoding, - data: encoded_data, - } + .map(|data| match params.encoding { + EncodingType::Base64 => base64_standard_engine.encode(data), + EncodingType::Hex => hex::encode(data), }) .collect(); + let binary = BinaryUpdate { + encoding: params.encoding, + data: encoded_data, + }; let parsed: Option> = if params.parsed { Some( diff --git a/apps/hermes/server/src/api/types.rs b/apps/hermes/server/src/api/types.rs index cdb6124351..aa430773b5 100644 --- a/apps/hermes/server/src/api/types.rs +++ b/apps/hermes/server/src/api/types.rs @@ -281,9 +281,9 @@ impl From for ParsedPriceFeedTwap { #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct TwapsResponse { - /// Each BinaryUpdate contains the start & end cumulative price updates used to + /// Contains the start & end cumulative price updates used to /// calculate a given price feed's TWAP. - pub binary: Vec, + pub binary: BinaryUpdate, /// The calculated TWAPs for each price ID #[serde(skip_serializing_if = "Option::is_none")] diff --git a/apps/hermes/server/src/state/aggregate.rs b/apps/hermes/server/src/state/aggregate.rs index 67cbfd18d4..43928b9dba 100644 --- a/apps/hermes/server/src/state/aggregate.rs +++ b/apps/hermes/server/src/state/aggregate.rs @@ -206,7 +206,7 @@ pub struct PublisherStakeCapsWithUpdateData { #[derive(Debug)] pub struct TwapsWithUpdateData { pub twaps: Vec, - pub update_data: Vec>>, + pub update_data: Vec>, } #[derive(Debug, Serialize)] @@ -688,12 +688,13 @@ where } // Construct update data. - // update_data[0] will contain the start VAA and merkle proofs - // update_data[1] will contain the end VAA and merkle proofs - let start_updates = + // update_data[0] contains the start VAA and merkle proofs + // update_data[1] contains the end VAA and merkle proofs + let mut update_data = construct_update_data(start_messages.into_iter().map(Into::into).collect())?; - let end_updates = construct_update_data(end_messages.into_iter().map(Into::into).collect())?; - let update_data = vec![start_updates, end_updates]; + update_data.extend(construct_update_data( + end_messages.into_iter().map(Into::into).collect(), + )?); Ok(TwapsWithUpdateData { twaps, update_data }) } @@ -1307,10 +1308,8 @@ mod test { assert_eq!(twap_2.start_timestamp, 100); assert_eq!(twap_2.end_timestamp, 200); - // Each update_data element contains a VAA and merkle proofs for both feeds + // update_data should have 2 elements, one for the start block and one for the end block. assert_eq!(result.update_data.len(), 2); - assert_eq!(result.update_data[0].len(), 1); // Start update - assert_eq!(result.update_data[1].len(), 1); // End update } #[tokio::test]