Skip to content

Commit 4aff4a8

Browse files
committed
[WIP] Wallet set up
1 parent 9692a2a commit 4aff4a8

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

src/blockchain/pruned_rpc.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,69 @@ impl GetHeight for PrunedRpcBlockchain {
117117
impl WalletSync for PrunedRpcBlockchain {
118118
fn wallet_setup<D: BatchDatabase>(
119119
&self,
120-
database: &mut D,
121-
progress_update: Box<dyn Progress>,
120+
_database: &mut D,
121+
_progress_update: Box<dyn Progress>,
122122
) -> 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+
123177
todo!()
124178
}
125179

126180
fn wallet_sync<D: BatchDatabase>(
127181
&self,
128-
db: &mut D,
182+
_db: &mut D,
129183
_progress_update: Box<dyn Progress>,
130184
) -> Result<(), Error> {
131185
todo!()

0 commit comments

Comments
 (0)