Skip to content

Commit

Permalink
Remove dead code (#1516)
Browse files Browse the repository at this point in the history
This code is no longer used after #1443 (genesis file)
  • Loading branch information
sveitser authored May 29, 2024
1 parent 2316c78 commit ea4945f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 66 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,3 @@ surf = "2.3.2"
tempfile = "3.9.0"
tracing = "0.1.37"
url = "2.3.1"

[dev-dependencies]
bincode = { workspace = true }
62 changes: 0 additions & 62 deletions utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use ethers::{
signers::{coins_bip39::English, Signer as _},
types::U256,
};
use serde::{Deserialize as _, Serialize as _};
use std::path::{Path, PathBuf};
use std::time::Duration;
use std::{
Expand Down Expand Up @@ -350,31 +349,6 @@ macro_rules! impl_to_fixed_bytes {
};
}

/// Serialize a U256 type as a decimal string for human readable serialization
pub fn serialize_as_decimal<S>(value: &U256, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
if serializer.is_human_readable() {
serializer.serialize_str(&value.to_string())
} else {
value.serialize(serializer)
}
}

/// Deserialize a U256 type from a decimal string for human readable serialization
pub fn deserialize_from_decimal<'de, D>(deserializer: D) -> Result<U256, D::Error>
where
D: serde::Deserializer<'de>,
{
if deserializer.is_human_readable() {
let s = String::deserialize(deserializer)?;
U256::from_dec_str(&s).map_err(serde::de::Error::custom)
} else {
U256::deserialize(deserializer)
}
}

/// send a transaction and wait for confirmation before returning the tx receipt and block included.
pub async fn contract_send<M: Middleware, T: Detokenize, E>(
call: &ContractCall<M, T>,
Expand Down Expand Up @@ -467,8 +441,6 @@ async fn wait_for_transaction_to_be_mined<P: JsonRpcClient>(
mod test {
use super::*;
use committable::RawCommitmentBuilder;
use serde::{Deserialize, Serialize};
use serde_json::Value;

struct TestCommittable;

Expand All @@ -485,38 +457,4 @@ mod test {
u256_to_commitment(commitment_to_u256(TestCommittable.commit())).unwrap()
);
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct AsDecimal(
#[serde(
serialize_with = "serialize_as_decimal",
deserialize_with = "deserialize_from_decimal"
)]
U256,
);

#[test]
fn test_serde_json_as_decimal() {
let value = AsDecimal(U256::from(123));
let serialized = serde_json::to_string(&value).unwrap();

// The value is serialized as decimal string
let json_value: Value = serde_json::from_str(&serialized).unwrap();
assert_eq!(json_value.as_str().unwrap(), "123");

// Deserialization produces the original value
let deserialized: AsDecimal = serde_json::from_str(&serialized).unwrap();
assert_eq!(deserialized, value);
}

#[test]
fn test_serde_bincode_unchanged() {
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct AsDefault(U256);
let custom = AsDecimal(U256::from(123));
let default = AsDefault(U256::from(123));
assert_eq!(
bincode::serialize(&custom).unwrap(),
bincode::serialize(&default).unwrap(),
);
}
}

0 comments on commit ea4945f

Please sign in to comment.