Struct grin_core::core::transaction::Transaction

source ·
pub struct Transaction {
    pub offset: BlindingFactor,
    pub body: TransactionBody,
}
Expand description

A transaction

Fields§

§offset: BlindingFactor

The kernel “offset” k2 excess is k1G after splitting the key k = k1 + k2

§body: TransactionBody

The transaction body - inputs/outputs/kernels

Implementations§

source§

impl Transaction

source

pub fn empty() -> Transaction

Creates a new empty transaction (no inputs or outputs, zero fee).

source

pub fn new( inputs: Inputs, outputs: &[Output], kernels: &[TxKernel] ) -> Transaction

Creates a new transaction initialized with the provided inputs, outputs, kernels

source

pub fn with_offset(self, offset: BlindingFactor) -> Transaction

Creates a new transaction using this transaction as a template and with the specified offset.

source

pub fn with_input(self, input: Input) -> Transaction

Builds a new transaction with the provided inputs added. Existing inputs, if any, are kept intact. Sort order is maintained.

source

pub fn with_output(self, output: Output) -> Transaction

Builds a new transaction with the provided output added. Existing outputs, if any, are kept intact. Sort order is maintained.

source

pub fn with_kernel(self, kernel: TxKernel) -> Transaction

Builds a new transaction with the provided kernel added. Existing kernels, if any, are kept intact. Sort order is maintained.

source

pub fn replace_kernel(self, kernel: TxKernel) -> Transaction

Builds a new transaction replacing any existing kernels with the provided kernel.

source

pub fn inputs(&self) -> Inputs

Get inputs

source

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

Get outputs

source

pub fn kernels(&self) -> &[TxKernel]

Get kernels

source

pub fn fee(&self) -> u64

Total fee for a transaction is the sum of fees of all kernels.

source

pub fn shifted_fee(&self) -> u64

Shifted fee for a transaction is the sum of fees of all kernels shifted right by the maximum fee shift

source

pub fn aggregate_fee_fields(&self) -> Result<FeeFields, Error>

aggregate fee_fields from all appropriate kernels in transaction into one

source

pub fn overage(&self) -> i64

Total overage across all kernels.

source

pub fn lock_height(&self) -> u64

Lock height of a transaction is the max lock height of the kernels.

source

pub fn validate_read(&self) -> Result<(), Error>

“Lightweight” validation that we can perform quickly during read/deserialization. Subset of full validation that skips expensive verification steps, specifically -

  • rangeproof verification (on the body)
  • kernel signature verification (on the body)
  • kernel sum verification
source

pub fn validate(&self, weighting: Weighting) -> Result<(), Error>

Validates all relevant parts of a fully built transaction. Checks the excess value against the signature as well as range proofs for each output.

source

pub fn fee_rate(&self) -> u64

Can be used to compare txs by their fee/weight ratio, aka feerate. Don’t use these values for anything else though due to precision multiplier.

source

pub fn weight(&self) -> u64

Calculate transaction weight

source

pub fn accept_fee(&self) -> u64

Transaction minimum acceptable fee

source

pub fn old_weight_by_iok( num_inputs: u64, num_outputs: u64, num_kernels: u64 ) -> u64

Old weight definition for pool acceptance

source

pub fn weight_by_iok(num_inputs: u64, num_outputs: u64, num_kernels: u64) -> u64

Calculate transaction weight from transaction details

Trait Implementations§

source§

impl Clone for Transaction

source§

fn clone(&self) -> Transaction

Returns a copy 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 Committed for Transaction

source§

fn inputs_committed(&self) -> Vec<Commitment>

Vector of input commitments to verify.
source§

fn outputs_committed(&self) -> Vec<Commitment>

Vector of output commitments to verify.
source§

fn kernels_committed(&self) -> Vec<Commitment>

Vector of kernel excesses to verify.
source§

fn sum_kernel_excesses( &self, offset: &BlindingFactor ) -> Result<(Commitment, Commitment), Error>

Gather the kernel excesses and sum them.
source§

fn sum_commitments(&self, overage: i64) -> Result<Commitment, Error>

Gathers commitments and sum them.
source§

fn verify_kernel_sums( &self, overage: i64, kernel_offset: BlindingFactor ) -> Result<(Commitment, Commitment), Error>

Verify the sum of the kernel excesses equals the sum of the outputs, taking into account both the kernel_offset and overage.
source§

impl Debug for Transaction

source§

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

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

impl Default for Transaction

source§

fn default() -> Transaction

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Transaction

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Transaction> for TransactionBody

source§

fn from(tx: Transaction) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Transaction

PartialEq

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Readable for Transaction

Implementation of Readable for a transaction, defines how to read a full transaction from a binary stream.

source§

fn read<R: Reader>(reader: &mut R) -> Result<Transaction, Error>

Reads the data necessary to this Readable from the provided reader
source§

impl Serialize for Transaction

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Writeable for Transaction

Implementation of Writeable for a fully blinded transaction, defines how to write the transaction as binary.

source§

fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error>

Write the data held by this Writeable to the provided writer
source§

impl DefaultHashable 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> 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> CloneAny for T
where T: Any + Clone,

source§

fn clone_any(&self) -> Box<dyn CloneAny>

source§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>
where T: Send,

source§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>
where T: Sync,

source§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Send + Sync>
where T: Send + Sync,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<D> Hashed for D
where D: DefaultHashable,

source§

fn hash(&self) -> Hash

Obtain the hash of the object
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> PMMRIndexHashable for T
where T: DefaultHashable,

source§

fn hash_with_index(&self, index: u64) -> Hash

Hash with a given index
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<H> ShortIdentifiable for H
where H: Hashed,

source§

fn short_id(&self, hash: &Hash, nonce: u64) -> ShortId

Generate a short_id via the following -

  • extract k0/k1 from block_hash hashed with the nonce (first two u64 values) * initialize a siphasher24 with k0/k1
    • self.hash() passing in the siphasher24 instance
    • drop the 2 most significant bytes (to return a 6 byte short_id)
source§

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

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<T> DebugAny for T
where T: Any + Debug,

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> UnsafeAny for T
where T: Any,