Skip to content

Commit 24eddcb

Browse files
committed
removes aeson and mtl
1 parent e08d308 commit 24eddcb

File tree

17 files changed

+95
-617
lines changed

17 files changed

+95
-617
lines changed

bitcoin.cabal

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ library
9393
src
9494
build-depends:
9595
QuickCheck >=2.13.2
96-
, aeson >=1.4.6.0
9796
, array >=0.5.4.0
9897
, base >=4.9 && <5
9998
, base16 >=0.3.0.1
@@ -108,7 +107,6 @@ library
108107
, hashable >=1.3.0.0
109108
, hspec >=2.7.1
110109
, memory >=0.15.0
111-
, mtl >=2.2.2
112110
, murmur3 >=1.0.3
113111
, network >=3.1.1.1
114112
, safe >=0.3.18
@@ -147,7 +145,6 @@ test-suite spec
147145
build-depends:
148146
HUnit >=1.6.0.0
149147
, QuickCheck >=2.13.2
150-
, aeson >=1.4.6.0
151148
, array >=0.5.4.0
152149
, base >=4.9 && <5
153150
, base16 >=0.3.0.1
@@ -166,7 +163,6 @@ test-suite spec
166163
, lens >=4.18.1
167164
, lens-aeson >=1.1
168165
, memory >=0.15.0
169-
, mtl >=2.2.2
170166
, murmur3 >=1.0.3
171167
, network >=3.1.1.1
172168
, safe >=0.3.18

package.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extra-source-files:
1919
- README.md
2020
- CHANGELOG.md
2121
dependencies:
22-
- aeson >= 1.4.6.0
2322
- array >= 0.5.4.0
2423
- base >=4.9 && <5
2524
- base16 >= 0.3.0.1
@@ -34,7 +33,6 @@ dependencies:
3433
- hashable >= 1.3.0.0
3534
- hspec >= 2.7.1
3635
- memory >= 0.15.0
37-
- mtl >= 2.2.2
3836
- murmur3 >= 1.0.3
3937
- network >= 3.1.1.1
4038
- QuickCheck >= 2.13.2

