File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -74,3 +74,6 @@ name = "esplora_blocking"
7474
7575[[example ]]
7676name  = " bitcoind_rpc" 
77+ 
78+ [[example ]]
79+ name  = " simple_keyring" 
Original file line number Diff line number Diff line change 1+ #![ allow( dead_code) ]  
2+ 
3+ use  bitcoin:: secp256k1:: Secp256k1 ; 
4+ use  miniscript:: { Descriptor ,  DescriptorPublicKey } ; 
5+ 
6+ pub  const  DESCRIPTORS :  [ & str ;  8 ]  = [ 
7+     "pkh([21a559b8/44h/1h/0h]tpubDD2jQhEsAU9uU6Qec2M6k5ygyLS96cCa9iwpQrGAS7p6GRW7eVjCiy1WGwTxqCPiACg99A4vUCZWs5w3xgHgTohxYu2z1ZzhLrLaFHG8at1/0/*)#8t439hyk" , 
8+     "pkh([21a559b8/44h/1h/0h]tpubDD2jQhEsAU9uU6Qec2M6k5ygyLS96cCa9iwpQrGAS7p6GRW7eVjCiy1WGwTxqCPiACg99A4vUCZWs5w3xgHgTohxYu2z1ZzhLrLaFHG8at1/1/*)#klsscz5w" , 
9+     "sh(wpkh([21a559b8/49h/1h/0h]tpubDCpBeRAYSsoF8LkbeSa1joNjNPMgTk8jttvydCXTxDwKHJsQab4pr6NeHn11fTKBjHE7NmHrUjEgH3mkQZrQ89qy9tLpZhpMc9w6NvkKkFL/0/*))#5adnu2fe" , 
10+     "sh(wpkh([21a559b8/49h/1h/0h]tpubDCpBeRAYSsoF8LkbeSa1joNjNPMgTk8jttvydCXTxDwKHJsQab4pr6NeHn11fTKBjHE7NmHrUjEgH3mkQZrQ89qy9tLpZhpMc9w6NvkKkFL/1/*))#pur9y4ux" , 
11+     "tr([21a559b8/86h/1h/0h]tpubDCdJ64usD8SEL17thc2K43vG4zHNMdgvnRWNvD3j2bEGCh2ER4KjJN3zhhD54AkBuc5k695JsgkTtdVaARepr2kNxv83zKP5Ra6CsUqoPuu/0/*)#2sd7vzr2" , 
12+     "tr([21a559b8/86h/1h/0h]tpubDCdJ64usD8SEL17thc2K43vG4zHNMdgvnRWNvD3j2bEGCh2ER4KjJN3zhhD54AkBuc5k695JsgkTtdVaARepr2kNxv83zKP5Ra6CsUqoPuu/1/*)#mygl3hnj" , 
13+     "wpkh([21a559b8/84h/1h/0h]tpubDCWfvMa9sCes3z6nxkF7ox5kc6gjddkkJJHTJKfnj96uRGXDWY9WbpNxupEYREV4kHij4JUBYzp9ziM7qhvsUjcisQHaSQgya39nDvuimkF/0/*)#7gmvfd4d" , 
14+     "wpkh([21a559b8/84h/1h/0h]tpubDCWfvMa9sCes3z6nxkF7ox5kc6gjddkkJJHTJKfnj96uRGXDWY9WbpNxupEYREV4kHij4JUBYzp9ziM7qhvsUjcisQHaSQgya39nDvuimkF/1/*)#0u7d5c94" 
15+ ] ; 
16+ 
17+ pub  fn  get_descriptor ( desc_str :  & str )  -> Descriptor < DescriptorPublicKey >  { 
18+     Descriptor :: parse_descriptor ( & Secp256k1 :: new ( ) ,  desc_str) 
19+         . unwrap ( ) 
20+         . 0 
21+ } 
Original file line number Diff line number Diff line change 1+ use  bdk_wallet:: keyring:: KeyRing ; 
2+ use  bdk_wallet:: { KeychainKind ,  Wallet } ; 
3+ use  bitcoin:: Network ; 
4+ 
5+ static  EXTERNAL_DESCRIPTOR :  & str  = "tr([5bc5d243/86'/1'/0']tpubDC72NVP1RK5qwy2QdEfWphDsUBAfBu7oiV6jEFooHP8tGQGFVUeFxhgZxuk1j6EQRJ1YsS3th2RyDgReRqCL4zqp4jtuV2z7gbiqDH2iyUS/0/*)" ; 
6+ static  INTERNAL_DESCRIPTOR :  & str  = "tr([5bc5d243/86'/1'/0']tpubDC72NVP1RK5qwy2QdEfWphDsUBAfBu7oiV6jEFooHP8tGQGFVUeFxhgZxuk1j6EQRJ1YsS3th2RyDgReRqCL4zqp4jtuV2z7gbiqDH2iyUS/1/*)" ; 
7+ 
8+ // Simple KeyRing, allowing us to build a standard 2-descriptor wallet with receive and change 
9+ // keychains. 
10+ 
11+ fn  main ( )  { 
12+     let  mut  keyring:  KeyRing < KeychainKind >  = KeyRing :: new ( 
13+         Network :: Regtest , 
14+         KeychainKind :: External , 
15+         EXTERNAL_DESCRIPTOR , 
16+     ) ; 
17+     keyring. add_descriptor ( KeychainKind :: Internal ,  INTERNAL_DESCRIPTOR ,  false ) ; 
18+ 
19+     let  mut  wallet = Wallet :: new ( keyring) ; 
20+     let  address = wallet. reveal_next_address ( KeychainKind :: External ) . unwrap ( ) ; 
21+     println ! ( "Address at index {}: {}" ,  address. index,  address. address) 
22+ } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments