-- Recursively finds a nonce that satisfies the difficulty target
-- If our blockHash already satisfies the PoW, return the current nonce
-- If not, increment the nonce and try again
-- TODO - Handle nonce overflow.
findNonce :: Block -> Int
findNonce block = do
  let bHash = calculateBlockHash block
      currentNonce = nonce block
  if satisfiesPow bHash
    then currentNonce
    else findNonce $ block {nonce = currentNonce + 1}

-- a hardcoded initial block, we need this to make sure all
-- nodes have the same starting point, so we have a hard coded
-- frame of reference to detect validity
findNonce :: Block -> Int
findNonce block = do
  let bHash = calculateBlockHash block
      currentNonce = nonce block
  if satisfiesPow bHash
    then currentNonce
    else findNonce $ block {nonce = currentNonce + 1}

-- a hardcoded initial block, we need this to make sure all
-- nodes have the same starting point, so we have a hard coded
-- frame of reference to detect validity
findNonce block = do
  let bHash = calculateBlockHash block
      currentNonce = nonce block
  if satisfiesPow bHash
    then currentNonce
    else findNonce $ block {nonce = currentNonce + 1}

-- a hardcoded initial block, we need this to make sure all
-- nodes have the same starting point, so we have a hard coded
-- frame of reference to detect validity