Struct themelio_structs::Transaction
source · [−]pub struct Transaction {
pub kind: TxKind,
pub inputs: Vec<CoinID>,
pub outputs: Vec<CoinData>,
pub fee: CoinValue,
pub covenants: Vec<Bytes>,
pub data: Bytes,
pub sigs: Vec<Bytes>,
}Expand description
Transaction represents an individual, serializable Themelio transaction.
Fields
kind: TxKindThe “kind” of the transaction. Most transactions are of kind TxKind::Normal.
inputs: Vec<CoinID>The coins that this transaction spends, identified by CoinID (transaction hash and index)
outputs: Vec<CoinData>The outputs that this transaction creates.
fee: CoinValueThe fee paid by this transaction, in MEL.
covenants: Vec<Bytes>The contents of the covenants locking the coins spent by this transaction. Themelio is uniformly “pay to script hash”, so coins (CoinDatas) themselves only contain the hash of the covenant locking the coin. The spending transaction must provide the actual covenants (in MelVM bytecode).
The ordering of this field does not matter. As long as there is some element in covenants corresponding to each unique covhash of the coins being spent, we’re good.
data: BytesArbitrary additional data of the transaction. Used mostly for unlocking covenants, as well as playing a special role in Melswap and Melmint transactions.
sigs: Vec<Bytes>A place to place cryptographically malleable data, usually signatures. The reason why we use this rather than data is because sigs is ignored when computing the unique hash of a transaction (see Transaction::hash_nosigs), which is important for checking whether a particular transaction went through while scanning the blockchain by transaction hash. (This is similar to the reason SegWit was included in Bitcoin)
Implementations
sourceimpl Transaction
impl Transaction
sourcepub fn new(kind: TxKind) -> Self
pub fn new(kind: TxKind) -> Self
Creates a new transaction with the given kind, no inputs, no outputs, no nothing.
sourcepub fn is_well_formed(&self) -> bool
pub fn is_well_formed(&self) -> bool
Checks whether or not the transaction is well formed, respecting coin size bounds and such. Does not fully validate the transaction.
sourcepub fn hash_nosigs(&self) -> TxHash
pub fn hash_nosigs(&self) -> TxHash
hash_nosigs returns the hash of the transaction with a zeroed-out signature field. This is what signatures are computed against.
sourcepub fn signed_ed25519(self, sk: Ed25519SK) -> Self
pub fn signed_ed25519(self, sk: Ed25519SK) -> Self
sign_ed25519 consumes the transaction, appends an ed25519 signature, and returns it.
sourcepub fn total_outputs(&self) -> HashMap<Denom, CoinValue>
pub fn total_outputs(&self) -> HashMap<Denom, CoinValue>
total_outputs returns a HashMap mapping each type of coin to its total value. Fees will be included in the Mel cointype.
sourcepub fn covenants_as_map(&self) -> HashMap<Address, Bytes>
pub fn covenants_as_map(&self) -> HashMap<Address, Bytes>
scripts_as_map returns a HashMap mapping the hash of each script in the transaction to the script itself.
sourcepub fn base_fee(
&self,
fee_multiplier: u128,
ballast: u128,
cov_to_weight: impl Fn(&[u8]) -> u128
) -> CoinValue
pub fn base_fee(
&self,
fee_multiplier: u128,
ballast: u128,
cov_to_weight: impl Fn(&[u8]) -> u128
) -> CoinValue
Returns the minimum fee of the transaction at a given fee multiplier, with a given “ballast”.
sourcepub fn weight(&self, cov_to_weight: impl Fn(&[u8]) -> u128) -> u128
pub fn weight(&self, cov_to_weight: impl Fn(&[u8]) -> u128) -> u128
Returns the weight of the transaction, given a function that maps a covenant to its weight.
sourcepub fn output_coinid(&self, index: u8) -> CoinID
pub fn output_coinid(&self, index: u8) -> CoinID
Convenience function that constructs a CoinID that points to a certain output of this transaction. Panics if the index is out of bounds.
Trait Implementations
sourceimpl Clone for Transaction
impl Clone for Transaction
sourcefn clone(&self) -> Transaction
fn clone(&self) -> Transaction
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresourceimpl Debug for Transaction
impl Debug for Transaction
sourceimpl Default for Transaction
impl Default for Transaction
sourcefn default() -> Transaction
fn default() -> Transaction
sourceimpl<'de> Deserialize<'de> for Transaction
impl<'de> Deserialize<'de> for Transaction
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
sourceimpl Hash for Transaction
impl Hash for Transaction
sourceimpl PartialEq<Transaction> for Transaction
impl PartialEq<Transaction> for Transaction
sourcefn eq(&self, other: &Transaction) -> bool
fn eq(&self, other: &Transaction) -> bool
sourceimpl Serialize for Transaction
impl Serialize for Transaction
impl Eq for Transaction
impl StructuralEq for Transaction
impl StructuralPartialEq for Transaction
Auto Trait Implementations
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnwindSafe for Transaction
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
sourceimpl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
sourcefn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
sourcefn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moresourcefn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moresourcefn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
sourcefn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
sourcefn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self, then passes self.as_ref() into the pipe function.sourcefn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
sourceimpl<T> StdcodeSerializeExt for Twhere
T: Serialize,
impl<T> StdcodeSerializeExt for Twhere
T: Serialize,
sourceimpl<T> Tap for T
impl<T> Tap for T
sourcefn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B> of a value. Read moresourcefn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B> of a value. Read moresourcefn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R> view of a value. Read moresourcefn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R> view of a value. Read moresourcefn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target of a value. Read moresourcefn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target of a value. Read moresourcefn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.sourcefn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds. Read moresourcefn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds. Read moresourcefn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds. Read moresourcefn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds. Read moresourcefn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds. Read more