Skip to content

Commit

Permalink
commit fourmolu diff
Browse files Browse the repository at this point in the history
  • Loading branch information
ProofOfKeags committed May 3, 2024
1 parent 43d968e commit 64a0760
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 58 deletions.
2 changes: 1 addition & 1 deletion bitcoin-test/lib/Bitcoin/BlockSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ withChain :: Network -> State HeaderMemory a -> a
withChain net f = evalState f (initialChain net)


chain :: BlockHeaders m => Network -> BlockHeader -> Int -> m ()
chain :: (BlockHeaders m) => Network -> BlockHeader -> Int -> m ()
chain net bh i = do
bnsE <- connectBlocks net myTime bhs
either error (const $ return ()) bnsE
Expand Down
2 changes: 1 addition & 1 deletion bitcoin-test/lib/Bitcoin/Keys/MnemonicSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ invalidMss =
]


binWordsToBS :: Binary a => [a] -> BSL.ByteString
binWordsToBS :: (Binary a) => [a] -> BSL.ByteString
binWordsToBS = foldr f BSL.empty
where
f b a = a `BSL.append` Bin.encode b
Expand Down
4 changes: 2 additions & 2 deletions bitcoin-test/lib/Bitcoin/ScriptSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ sigHashSpec net = do

testSigHashOne :: Network -> Tx -> Script -> Word64 -> Bool -> Property
testSigHashOne net tx s val acp =
not (null $ txIn tx)
==> if length (txIn tx) > length (txOut tx)
not (null $ txIn tx) ==>
if length (txIn tx) > length (txOut tx)
then res `shouldBe` one
else res `shouldNotBe` one
where
Expand Down
2 changes: 1 addition & 1 deletion bitcoin-test/lib/Bitcoin/Util/Arbitrary/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ arbitraryNetwork :: Gen Network
arbitraryNetwork = elements allNets


arbitraryNetData :: Arbitrary a => Gen (Network, a)
arbitraryNetData :: (Arbitrary a) => Gen (Network, a)
arbitraryNetData = do
net <- arbitraryNetwork
x <- arbitrary
Expand Down
2 changes: 1 addition & 1 deletion bitcoin-test/lib/Bitcoin/UtilSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ testMaybeToEither m str = maybeToEither str m == Left str

{-- Test Utilities --}

readTestFile :: A.FromJSON a => FilePath -> IO a
readTestFile :: (A.FromJSON a) => FilePath -> IO a
readTestFile fp =
A.eitherDecodeFileStrict ("data/" <> fp) >>= either (error . message) return
where
Expand Down
14 changes: 7 additions & 7 deletions bitcoin/src/Bitcoin/Address/Bech32.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type HRP = Text
type Data = [Word8]


(.>>.), (.<<.) :: Bits a => a -> Int -> a
(.>>.), (.<<.) :: (Bits a) => a -> Int -> a
(.>>.) = unsafeShiftR
(.<<.) = unsafeShiftL

Expand All @@ -94,14 +94,14 @@ instance Ix Word5 where


