MCPcopy Create free account
hub / github.com/BitVM/BitVM / bits_to_target

Function bits_to_target

header-chain/src/header_chain.rs:297–308  ·  view source on GitHub ↗
(bits: u32)

Source from the content-addressed store, hash-verified

295}
296
297pub fn bits_to_target(bits: u32) -> [u8; 32] {
298 let size = (bits >> 24) as usize;
299 let mantissa = bits & 0x00ffffff;
300
301 let target = if size <= 3 {
302 U256::from(mantissa >> (8 * (3 - size)))
303 } else {
304 U256::from(mantissa) << (8 * (size - 3))
305 };
306 // println!("Output: {:?}", target.to_be_bytes());
307 target.to_be_bytes()
308}
309
310fn target_to_bits(target: &[u8; 32]) -> u32 {
311 let target_u256 = U256::from_be_slice(target);

Callers 5

apply_blocksMethod · 0.85
calculate_new_difficultyFunction · 0.85
test_hash_check_passFunction · 0.85
test_target_conversionFunction · 0.85
test_bits_to_targetFunction · 0.85

Calls

no outgoing calls

Tested by 3

test_hash_check_passFunction · 0.68
test_target_conversionFunction · 0.68
test_bits_to_targetFunction · 0.68