11#![ allow( incomplete_features) ]
22
33mod config;
4- mod sled ;
4+ mod extractor ;
55mod routes;
6+ mod sled;
67
78use crate :: config:: Config ;
89use crate :: sled:: SledStorage ;
@@ -13,7 +14,7 @@ use bitcoin::bip32::ExtendedPrivKey;
1314use clap:: Parser ;
1415use log:: { debug, info} ;
1516use mutiny_core:: storage:: MutinyStorage ;
16- use mutiny_core:: { generate_seed, MutinyWalletBuilder , MutinyWalletConfig } ;
17+ use mutiny_core:: { generate_seed, MutinyWalletBuilder , MutinyWalletConfigBuilder } ;
1718use shutdown:: Shutdown ;
1819use std:: time:: Duration ;
1920
@@ -41,18 +42,22 @@ async fn main() -> anyhow::Result<()> {
4142 let seed = mnemonic. to_seed ( "" ) ;
4243 let xprivkey = ExtendedPrivKey :: new_master ( network, & seed) . unwrap ( ) ;
4344
44- let wallet_config = MutinyWalletConfig :: new (
45- xprivkey,
46- network,
47- config. esplora_url ,
48- config. rgs_url ,
49- config. lsp_url ,
50- ) ;
45+ let mut config_builder = MutinyWalletConfigBuilder :: new ( xprivkey) . with_network ( network) ;
46+ if let Some ( url) = config. esplora_url {
47+ config_builder. with_user_esplora_url ( url) ;
48+ }
49+ if let Some ( url) = config. rgs_url {
50+ config_builder. with_user_rgs_url ( url) ;
51+ }
52+ if let Some ( url) = config. lsp_url {
53+ config_builder. with_lsp_url ( url) ;
54+ }
55+ let wallet_config = config_builder. build ( ) ;
5156
5257 debug ! ( "Initializing wallet..." ) ;
53- let wallet = MutinyWalletBuilder :: new ( xprivkey, storage) . with_config ( wallet_config ) . build ( ) . await ? ;
54-
55- let listener = tokio :: net :: TcpListener :: bind ( format ! ( "{}:{}" , config . bind , config . port ) )
58+ let wallet = MutinyWalletBuilder :: new ( xprivkey, storage)
59+ . with_config ( wallet_config )
60+ . build ( )
5661 . await ?;
5762
5863 debug ! ( "Wallet initialized!" ) ;
@@ -61,17 +66,23 @@ async fn main() -> anyhow::Result<()> {
6166 mutiny_wallet : wallet. clone ( ) ,
6267 } ;
6368
64- let server_router = Router :: new ( )
65- . route ( "/newaddress" , get ( routes:: new_address) )
66- . route ( "/sendtoaddress" , post ( routes:: send_to_address) )
67- . route ( "/openchannel" , post ( routes:: open_channel) )
68- . route ( "/invoice" , post ( routes:: create_invoice) )
69- . route ( "/payinvoice" , post ( routes:: pay_invoice) )
70- . route ( "/balance" , get ( routes:: get_balance) )
71- . fallback ( fallback)
72- . layer ( Extension ( state. clone ( ) ) ) ;
69+ tokio:: spawn ( async move {
70+ let server_router = Router :: new ( )
71+ . route ( "/newaddress" , get ( routes:: new_address) )
72+ . route ( "/sendtoaddress" , post ( routes:: send_to_address) )
73+ . route ( "/openchannel" , post ( routes:: open_channel) )
74+ . route ( "/createinvoice" , post ( routes:: create_invoice) )
75+ . route ( "/payinvoice" , post ( routes:: pay_invoice) )
76+ . route ( "/balance" , get ( routes:: get_balance) )
77+ . fallback ( fallback)
78+ . layer ( Extension ( state. clone ( ) ) ) ;
79+
80+ let listener = tokio:: net:: TcpListener :: bind ( format ! ( "{}:{}" , config. bind, config. port) )
81+ . await
82+ . expect ( "failed to parse bind/port" ) ;
7383
74- axum:: serve ( listener, server_router) . await . unwrap ( ) ;
84+ axum:: serve ( listener, server_router) . await . unwrap ( ) ;
85+ } ) ;
7586
7687 // wait for shutdown hook
7788 shutdown. recv ( ) . await ;
0 commit comments