Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction {
    pub version: u32,
    pub inputs: Vec<TxInput>,
    pub outputs: Vec<TxOutput>,
    pub coinbase_data: Vec<u8>,
    pub shielded: Option<ShieldedBundle>,
    pub contract: Option<ContractAction>,
}

Fields§

§version: u32§inputs: Vec<TxInput>

Empty for coinbase transactions.

§outputs: Vec<TxOutput>§coinbase_data: Vec<u8>

Coinbase-only payload (block height + arbitrary tag); makes coinbase txids unique. Must be empty for regular transactions.

§shielded: Option<ShieldedBundle>§contract: Option<ContractAction>

Optional Blockle VM deploy/call.

Implementations§

Source§

impl Transaction

Source

pub fn is_coinbase(&self) -> bool

Coinbase: no transparent inputs, no shielded bundle, and no (the other input-less transaction kind).

Source

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

Total value entering from the shielded pool.

Source

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

Total value leaving into the shielded pool.

Source

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

Fees paid by hidden-amount transfers (their only public value flow).

Source

pub fn nullifiers(&self) -> Vec<Hash32>

All nullifiers this transaction reveals.

Source

pub fn encode(&self, for_sighash: bool) -> Vec<u8> ⓘ

Canonical consensus encoding. With for_sighash set, signatures are replaced by empty strings so inputs can be signed.

Source

pub fn txid(&self) -> Hash32

Examples found in repository?
examples/golden_gen.rs (line 39)
4fn main() {
5    let tx = Transaction {
6        version: 1,
7        inputs: vec![TxInput {
8            prev: OutPoint { txid: [0x11; 32], vout: 3 },
9            pubkey: vec![0x22; 8],
10            signature: vec![0x33; 4],
11        }],
12        outputs: vec![TxOutput { recipient: [0x44; 32], amount: 123_456_789 }],
13        coinbase_data: vec![],
14        shielded: Some(ShieldedBundle {
15            spends: vec![ShieldedSpend {
16                anchor: [0x55; 32],
17                nullifier: [0x66; 32],
18                value: 42,
19                proof: vec![0x77; 5],
20            }],
21            outputs: vec![ShieldedOutput { commitment: [0x88; 32], value: 7 }],
22            transfers: vec![ShieldedTransfer {
23                anchor: [0x99; 32],
24                nullifier: [0xaa; 32],
25                commitment1: [0xbb; 32],
26                commitment2: [0xcc; 32],
27                fee: 9,
28                memo: vec![0xdd; 3],
29                proof: vec![0xee; 6],
30            }],
31        }),
32        contract: Some(ContractAction::Call {
33            contract: [0xff; 32],
34            input: vec![1, 2, 3],
35            value: 55,
36            gas_limit: 1000,
37        }),
38    };
39    println!("txid:    {}", hex::encode(tx.txid()));
40    println!("sighash: {}", hex::encode(tx.sighash()));
41    println!("size:    {}", tx.serialized_size());
42
43    let header = BlockHeader {
44        version: 1,
45        prev_hash: [0x01; 32],
46        merkle_root: [0x02; 32],
47        state_root: [0x00; 32],
48        time: 1_790_000_000,
49        bits: 0x207fffff,
50        nonce: [0x03; 32],
51        solution: vec![0x04; 36],
52    };
53    println!("header_ser_len: {}", header.serialize().len());
54    println!("header_hash: {}", hex::encode(header.hash()));
55    let cb = Transaction::coinbase(5, [0x09; 32], 50, b"Blockle");
56    println!("coinbase_txid: {}", hex::encode(cb.txid()));
57}
Source

pub fn sighash(&self) -> Hash32

The message each input signs: the transaction with signatures blanked.

Examples found in repository?
examples/golden_gen.rs (line 40)
4fn main() {
5    let tx = Transaction {
6        version: 1,
7        inputs: vec![TxInput {
8            prev: OutPoint { txid: [0x11; 32], vout: 3 },
9            pubkey: vec![0x22; 8],
10            signature: vec![0x33; 4],
11        }],
12        outputs: vec![TxOutput { recipient: [0x44; 32], amount: 123_456_789 }],
13        coinbase_data: vec![],
14        shielded: Some(ShieldedBundle {
15            spends: vec![ShieldedSpend {
16                anchor: [0x55; 32],
17                nullifier: [0x66; 32],
18                value: 42,
19                proof: vec![0x77; 5],
20            }],
21            outputs: vec![ShieldedOutput { commitment: [0x88; 32], value: 7 }],
22            transfers: vec![ShieldedTransfer {
23                anchor: [0x99; 32],
24                nullifier: [0xaa; 32],
25                commitment1: [0xbb; 32],
26                commitment2: [0xcc; 32],
27                fee: 9,
28                memo: vec![0xdd; 3],
29                proof: vec![0xee; 6],
30            }],
31        }),
32        contract: Some(ContractAction::Call {
33            contract: [0xff; 32],
34            input: vec![1, 2, 3],
35            value: 55,
36            gas_limit: 1000,
37        }),
38    };
39    println!("txid:    {}", hex::encode(tx.txid()));
40    println!("sighash: {}", hex::encode(tx.sighash()));
41    println!("size:    {}", tx.serialized_size());
42
43    let header = BlockHeader {
44        version: 1,
45        prev_hash: [0x01; 32],
46        merkle_root: [0x02; 32],
47        state_root: [0x00; 32],
48        time: 1_790_000_000,
49        bits: 0x207fffff,
50        nonce: [0x03; 32],
51        solution: vec![0x04; 36],
52    };
53    println!("header_ser_len: {}", header.serialize().len());
54    println!("header_hash: {}", hex::encode(header.hash()));
55    let cb = Transaction::coinbase(5, [0x09; 32], 50, b"Blockle");
56    println!("coinbase_txid: {}", hex::encode(cb.txid()));
57}
Source

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

