Skip to content

Commit

Permalink
Now modeling transaction hash as Integer
Browse files Browse the repository at this point in the history
  • Loading branch information
solatis committed Apr 12, 2015
1 parent e7f1c2a commit 8e5e75d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/Bitcoin/Transaction/Types.hs
Expand Up @@ -11,6 +11,7 @@ import Data.Word ( Word32

import qualified Data.ByteString as BS

import Data.Bits (shiftL, shiftR)
import Data.Binary (Binary, get, put)

import Data.Binary.Get ( getByteString
Expand Down Expand Up @@ -65,22 +66,23 @@ data TxnOutputType = TxnPubKey -- ^ JSON of "pubkey" received.
deriving ( Show, Read, Ord, Eq )


data TransactionHash = TransactionHash [Word64]
data TransactionHash = TransactionHash Integer
deriving ( Show, Read, Eq )

instance Binary TransactionHash where
get = do
a <- getWord64be
b <- getWord64be
c <- getWord64be
d <- getWord64be
return $ TransactionHash [a, b, c, d]

put (TransactionHash [a, b, c, d]) = do
putWord64be a
putWord64be b
putWord64be c
putWord64be d
a <- fromIntegral <$> getWord64be
b <- fromIntegral <$> getWord64be
c <- fromIntegral <$> getWord64be
d <- fromIntegral <$> getWord64be

return $ TransactionHash ((a `shiftL` 192) + (b `shiftL` 128) + (c `shiftL` 64) + d)

put (TransactionHash i) = do
putWord64be $ fromIntegral (i `shiftR` 192)
putWord64be $ fromIntegral (i `shiftR` 128)
putWord64be $ fromIntegral (i `shiftR` 64)
putWord64be $ fromIntegral i

-- | A script signature.
data ScriptSig = ScriptSig {
Expand Down

0 comments on commit 8e5e75d

Please sign in to comment.