Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Moved UtxoId to fuel-types #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ required-features = ["std"]
name = "test-valid"
path = "tests/valid.rs"
required-features = ["std"]

[patch.crates-io]
fuel-types = { git = "https://github.com/FuelLabs/fuel-types/", branch = "feature/move-utxoid" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the pr is not flagged as draft, a reminder to remove this

22 changes: 3 additions & 19 deletions src/transaction/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@ mod tests {
bytes.as_mut().iter_mut().for_each(|b| *b = b.not());
}

fn invert_utxo_id(utxo_id: &mut UtxoId) {
let mut tx_id = *utxo_id.tx_id();
let mut out_idx = [utxo_id.output_index()];

invert(&mut tx_id);
invert(&mut out_idx);

*utxo_id = UtxoId::new(tx_id, out_idx[0])
}

fn invert_storage_slot(storage_slot: &mut StorageSlot) {
let mut data = [0u8; 64];
let _ = storage_slot.read(&mut data).unwrap();
Expand Down Expand Up @@ -199,28 +189,22 @@ mod tests {
assert_id_ne(tx, |t| t.set_maturity(t.maturity().not()));

if !tx.inputs().is_empty() {
assert_io_ne!(tx, _inputs_mut, Input::CoinSigned, utxo_id, invert_utxo_id);
assert_io_ne!(tx, _inputs_mut, Input::CoinSigned, utxo_id, invert);
assert_io_ne!(tx, _inputs_mut, Input::CoinSigned, owner, invert);
assert_io_ne!(tx, _inputs_mut, Input::CoinSigned, amount, not);
assert_io_ne!(tx, _inputs_mut, Input::CoinSigned, asset_id, invert);
assert_io_ne!(tx, _inputs_mut, Input::CoinSigned, witness_index, not);
assert_io_ne!(tx, _inputs_mut, Input::CoinSigned, maturity, not);

assert_io_ne!(
tx,
_inputs_mut,
Input::CoinPredicate,
utxo_id,
invert_utxo_id
);
assert_io_ne!(tx, _inputs_mut, Input::CoinPredicate, utxo_id, invert);
assert_io_ne!(tx, _inputs_mut, Input::CoinPredicate, owner, invert);
assert_io_ne!(tx, _inputs_mut, Input::CoinPredicate, amount, not);
assert_io_ne!(tx, _inputs_mut, Input::CoinPredicate, asset_id, invert);
assert_io_ne!(tx, _inputs_mut, Input::CoinPredicate, maturity, not);
assert_io_ne!(tx, _inputs_mut, Input::CoinPredicate, predicate, inv_v);
assert_io_ne!(tx, _inputs_mut, Input::CoinPredicate, predicate_data, inv_v);

assert_io_eq!(tx, _inputs_mut, Input::Contract, utxo_id, invert_utxo_id);
assert_io_eq!(tx, _inputs_mut, Input::Contract, utxo_id, invert);
assert_io_eq!(tx, _inputs_mut, Input::Contract, balance_root, invert);
assert_io_eq!(tx, _inputs_mut, Input::Contract, state_root, invert);
assert_io_ne!(tx, _inputs_mut, Input::Contract, contract_id, invert);
Expand Down
3 changes: 1 addition & 2 deletions src/transaction/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ mod input;
mod output;
mod storage;
mod tx_pointer;
mod utxo_id;
mod witness;

pub use fuel_types::UtxoId;
pub use input::{Input, InputRepr};
pub use output::{Output, OutputRepr};
pub use storage::StorageSlot;
pub use tx_pointer::TxPointer;
pub use utxo_id::UtxoId;
pub use witness::Witness;
21 changes: 7 additions & 14 deletions src/transaction/types/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,7 @@ impl io::Read for Input {
} => {
let buf = bytes::store_number_unchecked(buf, InputRepr::Coin as Word);

let n = utxo_id.read(buf)?;
let buf = &mut buf[n..];

let buf = bytes::store_array_unchecked(buf, utxo_id);
let buf = bytes::store_array_unchecked(buf, owner);
let buf = bytes::store_number_unchecked(buf, *amount);
let buf = bytes::store_array_unchecked(buf, asset_id);
Expand Down Expand Up @@ -590,9 +588,7 @@ impl io::Read for Input {
} => {
let buf = bytes::store_number_unchecked(buf, InputRepr::Coin as Word);

let n = utxo_id.read(buf)?;
let buf = &mut buf[n..];

let buf = bytes::store_array_unchecked(buf, utxo_id);
let buf = bytes::store_array_unchecked(buf, owner);
let buf = bytes::store_number_unchecked(buf, *amount);
let buf = bytes::store_array_unchecked(buf, asset_id);
Expand Down Expand Up @@ -620,8 +616,7 @@ impl io::Read for Input {
contract_id,
} => {
let buf = bytes::store_number_unchecked(buf, InputRepr::Contract as Word);
let buf = bytes::store_array_unchecked(buf, utxo_id.tx_id());
let buf = bytes::store_number_unchecked(buf, utxo_id.output_index() as Word);
let buf = bytes::store_array_unchecked(buf, utxo_id);
let buf = bytes::store_array_unchecked(buf, balance_root);
let buf = bytes::store_array_unchecked(buf, state_root);

Expand Down Expand Up @@ -707,10 +702,8 @@ impl io::Write for Input {
InputRepr::Coin => {
let mut n = INPUT_COIN_FIXED_SIZE;

let utxo_id = UtxoId::from_bytes(buf)?;
let buf = &buf[utxo_id.serialized_size()..];

// Safety: buf len is checked
let (utxo_id, buf) = unsafe { bytes::restore_array_unchecked(buf) };
let (owner, buf) = unsafe { bytes::restore_array_unchecked(buf) };
let (amount, buf) = unsafe { bytes::restore_number_unchecked(buf) };
let (asset_id, buf) = unsafe { bytes::restore_array_unchecked(buf) };
Expand All @@ -730,6 +723,7 @@ impl io::Write for Input {
let (size, predicate_data, _) = bytes::restore_raw_bytes(buf, predicate_data_len)?;
n += size;

let utxo_id = utxo_id.into();
let owner = owner.into();
let asset_id = asset_id.into();

Expand Down Expand Up @@ -762,10 +756,8 @@ impl io::Write for Input {
InputRepr::Contract if buf.len() < INPUT_CONTRACT_SIZE - WORD_SIZE => Err(bytes::eof()),

InputRepr::Contract => {
let utxo_id = UtxoId::from_bytes(buf)?;
let buf = &buf[utxo_id.serialized_size()..];

// Safety: checked buffer len
let (utxo_id, buf) = unsafe { bytes::restore_array_unchecked(buf) };
let (balance_root, buf) = unsafe { bytes::restore_array_unchecked(buf) };
let (state_root, buf) = unsafe { bytes::restore_array_unchecked(buf) };

Expand All @@ -774,6 +766,7 @@ impl io::Write for Input {

let (contract_id, _) = unsafe { bytes::restore_array_unchecked(buf) };

let utxo_id = utxo_id.into();
let balance_root = balance_root.into();
let state_root = state_root.into();
let contract_id = contract_id.into();
Expand Down
181 changes: 0 additions & 181 deletions src/transaction/types/utxo_id.rs

This file was deleted.

4 changes: 2 additions & 2 deletions tests/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ fn tx_offset() {

let ofs = input_ofs + i.repr().utxo_id_offset().expect("input have utxo_id");
let utxo_id_p =
UtxoId::from_bytes(&bytes[ofs..]).expect("failed to deserialize utxo id");
unsafe { UtxoId::as_ref_unchecked(&bytes[ofs..ofs + UtxoId::LEN]) };

assert_eq!(utxo_id, &utxo_id_p);
assert_eq!(utxo_id, utxo_id_p);
}

if let Some(owner) = i.input_owner() {
Expand Down