88use key_wallet:: account:: StandardAccountType ;
99use key_wallet:: wallet:: initialization:: WalletAccountCreationOptions ;
1010use key_wallet:: wallet:: managed_wallet_info:: transaction_building:: AccountTypePreference ;
11- use key_wallet:: wallet:: managed_wallet_info:: ManagedWalletInfo ;
1211use key_wallet:: { AccountType , Network } ;
13- use key_wallet_manager:: WalletInterface ;
14- use key_wallet_manager:: WalletManager ;
12+ use key_wallet_manager:: { ManagedWalletState , WalletInterface , WalletManager } ;
1513
16- fn main ( ) {
14+ #[ tokio:: main]
15+ async fn main ( ) {
1716 println ! ( "=== Wallet Creation Example ===\n " ) ;
1817
1918 // Example 1: Basic wallet creation with WalletManager
2019 println ! ( "1. Creating a basic wallet with WalletManager..." ) ;
2120
22- let mut manager = WalletManager :: < ManagedWalletInfo > :: new ( Network :: Testnet ) ;
21+ let mut manager = WalletManager :: < ManagedWalletState > :: new ( Network :: Testnet ) ;
2322
2423 let result = manager. create_wallet_with_random_mnemonic ( WalletAccountCreationOptions :: Default ) ;
2524
2625 let wallet_id = match result {
2726 Ok ( wallet_id) => {
28- println ! ( "✅ Wallet created successfully!" ) ;
27+ println ! ( "Wallet created successfully!" ) ;
2928 println ! ( " Wallet ID: {}" , hex:: encode( wallet_id) ) ;
3029 println ! ( " Total wallets: {}" , manager. wallet_count( ) ) ;
3130 wallet_id
3231 }
3332 Err ( e) => {
34- println ! ( "❌ Failed to create wallet: {:?}" , e) ;
33+ println ! ( "Failed to create wallet: {:?}" , e) ;
3534 return ;
3635 }
3736 } ;
@@ -50,12 +49,12 @@ fn main() {
5049
5150 let wallet_id2 = match result {
5251 Ok ( wallet_id2) => {
53- println ! ( "✅ Wallet created from mnemonic!" ) ;
52+ println ! ( "Wallet created from mnemonic!" ) ;
5453 println ! ( " Wallet ID: {}" , hex:: encode( wallet_id2) ) ;
5554 wallet_id2
5655 }
5756 Err ( e) => {
58- println ! ( "❌ Failed to create wallet from mnemonic: {:?}" , e) ;
57+ println ! ( "Failed to create wallet from mnemonic: {:?}" , e) ;
5958 return ;
6059 }
6160 } ;
@@ -64,26 +63,28 @@ fn main() {
6463 println ! ( "\n 3. Managing wallet accounts..." ) ;
6564
6665 // Add a new account to the first wallet
67- let account_result = manager. create_account (
68- & wallet_id, // Account index 1 (0 is created by default)
69- AccountType :: Standard {
70- index : 1 ,
71- standard_account_type : StandardAccountType :: BIP44Account ,
72- } ,
73- None ,
74- ) ;
66+ let account_result = manager
67+ . create_account (
68+ & wallet_id, // Account index 1 (0 is created by default)
69+ AccountType :: Standard {
70+ index : 1 ,
71+ standard_account_type : StandardAccountType :: BIP44Account ,
72+ } ,
73+ None ,
74+ )
75+ . await ;
7576
7677 match account_result {
7778 Ok ( _) => {
78- println ! ( "✅ Account created successfully!" ) ;
79+ println ! ( "Account created successfully!" ) ;
7980
8081 // Get all accounts
81- if let Ok ( accounts) = manager. get_accounts ( & wallet_id) {
82+ if let Ok ( accounts) = manager. get_accounts ( & wallet_id) . await {
8283 println ! ( " Total accounts: {}" , accounts. len( ) ) ;
8384 }
8485 }
8586 Err ( e) => {
86- println ! ( "❌ Failed to create account: {:?}" , e) ;
87+ println ! ( "Failed to create account: {:?}" , e) ;
8788 }
8889 }
8990
@@ -92,26 +93,28 @@ fn main() {
9293
9394 // Note: This might fail with InvalidNetwork error if the account collection
9495 // isn't properly initialized in the managed wallet info
95- let address_result = manager. get_receive_address (
96- & wallet_id,
97- 0 , // Account index
98- AccountTypePreference :: BIP44 ,
99- false , // Don't advance index
100- ) ;
96+ let address_result = manager
97+ . get_receive_address (
98+ & wallet_id,
99+ 0 , // Account index
100+ AccountTypePreference :: BIP44 ,
101+ false , // Don't advance index
102+ )
103+ . await ;
101104
102105 match address_result {
103106 Ok ( result) => {
104107 if let Some ( address) = result. address {
105- println ! ( "✅ Receive address: {}" , address) ;
108+ println ! ( "Receive address: {}" , address) ;
106109 if let Some ( account_type) = result. account_type_used {
107110 println ! ( " Account type used: {:?}" , account_type) ;
108111 }
109112 } else {
110- println ! ( "⚠️ No address generated" ) ;
113+ println ! ( "No address generated" ) ;
111114 }
112115 }
113116 Err ( e) => {
114- println ! ( "⚠️ Could not get address: {:?}" , e) ;
117+ println ! ( "Could not get address: {:?}" , e) ;
115118 println ! ( " (This is expected with the current implementation)" ) ;
116119 }
117120 }
@@ -125,8 +128,8 @@ fn main() {
125128 // Example 6: Getting wallet balance
126129 println ! ( "\n 6. Checking wallet balances..." ) ;
127130
128- for ( i, wallet_id ) in [ wallet_id, wallet_id2] . iter ( ) . enumerate ( ) {
129- match manager. get_wallet_balance ( wallet_id ) {
131+ for ( i, wid ) in [ wallet_id, wallet_id2] . iter ( ) . enumerate ( ) {
132+ match manager. get_wallet_balance ( wid ) . await {
130133 Ok ( balance) => {
131134 println ! ( " Wallet {}: {} satoshis" , i + 1 , balance. total( ) ) ;
132135 }
@@ -142,13 +145,13 @@ fn main() {
142145 // Example 7: Block height tracking
143146 println ! ( "\n 7. Block height tracking..." ) ;
144147
145- println ! ( " Current height (Testnet): {:?}" , manager . synced_height( ) ) ;
148+ println ! ( " Current height (Testnet): {:?}" , WalletInterface :: synced_height( & manager ) ) ;
146149
147150 // Update height
148- manager . update_synced_height ( 850_000 ) ;
149- println ! ( " Updated height to: {:?}" , manager . synced_height( ) ) ;
151+ WalletInterface :: update_synced_height ( & mut manager , 850_000 ) . await ;
152+ println ! ( " Updated height to: {:?}" , WalletInterface :: synced_height( & manager ) ) ;
150153
151154 println ! ( "\n === Summary ===" ) ;
152155 println ! ( "Total wallets created: {}" , manager. wallet_count( ) ) ;
153- println ! ( "✅ Example completed successfully!" ) ;
156+ println ! ( "Example completed successfully!" ) ;
154157}
0 commit comments