1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::fragment::FragmentId;
use crate::value::*;

pub type TransactionIndex = u8;

/// Unspent transaction pointer.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct UtxoPointer {
    /// the transaction identifier where the unspent output is
    pub transaction_id: FragmentId,
    /// the output index within the pointed transaction's outputs
    pub output_index: TransactionIndex,
    /// the value we expect to read from this output
    ///
    /// This setting is added in order to protect undesired withdrawal
    /// and to set the actual fee in the transaction.
    pub value: Value,
}

impl UtxoPointer {
    pub fn new(transaction_id: FragmentId, output_index: TransactionIndex, value: Value) -> Self {
        UtxoPointer {
            transaction_id,
            output_index,
            value,
        }
    }
}

impl std::fmt::Display for UtxoPointer {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(
            f,
            "{}@{}.{}",
            self.transaction_id, self.output_index, self.value
        )
    }
}