1
1
use ldk_node:: bitcoin:: Network ;
2
2
use ldk_node:: lightning:: ln:: msgs:: SocketAddress ;
3
+ use ldk_node:: lightning:: routing:: gossip:: NodeAlias ;
3
4
use ldk_node:: liquidity:: LSPS2ServiceConfig ;
4
5
use serde:: { Deserialize , Serialize } ;
5
6
use std:: net:: SocketAddr ;
@@ -11,6 +12,7 @@ use std::{fs, io};
11
12
#[ derive( Debug ) ]
12
13
pub struct Config {
13
14
pub listening_addr : SocketAddress ,
15
+ pub alias : Option < NodeAlias > ,
14
16
pub network : Network ,
15
17
pub rest_service_addr : SocketAddr ,
16
18
pub storage_dir_path : String ,
@@ -48,6 +50,21 @@ impl TryFrom<TomlConfig> for Config {
48
50
)
49
51
} ) ?;
50
52
53
+ let alias = if let Some ( alias_str) = toml_config. node . alias {
54
+ let mut bytes = [ 0u8 ; 32 ] ;
55
+ let alias_bytes = alias_str. trim ( ) . as_bytes ( ) ;
56
+ if alias_bytes. len ( ) > 32 {
57
+ return Err ( io:: Error :: new (
58
+ io:: ErrorKind :: InvalidInput ,
59
+ "node.alias must be at most 32 bytes long." . to_string ( ) ,
60
+ ) ) ;
61
+ }
62
+ bytes[ ..alias_bytes. len ( ) ] . copy_from_slice ( alias_bytes) ;
63
+ Some ( NodeAlias ( bytes) )
64
+ } else {
65
+ None
66
+ } ;
67
+
51
68
let ( rabbitmq_connection_string, rabbitmq_exchange_name) = {
52
69
let rabbitmq = toml_config. rabbitmq . unwrap_or ( RabbitmqConfig {
53
70
connection_string : String :: new ( ) ,
@@ -77,6 +94,7 @@ impl TryFrom<TomlConfig> for Config {
77
94
Ok ( Config {
78
95
listening_addr,
79
96
network : toml_config. node . network ,
97
+ alias,
80
98
rest_service_addr,
81
99
storage_dir_path : toml_config. storage . disk . dir_path ,
82
100
bitcoind_rpc_addr,
@@ -104,6 +122,7 @@ struct NodeConfig {
104
122
network : Network ,
105
123
listening_address : String ,
106
124
rest_service_address : String ,
125
+ alias : Option < String > ,
107
126
}
108
127
109
128
#[ derive( Deserialize , Serialize ) ]
@@ -209,6 +228,7 @@ mod tests {
209
228
network = "regtest"
210
229
listening_address = "localhost:3001"
211
230
rest_service_address = "127.0.0.1:3002"
231
+ alias = "LDK Server"
212
232
213
233
[storage.disk]
214
234
dir_path = "/tmp"
@@ -235,9 +255,14 @@ mod tests {
235
255
236
256
fs:: write ( storage_path. join ( config_file_name) , toml_config) . unwrap ( ) ;
237
257
258
+ let mut bytes = [ 0u8 ; 32 ] ;
259
+ let alias = "LDK Server" ;
260
+ bytes[ ..alias. as_bytes ( ) . len ( ) ] . copy_from_slice ( alias. as_bytes ( ) ) ;
261
+
238
262
let config = load_config ( storage_path. join ( config_file_name) ) . unwrap ( ) ;
239
263
let expected = Config {
240
264
listening_addr : SocketAddress :: from_str ( "localhost:3001" ) . unwrap ( ) ,
265
+ alias : Some ( NodeAlias ( bytes) ) ,
241
266
network : Network :: Regtest ,
242
267
rest_service_addr : SocketAddr :: from_str ( "127.0.0.1:3002" ) . unwrap ( ) ,
243
268
storage_dir_path : "/tmp" . to_string ( ) ,
0 commit comments