bitcoin-types (empty) → 0.9.0
raw patch · 8 files changed
+188/−0 lines, 8 filesdep +basedep +base58stringdep +binarysetup-changed
Dependencies added: base, base58string, binary, bitcoin-types, bytestring, hexstring, hspec, text
Files
- LICENSE +22/−0
- README.md +11/−0
- Setup.hs +3/−0
- bitcoin-types.cabal +59/−0
- src/Data/Bitcoin/Types.hs +78/−0
- test/Data/Bitcoin/TypesSpec.hs +6/−0
- test/Main.hs +8/−0
- test/Spec.hs +1/−0
+ LICENSE view
@@ -0,0 +1,22 @@+The MIT License (MIT) + +Copyright (c) 2015 Leon Mergen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +
+ README.md view
@@ -0,0 +1,11 @@+haskell-bitcoin-tx +================== + +[](https://travis-ci.org/solatis/haskell-bitcoin-tx) +[](https://coveralls.io/r/solatis/haskell-bitcoin-tx?branch=master) +[](http://en.wikipedia.org/wiki/MIT_License) +[](http://haskell.org) + +This library provides the same functionality as the bitcoin-tx command line +utility, which was introduced in Bitcoin Core v0.10. These functions are +pure and require no communication with a bitcoin daemon.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple + +main = defaultMain
+ bitcoin-types.cabal view
@@ -0,0 +1,59 @@+name: bitcoin-types +category: Network, Finance +version: 0.9.0 +license: MIT +license-file: LICENSE +copyright: (c) 2015 Leon Mergen +author: Leon Mergen +maintainer: leon@solatis.com +homepage: http://www.leonmergen.com/opensource.html +bug-reports: http://github.com/solatis/haskell-bitcoin-types/issues +stability: experimental +synopsis: Provides consistent low-level types used commonly among Bitcoin implementations +description: + Instead of having each Bitcoin library re-define the low level types it is using, + this library provides a ready-to-use collection of low-level types and aliases. + +build-type: Simple +data-files: LICENSE, README.md +cabal-version: >= 1.10 +tested-with: GHC == 7.6, GHC == 7.8, GHC == 7.10 + +library + hs-source-dirs: src + ghc-options: -Wall -ferror-spans + default-language: Haskell2010 + + exposed-modules: Data.Bitcoin.Types + + build-depends: base >= 4.3 && < 5 + , bytestring + , text + , binary + , hexstring + , base58string + +test-suite test-suite + type: exitcode-stdio-1.0 + ghc-options: -Wall -ferror-spans -threaded -auto-all -caf-all -fno-warn-type-defaults + default-language: Haskell2010 + hs-source-dirs: test + main-is: Main.hs + + other-modules: Data.Bitcoin.TypesSpec + Spec + Main + + build-depends: base >= 4.3 && < 5 + , hspec + + , bytestring + , base58string + , hexstring + + , bitcoin-types + +source-repository head + type: git + location: git://github.com/solatis/haskell-bitcoin-types.git + branch: master
+ src/Data/Bitcoin/Types.hs view
@@ -0,0 +1,78 @@+module Data.Bitcoin.Types ( TransactionId + , PrivateKey + , Address + , Account + , Btc + , VarInt (..) ) where + +import Control.Applicative ((<$>)) +import Data.Word ( Word64 ) + +import Data.Binary ( Binary, get, put ) +import Data.Binary.Get ( getWord8 + , getWord16le + , getWord32le + , getWord64le ) + +import Data.Binary.Put ( putWord8 + , putWord16le + , putWord32le + , putWord64le ) + +import Data.Fixed +import qualified Data.HexString as HS +import qualified Data.Base58String as B58S +import qualified Data.Text as T + +-- | Per Bitcoin documentation, An identifier used to uniquely identify a +-- particular transaction; specifically, the sha256d hash of the transaction. +type TransactionId = HS.HexString + +-- | A base58 private key to sign transactions +type PrivateKey = B58S.Base58String + +-- | Per Bitcoin documentation, an identifier used to uniquely identify a +-- particular address. +type Address = B58S.Base58String + +-- | A wallet account can be any easy to remember string. +type Account = T.Text + +-- | The smallest unit of payment possible in Bitcoin is a Satoshi +data Satoshi = Satoshi + +-- | We describe BTC in terms of Satoshi, where one BTC equals 10^8 Satoshis. +instance HasResolution Satoshi where + resolution _ = 10 ^ ( 8 :: Integer ) + +-- | A single Bitcoin, which represents 10^8 Satoshis. +type Btc = Fixed Satoshi + + + +-- | Data type representing a variable length integer. The 'VarInt' type +-- usually precedes an array or a string that can vary in length. +newtype VarInt = VarInt { getVarInt :: Word64 } + deriving (Eq, Show, Read) + +instance Binary VarInt where + + get = VarInt <$> ( getWord8 >>= go ) + where + go 0xff = getWord64le + go 0xfe = fromIntegral <$> getWord32le + go 0xfd = fromIntegral <$> getWord16le + go x = fromIntegral <$> return x + + put (VarInt x) + | x < 0xfd = + putWord8 $ fromIntegral x + | x <= 0xffff = do + putWord8 0xfd + putWord16le $ fromIntegral x + | x <= 0xffffffff = do + putWord8 0xfe + putWord32le $ fromIntegral x + | otherwise = do + putWord8 0xff + putWord64le x
+ test/Data/Bitcoin/TypesSpec.hs view
@@ -0,0 +1,6 @@+module Data.Bitcoin.TypesSpec where + +import Test.Hspec + +spec :: Spec +spec = return ()
+ test/Main.hs view
@@ -0,0 +1,8 @@+module Main where + +import Test.Hspec.Runner +import qualified Spec + +main :: IO () +main = + hspecWith defaultConfig Spec.spec
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-}