Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 2 additions & 10 deletions src/blocks/header.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2019-2026 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use std::ops::Deref;
use std::sync::{
OnceLock,
atomic::{AtomicBool, Ordering},
Expand Down Expand Up @@ -227,8 +226,9 @@ impl GetSize for RawBlockHeader {

/// A [`RawBlockHeader`] which caches calls to [`RawBlockHeader::cid`] and [`RawBlockHeader::verify_signature_against`]
#[cfg_attr(test, derive(Default))]
#[derive(Debug, GetSize)]
#[derive(Debug, GetSize, derive_more::Deref)]
pub struct CachingBlockHeader {
#[deref]
uncached: RawBlockHeader,
#[get_size(ignore)]
cid: OnceLock<Cid>,
Expand Down Expand Up @@ -257,14 +257,6 @@ impl Clone for CachingBlockHeader {
}
}

impl Deref for CachingBlockHeader {
type Target = RawBlockHeader;

fn deref(&self) -> &Self::Target {
&self.uncached
}
}

impl From<RawBlockHeader> for CachingBlockHeader {
fn from(value: RawBlockHeader) -> Self {
Self::new(value)
Expand Down
14 changes: 2 additions & 12 deletions src/db/car/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ use std::io::{Error, ErrorKind, Read, Result};
use std::path::{Path, PathBuf};
use std::sync::Arc;

#[derive(derive_more::From)]
pub enum AnyCar<ReaderT> {
Plain(super::PlainCar<ReaderT>),
Forest(super::ForestCar<ReaderT>),
#[from(skip)]
Memory(super::PlainCar<Vec<u8>>),
}

Expand Down Expand Up @@ -166,18 +168,6 @@ where
}
}

impl<ReaderT> From<super::ForestCar<ReaderT>> for AnyCar<ReaderT> {
fn from(car: super::ForestCar<ReaderT>) -> Self {
Self::Forest(car)
}
}

impl<ReaderT> From<super::PlainCar<ReaderT>> for AnyCar<ReaderT> {
fn from(car: super::PlainCar<ReaderT>) -> Self {
Self::Plain(car)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
14 changes: 1 addition & 13 deletions src/message/chain_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};

/// `Enum` to encapsulate signed and unsigned messages. Useful when working with
/// both types
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq, GetSize)]
#[derive(Clone, Debug, Serialize, Deserialize, Hash, Eq, PartialEq, GetSize, derive_more::From)]
#[serde(untagged)]
pub enum ChainMessage {
Unsigned(Message),
Expand Down Expand Up @@ -131,15 +131,3 @@ impl MessageTrait for ChainMessage {
}
}
}

impl From<Message> for ChainMessage {
fn from(value: Message) -> Self {
Self::Unsigned(value)
}
}

impl From<SignedMessage> for ChainMessage {
fn from(value: SignedMessage) -> Self {
Self::Signed(value)
}
}
64 changes: 4 additions & 60 deletions src/networks/network_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,12 @@
/// The network name as defined in the genesis block.
/// This is not necessarily the same as the network name that the node is
/// currently on. This is used by `libp2p` layer and the message pool.
#[derive(derive_more::Display, derive_more::From, derive_more::Into, derive_more::AsRef)]
#[from(String, &str)]
pub struct GenesisNetworkName(String);

impl AsRef<str> for GenesisNetworkName {
fn as_ref(&self) -> &str {
&self.0
}
}

impl std::fmt::Display for GenesisNetworkName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

impl From<&str> for GenesisNetworkName {
fn from(name: &str) -> Self {
Self(name.to_owned())
}
}

impl From<String> for GenesisNetworkName {
fn from(name: String) -> Self {
Self(name)
}
}

impl From<GenesisNetworkName> for String {
fn from(name: GenesisNetworkName) -> Self {
name.0
}
}

/// The network name as defined by the state of the node.
/// This is the network name that the node is currently on.
#[derive(derive_more::Display, derive_more::From, derive_more::Into, derive_more::AsRef)]
#[from(String, &str)]
pub struct StateNetworkName(String);

impl AsRef<str> for StateNetworkName {
fn as_ref(&self) -> &str {
&self.0
}
}

impl std::fmt::Display for StateNetworkName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

impl From<&str> for StateNetworkName {
fn from(name: &str) -> Self {
Self(name.to_owned())
}
}

impl From<String> for StateNetworkName {
fn from(name: String) -> Self {
Self(name)
}
}

impl From<StateNetworkName> for String {
fn from(name: StateNetworkName) -> Self {
name.0
}
}
14 changes: 1 addition & 13 deletions src/rpc/methods/eth/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ pub struct EthTopicSpec(pub Vec<EthHashList>);

/// Represents an [`EthAddress`] or a collection of thereof. This allows the caller to either use,
/// e.g., `0x1234...` or `["0x1234...", "0x5678..."]` as the address parameter.
#[derive(PartialEq, Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[derive(PartialEq, Serialize, Deserialize, Debug, Clone, JsonSchema, derive_more::From)]
#[serde(untagged)]
pub enum EthAddressList {
List(Vec<EthAddress>),
Expand All @@ -477,18 +477,6 @@ impl Default for EthAddressList {
}
}

impl From<EthAddress> for EthAddressList {
fn from(addr: EthAddress) -> Self {
EthAddressList::Single(addr)
}
}

impl From<Vec<EthAddress>> for EthAddressList {
fn from(addrs: Vec<EthAddress>) -> Self {
EthAddressList::List(addrs)
}
}

