@@ -33,78 +33,87 @@ public RpcServerSettings(IConfigurationSection section)
3333
3434 public record RpcServersSettings
3535 {
36- public uint Network { get ; init ; }
37- public IPAddress BindAddress { get ; init ; }
38- public ushort Port { get ; init ; }
39- public string SslCert { get ; init ; }
40- public string SslCertPassword { get ; init ; }
41- public string [ ] TrustedAuthorities { get ; init ; }
42- public int MaxConcurrentConnections { get ; init ; }
43- public int MaxRequestBodySize { get ; init ; }
44- public string RpcUser { get ; init ; }
45- public string RpcPass { get ; init ; }
46- public bool EnableCors { get ; init ; }
47- public string [ ] AllowOrigins { get ; init ; }
48- public int KeepAliveTimeout { get ; init ; }
49- public uint RequestHeadersTimeout { get ; init ; }
50- // In the unit of datoshi, 1 GAS = 10^8 datoshi
51- public long MaxGasInvoke { get ; init ; }
52- // In the unit of datoshi, 1 GAS = 10^8 datoshi
53- public long MaxFee { get ; init ; }
54- public int MaxIteratorResultItems { get ; init ; }
55- public int MaxStackSize { get ; init ; }
56- public string [ ] DisabledMethods { get ; init ; }
57- public bool SessionEnabled { get ; init ; }
58- public TimeSpan SessionExpirationTime { get ; init ; }
59- public int FindStoragePageSize { get ; init ; }
36+ public uint Network { get ; init ; } = 5195086u ;
37+ public IPAddress BindAddress { get ; init ; } = IPAddress . Loopback ;
38+ public ushort Port { get ; init ; } = 10332 ;
39+ public string SslCert { get ; init ; } = string . Empty ;
40+ public string SslCertPassword { get ; init ; } = string . Empty ;
41+ public string [ ] TrustedAuthorities { get ; init ; } = [ ] ;
42+ public int MaxConcurrentConnections { get ; init ; } = 40 ;
43+ public int MaxRequestBodySize { get ; init ; } = 5 * 1024 * 1024 ;
44+ public string RpcUser { get ; init ; } = string . Empty ;
45+ public string RpcPass { get ; init ; } = string . Empty ;
46+ public bool EnableCors { get ; init ; } = true ;
47+ public string [ ] AllowOrigins { get ; init ; } = [ ] ;
6048
61- public static RpcServersSettings Default { get ; } = new RpcServersSettings
49+ /// <summary>
50+ /// The maximum time in seconds allowed for the keep-alive connection to be idle.
51+ /// </summary>
52+ public int KeepAliveTimeout { get ; init ; } = 60 ;
53+
54+ /// <summary>
55+ /// The maximum time in seconds allowed for the request headers to be read.
56+ /// </summary>
57+ public uint RequestHeadersTimeout { get ; init ; } = 15 ;
58+
59+ /// <summary>
60+ /// In the unit of datoshi, 1 GAS = 10^8 datoshi
61+ /// </summary>
62+ public long MaxGasInvoke { get ; init ; } = ( long ) new BigDecimal ( 10M , NativeContract . GAS . Decimals ) . Value ;
63+
64+ /// <summary>
65+ /// In the unit of datoshi, 1 GAS = 10^8 datoshi
66+ /// </summary>
67+ public long MaxFee { get ; init ; } = ( long ) new BigDecimal ( 0.1M , NativeContract . GAS . Decimals ) . Value ;
68+ public int MaxIteratorResultItems { get ; init ; } = 100 ;
69+ public int MaxStackSize { get ; init ; } = ushort . MaxValue ;
70+ public string [ ] DisabledMethods { get ; init ; } = [ ] ;
71+ public bool SessionEnabled { get ; init ; } = false ;
72+ public TimeSpan SessionExpirationTime { get ; init ; } = TimeSpan . FromSeconds ( 60 ) ;
73+ public int FindStoragePageSize { get ; init ; } = 50 ;
74+
75+ public static RpcServersSettings Default { get ; } = new ( ) ;
76+
77+ public static RpcServersSettings Load ( IConfigurationSection section )
6278 {
63- Network = 5195086u ,
64- BindAddress = IPAddress . None ,
65- SslCert = string . Empty ,
66- SslCertPassword = string . Empty ,
67- MaxGasInvoke = ( long ) new BigDecimal ( 10M , NativeContract . GAS . Decimals ) . Value ,
68- MaxFee = ( long ) new BigDecimal ( 0.1M , NativeContract . GAS . Decimals ) . Value ,
69- TrustedAuthorities = Array . Empty < string > ( ) ,
70- EnableCors = true ,
71- AllowOrigins = Array . Empty < string > ( ) ,
72- KeepAliveTimeout = 60 ,
73- RequestHeadersTimeout = 15 ,
74- MaxIteratorResultItems = 100 ,
75- MaxStackSize = ushort . MaxValue ,
76- DisabledMethods = Array . Empty < string > ( ) ,
77- MaxConcurrentConnections = 40 ,
78- MaxRequestBodySize = 5 * 1024 * 1024 ,
79- SessionEnabled = false ,
80- SessionExpirationTime = TimeSpan . FromSeconds ( 60 ) ,
81- FindStoragePageSize = 50
82- } ;
79+ var @default = Default ;
80+ return new ( )
81+ {
82+ Network = section . GetValue ( "Network" , @default . Network ) ,
83+ BindAddress = IPAddress . Parse ( section . GetValue ( "BindAddress" , @default . BindAddress . ToString ( ) ) ) ,
84+ Port = section . GetValue ( "Port" , @default . Port ) ,
85+ SslCert = section . GetValue ( "SslCert" , string . Empty ) ,
86+ SslCertPassword = section . GetValue ( "SslCertPassword" , string . Empty ) ,
87+ TrustedAuthorities = GetStrings ( section , "TrustedAuthorities" ) ,
88+ RpcUser = section . GetValue ( "RpcUser" , @default . RpcUser ) ,
89+ RpcPass = section . GetValue ( "RpcPass" , @default . RpcPass ) ,
90+ EnableCors = section . GetValue ( nameof ( EnableCors ) , @default . EnableCors ) ,
91+ AllowOrigins = GetStrings ( section , "AllowOrigins" ) ,
92+ KeepAliveTimeout = section . GetValue ( nameof ( KeepAliveTimeout ) , @default . KeepAliveTimeout ) ,
93+ RequestHeadersTimeout = section . GetValue ( nameof ( RequestHeadersTimeout ) , @default . RequestHeadersTimeout ) ,
94+ MaxGasInvoke = ( long ) new BigDecimal ( section . GetValue < decimal > ( "MaxGasInvoke" , @default . MaxGasInvoke ) , NativeContract . GAS . Decimals ) . Value ,
95+ MaxFee = ( long ) new BigDecimal ( section . GetValue < decimal > ( "MaxFee" , @default . MaxFee ) , NativeContract . GAS . Decimals ) . Value ,
96+ MaxIteratorResultItems = section . GetValue ( "MaxIteratorResultItems" , @default . MaxIteratorResultItems ) ,
97+ MaxStackSize = section . GetValue ( "MaxStackSize" , @default . MaxStackSize ) ,
98+ DisabledMethods = GetStrings ( section , "DisabledMethods" ) ,
99+ MaxConcurrentConnections = section . GetValue ( "MaxConcurrentConnections" , @default . MaxConcurrentConnections ) ,
100+ MaxRequestBodySize = section . GetValue ( "MaxRequestBodySize" , @default . MaxRequestBodySize ) ,
101+ SessionEnabled = section . GetValue ( "SessionEnabled" , @default . SessionEnabled ) ,
102+ SessionExpirationTime = TimeSpan . FromSeconds ( section . GetValue ( "SessionExpirationTime" , ( long ) @default . SessionExpirationTime . TotalSeconds ) ) ,
103+ FindStoragePageSize = section . GetValue ( "FindStoragePageSize" , @default . FindStoragePageSize )
104+ } ;
105+ }
83106
84- public static RpcServersSettings Load ( IConfigurationSection section ) => new ( )
107+ private static string [ ] GetStrings ( IConfigurationSection section , string key )
85108 {
86- Network = section . GetValue ( "Network" , Default . Network ) ,
87- BindAddress = IPAddress . Parse ( section . GetSection ( "BindAddress" ) . Value ) ,
88- Port = ushort . Parse ( section . GetSection ( "Port" ) . Value ) ,
89- SslCert = section . GetSection ( "SslCert" ) . Value ,
90- SslCertPassword = section . GetSection ( "SslCertPassword" ) . Value ,
91- TrustedAuthorities = section . GetSection ( "TrustedAuthorities" ) . GetChildren ( ) . Select ( p => p . Get < string > ( ) ) . ToArray ( ) ,
92- RpcUser = section . GetSection ( "RpcUser" ) . Value ,
93- RpcPass = section . GetSection ( "RpcPass" ) . Value ,
94- EnableCors = section . GetValue ( nameof ( EnableCors ) , Default . EnableCors ) ,
95- AllowOrigins = section . GetSection ( nameof ( AllowOrigins ) ) . GetChildren ( ) . Select ( p => p . Get < string > ( ) ) . ToArray ( ) ,
96- KeepAliveTimeout = section . GetValue ( nameof ( KeepAliveTimeout ) , Default . KeepAliveTimeout ) ,
97- RequestHeadersTimeout = section . GetValue ( nameof ( RequestHeadersTimeout ) , Default . RequestHeadersTimeout ) ,
98- MaxGasInvoke = ( long ) new BigDecimal ( section . GetValue < decimal > ( "MaxGasInvoke" , Default . MaxGasInvoke ) , NativeContract . GAS . Decimals ) . Value ,
99- MaxFee = ( long ) new BigDecimal ( section . GetValue < decimal > ( "MaxFee" , Default . MaxFee ) , NativeContract . GAS . Decimals ) . Value ,
100- MaxIteratorResultItems = section . GetValue ( "MaxIteratorResultItems" , Default . MaxIteratorResultItems ) ,
101- MaxStackSize = section . GetValue ( "MaxStackSize" , Default . MaxStackSize ) ,
102- DisabledMethods = section . GetSection ( "DisabledMethods" ) . GetChildren ( ) . Select ( p => p . Get < string > ( ) ) . ToArray ( ) ,
103- MaxConcurrentConnections = section . GetValue ( "MaxConcurrentConnections" , Default . MaxConcurrentConnections ) ,
104- MaxRequestBodySize = section . GetValue ( "MaxRequestBodySize" , Default . MaxRequestBodySize ) ,
105- SessionEnabled = section . GetValue ( "SessionEnabled" , Default . SessionEnabled ) ,
106- SessionExpirationTime = TimeSpan . FromSeconds ( section . GetValue ( "SessionExpirationTime" , ( int ) Default . SessionExpirationTime . TotalSeconds ) ) ,
107- FindStoragePageSize = section . GetValue ( "FindStoragePageSize" , Default . FindStoragePageSize )
108- } ;
109+ List < string > list = [ ] ;
110+ foreach ( var child in section . GetSection ( key ) . GetChildren ( ) )
111+ {
112+ var value = child . Get < string > ( ) ;
113+ if ( value is null ) throw new ArgumentException ( $ "Invalid value for { key } ") ;
114+ list . Add ( value ) ;
115+ }
116+ return list . ToArray ( ) ;
117+ }
109118 }
110119}
0 commit comments