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
crate::ix!();

pub struct BlockIndexWorkComparator { }

impl BlockIndexWorkComparator {

    pub fn invoke(&self, 
        pa: *const BlockIndex,
        pb: *const BlockIndex) -> bool {
        
        unsafe {

            //  First sort by most total work, ...
            if (*pa).n_chain_work > (*pb).n_chain_work {
                return false;
            }

            if (*pa).n_chain_work < (*pb).n_chain_work {
                return true;
            }

            //  ... then by earliest time received, ...
            if (*pa).n_sequence_id < (*pb).n_sequence_id {
                return false;
            }

            if (*pa).n_sequence_id > (*pb).n_sequence_id {
                return true;
            }

            // Use pointer address as tie breaker
            // (should only happen with blocks loaded
            // from disk, as those all have id 0).
            if pa < pb {
                return false;
            }

            if pa > pb {
                return true;
            }
        }

        // Identical blocks.
        false
    }
}