Skip to content

Commit

Permalink
Replace derivative by educe (#876)
Browse files Browse the repository at this point in the history
* Replace derivative by educe

* fmt toml

---------

Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
  • Loading branch information
AurelienFT and xgreenx authored Dec 6, 2024
1 parent dd9ffb6 commit 319c43a
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 92 deletions.
6 changes: 3 additions & 3 deletions fuel-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ description = "FuelVM transaction."

[dependencies]
bitflags = { workspace = true, features = ["serde"], optional = true }
derivative = { version = "2.2.0", default-features = false, features = ["use_core"], optional = true }
derive_more = { version = "0.99", default-features = false, features = ["display"], optional = true }
derive_more = { version = "1", default-features = false, features = ["display"], optional = true }
educe = { version = "0.6", features = ["Eq", "PartialEq", "Hash", "Debug"], default-features = false, optional = true }
fuel-asm = { workspace = true, default-features = false }
fuel-compression = { workspace = true, optional = true }
fuel-crypto = { workspace = true, default-features = false }
Expand Down Expand Up @@ -55,7 +55,7 @@ internals = []
typescript = ["dep:serde_json", "alloc", "js-sys", "wasm-bindgen", "serde-wasm-bindgen", "fuel-types/typescript"]
random = ["fuel-crypto/random", "fuel-types/random", "rand"]
std = ["alloc", "fuel-asm/std", "fuel-crypto/std", "fuel-merkle/std", "fuel-types/std", "itertools/default", "rand?/default", "serde/default", "hex/std"]
alloc = ["hashbrown", "fuel-types/alloc", "itertools/use_alloc", "derivative", "fuel-merkle", "strum", "strum_macros", "bitflags", "postcard", "derive_more", "fuel-asm/serde", "fuel-types/serde"]
alloc = ["hashbrown", "fuel-types/alloc", "itertools/use_alloc", "fuel-merkle", "strum", "strum_macros", "bitflags", "postcard", "educe", "derive_more", "fuel-asm/serde", "fuel-types/serde"]
da-compression = ["fuel-compression"]

[lints.rust]
Expand Down
10 changes: 4 additions & 6 deletions fuel-tx/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
ValidityError,
};

