Transaction

Struct Transaction 

Source
pub struct Transaction { /* private fields */ }

Implementations§

Source§

impl Transaction

Source

pub fn match_output(&self, criteria: &MatchCriteria) -> Option<usize>

Returns the first output index that matches the given parameters, returns None or null if not found.

Source

pub fn match_outputs(&self, criteria: &MatchCriteria) -> Vec<usize>

Returns a list of outputs indexes that match the given parameters

Source

pub fn match_input(&self, criteria: &MatchCriteria) -> Option<usize>

Returns the first input index that matches the given parameters, returns None or null if not found.

Source

pub fn match_inputs(&self, criteria: &MatchCriteria) -> Vec<usize>

Returns a list of input indexes that match the given parameters

Source§

impl Transaction

Source

pub fn hash_inputs(&mut self, sighash: SigHash) -> Vec<u8>

(hashPrevouts) https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/replay-protected-sighash.md Checks the hash cache to see if there already are hashed inputs, otherwise calculates the hash and adds it to the cache.

Logic:

  • If SigHash does not contain ANYONECANPAY, SHA256d all input outpoints
  • Else 32 bytes of zeroes
Source§

impl Transaction

Source

pub fn verify(&self, pub_key: &PublicKey, sig: &SighashSignature) -> bool

Source§

impl Transaction

Source

pub fn sign( &mut self, priv_key: &PrivateKey, sighash: SigHash, n_tx_in: usize, unsigned_script: &Script, value: u64, ) -> Result<SighashSignature, BSVErrors>

Source

pub fn sign_with_k( &mut self, priv_key: &PrivateKey, ephemeral_key: &PrivateKey, sighash: SigHash, n_tx_in: usize, unsigned_script: &Script, value: u64, ) -> Result<SighashSignature, BSVErrors>

Source

pub fn sighash_preimage( &mut self, sighash: SigHash, n_tx_in: usize, unsigned_script: &Script, value: u64, ) -> Result<Vec<u8>, BSVErrors>

Source§

impl Transaction

Platform Agnostic Functions ie. Don’t need Result<T, E>

Source

pub fn get_version(&self) -> u32

Source

pub fn get_ninputs(&self) -> usize

Source

pub fn get_noutputs(&self) -> usize

Source

pub fn get_input(&self, index: usize) -> Option<TxIn>

Source

pub fn get_output(&self, index: usize) -> Option<TxOut>

Source

pub fn get_n_locktime(&self) -> u32

Source

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

Source

pub fn new(version: u32, n_locktime: u32) -> Transaction

Creates a new empty transaction where you need to add inputs and outputs Transaction.add_input(TxIn) and Transaction.add_output(TxOut)

Source

pub fn default() -> Transaction

Source

pub fn set_version(&mut self, version: u32) -> Transaction

Source

pub fn set_nlocktime(&mut self, n_locktime: u32) -> Transaction

Source

pub fn add_input(&mut self, input: &TxIn)

Source

pub fn prepend_input(&mut self, input: &TxIn)

Source

pub fn insert_input(&mut self, index: usize, input: &TxIn)

Source

pub fn add_output(&mut self, output: &TxOut)

Source

pub fn prepend_output(&mut self, output: &TxOut)

Source

pub fn insert_output(&mut self, index: usize, output: &TxOut)

Source

pub fn set_input(&mut self, index: usize, input: &TxIn)

Source

pub fn set_output(&mut self, index: usize, output: &TxOut)

Source

pub fn is_coinbase_impl(&self) -> bool

Source

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

XT Method: Returns the combined sum of all input satoshis. If any of the inputs dont have satoshis defined, this returns None or null

Source

pub fn satoshis_out(&self) -> u64

Returns the combined sum of all output satoshis.

Source§

impl Transaction

Native Specific Functions

Source

pub fn get_id_hex(&self) -> Result<String, BSVErrors>

Gets the ID of the current transaction as a hex string.

Source

pub fn get_id_bytes(&self) -> Result<Vec<u8>, BSVErrors>

Gets the ID of the current transaction as a Vec.

Source

pub fn get_size(&self) -> Result<usize, BSVErrors>

Get size of current serialised Transaction object

Source

pub fn from_hex(hex_str: &str) -> Result<Transaction, BSVErrors>

Source

pub fn from_bytes(tx_bytes: &[u8]) -> Result<Transaction, BSVErrors>

Source

pub fn to_json_string(&self) -> Result<String, BSVErrors>

Source

pub fn from_json_string(json_string: &str) -> Result<Transaction, BSVErrors>

Source

pub fn to_json(&self) -> Result<Value, BSVErrors>

Source

pub fn to_bytes(&self) -> Result<Vec<u8>, BSVErrors>

Source

pub fn to_hex(&self) -> Result<String, BSVErrors>

Source

pub fn to_compact_hex(&self) -> Result<String, BSVErrors>

Source

pub fn add_inputs(&mut self, tx_ins: Vec<TxIn>)

Source

pub fn add_outputs(&mut self, tx_outs: Vec<TxOut>)

Source

pub fn get_outpoints(&mut self) -> Vec<Vec<u8>>

Source

pub fn to_compact_bytes(&self) -> Result<Vec<u8>, BSVErrors>

Serialises this entire transaction to CBOR, preserving all fields from the standard Transaction format + XT

Source

pub fn from_compact_bytes(compact_buffer: &[u8]) -> Result<Self, BSVErrors>

Deserialises the provided CBOR buffer to the XT format

Source

pub fn from_compact_hex(compact_hex: &str) -> Result<Self, BSVErrors>

Source

pub fn is_coinbase(&self) -> bool

Trait Implementations§

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 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 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 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 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> 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> 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> Same for T

Source§

type Output = T

Should always be Self
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, 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.
Source§

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