Create a new persisted wallet from given wallet configuration options.
(
network: Network,
persister: &mut P,
wallet_opts: &WalletOpts,
)
| 258 | #[cfg(any(feature = "sqlite", feature = "redb"))] |
| 259 | /// Create a new persisted wallet from given wallet configuration options. |
| 260 | pub(crate) fn new_persisted_wallet<P: WalletPersister>( |
| 261 | network: Network, |
| 262 | persister: &mut P, |
| 263 | wallet_opts: &WalletOpts, |
| 264 | ) -> Result<PersistedWallet<P>, Error> |
| 265 | where |
| 266 | P::Error: std::fmt::Display, |
| 267 | { |
| 268 | let ext_descriptor = wallet_opts.ext_descriptor.clone(); |
| 269 | let int_descriptor = wallet_opts.int_descriptor.clone(); |
| 270 | |
| 271 | let mut wallet_load_params = Wallet::load(); |
| 272 | wallet_load_params = |
| 273 | wallet_load_params.descriptor(KeychainKind::External, Some(ext_descriptor.clone())); |
| 274 | |
| 275 | if int_descriptor.is_some() { |
| 276 | wallet_load_params = |
| 277 | wallet_load_params.descriptor(KeychainKind::Internal, int_descriptor.clone()); |
| 278 | } |
| 279 | wallet_load_params = wallet_load_params.extract_keys(); |
| 280 | |
| 281 | let wallet_opt = wallet_load_params |
| 282 | .check_network(network) |
| 283 | .load_wallet(persister) |
| 284 | .map_err(|e| Error::Generic(e.to_string()))?; |
| 285 | |
| 286 | let wallet = match wallet_opt { |
| 287 | Some(wallet) => wallet, |
| 288 | None => match int_descriptor { |
| 289 | Some(int_descriptor) => Wallet::create(ext_descriptor, int_descriptor) |
| 290 | .network(network) |
| 291 | .create_wallet(persister) |
| 292 | .map_err(|e| Error::Generic(e.to_string()))?, |
| 293 | None => Wallet::create_single(ext_descriptor) |
| 294 | .network(network) |
| 295 | .create_wallet(persister) |
| 296 | .map_err(|e| Error::Generic(e.to_string()))?, |
| 297 | }, |
| 298 | }; |
| 299 | |
| 300 | Ok(wallet) |
| 301 | } |
| 302 | |
| 303 | #[cfg(not(any(feature = "sqlite", feature = "redb")))] |
| 304 | /// Create a new non-persisted wallet from given wallet configuration options. |