Skip to content

Commit

Permalink
Log call data as hex string (#2392)
Browse files Browse the repository at this point in the history
# Changes
Some of the logs still contained calldata logged as an array of integers
instead of a hex string. This is fixed by using `Derivative` to only
overwrite the `Debug` implementation of these fields specifically.
For this I copied and slightly adjusted 1 helper function from the
`shared` crate to not make the `model` crate depend on `shared` just for
that.


## How to test
Look into the logs of the local node tests.
  • Loading branch information
MartinquaXD authored Feb 9, 2024
1 parent 9b90093 commit a0e6c05
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions crates/model/src/format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn debug_optional_bytes(
bytes: &Option<impl AsRef<[u8]>>,
formatter: &mut std::fmt::Formatter,
) -> Result<(), std::fmt::Error> {
match bytes {
Some(bytes) => formatter.write_fmt(format_args!("0x{}", hex::encode(bytes.as_ref()))),
None => formatter.write_str("None"),
}
}
1 change: 1 addition & 0 deletions crates/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pub mod app_data;
pub mod auction;
pub mod bytes_hex;
mod format;
pub mod interaction;
pub mod order;
pub mod quote;
Expand Down
6 changes: 5 additions & 1 deletion crates/model/src/solver_competition.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {
crate::{auction::AuctionId, bytes_hex::BytesHex, order::OrderUid},
derivative::Derivative,
number::serialization::HexOrDecimalU256,
primitive_types::{H160, H256, U256},
serde::{Deserialize, Serialize},
Expand Down Expand Up @@ -39,7 +40,8 @@ pub struct CompetitionAuction {
}

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Default, Deserialize, Serialize, PartialEq, Derivative)]
#[derivative(Debug)]
#[serde(rename_all = "camelCase")]
pub struct SolverSettlement {
pub solver: String,
Expand All @@ -54,9 +56,11 @@ pub struct SolverSettlement {
pub orders: Vec<Order>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<BytesHex>")]
#[derivative(Debug(format_with = "crate::format::debug_optional_bytes"))]
pub call_data: Option<Vec<u8>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde_as(as = "Option<BytesHex>")]
#[derivative(Debug(format_with = "crate::format::debug_optional_bytes"))]
pub uninternalized_call_data: Option<Vec<u8>>,
}

Expand Down

0 comments on commit a0e6c05

Please sign in to comment.