Migrate all Uint256s used for channel_ids to [u8; 32]
[rust-lightning] / src / util / rng.rs
index 818528b8e13e9f35c333c18769ea12dce4543b93..ae50154d95dea23b29d25c36aeff13372b4b101a 100644 (file)
@@ -1,16 +1,16 @@
 #[cfg(not(feature = "fuzztarget"))]
 mod real_rng {
        use rand::{thread_rng,Rng};
-       use bitcoin::util::uint::Uint256;
 
        pub fn fill_bytes(data: &mut [u8]) {
                let mut rng = thread_rng();
                rng.fill_bytes(data);
        }
 
-       pub fn rand_uint256() -> Uint256 {
-               let mut rng = thread_rng();
-               Uint256([rng.gen(), rng.gen(), rng.gen(), rng.gen()])
+       pub fn rand_u832() -> [u8; 32] {
+               let mut res = [0; 32];
+               fill_bytes(&mut res);
+               res
        }
 
        pub fn rand_f32() -> f32 {
@@ -23,7 +23,6 @@ pub use self::real_rng::*;
 
 #[cfg(feature = "fuzztarget")]
 mod fuzzy_rng {
-       use bitcoin::util::uint::Uint256;
        use util::byte_utils;
 
        static mut RNG_ITER: u64 = 0;
@@ -38,9 +37,15 @@ mod fuzzy_rng {
                data[off..].copy_from_slice(&byte_utils::be64_to_array(rng)[0..rem]);
        }
 
-       pub fn rand_uint256() -> Uint256 {
+       pub fn rand_u832() -> [u8; 32] {
                let rng = unsafe { RNG_ITER += 1; RNG_ITER - 1 };
-               Uint256([rng, rng, rng, rng])
+               let mut res = [0; 32];
+               let data = byte_utils::le64_to_array(rng);
+               res[8*0..8*1].copy_from_slice(&data);
+               res[8*1..8*2].copy_from_slice(&data);
+               res[8*2..8*3].copy_from_slice(&data);
+               res[8*3..8*4].copy_from_slice(&data);
+               res
        }
 
        pub fn rand_f32() -> f32 {