@@ -312,6 +312,49 @@ impl std::error::Error for ApplyBlockError {}
312
312
/// A `CanonicalTx` managed by a `Wallet`.
313
313
pub type WalletTx < ' a > = CanonicalTx < ' a , Arc < Transaction > , ConfirmationBlockTime > ;
314
314
315
+ impl < K > Wallet < K >
316
+ where
317
+ K : Clone + fmt:: Debug + Ord ,
318
+ {
319
+ /// Construct a new [`Wallet`] with the given `keyring`.
320
+ ///
321
+ /// Note: The network must be either the mainnet or one of the test networks. Also default value
322
+ /// of lookahead is used with no spk_cache.
323
+ pub fn new ( mut keyring : KeyRing < K > ) -> Self {
324
+ let network = keyring. network ;
325
+
326
+ let genesis_hash = bitcoin:: constants:: genesis_block ( network) . block_hash ( ) ;
327
+ let ( chain, chain_changeset) = LocalChain :: from_genesis_hash ( genesis_hash) ;
328
+
329
+ let keyring_changeset = keyring. initial_changeset ( ) ;
330
+
331
+ let mut index = KeychainTxOutIndex :: new ( DEFAULT_LOOKAHEAD , false ) ;
332
+ let descriptors = core:: mem:: take ( & mut keyring. descriptors ) ;
333
+ for ( keychain, desc) in descriptors {
334
+ let _inserted = index
335
+ . insert_descriptor ( keychain, desc)
336
+ . expect ( "err: failed to insert descriptor" ) ;
337
+ assert ! ( _inserted) ;
338
+ }
339
+
340
+ let tx_graph = KeychainTxGraph :: new ( index) ;
341
+
342
+ let stage = ChangeSet {
343
+ keyring : keyring_changeset,
344
+ local_chain : chain_changeset,
345
+ tx_graph : bdk_chain:: tx_graph:: ChangeSet :: default ( ) ,
346
+ indexer : bdk_chain:: keychain_txout:: ChangeSet :: default ( ) ,
347
+ } ;
348
+
349
+ Self {
350
+ keyring,
351
+ chain,
352
+ tx_graph,
353
+ stage,
354
+ }
355
+ }
356
+ }
357
+
315
358
// impl Wallet {
316
359
// /// Build a new single descriptor [`Wallet`].
317
360
// ///
0 commit comments