use derivative::Derivative;
use educe::Educe;
use fuel_crypto::Hasher;
use fuel_merkle::{
binary::root_calculator::MerkleRootCalculator as BinaryMerkleTree,
Expand Down Expand Up @@ -34,18 +34,16 @@ const LEAF_SIZE: usize = 16 * 1024;
const PADDING_BYTE: u8 = 0u8;
const MULTIPLE: usize = 8;

#[derive(Default, Derivative, Clone, PartialEq, Eq, Hash)]
#[derivative(Debug)]
#[derive(Default, Clone, PartialEq, Eq, Hash, Educe)]
#[educe(Debug)]
#[derive(
serde::Serialize,
serde::Deserialize,
fuel_types::canonical::Deserialize,
fuel_types::canonical::Serialize,
)]
/// Deployable representation of a contract code.
pub struct Contract(
#[derivative(Debug(format_with = "fmt_truncated_hex::<16>"))] Vec<u8>,
);
pub struct Contract(#[educe(Debug(method(fmt_truncated_hex::<16>)))] Vec<u8>);

impl Contract {
/// The `ContractId` of the contract with empty bytecode, zero salt, and empty state
Expand Down
26 changes: 14 additions & 12 deletions fuel-tx/src/receipt.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Output;
use alloc::vec::Vec;
use derivative::Derivative;
use educe::Educe;
use fuel_asm::PanicInstruction;
use fuel_crypto::Hasher;
use fuel_types::{
Expand All @@ -24,10 +24,8 @@ mod script_result;
use crate::input::message::compute_message_id;
pub use script_result::ScriptExecutionResult;

#[derive(
Clone, Derivative, serde::Serialize, serde::Deserialize, Deserialize, Serialize,
)]
#[derivative(Eq, PartialEq, Hash, Debug)]
#[derive(Clone, Educe, serde::Serialize, serde::Deserialize, Deserialize, Serialize)]
#[educe(Eq, PartialEq, Hash, Debug)]
pub enum Receipt {
Call {
id: ContractId,
Expand Down Expand Up @@ -55,8 +53,9 @@ pub enum Receipt {
digest: Bytes32,
pc: Word,
is: Word,
#[derivative(Debug(format_with = "fmt_option_truncated_hex::<16>"))]
#[derivative(PartialEq = "ignore", Hash = "ignore")]
#[educe(Debug(method("fmt_option_truncated_hex::<16>")))]
#[educe(PartialEq(ignore))]
#[educe(Hash(ignore))]
#[canonical(skip)]
data: Option<Vec<u8>>,
},
Expand All @@ -66,7 +65,8 @@ pub enum Receipt {
reason: PanicInstruction,
pc: Word,
is: Word,
#[derivative(PartialEq = "ignore", Hash = "ignore")]
#[educe(PartialEq(ignore))]
#[educe(Hash(ignore))]
#[canonical(skip)]
contract_id: Option<ContractId>,
},
Expand Down Expand Up @@ -97,8 +97,9 @@ pub enum Receipt {
digest: Bytes32,
pc: Word,
is: Word,
#[derivative(Debug(format_with = "fmt_option_truncated_hex::<16>"))]
#[derivative(PartialEq = "ignore", Hash = "ignore")]
#[educe(Debug(method("fmt_option_truncated_hex::<16>")))]
#[educe(PartialEq(ignore))]
#[educe(Hash(ignore))]
#[canonical(skip)]
data: Option<Vec<u8>>,
},
Expand Down Expand Up @@ -133,8 +134,9 @@ pub enum Receipt {
nonce: Nonce,
len: Word,
digest: Bytes32,
#[derivative(Debug(format_with = "fmt_option_truncated_hex::<16>"))]
#[derivative(PartialEq = "ignore", Hash = "ignore")]
#[educe(Debug(method("fmt_option_truncated_hex::<16>")))]
#[educe(PartialEq(ignore))]
#[educe(Hash(ignore))]
#[canonical(skip)]
data: Option<Vec<u8>>,
},
Expand Down
2 changes: 1 addition & 1 deletion fuel-tx/src/transaction/consensus_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MAX_GAS: u64 = 100_000_000;
const MAX_SIZE: u64 = 110 * 1024;

#[derive(Debug, derive_more::Display)]
#[display(fmt = "setting block transaction size limit is not supported")]
#[display("setting block transaction size limit is not supported")]
pub struct SettingBlockTransactionSizeLimitNotSupported;
#[cfg(feature = "std")]
impl std::error::Error for SettingBlockTransactionSizeLimitNotSupported {}
Expand Down
6 changes: 3 additions & 3 deletions fuel-tx/src/transaction/types/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::{
TransactionRepr,
ValidityError,
};
use derivative::Derivative;
use educe::Educe;
use fuel_types::{
bytes::WORD_SIZE,
canonical::Serialize,
Expand All @@ -45,14 +45,14 @@ pub type Blob = ChargeableTransaction<BlobBody, BlobMetadata>;
pub struct BlobMetadata;

/// The body of the [`Blob`] transaction.
#[derive(Clone, Default, Derivative, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Default, Educe, serde::Serialize, serde::Deserialize)]
#[cfg_attr(
feature = "da-compression",
derive(fuel_compression::Compress, fuel_compression::Decompress)
)]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[canonical(prefix = TransactionRepr::Blob)]
#[derivative(Eq, PartialEq, Hash, Debug)]
#[educe(Eq, PartialEq, Hash, Debug)]
pub struct BlobBody {
/// Hash of the bytecode. Used both as a unique identifier and to verify the
/// bytecode.
Expand Down
9 changes: 5 additions & 4 deletions fuel-tx/src/transaction/types/chargeable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
ValidityError,
Witness,
};
use derivative::Derivative;
use educe::Educe;
use fuel_types::{
bytes,
canonical::Serialize,
Expand Down Expand Up @@ -74,8 +74,8 @@ pub trait BodyConstraints {}
#[cfg(not(feature = "da-compression"))]
impl<T> BodyConstraints for T {}

#[derive(Clone, Derivative)]
#[derivative(Eq, PartialEq, Hash, Debug)]
#[derive(Clone, Educe)]
#[educe(Eq, PartialEq, Hash, Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[cfg_attr(
feature = "da-compression",
Expand All @@ -94,7 +94,8 @@ where
pub(crate) witnesses: Vec<Witness>,
#[serde(skip)]
#[cfg_attr(feature = "da-compression", compress(skip))]
#[derivative(PartialEq = "ignore", Hash = "ignore")]
#[educe(PartialEq(ignore))]
#[educe(Hash(ignore))]
#[canonical(skip)]
pub(crate) metadata: Option<ChargeableMetadata<MetadataBody>>,
}
Expand Down
10 changes: 5 additions & 5 deletions fuel-tx/src/transaction/types/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
TransactionRepr,
ValidityError,
};
use derivative::Derivative;
use educe::Educe;
use fuel_types::{
bytes::WORD_SIZE,
canonical,
Expand All @@ -43,8 +43,8 @@ mod ser_de_tests;

pub type Create = ChargeableTransaction<CreateBody, CreateMetadata>;

#[derive(Default, Debug, Clone, Derivative)]
#[derivative(Eq, PartialEq, Hash)]
#[derive(Default, Debug, Clone, Educe)]
#[educe(Eq, PartialEq, Hash)]
pub struct CreateMetadata {
pub contract_id: ContractId,
pub contract_root: Bytes32,
Expand All @@ -69,14 +69,14 @@ impl CreateMetadata {
}
}

#[derive(Default, Debug, Clone, Derivative, serde::Serialize, serde::Deserialize)]
#[derive(Default, Debug, Clone, Educe, serde::Serialize, serde::Deserialize)]
#[cfg_attr(
feature = "da-compression",
derive(fuel_compression::Compress, fuel_compression::Decompress)
)]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[canonical(prefix = TransactionRepr::Create)]
#[derivative(Eq, PartialEq, Hash)]
#[educe(Eq, PartialEq, Hash)]
pub struct CreateBody {
pub(crate) bytecode_witness_index: u16,
pub(crate) salt: Salt,
Expand Down
14 changes: 7 additions & 7 deletions fuel-tx/src/transaction/types/input/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
UtxoId,
};
use alloc::vec::Vec;
use derivative::Derivative;
use educe::Educe;
#[cfg(feature = "da-compression")]
use fuel_compression::Compressible;
use fuel_types::{
Expand Down Expand Up @@ -143,8 +143,8 @@ impl CoinSpecification for Full {
/// - [`Full`] - is used during the deserialization of the coin. It should be transformed
/// into [`Signed`] or [`Predicate`] sub-coin. If the `predicate` is empty, it is
/// [`Signed`], else [`Predicate`].
#[derive(Default, Derivative, Clone, PartialEq, Eq, Hash)]
#[derivative(Debug)]
#[derive(Default, Educe, Clone, PartialEq, Eq, Hash)]
#[educe(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "da-compression", derive(fuel_compression::Compress))]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
Expand All @@ -161,16 +161,16 @@ where
pub asset_id: AssetId,
#[cfg_attr(feature = "da-compression", compress(skip))]
pub tx_pointer: TxPointer,
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub witness_index: Specification::Witness,
/// Exact amount of gas used by the predicate.
/// If the predicate consumes different amount of gas,
/// it's considered to be false.
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub predicate_gas_used: Specification::PredicateGasUsed,
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub predicate: Specification::Predicate,
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub predicate_data: Specification::PredicateData,
}

Expand Down
16 changes: 8 additions & 8 deletions fuel-tx/src/transaction/types/input/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
transaction::types::input::AsField,
};
use alloc::vec::Vec;
use derivative::Derivative;
use educe::Educe;
#[cfg(feature = "da-compression")]
use fuel_compression::Compressible;
use fuel_types::{
Expand Down Expand Up @@ -205,8 +205,8 @@ pub mod specifications {
/// - [`specifications::MessageData`] with [`specifications::Signed`] usage rules.
/// - [`specifications::MessageData`] with [`specifications::Predicate`] usage rules.
/// - [`specifications::Full`].
#[derive(Default, Derivative, Clone, PartialEq, Eq, Hash)]
#[derivative(Debug)]
#[derive(Default, Educe, Clone, PartialEq, Eq, Hash)]
#[educe(Debug)]
#[derive(serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "da-compression", derive(fuel_compression::Compress))]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
Expand All @@ -224,19 +224,19 @@ where
pub amount: Word,
// Unique identifier of the message
pub nonce: Nonce,
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub witness_index: Specification::Witness,
/// Exact amount of gas used by the predicate.
/// If the predicate consumes different amount of gas,
/// it's considered to be false.
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub predicate_gas_used: Specification::PredicateGasUsed,
#[cfg_attr(feature = "da-compression", compress(skip))]
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub data: Specification::Data,
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub predicate: Specification::Predicate,
#[derivative(Debug(format_with = "fmt_as_field"))]
#[educe(Debug(method(fmt_as_field)))]
pub predicate_data: Specification::PredicateData,
}

Expand Down
8 changes: 4 additions & 4 deletions fuel-tx/src/transaction/types/input/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ use core::ops::{
Deref,
DerefMut,
};
use derivative::Derivative;
use educe::Educe;
use fuel_types::fmt_truncated_hex;

use alloc::vec::Vec;

#[derive(Clone, Default, Derivative, serde::Serialize, serde::Deserialize)]
#[derive(Clone, Default, Educe, serde::Serialize, serde::Deserialize)]
#[serde(transparent)]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[derivative(Eq, PartialEq, Hash, Debug)]
#[educe(Eq, PartialEq, Hash, Debug)]
pub struct PredicateCode {
#[derivative(Debug(format_with = "fmt_truncated_hex::<16>"))]
#[educe(Debug(method(fmt_truncated_hex::<16>)))]
pub bytes: Vec<u8>,
}

Expand Down
9 changes: 5 additions & 4 deletions fuel-tx/src/transaction/types/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
TxPointer,
ValidityError,
};
use derivative::Derivative;
use educe::Educe;
use fuel_asm::Word;
use fuel_types::{
bytes::WORD_SIZE,
Expand Down Expand Up @@ -47,11 +47,11 @@ impl MintMetadata {
///
/// This transaction can be created by the block producer and included in the block only
/// by it.
#[derive(Default, Debug, Clone, Derivative, serde::Serialize, serde::Deserialize)]
#[derive(Default, Debug, Clone, Educe, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "da-compression", derive(fuel_compression::Compress))]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[canonical(prefix = TransactionRepr::Mint)]
#[derivative(Eq, PartialEq, Hash)]
#[educe(Eq, PartialEq, Hash)]
pub struct Mint {
/// The location of the transaction in the block.
#[cfg_attr(feature = "da-compression", compress(skip))]
Expand All @@ -67,7 +67,8 @@ pub struct Mint {
/// Gas Price used for current block
pub(crate) gas_price: Word,
#[serde(skip)]
#[derivative(PartialEq = "ignore", Hash = "ignore")]
#[educe(PartialEq(ignore))]
#[educe(Hash(ignore))]
#[canonical(skip)]
#[cfg_attr(feature = "da-compression", compress(skip))]
pub(crate) metadata: Option<MintMetadata>,
Expand Down
Loading

0 comments on commit 319c43a

Please sign in to comment.