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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
crate::ix!();

/**
  | A generic txid reference (txid or wtxid).
  |
  */
pub struct GenTxId {
    is_wtxid: bool,
    hash:     u256,
}

impl PartialEq<GenTxId> for GenTxId {
    
    #[inline] fn eq(&self, other: &GenTxId) -> bool {
        self.is_wtxid == other.is_wtxid 
            && self.hash == other.hash
    }
}

impl Eq for GenTxId {}

impl Ord for GenTxId {
    
    #[inline] fn cmp(&self, other: &GenTxId) -> Ordering {
        (&self.is_wtxid, &self.hash.blob).cmp(&(&other.is_wtxid, &other.hash.blob))
    }
}

impl PartialOrd<GenTxId> for GenTxId {
    #[inline] fn partial_cmp(&self, other: &GenTxId) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

//-------------------------------------------[.cpp/bitcoin/src/primitives/transaction.cpp]
impl GenTxId {

    pub fn new(
        is_wtxid: bool,
        hash:     &u256) -> Self {
    
        Self {
            is_wtxid: is_wtxid,
            hash:     hash.clone(),
        }
    }
    
    pub fn txid(hash: &u256) -> GenTxId {
        GenTxId::new(false, hash)
    }
    
    pub fn wtxid(hash: &u256) -> GenTxId {
        GenTxId::new(true, hash)
    }
    
    pub fn is_wtxid(&self) -> bool {
        self.is_wtxid
    }
    
    pub fn get_hash(&self) -> &u256 {
        &self.hash
    }
}