-- | Convert an integer number into a five-bit word.
word5 :: Integral a => a -> Word5
word5 :: (Integral a) => a -> Word5
word5 x = UnsafeWord5 (fromIntegral x .&. 31)
{-# INLINE word5 #-}
{-# SPECIALIZE INLINE word5 :: Word8 -> Word5 #-}


-- | Convert a five-bit word into a number.
fromWord5 :: Num a => Word5 -> a
fromWord5 :: (Num a) => Word5 -> a
fromWord5 (UnsafeWord5 x) = fromIntegral x
{-# INLINE fromWord5 #-}
{-# SPECIALIZE INLINE fromWord5 :: Word5 -> Word8 #-}
Expand Down Expand Up @@ -165,9 +165,9 @@ bech32VerifyChecksum :: HRP -> [Word5] -> Maybe Bech32Encoding
bech32VerifyChecksum hrp dat =
let poly = bech32Polymod (bech32HRPExpand hrp ++ dat)
in if
| poly == bech32Const Bech32 -> Just Bech32
| poly == bech32Const Bech32m -> Just Bech32m
| otherwise -> Nothing
| poly == bech32Const Bech32 -> Just Bech32
| poly == bech32Const Bech32m -> Just Bech32m
| otherwise -> Nothing


-- | Maximum length of a Bech32 result.
Expand Down Expand Up @@ -300,7 +300,7 @@ noPadding frombits bits padValue result = do
-- \(2^{tobits}\). {frombits} and {twobits} must be positive and
-- \(2^{frombits}\) and \(2^{tobits}\) must be smaller than the size of Word.
-- Every value in 'dat' must be strictly smaller than \(2^{frombits}\).
convertBits :: Functor f => [Word] -> Int -> Int -> Pad f -> f [Word]
convertBits :: (Functor f) => [Word] -> Int -> Int -> Pad f -> f [Word]
convertBits dat frombits tobits pad = concat . reverse <$> go dat 0 0 []
where
go [] acc bits result =
Expand Down
40 changes: 20 additions & 20 deletions bitcoin/src/Bitcoin/Block/Headers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ data HeaderMemory = HeaderMemory


-- | Typeclass for block header chain storage monad.
class Monad m => BlockHeaders m where
class (Monad m) => BlockHeaders m where
-- | Add a new 'BlockNode' to the chain. Does not validate.
addBlockHeader :: BlockNode -> m ()

Expand All @@ -198,7 +198,7 @@ class Monad m => BlockHeaders m where
addBlockHeaders = mapM_ addBlockHeader


instance Monad m => BlockHeaders (StateT HeaderMemory m) where
instance (Monad m) => BlockHeaders (StateT HeaderMemory m) where
addBlockHeader = State.modify' . addBlockHeaderMemory
getBlockHeader bh = getBlockHeaderMemory bh <$> State.get
getBestBlockHeader = State.gets memoryBestHeader
Expand Down Expand Up @@ -255,7 +255,7 @@ addBlockToMap node =
-- | Get the ancestor of the provided 'BlockNode' at the specified
-- 'BlockHeight'.
getAncestor ::
BlockHeaders m =>
(BlockHeaders m) =>
BlockHeight ->
BlockNode ->
m (Maybe BlockNode)
Expand Down Expand Up @@ -309,7 +309,7 @@ genesisNode net =
-- | Validate a list of continuous block headers and import them to the
-- block chain. Return 'Left' on failure with error information.
connectBlocks ::
BlockHeaders m =>
(BlockHeaders m) =>
Network ->
-- | current time
Timestamp ->
Expand Down Expand Up @@ -363,7 +363,7 @@ connectBlocks net t bhs@(bh : _) =
-- | Block's parent. If the block header is in the store, its parent must also
-- be there. No block header get deleted or pruned from the store.
parentBlock ::
BlockHeaders m =>
(BlockHeaders m) =>
BlockHeader ->
m (Maybe BlockNode)
parentBlock bh = getBlockHeader (prevBlock bh)
Expand All @@ -372,7 +372,7 @@ parentBlock bh = getBlockHeader (prevBlock bh)
-- | Validate and connect single block header to the block chain. Return 'Left'
-- if fails to be validated.
connectBlock ::
BlockHeaders m =>
(BlockHeaders m) =>
Network ->
-- | current time
Timestamp ->
Expand Down Expand Up @@ -479,7 +479,7 @@ invertLowestOne height = height .&. (height - 1)

-- | Get a number of parents for the provided block.
getParents ::
BlockHeaders m =>
(BlockHeaders m) =>
Int ->
BlockNode ->
-- | starts from immediate parent
Expand Down Expand Up @@ -562,7 +562,7 @@ validVersion net height version

-- | Find last block with normal, as opposed to minimum difficulty (for test
-- networks).
lastNoMinDiff :: BlockHeaders m => Network -> BlockNode -> m BlockNode
lastNoMinDiff :: (BlockHeaders m) => Network -> BlockNode -> m BlockNode
lastNoMinDiff _ bn@BlockNode{nodeHeight = 0} = return bn
lastNoMinDiff net bn@BlockNode{..} = do
let i = nodeHeight `mod` diffInterval net /= 0
Expand All @@ -579,7 +579,7 @@ lastNoMinDiff net bn@BlockNode{..} = do
else return bn


mtp :: BlockHeaders m => BlockNode -> m Timestamp
mtp :: (BlockHeaders m) => BlockNode -> m Timestamp
mtp bn
| nodeHeight bn == 0 = return 0
| otherwise = do
Expand All @@ -588,23 +588,23 @@ mtp bn


firstGreaterOrEqual ::
BlockHeaders m =>
(BlockHeaders m) =>
Network ->
(BlockNode -> m Ordering) ->
m (Maybe BlockNode)
firstGreaterOrEqual = binSearch False


lastSmallerOrEqual ::
BlockHeaders m =>
(BlockHeaders m) =>
Network ->
(BlockNode -> m Ordering) ->
m (Maybe BlockNode)
lastSmallerOrEqual = binSearch True


binSearch ::
BlockHeaders m =>
(BlockHeaders m) =>
Bool ->
Network ->
(BlockNode -> m Ordering) ->
Expand Down Expand Up @@ -643,13 +643,13 @@ binSearch top net f = runMaybeT $ do
| otherwise = return b


extremes :: BlockHeaders m => Network -> m (BlockNode, BlockNode)
extremes :: (BlockHeaders m) => Network -> m (BlockNode, BlockNode)
extremes net = do
b <- getBestBlockHeader
return (genesisNode net, b)


middleBlock :: BlockHeaders m => BlockNode -> BlockNode -> m BlockNode
middleBlock :: (BlockHeaders m) => BlockNode -> BlockNode -> m BlockNode
middleBlock a b =
getAncestor h b >>= \case
Nothing -> error "You fell into a pit full of mud and snakes"
Expand All @@ -658,7 +658,7 @@ middleBlock a b =
h = middleOf (nodeHeight a) (nodeHeight b)


middleOf :: Integral a => a -> a -> a
middleOf :: (Integral a) => a -> a -> a
middleOf a b = a + ((b - a) `div` 2)


Expand Down Expand Up @@ -722,7 +722,7 @@ computeAssertBits halflife anchor_bits time_diff height_diff =
-- | Returns the work required on a block header given the previous block. This
-- coresponds to bitcoind function GetNextWorkRequired in main.cpp.
nextPowWorkRequired ::
BlockHeaders m => Network -> BlockNode -> BlockHeader -> m Word32
(BlockHeaders m) => Network -> BlockNode -> BlockHeader -> m Word32
nextPowWorkRequired net par bh
| nodeHeight par + 1 `mod` diffInterval net /= 0 =
if getAllowMinDifficultyBlocks net
Expand Down Expand Up @@ -811,7 +811,7 @@ chooseBest b1 b2


-- | Get list of blocks for a block locator.
blockLocatorNodes :: BlockHeaders m => BlockNode -> m [BlockNode]
blockLocatorNodes :: (BlockHeaders m) => BlockNode -> m [BlockNode]
blockLocatorNodes best =
reverse <$> go [] best 1
where
Expand All @@ -833,7 +833,7 @@ blockLocatorNodes best =


-- | Get block locator.
blockLocator :: BlockHeaders m => BlockNode -> m BlockLocator
blockLocator :: (BlockHeaders m) => BlockNode -> m BlockLocator
blockLocator bn = map (headerHash . nodeHeader) <$> blockLocatorNodes bn


Expand Down Expand Up @@ -872,7 +872,7 @@ appendBlocks net seed bh i =


-- | Find the last common block ancestor between provided block headers.
splitPoint :: BlockHeaders m => BlockNode -> BlockNode -> m BlockNode
splitPoint :: (BlockHeaders m) => BlockNode -> BlockNode -> m BlockNode
splitPoint l r = do
let h = min (nodeHeight l) (nodeHeight r)
ll <- fromMaybe e <$> getAncestor h l
Expand Down Expand Up @@ -905,5 +905,5 @@ computeSubsidy net height =
else ini `shiftR` fromIntegral halvings


encodeToShort :: Binary a => a -> ShortByteString
encodeToShort :: (Binary a) => a -> ShortByteString
encodeToShort = toShort . U.encodeS
2 changes: 1 addition & 1 deletion bitcoin/src/Bitcoin/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Data.String (IsString)


-- | Version of Bitcoin package.
versionString :: IsString a => a
versionString :: (IsString a) => a

#ifdef CURRENT_PACKAGE_VERSION
versionString = CURRENT_PACKAGE_VERSION
Expand Down
14 changes: 7 additions & 7 deletions bitcoin/src/Bitcoin/Crypto/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ instance Binary Hash160 where


-- | Use this function to produce hashes during the process of serialization
hashWithL :: HashAlgorithm alg => alg -> BSL.ByteString -> Digest alg
hashWithL :: (HashAlgorithm alg) => alg -> BSL.ByteString -> Digest alg
hashWithL _ = hashFinalize . hashUpdates hashInit . BSL.toChunks


-- | Calculate SHA512 hash.
sha512 :: ByteArrayAccess b => b -> Hash512
sha512 :: (ByteArrayAccess b) => b -> Hash512
sha512 = Hash512 . BSS.toShort . BA.convert . hashWith SHA512


-- | Calculate SHA256 hash.
sha256 :: ByteArrayAccess b => b -> Hash256
sha256 :: (ByteArrayAccess b) => b -> Hash256
sha256 = Hash256 . BSS.toShort . BA.convert . hashWith SHA256


Expand All @@ -192,17 +192,17 @@ sha256L = Hash256 . BSS.toShort . BA.convert . hashWithL SHA256


-- | Calculate RIPEMD160 hash.
ripemd160 :: ByteArrayAccess b => b -> Hash160
ripemd160 :: (ByteArrayAccess b) => b -> Hash160
ripemd160 = Hash160 . BSS.toShort . BA.convert . hashWith RIPEMD160


-- | Claculate SHA1 hash.
sha1 :: ByteArrayAccess b => b -> Hash160
sha1 :: (ByteArrayAccess b) => b -> Hash160
sha1 = Hash160 . BSS.toShort . BA.convert . hashWith SHA1


-- | Compute two rounds of SHA-256.
doubleSHA256 :: ByteArrayAccess b => b -> Hash256
doubleSHA256 :: (ByteArrayAccess b) => b -> Hash256
doubleSHA256 =
Hash256 . BSS.toShort . BA.convert . hashWith SHA256 . hashWith SHA256

Expand All @@ -214,7 +214,7 @@ doubleSHA256L =


-- | Compute SHA-256 followed by RIPMED-160.
addressHash :: ByteArrayAccess b => b -> Hash160
addressHash :: (ByteArrayAccess b) => b -> Hash160
addressHash =
Hash160 . BSS.toShort . BA.convert . hashWith RIPEMD160 . hashWith SHA256

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/Bitcoin/Network/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ instance Binary VarInt where
Put.putWord64le x


putVarInt :: Integral a => a -> Put
putVarInt :: (Integral a) => a -> Put
putVarInt = put . VarInt . fromIntegral


Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/Bitcoin/Script/Standard.hs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ encodeOutput s = Script $ case s of
(DataCarrier d) -> [OP_RETURN, opPushData d]


pushItem :: Binary a => a -> ScriptOp
pushItem :: (Binary a) => a -> ScriptOp
pushItem = opPushData . U.encodeS


Expand Down
14 changes: 7 additions & 7 deletions bitcoin/src/Bitcoin/Transaction/Genesis.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{-# LANGUAGE OverloadedStrings #-}

-- |
--Module : Bitcoin.Transaction.Genesis
--Copyright : No rights reserved
--License : UNLICENSE
--Maintainer : jprupp@protonmail.ch
--Stability : experimental
--Portability : POSIX
-- Module : Bitcoin.Transaction.Genesis
-- Copyright : No rights reserved
-- License : UNLICENSE
-- Maintainer : jprupp@protonmail.ch
-- Stability : experimental
-- Portability : POSIX
--
--Code related to transactions parsing and serialization.
-- Code related to transactions parsing and serialization.
module Bitcoin.Transaction.Genesis (
genesisTx,
) where
Expand Down
4 changes: 3 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ nix:
- secp256k1
- pkg-config
extra-deps:
- fourmolu-0.14.0.0
- cryptonite-0.30
- libsecp256k1-0.2.0
# for fourmolu CI
- fourmolu-0.14.0.0
- ghc-lib-parser-9.6.2.20230523
packages:
- ./bitcoin
- ./bitcoin-test
Expand Down
Loading

0 comments on commit 64a0760

Please sign in to comment.