@@ -24,6 +24,7 @@ use zcash_primitives::{
24
24
TxId ,
25
25
} ,
26
26
} ;
27
+
27
28
use zingo_status:: confirmation_status:: ConfirmationStatus ;
28
29
29
30
use crate :: {
@@ -38,19 +39,18 @@ pub type Locator = (BlockHeight, TxId);
38
39
/// Initial sync state.
39
40
///
40
41
/// All fields will be reset when a new sync session starts.
41
- #[ derive( Debug , Clone , CopyGetters , Setters ) ]
42
- #[ getset( get_copy = "pub" , set = "pub" ) ]
42
+ #[ derive( Debug , Clone ) ]
43
43
pub struct InitialSyncState {
44
44
/// One block above the fully scanned wallet height at start of sync session.
45
- sync_start_height : BlockHeight ,
45
+ pub ( crate ) sync_start_height : BlockHeight ,
46
46
/// The tree sizes of the fully scanned height and chain tip at start of sync session.
47
- sync_tree_boundaries : TreeBoundaries ,
47
+ pub ( crate ) sync_tree_boundaries : TreeBoundaries ,
48
48
/// Total number of blocks to scan.
49
- total_blocks_to_scan : u32 ,
49
+ pub ( crate ) total_blocks_to_scan : u32 ,
50
50
/// Total number of sapling outputs to scan.
51
- total_sapling_outputs_to_scan : u32 ,
51
+ pub ( crate ) total_sapling_outputs_to_scan : u32 ,
52
52
/// Total number of orchard outputs to scan.
53
- total_orchard_outputs_to_scan : u32 ,
53
+ pub ( crate ) total_orchard_outputs_to_scan : u32 ,
54
54
}
55
55
56
56
impl InitialSyncState {
@@ -78,26 +78,25 @@ impl Default for InitialSyncState {
78
78
}
79
79
80
80
/// Encapsulates the current state of sync
81
- #[ derive( Debug , Clone , Getters , MutGetters , CopyGetters , Setters ) ]
82
- #[ getset( get = "pub" , get_mut = "pub" ) ]
81
+ #[ derive( Debug , Clone ) ]
83
82
pub struct SyncState {
84
83
/// A vec of block ranges with scan priorities from wallet birthday to chain tip.
85
84
/// In block height order with no overlaps or gaps.
86
- scan_ranges : Vec < ScanRange > ,
85
+ pub ( crate ) scan_ranges : Vec < ScanRange > ,
87
86
/// The block ranges that contain all sapling outputs of complete sapling shards.
88
87
///
89
88
/// There is an edge case where a range may include two (or more) shards. However, this only occurs when the lower
90
89
/// shards are already scanned so will cause no issues when punching in the higher scan priorites.
91
- sapling_shard_ranges : Vec < Range < BlockHeight > > ,
90
+ pub ( crate ) sapling_shard_ranges : Vec < Range < BlockHeight > > ,
92
91
/// The block ranges that contain all orchard outputs of complete orchard shards.
93
92
///
94
93
/// There is an edge case where a range may include two (or more) shards. However, this only occurs when the lower
95
94
/// shards are already scanned so will cause no issues when punching in the higher scan priorites.
96
- orchard_shard_ranges : Vec < Range < BlockHeight > > ,
95
+ pub ( crate ) orchard_shard_ranges : Vec < Range < BlockHeight > > ,
97
96
/// Locators for relevant transactions to the wallet.
98
- locators : BTreeSet < Locator > ,
97
+ pub ( crate ) locators : BTreeSet < Locator > ,
99
98
/// Initial sync state.
100
- initial_sync_state : InitialSyncState ,
99
+ pub ( crate ) initial_sync_state : InitialSyncState ,
101
100
}
102
101
103
102
impl SyncState {
@@ -112,9 +111,13 @@ impl SyncState {
112
111
}
113
112
}
114
113
114
+ pub fn scan_ranges ( & self ) -> & [ ScanRange ] {
115
+ & self . scan_ranges
116
+ }
117
+
115
118
/// Returns true if all scan ranges are scanned.
116
119
pub ( crate ) fn scan_complete ( & self ) -> bool {
117
- self . scan_ranges ( )
120
+ self . scan_ranges
118
121
. iter ( )
119
122
. all ( |scan_range| scan_range. priority ( ) == ScanPriority :: Scanned )
120
123
}
@@ -124,13 +127,13 @@ impl SyncState {
124
127
/// Will panic if called before scan ranges are updated for the first time.
125
128
pub fn fully_scanned_height ( & self ) -> BlockHeight {
126
129
if let Some ( scan_range) = self
127
- . scan_ranges ( )
130
+ . scan_ranges
128
131
. iter ( )
129
132
. find ( |scan_range| scan_range. priority ( ) != ScanPriority :: Scanned )
130
133
{
131
134
scan_range. block_range ( ) . start - 1
132
135
} else {
133
- self . scan_ranges ( )
136
+ self . scan_ranges
134
137
. last ( )
135
138
. expect ( "scan ranges always non-empty" )
136
139
. block_range ( )
@@ -145,7 +148,7 @@ impl SyncState {
145
148
/// Will panic if called before scan ranges are updated for the first time.
146
149
pub fn highest_scanned_height ( & self ) -> BlockHeight {
147
150
if let Some ( last_scanned_range) = self
148
- . scan_ranges ( )
151
+ . scan_ranges
149
152
. iter ( )
150
153
. filter ( |scan_range| scan_range. priority ( ) == ScanPriority :: Scanned )
151
154
. last ( )
@@ -162,14 +165,14 @@ impl SyncState {
162
165
///
163
166
/// If the wallet birthday is below the sapling activation height, returns the sapling activation height instead.
164
167
pub fn wallet_birthday ( & self ) -> Option < BlockHeight > {
165
- self . scan_ranges ( )
168
+ self . scan_ranges
166
169
. first ( )
167
170
. map ( |range| range. block_range ( ) . start )
168
171
}
169
172
170
173
/// Returns the last known chain height to the wallet or `None` if `self.scan_ranges` is empty.
171
174
pub fn wallet_height ( & self ) -> Option < BlockHeight > {
172
- self . scan_ranges ( )
175
+ self . scan_ranges
173
176
. last ( )
174
177
. map ( |range| range. block_range ( ) . end - 1 )
175
178
}
0 commit comments