haskoin-core-0.9.0: Bitcoin & Bitcoin Cash library for Haskell

CopyrightNo rights reserved
Safe HaskellNone




This module defines various utility functions used across the library.


ByteString Helpers

bsToInteger :: ByteString -> Integer Source #

Decode a big endian Integer from a ByteString.

integerToBS :: Integer -> ByteString Source #

Encode an Integer to a ByteString as big endian.

encodeHex :: ByteString -> Text Source #

Encode as string of human-readable hex characters.

decodeHex :: Text -> Maybe ByteString Source #

Decode string of human-readable hex characters.

getBits :: Int -> ByteString -> ByteString Source #

Obtain Int bits from beginning of ByteString. Resulting ByteString will be smallest required to hold that many bits, padded with zeroes to the right.

Maybe & Either Helpers

eitherToMaybe :: Either a b -> Maybe b Source #

Transform an Either value into a Maybe value. Right is mapped to Just and Left is mapped to Nothing. The value inside Left is lost.

maybeToEither :: b -> Maybe a -> Either b a Source #

Transform a Maybe value into an Either value. Just is mapped to Right and Nothing is mapped to Left. Default Left required.

liftEither :: MonadError e m => Either e a -> m a #

Lifts an Either e into any MonadError e.

do { val <- liftEither =<< action1; action2 }

where action1 returns an Either to represent errors.

Since: mtl-2.2.2

liftMaybe :: Monad m => b -> Maybe a -> ExceptT b m a Source #

Lift a Maybe computation into the ExceptT monad.

Other Helpers

updateIndex Source #


:: Int

index of the element to change

-> [a]

list of elements

-> (a -> a)

function to apply

-> [a]

result with one element changed

Applies a function to only one element of a list defined by its index. If the index is out of the bounds of the list, the original list is returned.

matchTemplate Source #


:: [a]

input list

-> [b]

list to serve as a template

-> (a -> b -> Bool)

comparison function

-> [Maybe a] 

Use the list [b] as a template and try to match the elements of [a] against it. For each element of [b] return the (first) matching element of [a], or Nothing. Output list has same size as [b] and contains results in same order. Elements of [a] can only appear once.

convertBits :: Bool -> Int -> Int -> [Word] -> ([Word], Bool) Source #

Convert from one power-of-two base to another, as long as it fits in a Word.


fst3 :: (a, b, c) -> a Source #

Returns the first value of a triple.

snd3 :: (a, b, c) -> b Source #

Returns the second value of a triple.

lst3 :: (a, b, c) -> c Source #

Returns the last value of a triple.

JSON Utilities

dropFieldLabel :: Int -> Options Source #

Field label goes lowercase and first n characters get removed.

dropSumLabels :: Int -> Int -> String -> Options Source #

Transformation from dropFieldLabel is applied with argument f, plus constructor tags are lowercased and first c characters removed. tag is used as the name of the object field name that will hold the transformed constructor tag as its value.