1- using NBitcoin . DataEncoders ;
1+ #nullable enable
2+ using NBitcoin . DataEncoders ;
23using System ;
34using System . Collections . Generic ;
45using System . IO ;
1516using System . Runtime . InteropServices ;
1617#if ! NOSOCKET
1718using System . Net . Sockets ;
19+ using System . Diagnostics . CodeAnalysis ;
1820#endif
1921#if WINDOWS_UWP
2022using System . Net . Sockets ;
@@ -35,24 +37,24 @@ internal static Secp256k1.SecpECDSASignature Sign(this Secp256k1.ECPrivKey key,
3537 {
3638 Span < byte > hash = stackalloc byte [ 32 ] ;
3739 h . ToBytes ( hash ) ;
38- byte [ ] extra_entropy = null ;
39- Secp256k1 . RFC6979NonceFunction nonceFunction = null ;
40+ byte [ ] ? extra_entropy = null ;
41+ Secp256k1 . RFC6979NonceFunction ? nonceFunction = null ;
4042 Span < byte > vchSig = stackalloc byte [ Secp256k1 . SecpECDSASignature . MaxLength ] ;
41- Secp256k1 . SecpECDSASignature sig ;
43+ Secp256k1 . SecpECDSASignature ? sig ;
4244 uint counter = 0 ;
43- bool ret = key . TrySignECDSA ( hash , null , out recid , out sig ) ;
45+ key . TrySignECDSA ( hash , null , out recid , out sig ) ;
4446 // Grind for low R
45- while ( ret && sig . r . IsHigh && enforceLowR )
47+ while ( sig is not null && sig . r . IsHigh && enforceLowR )
4648 {
4749 if ( extra_entropy == null || nonceFunction == null )
4850 {
4951 extra_entropy = new byte [ 32 ] ;
5052 nonceFunction = new Secp256k1 . RFC6979NonceFunction ( extra_entropy ) ;
5153 }
5254 Utils . ToBytes ( ++ counter , true , extra_entropy . AsSpan ( ) ) ;
53- ret = key . TrySignECDSA ( hash , nonceFunction , out recid , out sig ) ;
55+ key . TrySignECDSA ( hash , nonceFunction , out recid , out sig ) ;
5456 }
55- return sig ;
57+ return sig ! ;
5658 }
5759#endif
5860 /// <summary>
@@ -174,7 +176,7 @@ public static T ToNetwork<T>(this T obj, ChainName chainName) where T : IBitcoin
174176 {
175177 if ( obj == null )
176178 throw new ArgumentNullException ( nameof ( obj ) ) ;
177- if ( chainName == null )
179+ if ( chainName is null )
178180 throw new ArgumentNullException ( nameof ( chainName ) ) ;
179181 if ( obj . Network . ChainName == chainName )
180182 return obj ;
@@ -183,7 +185,7 @@ public static T ToNetwork<T>(this T obj, ChainName chainName) where T : IBitcoin
183185
184186 public static T ToNetwork < T > ( this T obj , Network network ) where T : IBitcoinString
185187 {
186- if ( network == null )
188+ if ( network is null )
187189 throw new ArgumentNullException ( nameof ( network ) ) ;
188190 if ( obj == null )
189191 throw new ArgumentNullException ( nameof ( obj ) ) ;
@@ -195,7 +197,7 @@ public static T ToNetwork<T>(this T obj, Network network) where T : IBitcoinStri
195197 if ( b58 . Type != Base58Type . COLORED_ADDRESS )
196198 {
197199
198- byte [ ] version = network . GetVersionBytes ( b58 . Type , true ) ;
200+ byte [ ] version = network . GetVersionBytes ( b58 . Type , true ) ! ;
199201 var enc = network . NetworkStringParser . GetBase58CheckEncoder ( ) ;
200202 var inner = enc . DecodeData ( b58 . ToString ( ) ) . Skip ( version . Length ) . ToArray ( ) ;
201203 var newBase58 = enc . EncodeData ( version . Concat ( inner ) . ToArray ( ) ) ;
@@ -211,10 +213,10 @@ public static T ToNetwork<T>(this T obj, Network network) where T : IBitcoinStri
211213 else if ( obj is IBech32Data )
212214 {
213215 var b32 = ( IBech32Data ) obj ;
214- var encoder = b32 . Network . GetBech32Encoder ( b32 . Type , true ) ;
216+ var encoder = b32 . Network . GetBech32Encoder ( b32 . Type , true ) ! ;
215217 byte wit ;
216218 var data = encoder . Decode ( b32 . ToString ( ) , out wit ) ;
217- encoder = network . GetBech32Encoder ( b32 . Type , true ) ;
219+ encoder = network . GetBech32Encoder ( b32 . Type , true ) ! ;
218220 var str = encoder . Encode ( wit , data ) ;
219221 return ( T ) ( object ) Network . Parse < T > ( str , network ) ;
220222 }
@@ -257,12 +259,12 @@ public static int ReadBytes(this Stream stream, int count, out byte[] result)
257259 result = new byte [ count ] ;
258260 return stream . Read ( result , 0 , count ) ;
259261 }
260- public static IEnumerable < T > Resize < T > ( this List < T > list , int count )
262+ public static IEnumerable < T ? > Resize < T > ( this List < T ? > list , int count )
261263 {
262264 if ( list . Count == count )
263265 return new T [ 0 ] ;
264266
265- List < T > removed = new List < T > ( ) ;
267+ var removed = new List < T ? > ( ) ;
266268
267269 for ( int i = list . Count - 1 ; i + 1 > count ; i -- )
268270 {
@@ -419,9 +421,9 @@ public static void AddOrReplace<TKey, TValue>(this IDictionary<TKey, TValue> dic
419421 dico . Add ( key , value ) ;
420422 }
421423
422- public static TValue TryGet < TKey , TValue > ( this IDictionary < TKey , TValue > dictionary , TKey key )
424+ public static TValue ? TryGet < TKey , TValue > ( this IDictionary < TKey , TValue > dictionary , TKey key )
423425 {
424- TValue value ;
426+ TValue ? value ;
425427 dictionary . TryGetValue ( key , out value ) ;
426428 return value ;
427429 }
@@ -568,10 +570,6 @@ private static void Write(MemoryStream ms, byte[] bytes)
568570#if ! HAS_SPAN
569571 internal static byte [ ] BigIntegerToBytes ( BigInteger b , int numBytes )
570572 {
571- if ( b == null )
572- {
573- return null ;
574- }
575573 byte [ ] bytes = new byte [ numBytes ] ;
576574 byte [ ] biBytes = b . ToByteArray ( ) ;
577575 int start = ( biBytes . Length == numBytes + 1 ) ? 1 : 0 ;
@@ -653,7 +651,7 @@ public static DateTimeOffset UnixTimeToDateTime(long timestamp)
653651
654652 public static string ExceptionToString ( Exception exception )
655653 {
656- Exception ex = exception ;
654+ Exception ? ex = exception ;
657655 StringBuilder stringBuilder = new StringBuilder ( 128 ) ;
658656 while ( ex != null )
659657 {
@@ -670,7 +668,7 @@ public static string ExceptionToString(Exception exception)
670668 return stringBuilder . ToString ( ) ;
671669 }
672670
673- public static void Shuffle < T > ( T [ ] arr , Random rand )
671+ public static void Shuffle < T > ( T [ ] arr , Random ? rand )
674672 {
675673 rand = rand ?? new Random ( ) ;
676674 for ( int i = 0 ; i < arr . Length ; i ++ )
@@ -1000,7 +998,7 @@ public static ulong ToUInt64(byte[] value, bool littleEndian)
1000998
1001999#if ! NOSOCKET
10021000
1003- public static bool TryParseEndpoint ( string hostPort , int defaultPort , out EndPoint endpoint )
1001+ public static bool TryParseEndpoint ( string hostPort , int defaultPort , [ MaybeNullWhen ( false ) ] out EndPoint endpoint )
10041002 {
10051003 if ( hostPort == null )
10061004 throw new ArgumentNullException ( nameof ( hostPort ) ) ;
0 commit comments