Transaction

Enum Transaction 

Source
pub enum Transaction {
    Phoenix(Transaction),
    Moonlight(Transaction),
}
Expand description

The transaction used by the transfer contract.

Variants§

§

Phoenix(Transaction)

A phoenix transaction.

§

Moonlight(Transaction)

A moonlight transaction.

Implementations§

Source§

impl Transaction

Source

pub fn phoenix<R: RngCore + CryptoRng, P: Prove>( rng: &mut R, sender_sk: &PhoenixSecretKey, refund_pk: &PhoenixPublicKey, receiver_pk: &PhoenixPublicKey, inputs: Vec<(Note, Opening<(), NOTES_TREE_DEPTH>)>, root: BlsScalar, transfer_value: u64, obfuscated_transaction: bool, deposit: u64, gas_limit: u64, gas_price: u64, chain_id: u8, data: Option<impl Into<TransactionData>>, prover: &P, ) -> Result<Self, Error>

Create a new phoenix transaction.

§Errors

The creation of a transaction is not possible and will error if:

  • one of the input-notes doesn’t belong to the sender_sk
  • the transaction input doesn’t cover the transaction costs
  • the inputs vector is either empty or larger than 4 elements
  • the inputs vector contains duplicate Notes
  • the Prove trait is implemented incorrectly
Source

pub fn moonlight( sender_sk: &AccountSecretKey, receiver: Option<AccountPublicKey>, value: u64, deposit: u64, gas_limit: u64, gas_price: u64, nonce: u64, chain_id: u8, data: Option<impl Into<TransactionData>>, ) -> Result<Self, Error>

Create a new moonlight transaction.

§Errors

The creation of a transaction is not possible and will error if:

  • the memo, if given, is too large
Source

pub fn moonlight_sender(&self) -> Option<&AccountPublicKey>

Return the sender of the account for Moonlight transactions.

Source

pub fn moonlight_receiver(&self) -> Option<&AccountPublicKey>

Get the receiver of the transaction for Moonlight transactions, if it exists.

§Returns
  • Some(&AccountPublicKey) if the transaction is a Moonlight transaction and the receiver is different from the sender.
  • None if the transaction is a Moonlight transaction and the receiver is the same as the sender.
  • None if the transaction is a Phoenix transaction.
Source

pub fn value(&self) -> Option<u64>

Return the value transferred in a Moonlight transaction.

Source

pub fn nullifiers(&self) -> &[BlsScalar]

Returns the nullifiers of the transaction, if the transaction is a moonlight transaction, the result will be empty.

Source

pub fn root(&self) -> Option<&BlsScalar>

Return the root of the UTXO tree for Phoenix transactions.

Source

pub fn outputs(&self) -> &[Note]

Return the UTXO outputs of the transaction.

Source

pub fn phoenix_sender(&self) -> Option<&Sender>

Returns the sender data for Phoenix transactions.

Source

pub fn deposit(&self) -> u64

Returns the deposit of the transaction.

Source

pub fn gas_limit(&self) -> u64

Returns the gas limit of the transaction.

Source

pub fn gas_price(&self) -> u64

Returns the gas price of the transaction.

Source

pub fn refund_address(&self) -> RefundAddress<'_>

Returns the refund-address of the transaction.

Source

pub fn call(&self) -> Option<&ContractCall>

Return the contract call data, if there is any.

Call data is present only when inter-contract calls happen.

§Returns
  • Some(&ContractCall) if the transaction invokes another call to a contract.
  • None if the transaction is an entrypoint call to a protocol contract without a second call attached to it.
Source

pub fn deploy(&self) -> Option<&ContractDeploy>

Return the contract deploy data, if there is any.

Source

pub fn memo(&self) -> Option<&[u8]>

Returns the memo used with the transaction, if any.

Source

pub fn blob(&self) -> Option<&Vec<BlobData>>

Returns the Blob used with the transaction, if any.

Source

pub fn blob_mut(&mut self) -> Option<&mut Vec<BlobData>>

Returns the Blob used with the transaction, if any.

Source

pub fn strip_blobs(&mut self) -> Option<Vec<([u8; 32], BlobSidecar)>>

Extracts and removes the blob sidecar from the transaction, if any, and returns it as a vector of tuples containing the blob hash and the corresponding blob sidecar.

This function mutably accesses the blob storage within the transaction, clears the stored data, and returns the extracted parts while preserving their hashes.

Returns None if there are no blobs present in the transaction.

Source

pub fn blob_to_memo(&self) -> Option<Self>

Creates a modified clone of this transaction if it contains a Blob, clones all fields except for the Blob, whose versioned hashes are set as Memo.