src/Bitcoin/Address.hs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ module Bitcoin.Address (
2222
textToAddr,
2323
bech32ToAddr,
2424
base58ToAddr,
25-
addrToJSON,
26-
addrToEncoding,
27-
addrFromJSON,
2825
pubKeyAddr,
2926
pubKeyWitnessAddr,
3027
pubKeyCompatWitnessAddr,
@@ -46,13 +43,17 @@ module Bitcoin.Address (
4643
module Bitcoin.Address.Bech32,
4744
) where
4845

46+
import Bitcoin.Address.Base58
47+
import Bitcoin.Address.Bech32
48+
import Bitcoin.Crypto
49+
import Bitcoin.Data
50+
import Bitcoin.Keys.Common
51+
import Bitcoin.Script
52+
import Bitcoin.Util
4953
import Control.Applicative
5054
import Control.Arrow (second)
5155
import Control.DeepSeq
5256
import Control.Monad
53-
import Data.Aeson as A
54-
import Data.Aeson.Encoding as A
55-
import Data.Aeson.Types
5657
import Data.Binary (Binary (..))
5758
import Data.ByteString (ByteString)
5859
import qualified Data.ByteString as B
@@ -66,13 +67,6 @@ import Data.Text (Text)
6667
import qualified Data.Text as T
6768
import Data.Word (Word8)
6869
import GHC.Generics (Generic)
69-
import Bitcoin.Address.Base58
70-
import Bitcoin.Address.Bech32
71-
import Bitcoin.Crypto
72-
import Bitcoin.Data
73-
import Bitcoin.Keys.Common
74-
import Bitcoin.Script
75-
import Bitcoin.Util
7670

7771

7872
-- | Address format for Bitcoin
@@ -181,24 +175,6 @@ isWitnessAddress WitnessAddress{} = True
181175
isWitnessAddress _ = False
182176

183177

184-
addrToJSON :: Network -> Address -> Value
185-
addrToJSON net a = toJSON (addrToText net a)
186-
187-
188-
addrToEncoding :: Network -> Address -> Encoding
189-
addrToEncoding net = maybe null_ text . addrToText net
190-
191-
192-
-- | JSON parsing for Bitcoin addresses. Works with 'Base58', and
193-
-- 'Bech32'.
194-
addrFromJSON :: Network -> Value -> Parser Address
195-
addrFromJSON net =
196-
withText "address" $ \t ->
197-
case textToAddr net t of
198-
Nothing -> fail "could not decode address"
199-
Just x -> return x
200-
201-
202178
-- | Convert address to human-readable string. Uses 'Base58', or 'Bech32'
203179
-- depending on network.
204180
addrToText :: Network -> Address -> Maybe Text

src/Bitcoin/Block/Common.hs

Lines changed: 4 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,12 @@ module Bitcoin.Block.Common (
2626
encodeCompact,
2727
) where
2828

29+
import Bitcoin.Crypto.Hash
30+
import Bitcoin.Network.Common
31+
import Bitcoin.Transaction.Common
32+
import Bitcoin.Util
2933
import Control.DeepSeq
3034
import Control.Monad (forM_, liftM2, mzero, replicateM, (<=<))
31-
import Data.Aeson (
32-
FromJSON (..),
33-
ToJSON (..),
34-
Value (..),
35-
object,
36-
toJSON,
37-
withObject,
38-
withText,
39-
(.:),
40-
(.=),
41-
)
42-
import Data.Aeson.Encoding (pairs, unsafeToEncoding)
4335
import Data.Binary (Binary (..))
4436
import Data.Bits (shiftL, shiftR, (.&.), (.|.))
4537
import qualified Data.ByteString as B
@@ -66,10 +58,6 @@ import Data.String.Conversions (cs)
6658
import Data.Text (Text)
6759
import Data.Word (Word32)
6860
import GHC.Generics (Generic)
69-
import Bitcoin.Crypto.Hash
70-
import Bitcoin.Network.Common
71-
import Bitcoin.Transaction.Common
72-
import Bitcoin.Util
7361
import qualified Text.Read as R
7462

7563

@@ -111,17 +99,6 @@ instance Binary Block where
11199
put = serialize
112100

113101

114-
instance ToJSON Block where
115-
toJSON (Block h t) = object ["header" .= h, "transactions" .= t]
116-
toEncoding (Block h t) = pairs $ "header" .= h <> "transactions" .= t
117-
118-
119-
instance FromJSON Block where
120-
parseJSON =
121-
withObject "Block" $ \o ->
122-
Block <$> o .: "header" <*> o .: "transactions"
123-
124-
125102
-- | Block header hash. To be serialized reversed for display purposes.
126103
newtype BlockHash = BlockHash
127104
{ getBlockHash :: Hash256
@@ -155,21 +132,6 @@ instance IsString BlockHash where
155132
in fromMaybe e $ hexToBlockHash $ cs s
156133

157134

158-
instance FromJSON BlockHash where
159-
parseJSON =
160-
withText "BlockHash" $
161-
maybe mzero return . hexToBlockHash
162-
163-
164-
instance ToJSON BlockHash where
165-
toJSON = String . blockHashToHex
166-
toEncoding h =
167-
unsafeToEncoding $
168-
char7 '"'
169-
<> hexBuilder (BL.reverse (runPutL (serialize h)))
170-
<> char7 '"'
171-
172-
173135
-- | Block hashes are reversed with respect to the in-memory byte order in a
174136
-- block hash when displayed.
175137
blockHashToHex :: BlockHash -> Text
@@ -212,43 +174,6 @@ data BlockHeader = BlockHeader
212174
deriving (Eq, Ord, Show, Read, Generic, Hashable, NFData)
213175

214176

215-
-- 80 bytes
216-
217-
instance ToJSON BlockHeader where
218-
toJSON (BlockHeader v p m t b n) =
219-
object
220-
[ "version" .= v
221-
, "prevblock" .= p
222-
, "merkleroot" .= encodeHex (runPutS (serialize m))
223-
, "timestamp" .= t
224-
, "bits" .= b
225-
, "nonce" .= n
226-
]
227-
toEncoding (BlockHeader v p m t b n) =
228-
pairs
229-
( "version" .= v
230-
<> "prevblock" .= p
231-
<> "merkleroot" .= encodeHex (runPutS (serialize m))
232-
<> "timestamp" .= t
233-
<> "bits" .= b
234-
<> "nonce" .= n
235-
)
236-
237-
238-
instance FromJSON BlockHeader where
239-
parseJSON =
240-
withObject "BlockHeader" $ \o ->
241-
BlockHeader
242-
<$> o .: "version"
243-
<*> o .: "prevblock"
244-
<*> (f =<< o .: "merkleroot")
245-
<*> o .: "timestamp"
246-
<*> o .: "bits"
247-
<*> o .: "nonce"
248-
where
249-
f = maybe mzero return . (eitherToMaybe . runGetS deserialize <=< decodeHex)
250-
251-
252177
instance Serial BlockHeader where
253178
deserialize = do
254179
v <- getWord32le

src/Bitcoin/Block/Headers.hs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,18 @@ module Bitcoin.Block.Headers (
6060
lastSmallerOrEqual,
6161
) where
6262

63+
import Bitcoin.Block.Common
64+
import Bitcoin.Crypto
65+
import Bitcoin.Data
66+
import Bitcoin.Transaction.Genesis
67+
import Bitcoin.Util
6368
import Control.Applicative ((<|>))
6469
import Control.DeepSeq
6570
import Control.Monad (guard, mzero, unless, when)
66-
import Control.Monad.Except (
67-
ExceptT (..),
68-
runExceptT,
69-
throwError,
70-
)
71-
import Control.Monad.State.Strict as State (
72-
StateT,
73-
get,
74-
gets,
75-
lift,
76-
modify,
77-
)
71+
import Control.Monad.Trans.Class (lift)
72+
import Control.Monad.Trans.Except (ExceptT (..), runExceptT, throwE)
7873
import Control.Monad.Trans.Maybe
74+
import Control.Monad.Trans.State.Strict as State (StateT, get, gets, modify)
7975
import Data.Binary (Binary (..))
8076
import Data.Bits (shiftL, shiftR, (.&.))
8177
import qualified Data.ByteString as B
@@ -97,11 +93,6 @@ import Data.Serialize (Serialize (..))
9793
import Data.Typeable (Typeable)
9894
import Data.Word (Word32, Word64)
9995
import GHC.Generics (Generic)
100-
import Bitcoin.Block.Common
101-
import Bitcoin.Crypto
102-
import Bitcoin.Data
103-
import Bitcoin.Transaction.Genesis
104-
import Bitcoin.Util
10596

10697

10798
-- | Short version of the block hash. Uses the good end of the hash (the part
@@ -323,7 +314,7 @@ connectBlocks _ _ [] = return $ Right []
323314
connectBlocks net t bhs@(bh : _) =
324315
runExceptT $ do
325316
unless (chained bhs) $
326-
throwError "Blocks to connect do not form a chain"
317+
throwE "Blocks to connect do not form a chain"
327318
par <-
328319
maybeToExceptT
329320
"Could not get parent block"
@@ -347,13 +338,13 @@ connectBlocks net t bhs@(bh : _) =
347338
case skM of
348339
Just sk -> return sk
349340
Nothing ->
350-
throwError $
341+
throwE $
351342
"BUG: Could not get skip for block "
352343
++ show (headerHash $ nodeHeader par)
353344
| otherwise = do
354345
let sn = ls !! fromIntegral (nodeHeight par - sh)
355346
when (nodeHeight sn /= sh) $
356-
throwError "BUG: Node height not right in skip"
347+
throwE "BUG: Node height not right in skip"
357348
return sn
358349
where
359350
sh = skipHeight (nodeHeight par + 1)
@@ -394,7 +385,7 @@ connectBlock net t bh =
394385
case skM of
395386
Just sk -> return sk
396387
Nothing ->
397-
throwError $
388+
throwE $
398389
"BUG: Could not get skip for block "
399390
++ show (headerHash $ nodeHeader par)
400391
bb <- lift getBestBlockHeader

src/Bitcoin/Keys/Common.hs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,13 @@ module Bitcoin.Keys.Common (
3131
toWif,
3232
) where
3333

34+
import Bitcoin.Address.Base58
35+
import Bitcoin.Crypto.Hash
36+
import Bitcoin.Data
37+
import Bitcoin.Util
3438
import Control.DeepSeq
3539
import Control.Monad (guard, mzero, (<=<))
3640
import Crypto.Secp256k1
37-
import Data.Aeson (
38-
FromJSON,
39-
ToJSON (..),
40-
Value (String),
41-
parseJSON,
42-
withText,
43-
)
44-
import Data.Aeson.Encoding (unsafeToEncoding)
4541
import Data.Binary (Binary (..))
4642
import Data.ByteString (ByteString)
4743
import qualified Data.ByteString as BS
@@ -55,10 +51,6 @@ import Data.Serialize (Serialize (..))
5551
import Data.String (IsString, fromString)
5652
import Data.String.Conversions (cs)
5753
import GHC.Generics (Generic)
58-
import Bitcoin.Address.Base58
59-
import Bitcoin.Crypto.Hash
60-
import Bitcoin.Data
61-
import Bitcoin.Util
6254

6355

6456
-- | Elliptic curve public key type with expected serialized compression flag.
@@ -76,21 +68,6 @@ instance IsString PubKeyI where
7668
e = error "Could not decode public key"
7769

7870

79-
instance ToJSON PubKeyI where
80-
toJSON = String . encodeHex . runPutS . serialize
81-
toEncoding s =
82-
unsafeToEncoding $
83-
char7 '"'
84-
<> hexBuilder (runPutL (serialize s))
85-
<> char7 '"'
86-
87-
88-
instance FromJSON PubKeyI where
89-
parseJSON =
90-
withText "PubKeyI" $
91-
maybe mzero return . ((eitherToMaybe . runGetS deserialize) <=< decodeHex)
92-
93-
9471
instance Serial PubKeyI where
9572
deserialize =
9673
s >>= \case

0 commit comments

Comments
 (0)