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
impl Transaction
Sourcepub fn is_coinbase(&self) -> bool
pub fn is_coinbase(&self) -> bool
Coinbase: no transparent inputs, no shielded bundle, and no (the other input-less transaction kind).
Sourcepub fn shielded_in(&self) -> Option<u64>
pub fn shielded_in(&self) -> Option<u64>
Total value entering from the shielded pool.
Sourcepub fn shielded_out(&self) -> Option<u64>
pub fn shielded_out(&self) -> Option<u64>
Total value leaving into the shielded pool.
Sourcepub fn transfer_fees(&self) -> Option<u64>
pub fn transfer_fees(&self) -> Option<u64>
Fees paid by hidden-amount transfers (their only public value flow).
Sourcepub fn nullifiers(&self) -> Vec<Hash32>
pub fn nullifiers(&self) -> Vec<Hash32>
All nullifiers this transaction reveals.
Sourcepub fn encode(&self, for_sighash: bool) -> Vec<u8> ⓘ
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.
Sourcepub fn txid(&self) -> Hash32
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}Sourcepub fn sighash(&self) -> Hash32
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}pub fn total_output(&self) -> Option<u64>
Sourcepub fn serialized_size(&self) -> usize
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}Sourcepub fn coinbase(
height: u64,
recipient: Address,
amount: u64,
tag: &[u8],
) -> Self
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
impl Clone for Transaction
Source§impl Debug for Transaction
impl Debug for Transaction
Source§impl<'de> Deserialize<'de> for Transaction
impl<'de> Deserialize<'de> for Transaction
Source§fn 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>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Transaction
Source§impl PartialEq for Transaction
impl PartialEq for Transaction
Source§impl Serialize for Transaction
impl Serialize for Transaction
impl StructuralPartialEq for Transaction
Auto Trait Implementations§
impl Forget for Transaction
impl Freeze for Transaction
impl Move for Transaction
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnsafeUnpin for Transaction
impl UnwindSafe for Transaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more