Returns none if the transaction is not a Blob transaction.

Source

pub fn strip_off_bytecode(&self) -> Option<Self>

Creates a modified clone of this transaction if it contains data for deployment, clones all fields except for the bytecode’ ‘bytes’ part. Returns none if the transaction is not a deployment transaction.

Source

pub fn to_var_bytes(&self) -> Vec<u8>

Serialize the transaction into a byte buffer.

Source

pub fn from_slice(buf: &[u8]) -> Result<Self, BytesError>

Deserialize the transaction from a byte slice.

§Errors

Errors when the bytes are not canonical.

Source

pub fn to_hash_input_bytes(&self) -> Vec<u8>

Return input bytes to hash the transaction.

Note: The result of this function is only meant to be used as an input for hashing and cannot be used to deserialize the transaction again.

Source

pub fn hash(&self) -> BlsScalar

Create the unique transaction hash.

Source

pub fn deploy_charge( &self, gas_per_deploy_byte: u64, min_deploy_points: u64, ) -> u64

Returns the charge for a contract deployment. The deployment of a contract will cost at least min_deploy_points. If the transaction is not a deploy-transaction, the deploy-charge will be 0.

Source

pub fn blob_charge(&self, gas_per_blob: u64) -> Option<u64>

Returns the minimum gas charged for a blob transaction deployment. If the transaction is not a blob transaction, it returns None.

Source

pub fn deploy_check( &self, gas_per_deploy_byte: u64, min_deploy_gas_price: u64, min_deploy_points: u64, ) -> Result<(), TxPreconditionError>

Check if the transaction is a deployment transaction and if it meets the minimum requirements for gas price and gas limit.

§Errors

Returns an error if the transaction is a deployment transaction and the gas price is lower than the minimum required gas price or if the gas limit is lower than the required deployment charge.

Source

pub fn blob_check( &self, gas_per_blob: u64, ) -> Result<Option<u64>, TxPreconditionError>

Check if the transaction is a blob transaction and if it meets the minimum requirements for gas limit.

§Returns
  • Ok(Some(u64)) the minimum gas amount to charge if the transaction is a blob transaction.
  • Ok(None) if the transaction is not a blob transaction.
  • Err(TxPreconditionError) in case of an error.
§Errors

Returns an error if the transaction is a blob transaction and:

  • the gas limit is lower than the minimum charge.
  • the number of blobs is zero or greater than 6.

Trait Implementations§

Source§

impl Archive for Transaction

Source§

type Archived = ArchivedTransaction

The archived representation of this type. Read more
Source§

type Resolver = TransactionResolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

unsafe fn resolve( &self, pos: usize, resolver: <Self as Archive>::Resolver, out: *mut <Self as Archive>::Archived, )

Creates the archived version of this value at the given position and writes it to the given output. Read more
Source§

impl Clone for Transaction

Source§

fn clone(&self) -> Transaction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<__D: Fallible + ?Sized> Deserialize<Transaction, __D> for Archived<Transaction>

Source§

fn deserialize(&self, deserializer: &mut __D) -> Result<Transaction, __D::Error>

Deserializes using the given deserializer
Source§

impl From<Transaction> for Transaction

Source§

fn from(tx: PhoenixTransaction) -> Self

Converts to this type from the input type.
Source§

impl From<Transaction> for Transaction

Source§

fn from(tx: MoonlightTransaction) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Transaction

Source§

fn eq(&self, other: &Transaction) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<__S: Fallible + ?Sized> Serialize<__S> for Transaction

Source§

fn serialize( &self, serializer: &mut __S, ) -> Result<<Self as Archive>::Resolver, __S::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
Source§

impl Eq for Transaction

Source§

impl StructuralPartialEq for Transaction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> ArchiveUnsized for T
where T: Archive,

Source§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
Source§

type MetadataResolver = ()

The resolver for the metadata of this type. Read more
Source§

unsafe fn resolve_metadata( &self, _: usize, _: <T as ArchiveUnsized>::MetadataResolver, _: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata, )

Creates the archived version of the metadata for this value at the given position and writes it to the given output. Read more
Source§

unsafe fn resolve_unsized( &self, from: usize, to: usize, resolver: Self::MetadataResolver, out: *mut RelPtr<Self::Archived, <isize as Archive>::Archived>, )

Resolves a relative pointer to this value with the given from and to and writes it to the given output. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Serializer + ?Sized,

Source§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
Source§

fn serialize_metadata(&self, _: &mut S) -> Result<(), <S as Fallible>::Error>

Serializes the metadata for the given type.
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.