impl Deref for EthAddressList {
type Target = [EthAddress];

Expand Down
28 changes: 4 additions & 24 deletions src/shim/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ mod network_guard_impl {
Deserialize,
derive_more::Deref,
derive_more::DerefMut,
derive_more::From,
derive_more::Into,
)]
#[serde(transparent)]
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
Expand Down Expand Up @@ -284,6 +286,8 @@ impl GetSize for Address {
Serialize,
Deserialize,
displaydoc::Display,
derive_more::From,
derive_more::Into,
)]
#[serde(transparent)]
#[displaydoc("{0}")]
Expand All @@ -303,18 +307,6 @@ impl FromStr for StrictAddress {
// identical and able to do a conversion, otherwise it is a logic error and
// Forest should not continue so there is no point in `TryFrom`.

impl From<Address> for StrictAddress {
fn from(other: Address) -> Self {
StrictAddress(other)
}
}

impl From<StrictAddress> for Address {
fn from(other: StrictAddress) -> Self {
other.0
}
}

impl From<StrictAddress> for Address_v3 {
fn from(other: StrictAddress) -> Self {
other.0.into()
Expand All @@ -327,24 +319,12 @@ impl From<StrictAddress> for Address_v4 {
}
}

impl From<Address_v4> for Address {
fn from(other: Address_v4) -> Self {
Address(other)
}
}

impl From<&Address_v4> for Address {
fn from(other: &Address_v4) -> Self {
Address(*other)
}
}

impl From<Address> for Address_v4 {
fn from(addr: Address) -> Self {
addr.0
}
}

impl From<&Address> for Address_v4 {
fn from(other: &Address) -> Self {
other.0
Expand Down
7 changes: 1 addition & 6 deletions src/shim/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ use serde::{Deserialize, Serialize};
Deserialize,
derive_more::Deref,
derive_more::DerefMut,
derive_more::From,
)]
#[serde(transparent)]
pub struct BigInt(#[serde(with = "bigint_ser")] num_bigint::BigInt);

impl From<num_bigint::BigInt> for BigInt {
fn from(other: num_bigint::BigInt) -> Self {
BigInt(other)
}
}
30 changes: 4 additions & 26 deletions src/shim/econ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use num_traits::{One, Signed, Zero};
use serde::{Deserialize, Serialize};
use static_assertions::const_assert_eq;
use std::{
fmt,
ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Rem, Sub, SubAssign},
sync::LazyLock,
};
Expand All @@ -37,16 +36,14 @@ pub static TOTAL_FILECOIN: LazyLock<TokenAmount> =
Default,
derive_more::Deref,
derive_more::DerefMut,
derive_more::Debug,
derive_more::Display,
derive_more::From,
derive_more::Into,
)]
#[serde(transparent)]
pub struct TokenAmount(TokenAmount_latest);

impl fmt::Debug for TokenAmount {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.0, f)
}
}

impl GetSize for TokenAmount {
fn get_heap_size(&self) -> usize {
big_int_heap_size_helper(self.0.atto())
Expand Down Expand Up @@ -111,13 +108,6 @@ impl Neg for &TokenAmount {
}
}

impl std::fmt::Display for TokenAmount {
// This trait requires `fmt` with this exact signature.
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(f)
}
}

impl TokenAmount {
/// The logical number of decimal places of a token unit.
pub const DECIMALS: usize = TokenAmount_latest::DECIMALS;
Expand Down Expand Up @@ -218,12 +208,6 @@ impl From<TokenAmount_v3> for TokenAmount {
}
}

impl From<TokenAmount_v4> for TokenAmount {
fn from(other: TokenAmount_v4) -> Self {
TokenAmount(other)
}
}

impl From<&TokenAmount_v4> for TokenAmount {
fn from(other: &TokenAmount_v4) -> Self {
other.clone().into()
Expand Down Expand Up @@ -254,12 +238,6 @@ impl From<&TokenAmount> for TokenAmount_v3 {
}
}

impl From<TokenAmount> for TokenAmount_v4 {
fn from(other: TokenAmount) -> Self {
other.0
}
}

impl From<&TokenAmount> for TokenAmount_v4 {
fn from(other: &TokenAmount) -> Self {
other.0.clone()
Expand Down
25 changes: 12 additions & 13 deletions src/shim/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ use std::fmt;
/// assert_eq!(shim_from_v2, fvm2_success.into());
/// assert_eq!(shim_from_v3, fvm3_success.into());
/// ```
#[derive(PartialEq, Eq, Debug, Clone, Copy, Serialize, Deserialize, JsonSchema)]
#[derive(
PartialEq,
Eq,
Debug,
Clone,
Copy,
Serialize,
Deserialize,
JsonSchema,
derive_more::From,
derive_more::Into,
)]
pub struct ExitCode(#[schemars(with = "u32")] ExitCodeV4);

impl PartialOrd for ExitCode {
Expand Down Expand Up @@ -115,12 +126,6 @@ impl From<u32> for ExitCode {
}
}

impl From<ExitCodeV4> for ExitCode {
fn from(value: ExitCodeV4) -> Self {
Self(value)
}
}

impl From<ExitCodeV3> for ExitCode {
fn from(value: ExitCodeV3) -> Self {
value.value().into()
Expand All @@ -144,9 +149,3 @@ impl From<ExitCode> for ExitCodeV3 {
Self::new(value.0.value())
}
}

impl From<ExitCode> for ExitCodeV4 {
fn from(value: ExitCode) -> Self {
value.0
}
}
Loading
Loading