Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop deprecated call_data format #468

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Changes from all commits
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
59 changes: 1 addition & 58 deletions crates/shared/src/http_solver/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ pub struct InteractionData {
pub target: H160,
pub value: U256,
#[derivative(Debug(format_with = "crate::debug_bytes"))]
#[serde(deserialize_with = "bytes_hex_or_array::deserialize")]
#[serde(serialize_with = "model::bytes_hex::serialize")]
#[serde(with = "model::bytes_hex")]
pub call_data: Vec<u8>,
/// The input amounts into the AMM interaction - i.e. the amount of tokens
/// that are expected to be sent from the settlement contract into the AMM
Expand All @@ -151,35 +150,6 @@ pub struct InteractionData {
pub exec_plan: Option<ExecutionPlan>,
}

/// Module to allow for backwards compatibility with the HTTP solver API.
///
/// Specifically, the HTTP solver API used to expect calldata as a JSON array of
/// integers that fit in a `u8`. This changed to allow `0x-` prefixed hex
/// strings to be more consistent with how bytes are typically represented in
/// Ethereum-related APIs. This module implements JSON deserialization that
/// accepts either format.
mod bytes_hex_or_array {
use serde::{Deserialize, Deserializer};

#[derive(Deserialize)]
#[serde(untagged)]
enum HexOrArray {
Hex(#[serde(with = "model::bytes_hex")] Vec<u8>),
Array(Vec<u8>),
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
where
D: Deserializer<'de>,
{
let bytes = match HexOrArray::deserialize(deserializer)? {
HexOrArray::Hex(bytes) => bytes,
HexOrArray::Array(bytes) => bytes,
};
Ok(bytes)
}
}

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct SettledBatchAuctionModel {
Expand Down Expand Up @@ -820,33 +790,6 @@ mod tests {
);
}

#[test]
fn decode_interaction_data_backwards_compatibility() {
assert_eq!(
serde_json::from_str::<InteractionData>(
r#"
{
"target": "0xffffffffffffffffffffffffffffffffffffffff",
"value": "0",
"call_data": [1, 2, 3, 4],
"inputs": [],
"outputs": []
}
"#,
)
.unwrap(),
InteractionData {
target: H160([0xff; 20]),
value: 0.into(),
// the only backwards compatible thing remaining
call_data: vec![1, 2, 3, 4],
inputs: Vec::new(),
outputs: Vec::new(),
exec_plan: None,
},
);
}

#[test]
fn decode_foreign_liquidity_order() {
assert_eq!(
Expand Down