pub struct Transaction {
pub inputs: Vec<TransactionInput>,
pub outputs: Vec<TransactionOutput>,
pub transaction_id: Option<TransactionId>,
pub nonce: u64,
pub timestamp: u64,
}Expand description
A transaction containing transaction inputs (funding this transaction) and outputs (spending this transactions funds) The transaction id is a way of finding this transaction once it becomes part of this blockchain. It is also the transaction id that is the actual Hash of the transaction buffer obtained by get_tx_hashing_buf The timestamp is set by the sender, and only loosely validated The nonce is also set by the sender to allow the transaction to be mined (POW)
Fields§
§inputs: Vec<TransactionInput>§outputs: Vec<TransactionOutput>§transaction_id: Option<TransactionId>§nonce: u64§timestamp: u64Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn new_transaction_now(
inputs: Vec<TransactionInput>,
outputs: Vec<TransactionOutput>,
signing_keys: &mut Vec<Private>,
) -> Result<Self, EncodeError>
pub fn new_transaction_now( inputs: Vec<TransactionInput>, outputs: Vec<TransactionOutput>, signing_keys: &mut Vec<Private>, ) -> Result<Self, EncodeError>
Create a new transaction timestamped now with a set of inputs and outputs. Signed automatically with the signing_keys (in same order as transaction inputs) WARNING: The transaction still needs to be mined (POW)! compute_pow() must be called after
Sourcepub fn compute_pow(
&mut self,
live_tx_difficulty: &[u8; 32],
difficulty_margin: Option<f64>,
) -> Result<(), EncodeError>
pub fn compute_pow( &mut self, live_tx_difficulty: &[u8; 32], difficulty_margin: Option<f64>, ) -> Result<(), EncodeError>
Mine this transaction (aka. compute POW to allow it to be placed in the network) WARNING: You most likely want to supply this function with the LIVE transaction difficulty, which is adjusted for mempool difficulty pressure WARNING: This is single threaded and needs to complete before a new block is mined on the network as otherwise tx_difficulty becomes invalid, and so the transaction too. This effect can also be amplified, by mempool pressure, which might tell nodes to reject this transaction if the live transaction difficulty criteria is not met. Difficulty margin can be used to prevent the behavior mentioned above, however it will lead to a longer PoW compute time. Difficulty margin is a percentage [0 - 1), where 0 means no change to target difficulty, and 1 means difficulty is 0 (incomputable, ever). It is recommended, that users (if displayed) should be presented with a 0 - 50% logarithmically scaled slider.
Sourcepub fn get_input_signing_buf(&self) -> Result<Vec<u8>, EncodeError>
pub fn get_input_signing_buf(&self) -> Result<Vec<u8>, EncodeError>
Get the buffer that needs to be signed by each inputs private key
Sourcepub fn get_tx_hashing_buf(&self) -> Result<Vec<u8>, EncodeError>
pub fn get_tx_hashing_buf(&self) -> Result<Vec<u8>, EncodeError>
Get the buffer that needs to be hashed to compute the pow puzzle
pub fn check_completeness(&self) -> Result<(), TransactionError>
pub fn address_count(&self) -> usize
Sourcepub fn contains_address(&self, address: Public) -> bool
pub fn contains_address(&self, address: Public) -> bool
check if this tx contains a address
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for Transaction
impl<'__de, __Context> BorrowDecode<'__de, __Context> for Transaction
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Source§impl Clone for Transaction
impl Clone for Transaction
Source§fn clone(&self) -> Transaction
fn clone(&self) -> Transaction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more