Skip to content

Commit

Permalink
Merge branch 'master' into feature/chery-pick-release
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx authored Oct 1, 2024
2 parents a605736 + 49acdeb commit fa44125
Show file tree
Hide file tree
Showing 33 changed files with 221 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
- command: check
args: --target wasm32-unknown-unknown -p fuel-crypto --no-default-features
- command: check
args: --target wasm32-unknown-unknown -p fuel-tx --features serde --no-default-features
args: --target wasm32-unknown-unknown -p fuel-tx --features alloc --no-default-features
- command: check
args: --target wasm32-unknown-unknown -p fuel-types --features serde --no-default-features
- command: rustc
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- [#838](https://github.com/FuelLabs/fuel-vm/pull/838): Implemented `AsRef<[u8]>` and `TryFrom<&[u8]>` for DA compression types: ScriptCode, PredicateCode, RegistryKey.

### Removed

#### Breaking
- [#843](https://github.com/FuelLabs/fuel-vm/pull/843): Remove `serde` feature from the `fuel-tx` crate. It is default behaviour now if you enable `alloc` feature.

### Changed

#### Breaking
Expand Down
2 changes: 1 addition & 1 deletion ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ cargo check --all-targets --all-features &&
cargo check --target thumbv6m-none-eabi -p fuel-asm -p fuel-storage -p fuel-merkle --no-default-features &&
cargo check --target wasm32-unknown-unknown -p fuel-crypto --no-default-features &&
cargo check --target wasm32-unknown-unknown -p fuel-types --features serde --no-default-features &&
cargo check --target wasm32-unknown-unknown -p fuel-tx --features serde --no-default-features &&
cargo check --target wasm32-unknown-unknown -p fuel-tx --features alloc --no-default-features &&
cargo check --target wasm32-unknown-unknown -p fuel-vm --features alloc --no-default-features &&
cargo rustc --target wasm32-unknown-unknown -p fuel-types --features typescript --crate-type=cdylib &&
cargo rustc --target wasm32-unknown-unknown -p fuel-asm --features typescript --crate-type=cdylib &&
Expand Down
18 changes: 8 additions & 10 deletions fuel-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ repository = { workspace = true }
description = "FuelVM transaction."

[dependencies]
bitflags = { workspace = true }
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"] }
derive_more = { version = "0.99", default-features = false, features = ["display"], optional = true }
fuel-asm = { workspace = true, default-features = false }
fuel-compression = { workspace = true, optional = true }
fuel-crypto = { workspace = true, default-features = false }
fuel-merkle = { workspace = true, default-features = false, optional = true }
fuel-types = { workspace = true, default-features = false, features = ["serde"] }
fuel-types = { workspace = true, default-features = false }
hashbrown = { version = "0.14", optional = true }
itertools = { version = "0.10", default-features = false, optional = true }
js-sys = { version = "0.3", optional = true }
postcard = { version = "1.0", features = ["alloc"] }
postcard = { version = "1.0", features = ["alloc"], optional = true }
rand = { version = "0.8", default-features = false, features = ["std_rng"], optional = true }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
serde-wasm-bindgen = { version = "0.6", optional = true }
Expand All @@ -35,7 +35,7 @@ wasm-bindgen = { version = "0.2.88", optional = true }
bimap = "0.6"
bincode = { workspace = true }
fuel-crypto = { workspace = true, default-features = false, features = ["random"] }
fuel-tx = { path = ".", features = ["random", "serde", "test-helpers"] }
fuel-tx = { path = ".", features = ["random", "test-helpers", "da-compression"] }
fuel-types = { workspace = true, default-features = false, features = ["random"] }
hex = { version = "0.4", default-features = false }
insta = "1.0"
Expand All @@ -52,13 +52,11 @@ tokio = { version = "1.27", features = ["full"] }
default = ["fuel-asm/default", "fuel-crypto/default", "fuel-merkle/default", "fuel-types/default", "std"]
test-helpers = ["alloc", "internals"]
internals = []
typescript = ["alloc", "js-sys", "wasm-bindgen", "serde", "serde-wasm-bindgen", "fuel-types/typescript"]
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"]
# serde is requiring alloc because its mandatory for serde_json. to avoid adding a new feature only for serde_json, we just require `alloc` here since as of the moment we don't have a use case of serde without alloc.
serde = ["alloc", "fuel-asm/serde", "fuel-crypto/serde", "fuel-merkle/serde", "serde_json", "hashbrown/serde", "bitflags/serde"]
da-compression = ["serde", "fuel-compression"]
alloc = ["hashbrown", "fuel-types/alloc", "itertools/use_alloc", "derivative", "fuel-merkle", "strum", "strum_macros", "bitflags", "postcard", "derive_more", "fuel-asm/serde", "fuel-types/serde"]
da-compression = ["fuel-compression"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
8 changes: 6 additions & 2 deletions fuel-tx/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ const MULTIPLE: usize = 8;

#[derive(Default, Derivative, Clone, PartialEq, Eq, Hash)]
#[derivative(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[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>,
Expand Down
6 changes: 3 additions & 3 deletions fuel-tx/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ mod script_result;
use crate::input::message::compute_message_id;
pub use script_result::ScriptExecutionResult;

#[derive(Clone, Derivative)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Deserialize, Serialize)]
#[derive(
Clone, Derivative, serde::Serialize, serde::Deserialize, Deserialize, Serialize,
)]
#[derivative(Eq, PartialEq, Hash, Debug)]
pub enum Receipt {
Call {
Expand Down
15 changes: 12 additions & 3 deletions fuel-tx/src/receipt/script_result.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
use fuel_types::Word;

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[derive(
Debug,
Copy,
Clone,
PartialEq,
Eq,
Hash,
serde::Serialize,
serde::Deserialize,
fuel_types::canonical::Deserialize,
fuel_types::canonical::Serialize,
)]
#[repr(u64)]
pub enum ScriptExecutionResult {
Success,
Expand Down
12 changes: 0 additions & 12 deletions fuel-tx/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@
mod offset;
mod valid_cases;

#[cfg(feature = "serde")]
mod bytes;
#[cfg(feature = "da-compression")]
mod da_compression;
#[cfg(feature = "serde")]
mod display;

#[cfg(not(feature = "serde"))]
use bincode as _;

#[cfg(not(feature = "da-compression"))]
use bimap as _;
#[cfg(not(feature = "da-compression"))]
use pretty_assertions as _;
#[cfg(not(feature = "da-compression"))]
use tokio as _;
49 changes: 29 additions & 20 deletions fuel-tx/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,16 @@ pub use id::{
pub type TxId = Bytes32;

/// The fuel transaction entity <https://github.com/FuelLabs/fuel-specs/blob/master/src/tx-format/transaction.md>.
#[derive(Debug, Clone, PartialEq, Eq, Hash, strum_macros::EnumCount)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Hash,
strum_macros::EnumCount,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(
feature = "da-compression",
derive(fuel_compression::Compress, fuel_compression::Decompress)
Expand Down Expand Up @@ -339,15 +347,15 @@ impl Transaction {
/// transaction because all of its attributes are trivially serialized.
///
/// If an error happens, a JSON string with the error description will be returned
#[cfg(all(feature = "serde", feature = "alloc"))]
#[cfg(test)]
pub fn to_json(&self) -> alloc::string::String {
serde_json::to_string(self)
.unwrap_or_else(|e| alloc::format!(r#"{{"error": "{e}"}}"#))
}

/// Attempt to deserialize a transaction from a JSON string, returning `None` if it
/// fails
#[cfg(all(feature = "serde", feature = "alloc"))]
#[cfg(test)]
pub fn from_json<J>(json: J) -> Option<Self>
where
J: AsRef<str>,
Expand Down Expand Up @@ -1094,44 +1102,46 @@ pub mod typescript {
};
use fuel_types::Bytes32;

#[derive(Debug, Clone, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize)]
#[wasm_bindgen]
pub struct Transaction(#[wasm_bindgen(skip)] pub Box<crate::Transaction>);

#[derive(Default, Debug, Clone, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Default, Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize,
)]
#[wasm_bindgen]
pub struct Create(#[wasm_bindgen(skip)] pub Box<crate::Create>);

#[derive(Default, Debug, Clone, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Default, Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize,
)]
#[wasm_bindgen]
pub struct Script(#[wasm_bindgen(skip)] pub Box<crate::Script>);

#[derive(Default, Debug, Clone, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Default, Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize,
)]
#[wasm_bindgen]
pub struct Mint(#[wasm_bindgen(skip)] pub Box<crate::Mint>);

#[derive(Default, Debug, Clone, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Default, Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize,
)]
#[wasm_bindgen]
pub struct Upgrade(#[wasm_bindgen(skip)] pub Box<crate::Upgrade>);

#[derive(Debug, Clone, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize)]
#[wasm_bindgen]
pub struct UpgradePurpose(#[wasm_bindgen(skip)] pub Box<crate::UpgradePurpose>);

#[derive(Default, Debug, Clone, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(
Default, Debug, Clone, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize,
)]
#[wasm_bindgen]
pub struct Upload(#[wasm_bindgen(skip)] pub Box<crate::Upload>);

#[wasm_bindgen]
impl Transaction {
#[cfg(feature = "serde")]
#[wasm_bindgen(js_name = toJSON)]
pub fn to_json(&self) -> String {
serde_json::to_string(&self.0).expect("unable to json format")
Expand Down Expand Up @@ -1292,7 +1302,6 @@ pub mod typescript {
<$t>::default()
}

#[cfg(feature = "serde")]
#[wasm_bindgen(js_name = toJSON)]
pub fn to_json(&self) -> String {
serde_json::to_string(&self).expect("unable to json format")
Expand Down
40 changes: 20 additions & 20 deletions fuel-tx/src/transaction/consensus_parameters/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,10 +1181,10 @@ pub struct GasCostsValuesV1 {
pub lw: Word,
pub mint: Word,
pub mlog: Word,
#[cfg_attr(feature = "serde", serde(rename = "mod"))]
#[serde(rename = "mod")]
pub mod_op: Word,
pub modi: Word,
#[cfg_attr(feature = "serde", serde(rename = "move"))]
#[serde(rename = "move")]
pub move_op: Word,
pub movi: Word,
pub mroo: Word,
Expand All @@ -1199,9 +1199,9 @@ pub struct GasCostsValuesV1 {
pub popl: Word,
pub pshh: Word,
pub pshl: Word,
#[cfg_attr(feature = "serde", serde(rename = "ret_contract"))]
#[serde(rename = "ret_contract")]
pub ret: Word,
#[cfg_attr(feature = "serde", serde(rename = "rvrt_contract"))]
#[serde(rename = "rvrt_contract")]
pub rvrt: Word,
pub sb: Word,
pub sll: Word,
Expand Down Expand Up @@ -1246,7 +1246,7 @@ pub struct GasCostsValuesV1 {
pub mcp: DependentCost,
pub mcpi: DependentCost,
pub meq: DependentCost,
#[cfg_attr(feature = "serde", serde(rename = "retd_contract"))]
#[serde(rename = "retd_contract")]
pub retd: DependentCost,
pub s256: DependentCost,
pub scwq: DependentCost,
Expand Down Expand Up @@ -1308,10 +1308,10 @@ pub struct GasCostsValuesV2 {
pub lw: Word,
pub mint: Word,
pub mlog: Word,
#[cfg_attr(feature = "serde", serde(rename = "mod"))]
#[serde(rename = "mod")]
pub mod_op: Word,
pub modi: Word,
#[cfg_attr(feature = "serde", serde(rename = "move"))]
#[serde(rename = "move")]
pub move_op: Word,
pub movi: Word,
pub mroo: Word,
Expand All @@ -1326,9 +1326,9 @@ pub struct GasCostsValuesV2 {
pub popl: Word,
pub pshh: Word,
pub pshl: Word,
#[cfg_attr(feature = "serde", serde(rename = "ret_contract"))]
#[serde(rename = "ret_contract")]
pub ret: Word,
#[cfg_attr(feature = "serde", serde(rename = "rvrt_contract"))]
#[serde(rename = "rvrt_contract")]
pub rvrt: Word,
pub sb: Word,
pub sll: Word,
Expand Down Expand Up @@ -1374,7 +1374,7 @@ pub struct GasCostsValuesV2 {
pub mcp: DependentCost,
pub mcpi: DependentCost,
pub meq: DependentCost,
#[cfg_attr(feature = "serde", serde(rename = "retd_contract"))]
#[serde(rename = "retd_contract")]
pub retd: DependentCost,
pub s256: DependentCost,
pub scwq: DependentCost,
Expand Down Expand Up @@ -1436,10 +1436,10 @@ pub struct GasCostsValuesV3 {
pub lw: Word,
pub mint: Word,
pub mlog: Word,
#[cfg_attr(feature = "serde", serde(rename = "mod"))]
#[serde(rename = "mod")]
pub mod_op: Word,
pub modi: Word,
#[cfg_attr(feature = "serde", serde(rename = "move"))]
#[serde(rename = "move")]
pub move_op: Word,
pub movi: Word,
pub mroo: Word,
Expand All @@ -1454,9 +1454,9 @@ pub struct GasCostsValuesV3 {
pub popl: Word,
pub pshh: Word,
pub pshl: Word,
#[cfg_attr(feature = "serde", serde(rename = "ret_contract"))]
#[serde(rename = "ret_contract")]
pub ret: Word,
#[cfg_attr(feature = "serde", serde(rename = "rvrt_contract"))]
#[serde(rename = "rvrt_contract")]
pub rvrt: Word,
pub sb: Word,
pub sll: Word,
Expand Down Expand Up @@ -1504,7 +1504,7 @@ pub struct GasCostsValuesV3 {
pub mcp: DependentCost,
pub mcpi: DependentCost,
pub meq: DependentCost,
#[cfg_attr(feature = "serde", serde(rename = "retd_contract"))]
#[serde(rename = "retd_contract")]
pub retd: DependentCost,
pub s256: DependentCost,
pub scwq: DependentCost,
Expand Down Expand Up @@ -1565,10 +1565,10 @@ pub struct GasCostsValuesV4 {
pub lw: Word,
pub mint: Word,
pub mlog: Word,
#[cfg_attr(feature = "serde", serde(rename = "mod"))]
#[serde(rename = "mod")]
pub mod_op: Word,
pub modi: Word,
#[cfg_attr(feature = "serde", serde(rename = "move"))]
#[serde(rename = "move")]
pub move_op: Word,
pub movi: Word,
pub mroo: Word,
Expand All @@ -1583,9 +1583,9 @@ pub struct GasCostsValuesV4 {
pub popl: Word,
pub pshh: Word,
pub pshl: Word,
#[cfg_attr(feature = "serde", serde(rename = "ret_contract"))]
#[serde(rename = "ret_contract")]
pub ret: Word,
#[cfg_attr(feature = "serde", serde(rename = "rvrt_contract"))]
#[serde(rename = "rvrt_contract")]
pub rvrt: Word,
pub sb: Word,
pub sll: Word,
Expand Down Expand Up @@ -1636,7 +1636,7 @@ pub struct GasCostsValuesV4 {
pub mcp: DependentCost,
pub mcpi: DependentCost,
pub meq: DependentCost,
#[cfg_attr(feature = "serde", serde(rename = "retd_contract"))]
#[serde(rename = "retd_contract")]
pub retd: DependentCost,
pub s256: DependentCost,
pub scwq: DependentCost,
Expand Down
Loading

0 comments on commit fa44125

Please sign in to comment.