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,
tx_difficulty: &[u8; 32],
difficulty_margin: Option<f64>,
) -> Result<(), EncodeError>
pub fn compute_pow( &mut self, 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: 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 Difficulty margin can be used to prevent the behavior mentioned above, however it will lead to a longer compute time. The bugger difficulty margin is, the more likely is the transaction to be valid next block. Difficulty margin is a multiplier by how much harder does the actual difficulty need to be
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
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