pub struct Coin<Specification>where
Specification: CoinSpecification,{
pub utxo_id: UtxoId,
pub owner: Address,
pub amount: Word,
pub asset_id: AssetId,
pub tx_pointer: TxPointer,
pub witness_index: Specification::Witness,
pub maturity: BlockHeight,
pub predicate: Specification::Predicate,
pub predicate_data: Specification::PredicateData,
}
Expand description
It is a full representation of the coin from the specification: https://github.com/FuelLabs/fuel-specs/blob/master/src/protocol/tx_format/input.md#inputcoin.
The specification defines the layout of the Coin
in the serialized form for the fuel-vm
.
But on the business logic level, we don’t use all fields at the same time. It is why in the
super::Input
the coin is represented by several forms based on the usage context.
Leaving some fields empty reduces the memory consumption by the structure and erases the
empty useless fields.
The CoinSpecification
trait specifies the sub-coin for the corresponding usage context.
It allows us to write the common logic of all sub-coins without the overhead and duplication.
Sub-coin:
Signed
- means that the coin should be signed by theowner
, and the signature(witness) should be stored under thewitness_index
index in thewitnesses
vector of thecrate::Transaction
.Predicate
- means that the coin is not signed, and theowner
is apredicate
bytecode. The merkle root from thepredicate
should be equal to theowner
.Full
- is used during the deserialization of the coin. It should be transformed intoSigned
orPredicate
sub-coin. If thepredicate
is empty, it isSigned
, elsePredicate
.
Fields§
§utxo_id: UtxoId
§owner: Address
§amount: Word
§asset_id: AssetId
§tx_pointer: TxPointer
§witness_index: Specification::Witness
§maturity: BlockHeight
§predicate: Specification::Predicate
§predicate_data: Specification::PredicateData
Implementations§
source§impl<Specification> Coin<Specification>where
Specification: CoinSpecification,
impl<Specification> Coin<Specification>where Specification: CoinSpecification,
sourcepub fn prepare_sign(&mut self)
pub fn prepare_sign(&mut self)
The “Note” section from the specification: https://github.com/FuelLabs/fuel-specs/blob/master/src/protocol/tx_format/input.md#inputcoin.
Trait Implementations§
source§impl<Specification> Clone for Coin<Specification>where
Specification: CoinSpecification + Clone,
Specification::Witness: Clone,
Specification::Predicate: Clone,
Specification::PredicateData: Clone,
impl<Specification> Clone for Coin<Specification>where Specification: CoinSpecification + Clone, Specification::Witness: Clone, Specification::Predicate: Clone, Specification::PredicateData: Clone,
source§impl<Specification> Debug for Coin<Specification>where
Specification: CoinSpecification,
impl<Specification> Debug for Coin<Specification>where Specification: CoinSpecification,
source§impl<Specification> Default for Coin<Specification>where
Specification: CoinSpecification + Default,
Specification::Witness: Default,
Specification::Predicate: Default,
Specification::PredicateData: Default,
impl<Specification> Default for Coin<Specification>where Specification: CoinSpecification + Default, Specification::Witness: Default, Specification::Predicate: Default, Specification::PredicateData: Default,
source§impl<Specification> Hash for Coin<Specification>where
Specification: CoinSpecification + Hash,
Specification::Witness: Hash,
Specification::Predicate: Hash,
Specification::PredicateData: Hash,
impl<Specification> Hash for Coin<Specification>where Specification: CoinSpecification + Hash, Specification::Witness: Hash, Specification::Predicate: Hash, Specification::PredicateData: Hash,
source§impl<Specification> PartialEq<Coin<Specification>> for Coin<Specification>where
Specification: CoinSpecification + PartialEq,
Specification::Witness: PartialEq,
Specification::Predicate: PartialEq,
Specification::PredicateData: PartialEq,
impl<Specification> PartialEq<Coin<Specification>> for Coin<Specification>where Specification: CoinSpecification + PartialEq, Specification::Witness: PartialEq, Specification::Predicate: PartialEq, Specification::PredicateData: PartialEq,
source§impl<Specification> Read for Coin<Specification>where
Specification: CoinSpecification,
impl<Specification> Read for Coin<Specification>where Specification: CoinSpecification,
source§fn read(&mut self, full_buf: &mut [u8]) -> Result<usize>
fn read(&mut self, full_buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,
Read
. Read moresource§impl<Specification> SizedBytes for Coin<Specification>where
Specification: CoinSpecification,
impl<Specification> SizedBytes for Coin<Specification>where Specification: CoinSpecification,
source§fn serialized_size(&self) -> usize
fn serialized_size(&self) -> usize
source§impl<Specification> Write for Coin<Specification>where
Specification: CoinSpecification,
impl<Specification> Write for Coin<Specification>where Specification: CoinSpecification,
source§fn write(&mut self, full_buf: &[u8]) -> Result<usize>
fn write(&mut self, full_buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)