Source

pub fn serialized_size(&self) -> usize

Examples found in repository?
examples/golden_gen.rs (line 41)
4fn main() {
5    let tx = Transaction {
6        version: 1,
7        inputs: vec![TxInput {
8            prev: OutPoint { txid: [0x11; 32], vout: 3 },
9            pubkey: vec![0x22; 8],
10            signature: vec![0x33; 4],
11        }],
12        outputs: vec![TxOutput { recipient: [0x44; 32], amount: 123_456_789 }],
13        coinbase_data: vec![],
14        shielded: Some(ShieldedBundle {
15            spends: vec![ShieldedSpend {
16                anchor: [0x55; 32],
17                nullifier: [0x66; 32],
18                value: 42,
19                proof: vec![0x77; 5],
20            }],
21            outputs: vec![ShieldedOutput { commitment: [0x88; 32], value: 7 }],
22            transfers: vec![ShieldedTransfer {
23                anchor: [0x99; 32],
24                nullifier: [0xaa; 32],
25                commitment1: [0xbb; 32],
26                commitment2: [0xcc; 32],
27                fee: 9,
28                memo: vec![0xdd; 3],
29                proof: vec![0xee; 6],
30            }],
31        }),
32        contract: Some(ContractAction::Call {
33            contract: [0xff; 32],
34            input: vec![1, 2, 3],
35            value: 55,
36            gas_limit: 1000,
37        }),
38    };
39    println!("txid:    {}", hex::encode(tx.txid()));
40    println!("sighash: {}", hex::encode(tx.sighash()));
41    println!("size:    {}", tx.serialized_size());
42
43    let header = BlockHeader {
44        version: 1,
45        prev_hash: [0x01; 32],
46        merkle_root: [0x02; 32],
47        state_root: [0x00; 32],
48        time: 1_790_000_000,
49        bits: 0x207fffff,
50        nonce: [0x03; 32],
51        solution: vec![0x04; 36],
52    };
53    println!("header_ser_len: {}", header.serialize().len());
54    println!("header_hash: {}", hex::encode(header.hash()));
55    let cb = Transaction::coinbase(5, [0x09; 32], 50, b"Blockle");
56    println!("coinbase_txid: {}", hex::encode(cb.txid()));
57}
Source

pub fn coinbase( height: u64, recipient: Address, amount: u64, tag: &[u8], ) -> Self

Build a coinbase transaction paying recipient at height.

Examples found in repository?
examples/golden_gen.rs (line 55)
4fn main() {
5    let tx = Transaction {
6        version: 1,
7        inputs: vec![TxInput {
8            prev: OutPoint { txid: [0x11; 32], vout: 3 },
9            pubkey: vec![0x22; 8],
10            signature: vec![0x33; 4],
11        }],
12        outputs: vec![TxOutput { recipient: [0x44; 32], amount: 123_456_789 }],
13        coinbase_data: vec![],
14        shielded: Some(ShieldedBundle {
15            spends: vec![ShieldedSpend {
16                anchor: [0x55; 32],
17                nullifier: [0x66; 32],
18                value: 42,
19                proof: vec![0x77; 5],
20            }],
21            outputs: vec![ShieldedOutput { commitment: [0x88; 32], value: 7 }],
22            transfers: vec![ShieldedTransfer {
23                anchor: [0x99; 32],
24                nullifier: [0xaa; 32],
25                commitment1: [0xbb; 32],
26                commitment2: [0xcc; 32],
27                fee: 9,
28                memo: vec![0xdd; 3],
29                proof: vec![0xee; 6],
30            }],
31        }),
32        contract: Some(ContractAction::Call {
33            contract: [0xff; 32],
34            input: vec![1, 2, 3],
35            value: 55,
36            gas_limit: 1000,
37        }),
38    };
39    println!("txid:    {}", hex::encode(tx.txid()));
40    println!("sighash: {}", hex::encode(tx.sighash()));
41    println!("size:    {}", tx.serialized_size());
42
43    let header = BlockHeader {
44        version: 1,
45        prev_hash: [0x01; 32],
46        merkle_root: [0x02; 32],
47        state_root: [0x00; 32],
48        time: 1_790_000_000,
49        bits: 0x207fffff,
50        nonce: [0x03; 32],
51        solution: vec![0x04; 36],
52    };
53    println!("header_ser_len: {}", header.serialize().len());
54    println!("header_hash: {}", hex::encode(header.hash()));
55    let cb = Transaction::coinbase(5, [0x09; 32], 50, b"Blockle");
56    println!("coinbase_txid: {}", hex::encode(cb.txid()));
57}

Trait Implementations§

Source§

impl Clone for Transaction

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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<'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 Eq for Transaction

Source§

impl PartialEq for Transaction

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.