@@ -15,6 +15,7 @@ use serde::Deserialize;
15
15
use spaces_protocol:: bitcoin:: Network ;
16
16
17
17
use crate :: {
18
+ auth:: basic_auth_token,
18
19
source:: { BitcoinRpc , BitcoinRpcAuth } ,
19
20
store:: { LiveStore , Store } ,
20
21
spaces:: Spaced ,
@@ -58,6 +59,12 @@ pub struct Args {
58
59
/// Bitcoin RPC password
59
60
#[ arg( long, env = "SPACED_BITCOIN_RPC_PASSWORD" ) ]
60
61
bitcoin_rpc_password : Option < String > ,
62
+ /// Spaced RPC user
63
+ #[ arg( long, requires = "rpc_password" , env = "SPACED_RPC_USER" ) ]
64
+ rpc_user : Option < String > ,
65
+ /// Spaced RPC password
66
+ #[ arg( long, env = "SPACED_RPC_PASSWORD" ) ]
67
+ rpc_password : Option < String > ,
61
68
/// Bind to given address to listen for JSON-RPC connections.
62
69
/// This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost)
63
70
#[ arg( long, help_heading = Some ( RPC_OPTIONS ) , default_values = [ "127.0.0.1" , "::1" ] , env = "SPACED_RPC_BIND" ) ]
@@ -102,7 +109,7 @@ impl Args {
102
109
/// Configures spaced node by processing command line arguments
103
110
/// and configuration files
104
111
pub async fn configure ( args : Vec < String > ) -> anyhow:: Result < Spaced > {
105
- let mut args = Args :: try_parse_from ( args) ?;
112
+ let mut args = Args :: try_parse_from ( args) ?;
106
113
let default_dirs = get_default_node_dirs ( ) ;
107
114
108
115
if args. bitcoin_rpc_url . is_none ( ) {
@@ -132,6 +139,12 @@ impl Args {
132
139
} )
133
140
. collect ( ) ;
134
141
142
+ let auth_token = if args. rpc_user . is_some ( ) {
143
+ Some ( basic_auth_token ( args. rpc_user . as_ref ( ) . unwrap ( ) , args. rpc_password . as_ref ( ) . unwrap ( ) ) )
144
+ } else {
145
+ None
146
+ } ;
147
+
135
148
let bitcoin_rpc_auth = if let Some ( cookie) = args. bitcoin_rpc_cookie {
136
149
let cookie = std:: fs:: read_to_string ( cookie) ?;
137
150
BitcoinRpcAuth :: Cookie ( cookie)
@@ -144,7 +157,7 @@ impl Args {
144
157
let rpc = BitcoinRpc :: new (
145
158
& args. bitcoin_rpc_url . expect ( "bitcoin rpc url" ) ,
146
159
bitcoin_rpc_auth,
147
- !args. bitcoin_rpc_light
160
+ !args. bitcoin_rpc_light ,
148
161
) ;
149
162
150
163
let genesis = Spaced :: genesis ( args. chain ) ;
@@ -196,13 +209,14 @@ impl Args {
196
209
rpc,
197
210
data_dir,
198
211
bind : rpc_bind_addresses,
212
+ auth_token,
199
213
chain,
200
214
block_index,
201
215
block_index_full : args. block_index_full ,
202
216
num_workers : args. jobs as usize ,
203
217
anchors_path,
204
218
synced : false ,
205
- cbf : args. bitcoin_rpc_light
219
+ cbf : args. bitcoin_rpc_light ,
206
220
} )
207
221
}
208
222
}
0 commit comments