@@ -117,15 +117,69 @@ impl GetHeight for PrunedRpcBlockchain {
117
117
impl WalletSync for PrunedRpcBlockchain {
118
118
fn wallet_setup < D : BatchDatabase > (
119
119
& self ,
120
- database : & mut D ,
121
- progress_update : Box < dyn Progress > ,
120
+ _database : & mut D ,
121
+ _progress_update : Box < dyn Progress > ,
122
122
) -> Result < ( ) , Error > {
123
+ let mut script_pubkeys = database. iter_script_pubkeys ( Some ( KeychainKind :: External ) ) ?;
124
+ script_pubkeys. extend ( database. iter_script_pubkeys ( Some ( KeychainKind :: Internal ) ) ) ;
125
+
126
+ debug ! (
127
+ "importing {} script_pubkeys (some maybe aleady imported)" ,
128
+ script_pubkeys. len( )
129
+ ) ;
130
+
131
+ if self . is_descriptors {
132
+ let requests = Value :: Array (
133
+ script_pubkeys
134
+ . iter ( )
135
+ . map ( |s| {
136
+ let desc = format ! ( "raw({})" , s. to_hex) ;
137
+ jsom ! ( {
138
+ "timestamp" : "now" ,
139
+ "desc" : format!( "{}#{}" , desc, get_checksum( & desc) . unwrap( ) ) ,
140
+ } )
141
+ } )
142
+ . collect ( ) ,
143
+ ) ;
144
+ let res: Vec < Value > = self . client . call ( "importdescriptors" , & [ requests] ) ?;
145
+ res. into_iter ( )
146
+ . map ( |v| match v[ "success" ] . as_bool ( ) {
147
+ Some ( true ) => Ok ( ( ) ) ,
148
+ Some ( false ) => Err ( Error :: Generic (
149
+ v[ "error" ] [ "message" ]
150
+ . as_str ( )
151
+ . unwrap_or ( "Unknown error" )
152
+ . to_string ( ) ,
153
+ ) ) ,
154
+ _ => Err ( Error :: Generic ( "Unexpected response from Core" . to_string ( ) ) ) ,
155
+ } )
156
+ . collect :: < Result < Vec < _ > , _ > > ( ) ?;
157
+ } else {
158
+ let requests: Vec < _ > = script_pubkeys
159
+ . iter ( )
160
+ . map ( |s| ImportMultiRequest {
161
+ timestamp : ImportMultiRescanSince :: Timestamp ( 0 ) ,
162
+ script_pubkeys : Some ( ImportMultiRequestScriptPubkey :: Script ( s) ) ,
163
+ watchonly : Some ( true ) ,
164
+ ..Default :: default ( )
165
+ } )
166
+ . collect ( ) ;
167
+ let options = ImportMultiOptions {
168
+ rescan : Some ( false ) ,
169
+ } ;
170
+ self . client . import_multi ( & requests, Some ( & options) ) ?;
171
+ }
172
+
173
+ // make a request using scantxout and loop through it here
174
+ // the scan needs to have all the descriptors in it
175
+ // see how to make sure you're scanning the minimum possible set
176
+
123
177
todo ! ( )
124
178
}
125
179
126
180
fn wallet_sync < D : BatchDatabase > (
127
181
& self ,
128
- db : & mut D ,
182
+ _db : & mut D ,
129
183
_progress_update : Box < dyn Progress > ,
130
184
) -> Result < ( ) , Error > {
131
185
todo ! ( )
0 commit comments